For this program, you are going to modify your previous program (program 3) so t
ID: 3537923 • Letter: F
Question
For this program, you are going to modify your previous program (program 3) so that it will now have a menu to see if the user wants to read the input from a file or interactively. If the user wants to read the input from a file, then the output will also go into a different file. If the user wants to read the input interactively, then the output will go to the screen. Your initial menu will look like the following: Menu <1> Read data from a file <2> Read data interactively Enter choice: Here is a sample input file: 21 25 30 30 10 12 55 60 -1 /* this is the flag to end inputting the assignment data */ 21 25 30 30 10 12 21 25 30 30 Here is another sample input file: 21 25 30 30 10 12 55 60 -1 /* this is the flag to end inputting the assignment data */ 21 25 -1 /* this is the flag to end inputting the midterm exam data */ 21 25 30 30 #include #include #include #include #include double Homework ( double homework); // fuction for homework weight double Midterm ( double midterm); // function for midterm weight double Final ( double final); // function for final test weight //function to calculate final grade char CalcGrade (double homework, double midterm, double final, double totalScore, char grade); //function to print int Print( double homework, double midterm, double final, double totalScore, char grade); int main() { //local delcarations double homework; double midterm; double final; double totalScore; char grade; //informs the user what this program does printf("This program will calculate the final grade after homework "); printf("midterm, and final test grades are inputed in. "); system("cls"); //clears screen //function calls //update values at each step homework = Homework(homework); midterm = Midterm(midterm); final = Final(final); grade = CalcGrade ( homework, midterm, final,totalScore, grade); Print(homework, midterm, final, totalScore, grade); system("pause"); //holds screen for dev C++ return 0; } //end of main double Homework (double homework) { system("cls"); //function delcarations int x ; int i ; double sum; double homeworkMaxPts ; homework = 0; //prompts users for input, and how to terminate printf("Enter the homework assignment grades: Enter < 999 > to stop. "); do //loop to collect input for homework grades { scanf("%d", &x); if ( x <900) //termination of loop sum += x; // calculated total amount of points }while ( x < 900); //prompts user to input maxmum score for each assignment printf("Enter the max points for each assignemnt: "); printf("Enter < 999 > to stop "); //loop to collect imput for maximun points possible for homework do { scanf("%d", &i); if ( i < 900) //loop termination homeworkMaxPts += i; // calculates total amount of points }while ( i < 900); //calculates the total weight of homework homework = (sum*50/homeworkMaxPts); system("pause"); return homework; // returns weighted homeword } //end of homework // Function to determine weight of midterm tests double Midterm ( double midterm) { system("cls"); // clear screen //declarations int a=0; int i=1; double sum; int x =1; double midMaxPts = 0; int b=0; midterm = 0; // prompts user to input midterm grades printf("Enter the midterm grades: "); //loop to calculate total midterm points while(i<=3) { scanf("%d", &a); sum +=a; i++; }//end of while //prompts user to imput maximun amount of points possible printf(" Enter the max points for midterm grades: "); //loop to calculate total possible points while ( x <=3) { scanf("%d", &b); midMaxPts += b; x++; }//end of while system("cls"); //clear screen midterm = (sum*20/midMaxPts); //calculate midterm weights system("pause"); return midterm; //return midterm } //end of midterm //Final test function double Final ( double final) { system("cls"); //clear screen //declarations int final1, final2; int finalSum = 0; int points1, points2; double finalMaxpts = 0; final = 0; //prompts user to input the two final grades printf("Enter the final grades: " ); scanf("%d %d", &final1, &final2); //prompts user to input the maximum points for finals printf("Enter the max points possible for each grade: "); scanf("%d %d", &points1, &points2); finalSum = final1 + final2; //calculates total points made finalMaxpts = points1 + points2; //calculates total points possible final = (finalSum*30/finalMaxpts); //calculates weight of final system("cls"); system("pause"); return final; // returns final weight } //end final function // grade calculation function char CalcGrade (double homework, double midterm, double final, double totalScore, char grade) { //calculate final overall grade totalScore = homework + midterm + final; //to calculate the letter grade if (totalScore >= 90) grade = 'A'; else if ( totalScore >= 80) grade = 'B'; else if ( totalScore >= 70) grade = 'C'; else if ( totalScore >= 60) grade = 'D'; else grade = 'F'; system("pause"); return grade; //return grade } // print function int Print( double homework, double midterm, double final, double totalScore, char grade) { totalScore = homework + midterm + final; // prints out all grades printf(" Final exam score was %2.2f ", final); printf("Midterm exam score was %2.2f ", midterm); printf("Homework assignments score were %2.2f ", final); printf("------------------------------------------ "); printf("Total score is %2.2f ", totalScore); printf("Grade for the class is %c ", grade); system("pause"); return 0; }Explanation / Answer
int x;
double sum;
do //loop to collect input for homework grades
{
scanf("%d", &x);
if ( x <900) //termination of loop
sum += x; // calculated total amount of points
}while ( x < 900);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.