how do call these functions into main and if possible in c++ style : int loadRes
ID: 3667702 • Letter: H
Question
how do call these functions into main and if possible in c++ style :
int loadResults(ifstream & file, string teamNames[], int problem1[], int problem2[], int problem3[], int problem4[], int problem5[]) { int i=0,count=0; file = fopen("sampleScores.txt", "r"); if(!file) { printf("Could not open file. Exiting application. Bye"); return 1; while(!feof(file)) { fscanf(file,"%[^ ]s",line); //Get text string teamNames[i]=line[i]; if(i>1) //Here we are checking for all the values in the lines and trying to separate them in the problem1[i]=line[i]; //Different array to continue with the processing. else if(i>2) problem2[i]=line[i]; else if(i>3) problem3[i]=line[i]; else if(i>4) problem4[i]=line[i]; else problem5[i]=line[i]; i++; // Incrementing the value of i to continue to process the subsequent character in the line. } } } // Here the results from the text file have been loaded into their respective arrays. double calculateAverage(int teamCount, const int problemTimes[]) { // Here the teamcount is taken as 5 according to the text file passed while calling the function. int i,sum1=0,sum2=0,sum3=0,sum4=0,sum5=0,j=0; for(i=0;i
Explanation / Answer
There are two methods,
This method takes 6 integer array and one ifstram object;
int loadResults(ifstream &file, string teamNames[], int problem1[],
int problem2[], int problem3[], int problem4[], int problem5[]) {
}
double calculateAverage(int teamCount, const int problemTimes[]) {
}
int main(){
//initialize these arrays with your data
int teamNames[20];
int problem1[20];
int problem2[20];
int problem3[20];
int problem4[20];
int problem5[20];
// open a file in read mode.
ifstream infile;
infile.open("afile.dat");
//calling first method
int result = loadResults(infile,teamNames,problem1,problem2,problem3,problem4,problem5);
int problemTimes[20];
int teamCount = 20;
//calling second method
double avg = calculateAverage(teamCount,problemTimes);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.