Advertisement
ivodevweb

Untitled

Dec 22nd, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. #include <string>
  5. #include <vector>
  6.  
  7. class Jogador {
  8.     public:
  9.         Jogador(int number
  10.                 , std::string name
  11.                 , std::string position) : m_number{number}
  12.                                         , m_name{name}
  13.                                         , m_position{position} {}
  14.         void Print() {
  15.             std::cout << m_number << "," << m_name << "," << m_position << std::endl;
  16.         }
  17.  
  18.         int getNumber() const;
  19.         std::string getName() const;
  20.         std::string getPostition() const;
  21.  
  22.     protected:
  23.         int m_number = -1;
  24.         int op{-1};
  25.         std::string m_name;
  26.         std::string m_position;
  27. };
  28.  
  29.  
  30.  
  31. int main(int argc, char **argv) {
  32.     int op = -1;
  33.  
  34.     while(true){    
  35.         std::cout << " (1)prencher vector - (2)Motrar dados do vector" << std::endl;
  36.         std::cin >> op;
  37.            if(op !=2){
  38.             std::ifstream in;
  39.             std::ofstream out;
  40.  
  41.             std::string line;
  42.  
  43.             std::vector<Jogador> jogadores;
  44.            
  45.  
  46.             out.open("output.txt", std::ios_base::app);
  47.             in.open("FutTeamA.txt");
  48.  
  49.             while(!in.eof()) {
  50.                 int number = -1;
  51.                 std::string name;
  52.                 std::string position;
  53.  
  54.                 in >> number >> name >> position;
  55.  
  56.                 out << number << " " << name << " " << position << std::endl;
  57.  
  58.                 jogadores.emplace_back(number, name, position);
  59.             }
  60.          
  61.        }
  62.         int number = -1;
  63.         std::string name;
  64.         std::string position;
  65.         std::cout << "Mostrando dados do vector.............." << std::endl;
  66.  
  67.              std::vector<Jogador> jogadores;
  68.              for (int i = 0; i < jogadores.size(); ++i) {
  69.             jogadores[i].Print();
  70.              }  
  71.  
  72.            
  73.     }
  74.  
  75.     return EXIT_SUCCESS;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement