

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>
#include <vector>


using namespace std;

// definice typu MatLine (linka, radek matice), potom
// vektor MatLine je kompletni matice
typedef vector<unsigned short int> MatLine;
typedef vector<MatLine> Mat;

// druha moznost definice matice, podle me vice
// neprehledna je vektor vektoru (nebude pouzit v prikladu)
//typedef vector< vector<unsigned short int> > Mat;

bool CreateLine(MatLine& rml);
bool AddLineToMat(Mat& rmat, const MatLine& rml);
void ShowMat(Mat& rmat);

bool CreateLine(MatLine& rml)
{
  // Metoda zajisti uzivatelem do konzole definici dvou cisel,
  // program vypocita soucet a soucin techto cisel. Tyto ctyri
  // cisla (dve zadana, soucet, soucin) vlozi do MatLine& rml
  // a hotovo. Pokud definovana cisla jsou dve 0, vrati false.
  // Metoda vrati false i pri jakekoliv chybe (ukonci se aplikace).

  // nutno vymazat minule vlozene hodnoty
  rml.clear();

  // pomocne promenne
  int iV1, iV2, iVPlus, iVKrat;

  // prostor pro definici dvou celych kladnych cisel k operaci soucin a soucet
  printf("\nZadejte dve cela kladna cisla oddelena carkou  : ");
  scanf("%i,%i", &iV1, &iV2);

  // pokud jsou zadane cisla 0ly (obe), vracim false
  if(iV1==0 && iV2==0)
    return false;

  // neresim preteceni kladneho dvoubyte!!!
  
  // soucet a soucin definovanych cisel
  iVPlus=iV1+iV2;
  iVKrat=iV1*iV2;
  
  // kontrolni vypis
  printf("%i, %i", iVPlus, iVKrat);
  
  // hodnoty pridam do MatLine, do vektoru unsigned short intu
  rml.push_back((unsigned short int)iV1);
  rml.push_back((unsigned short int)iV2);
  rml.push_back((unsigned short int)iVPlus);
  rml.push_back((unsigned short int)iVKrat);

  return true;
}

bool AddLineToMat(Mat& rmat, const MatLine& rml)
{
  // zadana cisla a vypocty (MatLine& rml) vlozi do 
  // matice (Mat& rmat). Vrati false pri chybe.

  rmat.push_back(rml);

  return true;
}

void ShowMat(Mat& rmat)
{
  // Zobrazi prvky matice

  // pocet radku v matici
  int ni, iCnt=rmat.size();

  printf("\nZobrazeni matice : \n");

  // v cyklu zobrazim jednotlive radky matice, kontroluji
  // pocet parametru v radku
  for(ni=0; ni<iCnt; ni++)
  {
    MatLine& rmline=rmat[ni];
    if(rmline.size()==4)
    {
      printf("%4i %4i %4i %4i\n", rmline[0], rmline[1], rmline[2], rmline[3]);
    }
  }
}

int main(int argc, char *argv[])
{
  MatLine mline;
  Mat mat;
  bool fAdded;

  do
  {
    // definice cisel k operacim souctu a soucinu,
    // konstrukce linky
    fAdded=CreateLine(mline);

    // pripadne vlozit radek do matice
    if(fAdded)
    {
      AddLineToMat(mat, mline);
    }
  }while(fAdded);

  // zobrazeni matice
  ShowMat(mat);

  return EXIT_SUCCESS;
}
