Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Modify this lab and create a CLASS that has all the functionality. i.e., USE YOUR USER-DEFINED FUNCTIONS as the FUNCTION MEMBERS OF YOUR CLASS.

C++

Modify this lab and create a CLASS that has all the functionality.

i.e., USE YOUR USER-DEFINED FUNCTIONS as the FUNCTION MEMBERS OF YOUR CLASS.

WRITE A PROGRAM THAT USES ALL THE FUNCTIONALITY of THE CLASS and OUTPUTS the RESULTS, and provide

  1. Source File
  2. Text File
  3. Output

#include #include #include #include

using namespace std;

struct SG { float arraySG[10]; string name; char LG; }; class Grade { public: SG Data[10]; int i, j, total,count; Grade() { i=0; j=0; total = 0; count=0; readFromFile(); //call this function to see the modification in output screen modificationsHighestLowest(); } void readFromFile() { char line[20]; //considering max size of any line in file is 20 character. change if required. FILE *fileRead = fopen("scores.txt", "r"); //r means opening file in read mode if(fileRead == NULL) //NULL means either file does not exists or there is no permission to open file { cout<<"Error while opening file."; exit(1); // exit program } while(fgets(line, sizeof(line), fileRead) != NULL) //End of file returns NULL. When NULL found, it will stop. { Data[count].name=line; //count will keep a track of total no of student details in file for(j=0;j<10;j++) //read grades of each student. we have given 10 grades for each student { fgets(line, sizeof(line), fileRead); //read next line Data[count].arraySG[j] = atoi(line); //atoi is to convert a string to int } count++; } //calculate grade for(i=0; i { total = 0; for(j=0; j<10; j++) { total = total + Data[i].arraySG[j]; } if(total < 10) Data[i].LG = 'F'; else //changed the grade to A if total score is more than equal to 10 as asked in comments Data[i].LG = 'A'; //please give a char if total grade >= 10, I have given P. Please change it }

//show details on screen for(i=0; i { cout< for(j=0; j<10; j++) { cout< } cout< } fclose(fileRead); //Close file pointer once task is finished }

/*--------------MADE CHANGES HERE-----------------------*/

//modification to print highest and lowest grade along with test number is coded in this function void modificationsHighestLowest(){ //loops over the number of students denoted by count for(int i=0;i //variables to store the maximum Score, minimum Score and sum of all Scores int maxScore = 0,minScore = 9999, sumScore = 0; //variables to store the position of test,i.e, test number int maxIndex, minIndex; //iterate over all the test scores for(int j=0;j<10;j++){ //check for highest test score if(maxScore //store highest score maxScore = Data[i].arraySG[j]; //store index of highest score maxIndex = j; } //check for lowest score if(minScore>Data[i].arraySG[j]){ //store lowest score minScore = Data[i].arraySG[j]; //store index of lowest score minIndex = j; } //add the score to sum of all scores sumScore = sumScore + Data[i].arraySG[j]; } //calculate and store the average of all scores double avgScore = sumScore/10.0; //p[rint student name cout<<" For "< //print student highest and lowest score along with the test number //test number is index value+1, as indexing is from 0 cout<<"Student's Highest Grade was "< cout<<"Average of all grades = "< } } };

int main() { Grade grade; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What are no-fault grounds for dissolution?

Answered: 1 week ago

Question

3. Evaluate a Web-based training site.

Answered: 1 week ago