Hello, would someone mind taking a look at this as this program will not run. The input file is filled vertically with words/data. I have taken initiative to move things around, redefine them, but this stage of the program is the best I have gotten it to.
I am getting these errors:
1 IntelliSense: identifier "Total_Examgrade" is undefined
2 IntelliSense: identifier "Total_Labgrade" is undefined
3 IntelliSense: identifier "Final_grade" is undefined
4 IntelliSense: identifier "Average_Examgrade" is undefined
5 IntelliSense: identifier "Average_Labgrade" is undefined
6 IntelliSense: function "std::basic_ofstream<_Elem, _Traits>::basic_ofstream(const std::basic_ofstream<_Elem, _Traits>::_Myt &) [with _Elem=char, _Traits=std::char_traits<char>]" (declared at line 1016 of "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\fstream") cannot be referenced -- it is a deleted function
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int size = 20;//change here to change array size
class Student//declares class type Student
{
public:
string Firstname, Middlename, Lastname;
float GPA;//each student has 1 GPA
char Lettergrade;
int Examgrade[3];
//holds Examgrade1, Examgrade2, Examgrade3;
int Labgrade[4];
//holds Labgrade1, Labgrade2, Labgrade3, Labgrade4;
//function declarations
void Initialize(Student Compstud[]);
//function initializes all the elements
void Read_Data(ifstream& In_Data, Student Compstud[]);
//function read values from a file, these values will be used for calculations
//postcondition: replaces 0 initialization with those values
float Calc_GPA(int Examgrade[], int Labgrade[], Student Compstud[]);
//function calculates the GPA of each of the students
//Postcondition: Able to use the return values of this function to assign letter grade
char LetterGrade(float GPA, Student Compstud[]);
//Precondition: Student has a GPA calculated
//function outputs a letter grade according to the student's calculated GPA
//Grading scale: 100-90: A , 90-80: B, 80-70: C, 70-0: D: Failure
float calc_ClassAverage(float GPA, Student Compstud[]);
//Precondition: Each student has a GPA calculated
//function uses all student's GPA to calculates average grade of the class
//use pointer to point to each student's GPA and sum them up
void Display_File(ofstream Out_Data, Student Compstud[]);
//Postconditions:
//Outputs each of the 20 students' full name, 3 exam grades,
//each of the 4 lab grades, and final grade to an output file
//Outputs the average GPA of whole class
void Display_Screen(Student Compstud[]);
//Postconditions:
//Outputs each of the 20 students' full name, 3 exam grades,
//each of the 4 lab grades, and final grade to the screen
//Outputs the average GPA of whole class
};
//to "access" any student's ID number: Student.IDnumber
//to "access" a student's 1st exam grade: Student.Examgrade[0]
Student Compstud[size];
//initializes an array within type Student to hold 'size' Compsci students
ifstream In_Data;
ofstream Out_Data;
float ClassAverage;
int main()
{
//function calls begin, Still getting the "identifier" is UNDEFINED
Compstud[size].Read_Data(In_Data, Compstud);
Compstud[size].Calc_GPA(Examgrade, Labgrade, Compstud);
Compstud[size].LetterGrade(GPA, Compstud);
Compstud[size].calc_ClassAverage(GPA, Compstud);
Compstud[size].Display_File(Out_Data, Compstud);
Compstud[size].Display_Screen(Compstud);
}
void Student:: Read_Data(ifstream& In_Data, Student Compstud[])
{
In_Data.open("inputlab10.txt");
if (!In_Data.is_open())
exit(1);
for (int i = 0; i < size; i++)//loop through each student in array
{
In_Data >> Compstud[i].Firstname >> Compstud[i].Middlename >> Compstud[i].Lastname;
for (int j = 0; j < 3; j++)//loop and read in exam grades
{
In_Data >> Compstud[i].Examgrade[j];
}
for (int k = 0; k < 4; k++)//loop and read in lab grades
{
In_Data >> Compstud[i].Labgrade[k];
}
}
In_Data.close();
return;
}
float Student:: Calc_GPA(int Examgrade[], int Labgrade[], Student Compstud[])
{
int sum1, sum2;//holds value of sums
float StudGPA;
for (int i = 0; i < size; i++)//loop through each student in array
{
for (int j = 0; j < size; j++)
{
sum1 += Compstud[i].Examgrade[j];//loop and add up student's exam grades
}
for (int k = 0; k < size; k++)
{
sum2 += Compstud[i].Labgrade[k];//loop and add up student's lab grades
}
StudGPA = ((.60 * sum1) + (.40 * sum2) / 2);
Compstud[i].GPA = ((.60 * sum1) + (.40 * sum2) / 2);
} return StudGPA;//student (element's) calculated GPA
}
char Student:: LetterGrade(float GPA, Student Compstud[])
{
for (int i = 0; i < size; i++)//loop through each student in array
{
char letter = 0;//variable to hold the letter
if (Compstud[i].GPA > 90)
letter = 'A';
else if (Compstud[i].GPA > 80)
letter = 'B';
else if (Compstud[i].GPA > 70)
letter = 'C';
else if (Compstud[i].GPA > 60)
letter = 'D';
else
letter = 'F';
char Lettergrade = letter;//assign the Lettergrade value of letter.
return Lettergrade;
}
}
float Student:: calc_ClassAverage(float GPA, Student Compstud[])
{
float GPAsum;//hold all student's GPA
for (int i = 0; i < size; i++)//loop through each student in array
{
//sum all student's GPAs and store value in GPAsum
GPAsum += Compstud[i].GPA;
ClassAverage = (GPAsum / size);
return ClassAverage;
}
}
void Student:: Display_File(ofstream Out_Data, Student Compstud[])
{
for (int i = 0; i < size; i++)//loop through each student in array
{
Out_Data.open("outputlab10.txt");
if (!Out_Data.is_open())
exit(1);
//write each student's record to file
Out_Data <<
Compstud[i].Firstname << " " << Compstud[i].Middlename << " " << Compstud[i].Lastname << " "
<< Compstud[i].GPA << " " << Compstud[i].Lettergrade << " ";
for (int j = 0; j < 3; i++)//loop and output exam grades
{
Out_Data << Compstud[i].Examgrade[j];
}
for (int k = 0; k < 4; i++)//loop and output lab grades
{
Out_Data << Compstud[i].Labgrade[k];
}
Out_Data.close();
return;
}
}
void Student::Display_Screen(Student Compstud[])
{
const int width = 6;
for (int i = 0; i < size; i++)//loop through each student in array
{
cout << "Name: " << Compstud[i].Firstname << setw(width) << Compstud[i].Middlename << setw(width)
<< Compstud[i].Lastname << endl;
cout << "Exam Grades: " << Compstud[i].Examgrade[3] << setw(width) << endl;
cout << "Lab Grades: " << Compstud[i].Labgrade[4] << setw(width) << endl;
cout << "GPA: " << Compstud[i].GPA << endl;
cout << "Grade: " << Compstud[i].Lettergrade << endl;
cout << "The class grade average was" << ClassAverage << endl;
return;
}
for (int i = 0; i < size; i++)//loop through each student in array
{
Out_Data.open("outputlab10.txt");
if (!Out_Data.is_open())
exit(1);
//write each student's record to file
Out_Data <<
Compstud[i].Firstname << " " << Compstud[i].Middlename << " " << Compstud[i].Lastname << " "
<< Compstud[i].GPA << " " << Compstud[i].Lettergrade << " ";
for (int j = 0; j < 3; i++)//loop and output exam grades
{
Out_Data << Compstud[i].Examgrade[j];
}
for (int k = 0; k < 4; i++)//loop and output lab grades
{
Out_Data << Compstud[i].Labgrade[k];
}
Out_Data.close();
return;
}
}