include include include include include using namespace std
#include <string>
 #include <fstream>
 #include <iostream>
 #include <sstream>
 #include <iomanip>
 using namespace std;
int main(){
 string name[3];
 int tmpScore, studentTotal, minScore, maxScore, countStudent, countClass;
 double classTotal;
 minScore = 100;
 maxScore = 0;
 classTotal = 0.0;
 countClass = 0;
cout << setw(20) << left << \"students\";
 cout << setw(5) << left << \"Data\" << endl;
 while(!namelist.eof()){
 for(int i=0;i<3;i++){
 namelist >> name[i];
 }
 studentDat.open((name[1]+name[0]+\".dat\").c_str());
 studentTotal = countStudent = 0;
 while(!studentDat.eof()){
 studentDat >> tmpScore;
if(tmpScore>maxScore){
 maxScore = tmpScore;
 }
 if(tmpScore>maxScore){
 minScore = tmpScore;
 }
 studentTotal += tmpScore;
 countStudent ++;
 }
 studentDat.close();
 classTotal += (double)studentTotal / (double)countStudent;
 countClass++;
cout<<setw(20)<<left
 <<name[0] + \" \"
 <<name[1] + \" \"
 <<name[2];
 cout<<setprecision(2)<<fixed
 <<(double)studentTotal/(double)countStudent
 <<endl;
 }
 cout << setw(20)<<left<<\"Class Average:\";
 cout << (double)classTotal/(double)countClass
 <<endl;
 cout << setw(20) << left << \"Max Score:\";
 cout << (double)maxScore << endl;
 cout << setw(20) << left << \"min Score:\";
 cout << (double)minScore << endl;
 namelist.close();
return 0;
 }
namelist and studentDat was not declared, how to fix it?
and if this program is right?
Solution
I have added the declaration of studentDat and namelist variable in below program.
#include <string>
 #include <fstream>
 #include <iostream>
 #include <sstream>
 #include <iomanip>
 using namespace std;
 int main(){
 string name[3];
 int tmpScore, studentTotal, minScore, maxScore, countStudent, countClass;
 ifstream studentDat;
 ifstream namelist; //Please write the open command to open require file.
 double classTotal;
 minScore = 100;
 maxScore = 0;
 classTotal = 0.0;
 countClass = 0;
 cout << setw(20) << left << \"students\";
 cout << setw(5) << left << \"Data\" << endl;
 while(!namelist.eof()){
 for(int i=0;i<3;i++){
 namelist >> name[i];
 }
 studentDat.open((name[1]+name[0]+\".dat\").c_str());
 studentTotal = countStudent = 0;
 while(!studentDat.eof()){
 studentDat >> tmpScore;
 if(tmpScore>maxScore){
 maxScore = tmpScore;
 }
 if(tmpScore>maxScore){
 minScore = tmpScore;
 }
 studentTotal += tmpScore;
 countStudent ++;
 }
 studentDat.close();
 classTotal += (double)studentTotal / (double)countStudent;
 countClass++;
 cout<<setw(20)<<left
 <<name[0] + \" \"
 <<name[1] + \" \"
 <<name[2];
 cout<<setprecision(2)<<fixed
 <<(double)studentTotal/(double)countStudent
 <<endl;
 }
 cout << setw(20)<<left<<\"Class Average:\";
 cout << (double)classTotal/(double)countClass
 <<endl;
 cout << setw(20) << left << \"Max Score:\";
 cout << (double)maxScore << endl;
 cout << setw(20) << left << \"min Score:\";
 cout << (double)minScore << endl;
 namelist.close();
 return 0;
 }


