Advertisement
CamolaZ

main

May 11th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. #include "Vende++.h"
  6. #include "Menus.h"
  7. #include "utils.h"
  8. // More
  9. #include "Cliente.h"
  10. #include "Produto.h"
  11. #include  "Transacao.h"
  12. #include "Data.h"
  13. #include "defs.h"
  14.  
  15. using namespace std;
  16.  
  17. vector<Cliente> readclientetxt();
  18. // files reading
  19. vector<Cliente> clientes = readclientetxt();
  20.  
  21. vector<Cliente> readclientetxt() //save the file clientes.txt in one vector of clientes (int ; string ; double)
  22. {
  23.     vector<Cliente> clienteslista;//vector that is returned in the end (which is going to have Clients.txt info)
  24.     ifstream fichClientes;//ifstream to store the text file, and then extract the information from it
  25.     fichClientes.open("clientes.txt");//store the text file in the ifstream
  26.     if (!fichClientes)//error message in case of non-existence of the file
  27.         cerr << "ERROR 404 - Clients file not found";
  28.  
  29.     while (!fichClientes.eof())//cicle to create the vector (ends in end of file)
  30.     {
  31.         Cliente clienteauxdata(fichClientes);//create the cliente which is going to store the info of one line
  32.         string clienteinfo; //string to store the line
  33.         int numCliRead; // number of clients to read
  34.         string numClientesR;
  35.         getline(fichClientes, numClientesR); // Define conditions if a user don't digit a number
  36.         numCliRead = stoi(numClientesR, nullptr, 10);
  37.         while (numCliRead)
  38.         {
  39.             getline(fichClientes, clienteinfo);//store the line in clientinfo, next time its called, reads the next line
  40.             string idRead;//string which stores id information
  41.             string nameRead;//string which stores name information
  42.             string amountRead; //string which stores amount information
  43.             int stringcounter = 0; //store string character place
  44.             for (int i = 0; clienteinfo[i] != char(32); i++)//cicle to read id , lê até encontrar o primeiro espaço char(20) é o espaço!
  45.             {
  46.                 idRead = idRead + clienteinfo[i];
  47.                 stringcounter = i;
  48.             }
  49.             for (int k = stringcounter + 3; clienteinfo[k] != ';'; k++)//cicle to read name
  50.             {
  51.                 nameRead = nameRead + clienteinfo[k];
  52.                 stringcounter = k;
  53.             }
  54.             nameRead = nameRead.substr(1, nameRead.size() - 2);
  55.             for (int j = stringcounter + 2; clienteinfo[j]; j++)//cicle to read amount
  56.             {
  57.                 amountRead = amountRead + clienteinfo[j];
  58.             }
  59.             clienteauxdata.setId(idRead);//convert string to int
  60.             clienteauxdata.setNome(nameRead);
  61.             clienteauxdata.setVolCompras(amountRead);//convert string to double
  62.             //create the client
  63.             clienteslista.push_back(clienteauxdata);//store client in vector next line
  64.  
  65.         }
  66.     }
  67.     return clienteslista;//return the vector
  68. }
  69. int main(){
  70.   string loja, fichClients, fichProdutos, fichTransacoes;
  71.  
  72.   // pede a informacoo sobre o nome da loja e os 3 ficheiros com
  73.   // informacoo de clientes, produtos e transacoes
  74.   if(! infoInicial(loja, fichClients, fichProdutos, fichTransacoes))
  75.     return(-1);
  76.  
  77.   // cria uma loja
  78.   VendeMaisMais supermercado(loja, fichClients, fichProdutos, fichTransacoes);
  79.  
  80.   cout << "Informacao da loja '" << loja << " do supermercado Vende++:" << endl;
  81.   cout << supermercado << endl;  // mostra estatisticas da loja
  82.  
  83.   opcoesIniciais(supermercado); // menu inicial com as grandes opcoes
  84.                 // que implementam as funcioanlidades
  85.                 // disonibilizadas
  86.  
  87.   return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement