Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can\'t figure out how to make this program compile. There are a couple errors...

ID: 654024 • Letter: C

Question

Can't figure out how to make this program compile. There are a couple errors... any help? It's in C++. The requirements for the assignment are written underneath my code... any help appreciated, thanks..

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cctype>
using namespace std;
struct studt
{
string ln;
string fn;
char crc;
int tg1,tg2,tg3;
double tavg;
};
int main()
{
ifstream ipf;
ofstream opf;
char op[20], ip[20];
int ch=0,n,i,rownum, z0;
double average=0.0, crc_avg=0.0;
while(ch!=1)
{
cout<<"please enter the name of the input file" <<endl;
cout<<"filename : ";
cin>>ip;
ipf.open(ip);
if (ipf.fail())
{
cout<<" the given file was incorrect";
cout<<" make sure file exist ";
cout<<endl;
}
else
ch=1;
}
studt *ptr;
ptr = new studt[n];
ipf >> new studt[n];
while(!ipf.eof())
{
for(rownum=0; rownum<n; rownum++)
{
ipf >> ptr[rownum].ln;
   ipf >> ptr[rownum].fn;
ipf >> ptr[rownum].crc;
ipf >> ptr[rownum].tg1;
ipf >> ptr[rownum].tg2;
ipf >> ptr[rownum].tg3;
   ipf >> ptr[rownum].tavg;
}
}
ipf.close();
ch=0;
while(ch!=1)
{
cout<<"please enter the name of the output file "<<endl;
cout<<"file name:";
cin>>op;
opf.open(op);
if(opf.fail())
{
cout<<" file" <<op<<"failed to open "<< endl;
}
else
ch=1;
}
opf<<"student grade summary"<<endl<<endl;
opf<<"English Class"<<endl;
opf << "student name" << " " <<"Test avg"<<endl;
for(i=0;i<100;i++)
opf<<"_";
opf<<endl;
double avg;
if(ptr[rownum].crc=='E')
{
opf<<ptr[rownum].fn<< ptr[rownum].ln << " ";
avg=(0.3 * ptr[rownum].tg1) +(0.3* ptr[rownum].tg2) +(0.4 * ptr[rownum].tg3);
crc_avg=crc_avg+avg;
z0++;
opf<<avg<<" ";
if(avg>=90)
opf<<"A";
else if(avg>=80)
opf<< "B ";
else if(avg>=70)
opf<<"C";
else if(avg>=60)
opf<<"D ";
else
opf<<"E";
opf<<endl;
}
//ENGLISH CLASS AVERAGE:
double z;
opf << endl;
opf <<" " <<"class average: " <<( crc_avg/z)<<endl;
crc_avg=0.0;
z=0;
for(i=0;i<100;i++)
opf<<"_";
opf << endl;
opf<<"HISTORY Class"<<endl;
opf << "student name"<<" " <<"Test avg"<<endl;
for(i=0;i<100;i++)
opf<<"_";
opf<<endl;
if(ptr[rownum].crc=='E')
{
opf<<ptr[rownum].fn<<ptr[rownum].ln<<" ";
avg=(0.3 * ptr[rownum].tg1) +(0.3* ptr[rownum].tg2) +(0.4 * ptr[rownum].tg3);
crc_avg=crc_avg+avg;
z++;
opf<<avg<<" ";
if(avg>=90)
opf<<"A";
else if(avg>=80)
opf<<"B ";
else if(avg>=70)
opf<<"C";
else if(avg>=60)
opf<<"D ";
else
opf<<"E";
opf<<endl;
}
//HISTORY CLASS AVERAGE:
opf << endl;
opf << ' ' << "class average: " <<( crc_avg/z)<<endl;
crc_avg=0.0;
z=0;
for(i=0;i<100;i++)
opf<<"_";
opf << endl;
opf << "MATH Class" << endl;
opf << "student name"<<" " <<"Test avg"<<endl;
for(i=0;i<100;i++)
opf<<"_";
opf << endl;
if(ptr[rownum].crc=='E')
{
opf<<ptr[rownum].fn<<ptr[rownum].ln<<" ";
avg=(0.3 * ptr[rownum].tg1) +(0.3* ptr[rownum].tg2) +(0.4 * ptr[rownum].tg3);
crc_avg=crc_avg+avg;
z++;
opf<<avg<<" ";
if(avg>=90)
opf<<"A";
else if(avg>=80)
opf<< "B ";
else if(avg>=70)
opf<< "C";
else if(avg>=60)
opf<<"D ";
else
opf<<"E";
opf<<endl;
}
//MATH CLASS AVERAGE
opf<<endl;
opf <<" "<<"class average: " <<( crc_avg/z)<<endl;
crc_avg=0.0;
z=0;
for(i=0;i<100;i++)
opf<<"_";
opf<<endl;
cout << "N PROCESS COMPLETED!!!!"<<endl;
opf.close();

return 0;
}

You will write a program that reads and stores student data from an input file, computes and stores each student's test average, then prints a report to an output file, along with class averages.

Input File Format

The first line of the input file will be a single integer number -- this value tells how many records are in the file.

After this, each line represents one student record. Each record consists of the following fields (in this order), separated by commas:

last name: a character string (assume no more than 20 characters)

first name: a character string (assume no more than 20 characters)

course: a single character. 'M' for math, 'H' for history, 'E' for English. Represents the course that the student is taking.

Test 1 grade: an integer

Test 2 grade: an integer

Final exam grade: an integer

You may assume that a file is in the correct format, that there is no trailing whitespace in the file, and that the types and limits will be as described above

A sample input file

Program Details

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.

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

General Requirements

No global variables, other than constants

You may use any of these libraries:

iostream

string

iomanip

fstream

cctype

cstdlib

cstring

HINT: Be careful if you change the example input file. If you have trailing whitespace at the end of a text file your program attempts to read you could encounter off by one errors. You SHOULD test your program on multiple input files (all of the required format of course)

Write your source code so that it is readable and well-documented

Part of assessing readability and style will be how well you break your program into appropriate functions. You should have at least one function in this program that takes in a Student structure, or the array of Students, as a parameter

Sample Program Run

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.

Sample Input File

Output File Contents (after the program run)

Explanation / Answer

change this line for(i=0;i<100;i++)

to for(i=0;i<=100;i++)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote