how can I output on the main screen just the final grades and their names with t
ID: 3642156 • Letter: H
Question
how can I output on the main screen just the final grades and their names with two columns.Here is my code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void MainMenu ()
{
cout <<""<< endl;
cout <<" =================================================================="<< endl;
cout <<" Computation of Final Grades of Students initiated "<< endl;
cout <<" =================================================================="<< endl;
}
class myStudent
{
private:
char fname[46];
int midExam[46];
int finExam[46];
double QuizAvg[46];
double finGrade[46];
public:
void getData ();
void showFinGrade ();
double calFinGrade ();
};
void myStudent::getData ()
{
ifstream Student_data;// opens students data
Student_data.open("FirstName.txt");// opens the names of the student and puts it in a 1D array.
for(int i=0; i<46; i++)
{
Student_data >> fname[i];
}
Student_data.open("QuizAvg.txt");// opens the Quiz avgs and puts them into a 1d array.
for(int j=0; j<46; j++)
{
Student_data >> midExam[j];
}
Student_data.open("MidtermExam.txt");
for(int k=0; k<46; k++)
{
Student_data >> midExam[k];
}
Student_data.open("FinalExam");
for(int f; f<46; f++)
{
Student_data >> finExam[f];
}
}
void myStudent::showFinGrade ()
{
cout <<setw(50)<<fname<<setw(50) <<finGrade <<endl;
}
double myStudent::calFinGrade()
{
for(int z=0; z<46; z++)
finGrade[z] = 0.35*midExam[z] + 0.3*QuizAvg[z] + .35*finExam[z];
return finGrade[46];
}
int main()
{
int sum=0;
MainMenu();
myStudent students[46];
cout<<setw(46) <<" Last Name"<< setw(46) <<" Final Grade " << endl;
for (int i= 0; i<46; i++)
{
students[i].getData();
students[i].calFinGrade();
students[i].showFinGrade();
}
system("pause");
return 0;
}
Explanation / Answer
Try this. You have to dereference a char[] in order to get the contents inside, you cant just say "coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.