Need advice classes. Had swine flu and missed school for two weeks =(
Ok, since this is my first post here I guess I better explain some things =)
Well I have had swine flu for the past two weeks and in those two weeks I missed a bunch of my C++ classes in school. Turns out we covered structures and classes in that time, which was bad for me to miss because from what I can tell they are both extremely important in C++.
I managed to do most of my homework I missed, but I'm still stuck on two problems. The first is this:
1.) Construct a class named Student consisting of an integer student ID number, an array of five double-precision grades, and an integer representing the total number of grades entered. The constructor for this class should initialize all Student data members to 0. Included in the class should be member functions to: 1.) enter a student ID number, 2.) enter a single test grade and update the total number of grades entered, and 3.) compute an average grade and display the student ID followed by the average grade.
so far for this problem I have:
Code:
#include <iostream>
#include <string>
#include <iomanip>
class Student
{
private:
int id_number;
double grade[5];
int count;
double average;
public:
int enterID();
void enterGrade();
void display();
};
Student::enterID()
{
std::cout << "Enter student ID number: ";
cin >> xx;
id_number = xx;
return;
}
Student::enterGrade()
{
std::cout << "Enter a grade: ";
for (count = 0; count < 5; count++)
{
cin >> grade[count];
}
return;
}
Student::display();
{
for (count = 0; count < 5; count++)
{
average += grade[i];
if (count = 5)
average = (average / 5);
}
std::cout << "Student ID: " << id_number << std::endl;
std::cout << "Average: " << average << std:: endl;
return;
}
int main()
{
int i = 0;
Student a;
for (i = 0; i < 5; i++)
{
a.enterID();
a.enterGrade();
a.display();
}
return 0;
}
and obtaining these errors when compiling it:
Code:
class2.cpp:19: error: ISO C++ forbids declaration of `enterID' with no type
class2.cpp: In member function `int Student::enterID()':
class2.cpp:21: error: `cin' undeclared (first use this function)
class2.cpp:21: error: (Each undeclared identifier is reported only once for each
function it appears in.)
class2.cpp:21: error: `xx' undeclared (first use this function)
class2.cpp:24: error: return-statement with no value, in function returning 'int
'
class2.cpp: At global scope:
class2.cpp:28: error: ISO C++ forbids declaration of `enterGrade' with no type
class2.cpp:28: error: prototype for `int Student::enterGrade()' does not match a
ny in class `Student'
class2.cpp:14: error: candidate is: void Student::enterGrade()
class2.cpp:28: error: `int Student::enterGrade()' and `void Student::enterGrade(
)' cannot be overloaded
class2.cpp: In member function `int Student::enterGrade()':
class2.cpp:32: error: `cin' undeclared (first use this function)
class2.cpp:34: error: return-statement with no value, in function returning 'int
'
class2.cpp: At global scope:
class2.cpp:37: error: expected constructor, destructor, or type conversion befor
e ';' token
class2.cpp:38: error: expected unqualified-id before '{' token
class2.cpp:38: error: expected `,' or `;' before '{' token
class2.cpp:67:2: warning: no newline at end of file
Can anyone tell me whats wrong and what I'm missing? Or at least point me in the right direction?
Thank you so much.
(I'll post the structures problem after I find my source file lol)