help writing this program!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charmeda103
    New Member
    • Oct 2008
    • 36

    #1

    help writing this program!

    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.pleas e 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.

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <string>
    #include <fstream>
    
    using namespace std;
     
    struct basketballStat
    {
    	string schoolName;
    	int numberWins;
    	int numberLosses;
    	int numberPointsTheTeamScored;
    	int numberPointsTheTeamScoredAgainst;
    	int teamOverallWins;
    	int teamOverallLosses;
    	int numberPointsTheTeamScoredInAll;
    	int numberPointsTheTeamScoredInAllAgainst;
    };
    
    struct basketballStatUpdate
    {
    	string date;
    	string nameOfHomeTeam;
    	int homeTeamsPointTotal;
    	string nameOfVisitTeam;
    	int VisitingTeamsPointTotal;
    };
    
    void FormerStats (ifstream&, basketballStat&);
    void Updates (ifstream&, basketballStatUpdate&);
    void DoUpdate(basketballStat[], basketballStatUpdate&);
    void UpdatedStats(ostream&, basketballStat[]);
    
    
    
    int main ()
    {
    	basketballStat formerStats[10];
    
    	ifstream inFile1;
    	inFile1.open ("G:\\formerstats.txt");
    	ifstream inFile2;
    	inFile2.open("G:\\updates.txt");
    	ofstream outFile1;
    	outFile1.open ("G:\\updatedStats.txt");
    	ofstream outFile2;
    	outFile2.open ("G:\\standings.txt");
    
    	for (int k=0; k<10; k++)
    	{
    		FormerStats (inFile1, formerStats[k]);
    	}
    	
    	while (!inFile2.eof())
    	{
    		basketballStatUpdate update;
    		Updates (inFile2, update);
    		DoUpdate(formerStats, update);
    	}
    	
    	inFile1.close();
    	inFile2.close();
    
    	UpdatedStats(outFile1, formerStats);
    
    	outFile2<<setw(30)<<"CONFERENCE"<<setw(10)<<"OVERALL"<<endl;
    	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;
    	
    	 
    
    
    	
    
    
    	return 0;
    }
    
    void FormerStats (ifstream &inFile1, basketballStat &myStat)  //this void function reads in the data from formerstats
    //within the basketballStat struct.
    {
    	
    	inFile1 >> myStat.schoolName;
    	inFile1 >> myStat.numberWins;
    	inFile1 >> myStat.numberLosses;
    	inFile1 >> myStat.numberPointsTheTeamScored;
    	inFile1 >>myStat.numberPointsTheTeamScoredAgainst;
    	inFile1 >> myStat.teamOverallWins;
    	inFile1 >> myStat.teamOverallLosses;
    	inFile1 >> myStat.numberPointsTheTeamScoredInAll;
    	inFile1 >> myStat.numberPointsTheTeamScoredInAllAgainst;
    }
    
    void Updates (ifstream& inFile2, basketballStatUpdate &update) //this void function reads in the data from updates.txt and
    //struct called basketballStat update is being used to read in the data.
    {
    	
    	inFile2 >> update.date;
    	inFile2 >> update.nameOfHomeTeam;
    	inFile2 >> update.homeTeamsPointTotal;
    	inFile2 >> update.nameOfVisitTeam;
    	inFile2 >> update.VisitingTeamsPointTotal;
    }
    
    void DoUpdate(basketballStat myStat[], basketballStatUpdate &update) // this function updates the stats of the conference games
    // and calculates each data for each game and updates it into a recent and update form of the stats in the conference games. 
    {
    	bool homeOfTheConfTeam = false, visitConfTeam = false;
    	int homeTeamIndex, visitTeamIndex;
    	for (int j=0; j<10; j++)
    	{
    		if (myStat[j].schoolName==update.nameOfHomeTeam) 
    		{
    			homeOfTheConfTeam = true;
    			homeTeamIndex = j;
    		} else if (myStat[j].schoolName==update.nameOfVisitTeam) 
    		{
    			visitConfTeam = true;
    			visitTeamIndex = j;
    		}
    		if (homeOfTheConfTeam&&visitConfTeam) break;
    	}
    
    	bool homeWin = (update.homeTeamsPointTotal > update.VisitingTeamsPointTotal);
    
    	if (homeOfTheConfTeam) 
    	{
    		myStat[homeTeamIndex].numberPointsTheTeamScoredInAll += update.homeTeamsPointTotal;
    		myStat[homeTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.VisitingTeamsPointTotal;
    		if (homeWin)
    			myStat[homeTeamIndex].teamOverallWins++;
    		else
    			myStat[homeTeamIndex].teamOverallLosses++;
    	}
    	if (visitConfTeam) 
    	{
    		myStat[visitTeamIndex].numberPointsTheTeamScoredInAll += update.VisitingTeamsPointTotal;
    		myStat[visitTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.homeTeamsPointTotal;
    		if (!homeWin)
    			myStat[visitTeamIndex].teamOverallWins++;
    		else
    			myStat[visitTeamIndex].teamOverallLosses++;
    	}
    	if (homeOfTheConfTeam&&visitConfTeam) 
    	{
    		myStat[homeTeamIndex].numberPointsTheTeamScored += update.homeTeamsPointTotal;
    		myStat[homeTeamIndex].numberPointsTheTeamScoredAgainst += update.VisitingTeamsPointTotal;
    		myStat[visitTeamIndex].numberPointsTheTeamScored += update.VisitingTeamsPointTotal;
    		myStat[visitTeamIndex].numberPointsTheTeamScoredAgainst += update.homeTeamsPointTotal;
    		if (homeWin) 
    		{
    			myStat[homeTeamIndex].numberWins++;
    			myStat[visitTeamIndex].numberLosses++;
    		} else
    		{
    			myStat[visitTeamIndex].numberWins++;
    			myStat[homeTeamIndex].numberLosses++;
    		}
    	}
    }
    
    void UpdatedStats(ostream &outFile1, basketballStat myStats[])// this  function stores the calculations from the upbove function
    // and uses a set of arrays to write the updated stats data in the outfile1.
    {
    	for (int m=0; m<10; m++) 
    	{
    		outFile1 << myStats[m].schoolName << " ";
    		outFile1 << myStats[m].numberWins << " ";
    		outFile1 << myStats[m].numberLosses << " ";
    		outFile1 << myStats[m].numberPointsTheTeamScored << " ";
    		outFile1 << myStats[m].numberPointsTheTeamScoredAgainst << " ";
    		outFile1 << myStats[m].teamOverallWins << " ";
    		outFile1 << myStats[m].teamOverallLosses << " ";
    		outFile1 << myStats[m].numberPointsTheTeamScoredInAll << " ";
    		outFile1 << myStats[m].numberPointsTheTeamScoredInAllAgainst << " " << endl;
    	}
    
    }
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Aren't they already put together?

    Comment

    • charmeda103
      New Member
      • Oct 2008
      • 36

      #3
      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

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        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

        Comment

        • newb16
          Contributor
          • Jul 2008
          • 687

          #5
          Originally posted by charmeda103
          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
          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.

          Comment

          Working...