Create a structure type called Student. A variable of type Student should contai
ID: 652967 • Letter: C
Question
Create a structure type called Student. A variable of type Student should contain fields for the following:
last name
first name
course
test 1 grade
test 2 grade
final exam grade
test average -- (use type double)
The other fields match the data described in the input file format section. Use C-strings for the last name and first name.
sample input file
Your program should start by asking the user to type the names of the input and output files (in that order). Whenever a bad filename is entered, print an error message and prompt the user to re-enter the filename.
Open the input file and read the records into an array of Student structures. You'll need to create this array dynamically, because you won't know how many records there are until you start reading the file itself. The data from each record in the file should be stored in one Student structure (i.e. one array slot per student record)
For each student, compute the test average and store it in the test average member variable for that student struct. The test average should be computed according to the following weights for the tests:
Print a grade summary report to the output file, as specified below in the "Output File Format" section
Close the files and clean up any dynamically allocated space before ending the program
Output File Format
The summary report is to be sorted by course, with English first, then History, then Math. Each course's section in the summary should have a header, with the student detail records printed below
The summary output of a student record should consist of:
The student's name, in the format firstName lastName -- with no extra punctuation between the names.
Test Average, printed to 2 decimal places
Letter Grade of the test average, based on standard 10-point scale (i.e. 90-100 = A, 80-89.99 = B, etc.)
After each course section, print the test average for the class. (This means there will be three class averages -- one for English, one for History, one for Math)
See sample output file below to see the formatting
Here is one sample program run, on the sample input file linked previously. Note that this is just one example. You can (and should) create your own test cases to test this program more fully. The keyboard/screen interaction is shown first (keyboard input is underlined), then the sample input file and output file contents are shown.
Output File Contents (after the program run)
Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,i=0;
struct student
{
String lname;
String name;
String course;
int test1;
int test2;
int fexam;
double test_avg;
}
struct student s[3];
ifstream inf;
fin.open("std.txt");
clrscr();
for(i=0;i<3;i++)
{
inf>>s[i].lname;
inf>>s[i].name;
inf>>s[i].test1;
inf>>s[i].test2;
inf>>s[i].fexam;
inf>>s[i].test_avg;
}
inf.close();
ofstream outf;
outf.open("std1.txt");
for(i=0;i<3;i++)
{
outf<<s[i].lname;
outf<<s[i].name;
outf<<s[i].test1;
outf<<s[i].test2;
outf<<s[i].fexam;
outf<<s[i].test_avg;
}
outf.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.