Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <istream>
- #include <cstdlib>
- #include <sstream>
- #include <time.h>
- using namespace std;
- class Player
- {
- public:
- //metody
- Player(string name, string sname, string height, string age, string handling);
- Player(const Player &source);
- void review();
- void modify();
- //pola
- string retName() { return this->name; }
- string retSname() { return this->sname; }
- string retAge() { return this->age; }
- string retHeight() { return this->height; }
- string retHandling() { return this->handling; }
- private:
- string name, sname;
- string height;
- string age;
- string handling;
- };
- void Player::modify()
- {
- this->name = "Sent to";
- this->sname = "Gulag (TM)";
- this->age = "nA";
- this->handling = "nA";
- this->height = "nA";
- }
- void Player::review()
- {
- cout.width(15); cout << this->name;
- cout.width(20); cout << this->sname;
- cout.width(10); cout << this->height;
- cout.width(9); cout << this->age;
- cout.width(10); cout << this->handling;
- cout << "\n";
- }
- Player::Player(const Player &source)
- {
- this->name = source.name;
- this->sname = source.sname;
- this->height = source.height;
- this->age = source.age;
- this->handling = source.handling;
- }
- Player::Player(string name, string sname, string _height, string age, string handling)
- {
- this->name = name;
- this->sname = sname;
- this->height = _height;
- this->age = age;
- this->handling = handling;
- }
- class Team
- {
- public:
- vector<Player> players;
- int add(Player p1, Player p2, Player p3, Player p4, Player p5)
- {
- players.push_back(p1);
- players.push_back(p2);
- players.push_back(p3);
- players.push_back(p4);
- players.push_back(p5);
- return 0;
- }
- void addOne(Player P)
- {
- players.push_back(P);
- }
- Team() { ; }
- Team(const Team &source);
- void Treview();
- void modPlayer(int who);
- int readFromFile();
- void saveToFile(string teamname);
- };
- void Team::modPlayer(int who)
- {
- players[who].modify();
- }
- Team::Team(const Team &source)
- {
- this->players = source.players;
- }
- void Team::Treview()
- {
- cout.width(15); cout << "Name: ";
- cout.width(20); cout << "Surname: ";
- cout.width(9); cout << "Height: ";
- cout.width(9); cout << "Age: ";
- cout.width(15); cout << "Handling: ";
- cout << endl;
- for (int i = 0; i != players.size(); i++)
- {
- players[i].review();
- }
- cout << "\n";
- }
- void Team::saveToFile(string teamname)
- {
- time_t t = time(0);
- struct tm now;
- localtime_s(&now, &t);
- string currenttime;
- //cout << now.tm_hour << now.tm_min << now.tm_sec << endl;
- currenttime = now.tm_hour + now.tm_min + now.tm_sec;
- cout << currenttime;
- string filename = "";
- filename = filename + "druzyna " + teamname + " " + currenttime + ".txt";
- ofstream outputFile;
- outputFile.open(filename.c_str(), ios::app);
- if (outputFile.good() == false)
- {
- cout << "Could not save this file!" << endl;
- }
- else
- {
- string line;
- int i = 0;
- while (i<players.size())
- {
- line.clear();
- line = players[i].retName() + ';' + players[i].retSname() + ';' + players[i].retHeight() + ';' + players[i].retAge() + ';' + players[i].retHandling();
- outputFile << line << endl;
- ++i;
- }
- }
- outputFile.close();
- }
- /*void Team::saveToFile()
- {
- string filetitle;
- stringstream ss;
- }*/
- int Team::readFromFile() //dziala git
- {
- fstream inputFile;
- inputFile.open("indata.txt", ios_base::in);
- if (inputFile.good() == false)
- {
- cout << "Could not open this file!" << endl;
- return 0;
- }
- else
- {
- string lineAsString;
- while (!inputFile.eof())
- {
- getline(inputFile, lineAsString);
- int length = lineAsString.length();
- int i = 0;
- int j = 0;
- int columnID = 0;
- string a, b, c, d, e;
- do
- {
- while (i < length)
- {
- if (lineAsString[i] != ';' && columnID == 0) a = a + lineAsString[i];
- if (lineAsString[i] != ';' && columnID == 1) b = b + lineAsString[i];
- if (lineAsString[i] != ';' && columnID == 2) c = c + lineAsString[i];
- if (lineAsString[i] != ';' && columnID == 3) d = d + lineAsString[i];
- if (lineAsString[i] != ';' && columnID == 4) e = e + lineAsString[i];
- if (lineAsString[i] == ';') columnID++;
- i++;
- }
- if (e.length() != 0)
- {
- Player P(a, b, c, d, e);
- this->addOne(P);
- }
- columnID = 0;
- a.clear(); b.clear(); c.clear(); d.clear(); e.clear();
- j++;
- } while (j < 5);
- }
- }
- inputFile.close();
- }
- int main()
- {
- Player p1("Jaroslaw", "Psikuta", "180", "30", "90");
- Player p2("Stachu", "Jones", "182", "70", "9001");
- Player p3("Nie", "Mam", "18", "3", "9");
- Player p4("Juz", "Pomyslow", "184", "29", "70");
- Player p5("Na", "Zawodnikow", "166", "66", "66");
- Player p6("Lew", "Trocki", "150", "63", "117");
- Player p7("Iwan", "Grozny", "199", "24", "191");
- Player p8("Adolf", "Hitler", "175", "45", "200");
- Player p9("Wladimir", "Putin", "180", "68", "195");
- Player p10("Josif", "Stalin", "160", "74", "123");
- Team T1;
- T1.add(p1, p2, p3, p4, p5);
- Team T2;
- T2.add(p6, p7, p8, p9, p10);
- Team T3(T2);
- Team T4;
- T4.readFromFile();
- /*cout << "T1:" << endl;
- T1.Treview();
- cout << "T2:" << endl;
- T2.Treview();
- cout << "T3 -(kopia T2)- :" << endl;
- T3.Treview();
- */
- T4.modPlayer(2); //modyfikacja (od 0 do 4) zawodnika drużyny od 1 do 4
- cout << "Po modyfikacji: " << endl;
- cout << "T1:" << endl;
- T1.Treview();
- cout << "T2:" << endl;
- T2.Treview();
- cout << "T3 -(kopia T2)- :" << endl;
- T3.Treview();
- cout << "T4 -(z pliku)- :" << endl;
- T4.Treview();
- //zapisywanie drużyn
- //WORK IN PROGRESS
- T1.saveToFile("T1");
- T2.saveToFile("T2");
- T3.saveToFile("T3");
- T4.saveToFile("T4");
- cout << endl << "Koniec" << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement