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

i wish to develope a program that will use a class. Declaration of class ( i.e.

ID: 3642155 • Letter: I

Question

i wish to develope a program that will use a class. Declaration of class ( i.e. myStudent )

Main Program will
o Initiated the class by reading the data from given data files.
? Data will be obtained from the given data file. No user input needed here.
o Make individual objects for each student using the student data entered by the user
o Use the objects to do the calculation (i.e. finding Final Grades , and Letter grades )
The final letter grades are going to be shown on the screen only. You do NOT need to save the final
letter grades in an output data file.

here is my code please what am i doing wrong?
#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

I made corrections to everything in bold:


----------------------------------------------------
Student_data.open("FinalExam.txt");
for( int f = 0 ; f<46; f++)
{
Student_data >> finExam[f];
}
}

------------------------------------------------


void myStudent::showFinGrade ()
{

cout << setw(50) << *fname << setw(50) << *finGrade <<endl;
}

You CAN'T print a char array by saying 'cout << fname', you have to dereference it by saying 'cout << *fname'

Also, you can't open a file by saying 'Student_data.open("FinalExam");' you have to put the file type at the end like: ''Student_data.open("FinalExam.txt");

Also, you can't start a for loop without initializing your counter to something like 'for( int f ; f<46; f++)', you have to set f equal to something before you start like 'for( int f = 0 ; f<46; f++)'

Hope that makes sense. That's what I changed.