Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int Avg(int SumR, int PeopleS)
- {
- int AvgR = SumR / PeopleS;
- return AvgR;
- }
- int Diff(int A1, int A2)
- {
- int DiffR = A1 - A2;
- return DiffR;
- }
- int main()
- {
- cout << "\t Object 1" << endl;
- //OBJ 1:
- string Name; int Point1, Point2; string Team;
- int redPoints1 = 0, bluePoints1 = 0, yellowPoints1 = 0;
- int redPoints2 = 0, bluePoints2 = 0, yellowPoints2 = 0;
- fstream myFile;
- myFile.open("Text.txt");
- //red avg
- cout << "RED: " << endl;
- int person = 0;
- for (int count = 9; count > 0; count--)
- {
- myFile >> Name >> Point1 >> Point2 >> Team;
- if (Team == "Red")
- {
- person++;
- cout << setw(10) << Name << " " << Point1 << " " << Point2 << endl;
- redPoints1 += Point1;
- redPoints2 += Point2;
- }
- }
- int AvgReactScoreRed = Avg(redPoints1, person);
- int AvgRespondScoreRed = Avg(redPoints2, person);
- cout << setw(10) << "Avg." << " " << AvgReactScoreRed << " " << AvgRespondScoreRed << endl;
- person = 0;
- myFile.close();
- myFile.open("Text.txt");
- //blue avg
- cout << "BLUE: " << endl;
- for (int count = 9; count > 0; count--)
- {
- myFile >> Name >> Point1 >> Point2 >> Team;
- if (Team == "Blue")
- {
- person++;
- cout << setw(10) << Name << " " << Point1 << " " << Point2 << endl;
- bluePoints1 += Point1;
- bluePoints2 += Point2;
- }
- }
- int AvgRespondScoreBlue = Avg(bluePoints2, person);
- int AvgReactScoreBlue = Avg(bluePoints1, person);
- person = 0;
- cout << setw(10) << "Avg." << " " << AvgReactScoreBlue << " " << AvgRespondScoreBlue << endl;
- myFile.close();
- myFile.open("Text.txt");
- //yellow avg
- cout << "YELLOW: " << endl;
- for (int count = 9; count > 0; count--)
- {
- myFile >> Name >> Point1 >> Point2 >> Team;
- if (Team == "Yellow")
- {
- person++;
- cout << setw(10) << Name << " " << Point1 << " " << Point2 << endl;
- yellowPoints1 += Point1;
- yellowPoints2 += Point2;
- }
- }
- int AvgReactScoreYellow = Avg(yellowPoints1, person);
- int AvgRespondScoreYellow = Avg(yellowPoints2, person);
- cout << setw(10) << "Avg." << " " << AvgReactScoreYellow << " " << AvgRespondScoreYellow << endl;
- person = 0;
- myFile.close();
- cout << "\n\t Object 2 \n" << endl;
- // Objective 2:
- fstream readFile2;
- int Point1_1, Point2_1;
- string Name2, Team2;
- cout << setw(10) << " " << "Scenario 1" << setw(15) << "Scenario 2" << setw(15) << "Differences" << endl;
- myFile.open("Text.txt");
- for (int loop1 = 9; loop1 > 0; loop1--)
- {
- myFile >> Name >> Point1 >> Point2 >> Team;
- for (int loop2 = 9; loop2 > 0; loop2--)
- {
- readFile2.open("Text1.txt");
- readFile2 >> Name2 >> Point1_1 >> Point2_1 >> Team2;
- if (Name2 == Name)
- {
- int Diff1 = Diff(Point1, Point1_1), Diff2 = Diff(Point2, Point2_1);
- cout << Name2 << " " << Point1 << " " << Point2 << " " << Point1_1 << " " << Point2_1 << " " << Diff1 << " " << Diff2 << endl;
- break;
- }
- }
- }
- system(("Pause"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement