Using Data I/O write a C++ program that allows users to enter the following info
ID: 655310 • Letter: U
Question
Using Data I/O write a C++ program that allows users to enter the following information from the keyboard for each student in a class (up to 20 students) and stores the data in a text file named grade.dat:
Name Exam1 Grade Exam2 Grade Homework Grade Final Exam Grade
For each student, your program should first calculate a final grade, using this formula:
Final Grade = 0.20 x Exam 1 + 0.20 x Exam 2 + 0.35 x Homework + 0.25 x Final Exam
Then assign a letter grade on the basis of 90-100 = A, 80-89 = B, 70-79 = C, 60-69 = D, and less than 60 = F. All the information, including the final grade and the letter grade, should then be displayed and written to a file.
(This is not a Graded assignment, It's PRACTICE
Explanation / Answer
#include<fstream.h>
#include<iomanip.h>
#include<stdlib.h>
int main()
{
const int MX_STUD = 20;
const int MX_NAM = 10
const int MX_CHAR = 10;
char first_name [MX_CHAR] = "grad.dat";
int x;
char last_name [MX_NAM],letter_grade;
float ex1,ex2,hwork,annualexm,annualgrade;
ofstream outFunction;
char quit;
int count;
outFile.open(first_nam);
if (outFunction.fail())
{
cout <<"not success opening"<<firstname<<end1;
exit(1);
}
outFunction <<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2);
count = 0;
quit = 'a';
while((count < 10)&&(quit == 'a')
{
cout<<"enter the student last name");
cin >> last name;
cout<<"enter exam 1's grade";
cin >> exam1;
cout<<"enter exam 2's grade";
cin >> exam2;
cout<<"enter student homework grade";
cin >> finalexam;
finalgrade = 0.20 * exam1 + 0.20 * 0.35 * homework + 0.25 finalexam;
if(finalgrade >=90) lettergrade ='A';
if(finalgrade >=80) lettergrade ='B';
else if(finalgrade >- 60) lettergrade ='D';
else finalgrade = 'F';
cout <<lastname <<""<<exam1<<""exam2<<""homework<<""<<finalexam<<""<<finalgrade<<""<<lettergrade<<end1;
outFile<<lastname<<""<<exam1<<""<<exam2<<""homework<<""<<finalexam<<""<<lettergrade<<end1;
cout<<"Continue?(yes or no):";
cin>>quit;
cout<<end1;
++count;
}
outFile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.