his program consist of two parts: 1) reading and processing a student data file,
ID: 3661806 • Letter: H
Question
his program consist of two parts:
1) reading and processing a student data file, and writing the results to a student report file
2) modifying part 1 to calculate some statistics and writing them to another file.
For this assignment, you will be reading one input file and writing out two other files.
You only need to email the source code. It should generate the necessary output files.
Part 1 Detail
Read in the student data file, partially shown below. This 50 record file consists of a (8-digit numeric) student id, lab exercise points, 8 assignment's points, midterm points, final points, and CodeLab points. You must follow the syllabus specifications for the determination of the letter grades. You will write the input student data and the results of the processing into a student report file that looks "just like" the output shown below. In addition to the input student data, the report should contain the "total" of the assignment grades, the total and percent of all points achieved, and the letter grade. You may assume that the input data file does not contain any errant data.
The Student Data Input File
The Student Report Output File
Explanation / Answer
Good wishes,
PROGRAM 1
#include <iostream>
#include <fstream>
#include <iomanip>
char add_pts(char ex,char tot,char mi,char fi,char cl)
{
return (ex+tot+mi+fi+cl);
}
char total_ass(char ass[])
{
int t=0;
for(int i=0;i<8;i++)
t=t+ass[i];
return char(t);
}
char percent(char pts)
{
int p;
p=pts/5;
return char(pts);
}
char grade(char pts)
{
char gr;
if(((pts>90)&&(pts<100))||(pts==100))
{
gr='A';
/*if((pts==99)||(pts==100))
gr='A+';*/
}
else if((pts<89)&&(pts>80))
{
gr='B';
/*if((pts==88)||(pts==89))
gr='B+';*/
}
else if((pts<79)&&(pts>70))
{
gr='C';
/*if((pts==78)||(pts==79))
gr='C+';*/
}
else if((pts<69)&&(pts>60))
{
gr='D';
/*if((pts==68)||(pts==69))
gr='D+';*/
}
else
{
gr='F';
}
return gr;
}
int main()
{
ifstream infile;
infile.open("std_data.txt",ios::nocreate);
ofstream outfile("std_report.txt");
ofstream outfile2("std_summary.txt");
char std_id[8],ch,ex,ass[8],mi,fi,cl,tot,pts,pct,gr;
while(infile)
{ int i=0;
infile.get(ch);
while(ch!=' ')
{
infile.get(ch);
cout<<"hi "<<ch;
outfile.put(ch);
std_id[i]=ch;
i++;
}
outfile.put(' ');
infile.get(ch);
while(ch!=' ')
{
ex=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
infile.get(ch);
for(int i=0; i<8;i++)
{
infile.get(ch);
while(ch!=' ')
{
ass[i]=ass[i]+ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
}
tot=total_ass(ass);
infile.get(ch);
while(ch!=' ')
{
mi=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
infile.get(ch);
while(ch!=' ')
{
fi=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
infile.get(ch);
while(ch!=' ')
{
cl=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
pts=add_pts(ex,tot,mi,fi,cl);
outfile.put(pts);
pct=percent(pts);
outfile.put(' ');
outfile.put(pct);
gr=grade(pts);
outfile.put(' ');
outfile.put(gr);
}
return 0;
}
PROGRAM 2
#include <iostream>
#include <fstream>
#include <iomanip>
char add_pts(char ex,char tot,char mi,char fi,char cl)
{
return (ex+tot+mi+fi+cl);
}
char total_ass(char ass[])
{
int t=0;
for(int i=0;i<8;i++)
t=t+ass[i];
return char(t);
}
char percent(char pts)
{
int p;
p=pts/5;
return char(pts);
}
char grade(char pts,char count_gr[])
{
char gr;
if(((pts>90)&&(pts<100))||(pts==100))
{
gr='A';
/*if((pts==99)||(pts==100))
gr='A+';*/
count_gr[0]++;
}
else if((pts<89)&&(pts>80))
{
gr='B';
/*if((pts==88)||(pts==89))
gr='B+';*/
count_gr[1]++;
}
else if((pts<79)&&(pts>70))
{
gr='C';
/*if((pts==78)||(pts==79))
gr='C+';*/
count_gr[2]++;
}
else if((pts<69)&&(pts>60))
{
gr='D';
/*if((pts==68)||(pts==69))
gr='D+';*/
count_gr[3]++;
}
else
{
gr='F';
count_gr[4]++;
}
return gr;
}
int main()
{
ifstream infile;
infile.open("std_data.txt",ios::nocreate);
ofstream outfile("std_report.txt");
ofstream outfile2("std_summary.txt");
char std_id[8],ch,ex,ass[8],mi,fi,cl,tot,pts,pct,gr,count_gr[5],avg=0,max=0;
while(infile)
{ int i=0;
infile.get(ch);
while(ch!=' ')
{
infile.get(ch);
cout<<"hi "<<ch;
outfile.put(ch);
std_id[i]=ch;
i++;
}
outfile.put(' ');
infile.get(ch);
while(ch!=' ')
{
ex=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
infile.get(ch);
for(int i=0; i<8;i++)
{
infile.get(ch);
while(ch!=' ')
{
ass[i]=ass[i]+ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
}
tot=total_ass(ass);
infile.get(ch);
while(ch!=' ')
{
mi=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
infile.get(ch);
while(ch!=' ')
{
fi=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
infile.get(ch);
while(ch!=' ')
{
cl=ch;
outfile.put(ch);
infile.get(ch);
}
outfile.put(ch);
pts=add_pts(ex,tot,mi,fi,cl);
outfile.put(pts);
pct=percent(pts);
outfile.put(' ');
outfile.put(pct);
gr=grade(pts,count_gr);
outfile.put(' ');
outfile.put(gr);
avg=avg+pct;
max=max+pts;
}
outfile2.put(count_gr[0]);
outfile2.put(' ');
outfile2.put(count_gr[1]);
outfile2.put(' ');
outfile2.put(count_gr[2]);
outfile2.put(' ');
outfile2.put(count_gr[3]);
outfile2.put(' ');
outfile2.put(count_gr[4]);
outfile2.put(' ');
outfile2.put(avg);
outfile2.put(' ');
outfile2.put(max);
outfile2.put(' ');
return 0;
}
The question size is too big hence I tried to accomodated all the rules/specifications mentioned in the question in my program. I have no time to explain it. Hope you understand. Certain information like maximum marks to find percentage and many other were not provide hence I took dummy values like 500, etc. Do replace them with your values. And do mention the file paths completely and accurately. If file name and path is not given accurately then ios::nocreate treats as no such file exists and displays error.
Hope this is clear.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.