I cant figure out this problem i think i have everything right but i cant get it to compile, no idea where i messed up, please help if you can.
Create a class Student. The class has member data: name and tests (array of 3 test scores). It has several functions: setName, getName, setTests, and displayResult. The function setTests will copy the test scores from the integer array argument into the class data tests. The function displayResult will first calculate the average score from the 3 test scores. It then displays student’s name, 3 test scores and the average score on the same line. You must create Student.h file to store class definition; Student.cpp file to store the class implementation code; and mid2.cpp to store the main function of the program.
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Student
{
public:
Student();
void setName(string);
void setTests(int[]);
string getName();
void displayResult();
private:
string n;
int t[3];
};
Code:
#include "Student.h"
Student::Student()
{
setName(0);
setTests(0);
}
void Student::setName(string name)
{
n = name;
}
void Student::setTests(int tests[])
{
for (int i=0;i<3;i++)
t[i] = tests[i];
}
string Student::getName()
{
return n;
}
void Student::displayResult()
{
double a;
a = (t[0]+t[1]+t[2])/3;
cout << "Name" << "Tests" << "Average" << endl;
cout << getName << t[0] << " " << t[1] << " " << t[2] << a << endl;
}
Code:
int main()
{
Student student;
string n;
int t[3];
cout << "Enter student name: ";
getline(cin, n);
student.setName(n);
cout << "Enter student test scores: ";
cin >> t[0] >> t[1] >> t[2];
student.setTests(t);
student.displayResult();
system("PAUSE");
return EXIT_SUCCESS;
}