By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,370 Members | 1,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,370 IT Pros & Developers. It's quick & easy.

help writing this program!

P: 36
i have this program that i am almost done with, i am one part away from being done.

the last part is putting the results together;
here is the results that i need to put in code. do u have any ideas on how to write code to this using functions.please any thing will help

CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L % WINS MARGIN
1 KSU 3-1 .750 +10.50 8-1 .889 +13.56
1 CAP 3-1 .750 +11.75 7-2 .778 +13.67
1 ONU 3-1 .750 +15.25 7-2 .778 +17.78
1 OTT 3-1 .750 +14.00 5-4 .556 +7.56
1 WILM 3-1 .750 +7.25 7-2 .778 +10.00
6 MUC 2-2 .500 -6.25 4-4 .500 -0.50
7 MUSK 1-2 .333 -12.00 5-3 .625 +2.63
8 HEID 1-3 .250 -4.00 3-4 .429 +1.57
9 JCU 0-3 .000 -13.00 2-5 .286 -3.00
9 MAR 0-4 .000 -29.75 2-7 .222 -10.89



here is the code for what i have for my program so far.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5. #include <string>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. struct basketballStat
  11. {
  12.     string schoolName;
  13.     int numberWins;
  14.     int numberLosses;
  15.     int numberPointsTheTeamScored;
  16.     int numberPointsTheTeamScoredAgainst;
  17.     int teamOverallWins;
  18.     int teamOverallLosses;
  19.     int numberPointsTheTeamScoredInAll;
  20.     int numberPointsTheTeamScoredInAllAgainst;
  21. };
  22.  
  23. struct basketballStatUpdate
  24. {
  25.     string date;
  26.     string nameOfHomeTeam;
  27.     int homeTeamsPointTotal;
  28.     string nameOfVisitTeam;
  29.     int VisitingTeamsPointTotal;
  30. };
  31.  
  32. void FormerStats (ifstream&, basketballStat&);
  33. void Updates (ifstream&, basketballStatUpdate&);
  34. void DoUpdate(basketballStat[], basketballStatUpdate&);
  35. void UpdatedStats(ostream&, basketballStat[]);
  36.  
  37.  
  38.  
  39. int main ()
  40. {
  41.     basketballStat formerStats[10];
  42.  
  43.     ifstream inFile1;
  44.     inFile1.open ("G:\\formerstats.txt");
  45.     ifstream inFile2;
  46.     inFile2.open("G:\\updates.txt");
  47.     ofstream outFile1;
  48.     outFile1.open ("G:\\updatedStats.txt");
  49.     ofstream outFile2;
  50.     outFile2.open ("G:\\standings.txt");
  51.  
  52.     for (int k=0; k<10; k++)
  53.     {
  54.         FormerStats (inFile1, formerStats[k]);
  55.     }
  56.  
  57.     while (!inFile2.eof())
  58.     {
  59.         basketballStatUpdate update;
  60.         Updates (inFile2, update);
  61.         DoUpdate(formerStats, update);
  62.     }
  63.  
  64.     inFile1.close();
  65.     inFile2.close();
  66.  
  67.     UpdatedStats(outFile1, formerStats);
  68.  
  69.     outFile2<<setw(30)<<"CONFERENCE"<<setw(10)<<"OVERALL"<<endl;
  70.     outFile2<<"RANK"<<setw(6)<<"TEAM"<<setw(7)<<"W-L"<<setw(9)<<"% WINS"<<setw(11)<<"MARGIN"<<setw(8)<<"W-L"<<setw(9)<<"% WINS"<<setw(11)<< "MARGIN"<<endl;
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.     return 0;
  79. }
  80.  
  81. void FormerStats (ifstream &inFile1, basketballStat &myStat)  //this void function reads in the data from formerstats
  82. //within the basketballStat struct.
  83. {
  84.  
  85.     inFile1 >> myStat.schoolName;
  86.     inFile1 >> myStat.numberWins;
  87.     inFile1 >> myStat.numberLosses;
  88.     inFile1 >> myStat.numberPointsTheTeamScored;
  89.     inFile1 >>myStat.numberPointsTheTeamScoredAgainst;
  90.     inFile1 >> myStat.teamOverallWins;
  91.     inFile1 >> myStat.teamOverallLosses;
  92.     inFile1 >> myStat.numberPointsTheTeamScoredInAll;
  93.     inFile1 >> myStat.numberPointsTheTeamScoredInAllAgainst;
  94. }
  95.  
  96. void Updates (ifstream& inFile2, basketballStatUpdate &update) //this void function reads in the data from updates.txt and
  97. //struct called basketballStat update is being used to read in the data.
  98. {
  99.  
  100.     inFile2 >> update.date;
  101.     inFile2 >> update.nameOfHomeTeam;
  102.     inFile2 >> update.homeTeamsPointTotal;
  103.     inFile2 >> update.nameOfVisitTeam;
  104.     inFile2 >> update.VisitingTeamsPointTotal;
  105. }
  106.  
  107. void DoUpdate(basketballStat myStat[], basketballStatUpdate &update) // this function updates the stats of the conference games
  108. // and calculates each data for each game and updates it into a recent and update form of the stats in the conference games. 
  109. {
  110.     bool homeOfTheConfTeam = false, visitConfTeam = false;
  111.     int homeTeamIndex, visitTeamIndex;
  112.     for (int j=0; j<10; j++)
  113.     {
  114.         if (myStat[j].schoolName==update.nameOfHomeTeam) 
  115.         {
  116.             homeOfTheConfTeam = true;
  117.             homeTeamIndex = j;
  118.         } else if (myStat[j].schoolName==update.nameOfVisitTeam) 
  119.         {
  120.             visitConfTeam = true;
  121.             visitTeamIndex = j;
  122.         }
  123.         if (homeOfTheConfTeam&&visitConfTeam) break;
  124.     }
  125.  
  126.     bool homeWin = (update.homeTeamsPointTotal > update.VisitingTeamsPointTotal);
  127.  
  128.     if (homeOfTheConfTeam) 
  129.     {
  130.         myStat[homeTeamIndex].numberPointsTheTeamScoredInAll += update.homeTeamsPointTotal;
  131.         myStat[homeTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.VisitingTeamsPointTotal;
  132.         if (homeWin)
  133.             myStat[homeTeamIndex].teamOverallWins++;
  134.         else
  135.             myStat[homeTeamIndex].teamOverallLosses++;
  136.     }
  137.     if (visitConfTeam) 
  138.     {
  139.         myStat[visitTeamIndex].numberPointsTheTeamScoredInAll += update.VisitingTeamsPointTotal;
  140.         myStat[visitTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.homeTeamsPointTotal;
  141.         if (!homeWin)
  142.             myStat[visitTeamIndex].teamOverallWins++;
  143.         else
  144.             myStat[visitTeamIndex].teamOverallLosses++;
  145.     }
  146.     if (homeOfTheConfTeam&&visitConfTeam) 
  147.     {
  148.         myStat[homeTeamIndex].numberPointsTheTeamScored += update.homeTeamsPointTotal;
  149.         myStat[homeTeamIndex].numberPointsTheTeamScoredAgainst += update.VisitingTeamsPointTotal;
  150.         myStat[visitTeamIndex].numberPointsTheTeamScored += update.VisitingTeamsPointTotal;
  151.         myStat[visitTeamIndex].numberPointsTheTeamScoredAgainst += update.homeTeamsPointTotal;
  152.         if (homeWin) 
  153.         {
  154.             myStat[homeTeamIndex].numberWins++;
  155.             myStat[visitTeamIndex].numberLosses++;
  156.         } else
  157.         {
  158.             myStat[visitTeamIndex].numberWins++;
  159.             myStat[homeTeamIndex].numberLosses++;
  160.         }
  161.     }
  162. }
  163.  
  164. void UpdatedStats(ostream &outFile1, basketballStat myStats[])// this  function stores the calculations from the upbove function
  165. // and uses a set of arrays to write the updated stats data in the outfile1.
  166. {
  167.     for (int m=0; m<10; m++) 
  168.     {
  169.         outFile1 << myStats[m].schoolName << " ";
  170.         outFile1 << myStats[m].numberWins << " ";
  171.         outFile1 << myStats[m].numberLosses << " ";
  172.         outFile1 << myStats[m].numberPointsTheTeamScored << " ";
  173.         outFile1 << myStats[m].numberPointsTheTeamScoredAgainst << " ";
  174.         outFile1 << myStats[m].teamOverallWins << " ";
  175.         outFile1 << myStats[m].teamOverallLosses << " ";
  176.         outFile1 << myStats[m].numberPointsTheTeamScoredInAll << " ";
  177.         outFile1 << myStats[m].numberPointsTheTeamScoredInAllAgainst << " " << endl;
  178.     }
  179.  
  180. }
  181.  
Dec 7 '08 #1
Share this Question
Share on Google+
4 Replies


100+
P: 687
Aren't they already put together?
Dec 7 '08 #2

P: 36
no its not put together, that data from the chart has to be displayed into another outfile. using functions and thats what im having trouble with.
i need help with the code
Dec 7 '08 #3

sicarie
Expert Mod 2.5K+
P: 4,677
charmeda103-

Please do not double-post your questions. I have deleted your other thread on this question.

If you have any more information, post it in this thread only.

Thanks,

sicarie
Dec 8 '08 #4

100+
P: 687
@charmeda103
Not that I'm going to write the code for you, but I still can't get what your program is expected to do. Do you? I see some data ( input? expected output? ) and some code that I definitely am not going to compile and feed with provided data.
Dec 8 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.