//// code,and output file for grading//// the codes out put assigns all the grad
ID: 3547402 • Letter: #
Question
////
code,and output file for grading////
the codes out put assigns all the grades to the fist name instead of 5 grades for each name.
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
const int Num=10;
const int iScore=50;
string names[Num];
string score[iScore];
int count;
ifstream inFile;
ifstream inFile1;
ofstream outFile;
inFile.open("D: ames.txt");
outFile.open("D: ameslin.
Explanation / Answer
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
const int Num=10;
const int iScore=5;
string names[Num];
double score[Num][iScore];
int count;
ifstream inFile;
ifstream inFile1;
ofstream outFile;
inFile.open("D: ames.txt");
outFile.open("D: ameslin.txt");
/*
names[0]="Ahmed";
names[1]="Ali";
names[2]="Eddie";
names[3]="Diego";
names[4]="Musaab";
names[5]="Ibrahim";
names[6]="Hawa";
names[7]="Ashley";
names[8]="john";
names[9]="shanoo"; */
for (count=0; count<Num;count++)
{
inFile>>names[count];
}
inFile.close();
inFile1.open("D:\grades.txt") ;
/*score[0]={"A=98,A=98,B=88,D= 68,C=78"};
score[1]={"F=56,C=78,A=90,A= 100,F=54"};
score[2]={"D=67,C=78,A=98,F= 60,B=89"};
score[3]={"B=85,F=49,C=79,B= 86,F=55"};
score[4]={"C=78,F=39,B=80,C= 79,A=90"};*/
for(int i=0; i<Num; i++)
{
for(count=0; count<iScore; count++)
{
inFile1>>score[i][count];
}
}
inFile1.close();
for (count=0; count<Num;count++)
{
outFile<<setw(2)<<right<< count+1<<" : ";
outFile<<setw(6)<<names[count]
<<" : "<<score[count][0]
<<" "<<score[count][1]
<<" "<<score[count][2]
<<" "<<score[count][3]
<<" "<<score[count][4]<<" ";
}
outFile.close();
cout<<"These names are: ";
for (count=0; count<Num;count++)
{
cout<<setw(3)<<count+1<<": ";
cout <<names[count]
<<" : "<<score[count][0]
<<" "<<score[count][1]
<<" "<<score[count][2]
<<" "<<score[count][3]
<<" "<<score[count][4]<<" ";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.