Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int Avg(int SumR, int PeopleS)
  8. {
  9.     int AvgR = SumR / PeopleS;
  10.     return AvgR;
  11. }
  12. int Diff(int A1, int A2)
  13. {
  14.     int DiffR = A1 - A2;
  15.     return DiffR;
  16. }
  17.  
  18. int main()
  19. {
  20.     cout << "\t Object 1" << endl;
  21.     //OBJ 1:
  22.  
  23.     string Name; int Point1, Point2; string Team;
  24.     int redPoints1 = 0, bluePoints1 = 0, yellowPoints1 = 0;
  25.     int redPoints2 = 0, bluePoints2 = 0, yellowPoints2 = 0;
  26.     fstream myFile;
  27.     myFile.open("Text.txt");
  28.  
  29.     //red avg
  30.     cout << "RED: " << endl;
  31.     int person = 0;
  32.     for (int count = 9; count > 0; count--)
  33.     {
  34.  
  35.         myFile >> Name >> Point1 >> Point2 >> Team;
  36.  
  37.         if (Team == "Red")
  38.         {
  39.             person++;
  40.             cout << setw(10) << Name << " " << Point1 << " " << Point2 << endl;
  41.             redPoints1 += Point1;
  42.             redPoints2 += Point2;
  43.         }
  44.     }
  45.  
  46.     int AvgReactScoreRed = Avg(redPoints1, person);
  47.     int AvgRespondScoreRed = Avg(redPoints2, person);
  48.     cout << setw(10) << "Avg." << " " << AvgReactScoreRed << " " << AvgRespondScoreRed << endl;
  49.     person = 0;
  50.     myFile.close();
  51.     myFile.open("Text.txt");
  52.  
  53.     //blue avg
  54.     cout << "BLUE: " << endl;
  55.     for (int count = 9; count > 0; count--)
  56.     {
  57.         myFile >> Name >> Point1 >> Point2 >> Team;
  58.  
  59.         if (Team == "Blue")
  60.         {
  61.             person++;
  62.             cout << setw(10) << Name << " " << Point1 << " " << Point2 << endl;
  63.             bluePoints1 += Point1;
  64.             bluePoints2 += Point2;
  65.         }
  66.     }
  67.  
  68.     int AvgRespondScoreBlue = Avg(bluePoints2, person);
  69.     int AvgReactScoreBlue = Avg(bluePoints1, person);
  70.     person = 0;
  71.     cout << setw(10) << "Avg." << " " << AvgReactScoreBlue << " " << AvgRespondScoreBlue << endl;
  72.     myFile.close();
  73.     myFile.open("Text.txt");
  74.  
  75.     //yellow avg
  76.     cout << "YELLOW: " << endl;
  77.     for (int count = 9; count > 0; count--)
  78.     {
  79.         myFile >> Name >> Point1 >> Point2 >> Team;
  80.  
  81.         if (Team == "Yellow")
  82.         {
  83.             person++;
  84.             cout << setw(10) << Name << " " << Point1 << " " << Point2 << endl;
  85.             yellowPoints1 += Point1;
  86.             yellowPoints2 += Point2;
  87.         }
  88.     }
  89.  
  90.     int AvgReactScoreYellow = Avg(yellowPoints1, person);
  91.     int AvgRespondScoreYellow = Avg(yellowPoints2, person);
  92.     cout << setw(10) << "Avg." << " " << AvgReactScoreYellow << " " << AvgRespondScoreYellow << endl;
  93.     person = 0;
  94.     myFile.close();
  95.  
  96.     cout << "\n\t Object 2 \n" << endl;
  97.  
  98.    
  99.     // Objective 2:
  100.  
  101.  
  102.     fstream readFile2;
  103.     int Point1_1, Point2_1;
  104.     string Name2, Team2;
  105.     cout << setw(10) << "  " << "Scenario 1" << setw(15) << "Scenario 2" << setw(15) << "Differences" << endl;
  106.     myFile.open("Text.txt");
  107.  
  108.     for (int loop1 = 9; loop1 > 0; loop1--)
  109.     {
  110.         myFile >> Name >> Point1 >> Point2 >> Team;
  111.        
  112.         for (int loop2 = 9; loop2 > 0; loop2--)
  113.         {
  114.             readFile2.open("Text1.txt");
  115.             readFile2 >> Name2 >> Point1_1 >> Point2_1 >> Team2;
  116.             if (Name2 == Name)
  117.             {
  118.                 int Diff1 = Diff(Point1, Point1_1), Diff2 = Diff(Point2, Point2_1);
  119.                 cout  << Name2 << " " << Point1 << " " << Point2 << " " << Point1_1 << " " << Point2_1 << " " << Diff1 << " " << Diff2 << endl;
  120.                 break;
  121.             }
  122.  
  123.         }
  124.  
  125.     }
  126.  
  127.     system(("Pause"));
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement