Advertisement
CamolaZ

Cliente.cpp

May 20th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include "Cliente.h"
  2. #include <vector>
  3. #include "utils.h"
  4. #include "Data.h"
  5.  
  6. Cliente::Cliente(ifstream & in){ // le uma cliente na forma de  idcliente ; nome ; data ; montante
  7.     string data_aux, cli_aux;
  8.     float montante;
  9.     string nome;
  10.  
  11.     //idcliente
  12.     in >> id; in.ignore();
  13.    
  14.     //nome
  15.     getline(in, nome, ';');
  16.     trimSpaces(cli_aux);
  17.      //in.ignore();
  18.  
  19.     //data
  20.     getline(in, cli_aux, ';');
  21.    
  22.     data_aux.erase(data_aux.begin());
  23.     data_aux.erase(data_aux.end() - 1);               //apaga 1 e último espaço
  24.     Data data(data_aux);
  25.  
  26.     //montante
  27.  
  28.     in >> montante; in.ignore();
  29.  
  30.    
  31. }
  32.  
  33.  
  34. string Cliente::getNome() const{
  35.   return nome;
  36. }
  37. void Cliente::setId(string idRead) {
  38.     id = stoi(idRead);
  39. }
  40.  
  41. void Cliente::setNome(string nameRead)
  42. {
  43.     nome = nameRead;
  44. }
  45.  
  46. void Cliente::setVolCompras(string amountRead)
  47. {
  48.     volCompras = stof(amountRead);
  49. }
  50. unsigned int Cliente::getId() const{
  51.     return id;
  52. }
  53.  
  54.  
  55. float Cliente::getVolCompras() const{
  56.   return volCompras;
  57. }
  58.  
  59. void Cliente::save(ofstream & out) const{
  60.  
  61.   //duvida como modifico o valor que aparece e que indica o numero de clientes a serem lido, não necessario
  62.     out << id << ' ; ';
  63.     out << nome << ' ; ';
  64.     cartaoCliente.save(out);
  65.     out << ' ; ';
  66.     out << volCompras;
  67.  
  68. }
  69.  
  70.  ostream& operator<<(ostream& out, const Cliente & cli){
  71.      out << cli.getId() << ' ; ' << cli.getNome() << ' ; ';
  72.      cartaoCliente.save(out);
  73.     return out;
  74. }
  75.  
  76.  
  77. bool operator<(const Cliente &cli1, const Cliente &cli2){
  78.   // A IMPLEMENTAR
  79.     return true;
  80. }
  81.  
  82.  
  83. //////////////////////
  84. // Leitura ficheiro //
  85. //////////////////////
  86.  
  87. vector<Cliente> le_fichClientes(string fichClientes){
  88.     ifstream f_clientes;
  89.     vector<Cliente> v_clientes;
  90.     int num_clientes;
  91.  
  92.     f_clientes.open(fichClientes);
  93.  
  94.     f_clientes >> num_clientes; f_clientes.ignore();
  95.  
  96.     while (num_clientes)
  97.     {
  98.         Cliente cli(f_clientes);
  99.         v_clientes.push_back(cli);
  100.         num_clientes--;
  101.     }
  102.     f_clientes.close();
  103.  
  104.     return v_clientes;
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement