help in combining objects
am having problems with using classes as a variable in another class..
someone should pls help..what is wrong with the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <vector>
using namespace std;
class courses
{
private:
string course_name;
int grade_int;
char grade_gotten;
int semester_hours;
int totalHours ()
{
return semester_hours * grade_int;
}
public:
void getData ()
{
cout << "Enter course name: ";
cin >> course_name;
cout << "Enter course_grade: ";
cin >> grade_gotten;
cout << "Enter course grade in int: ";
cin >> grade_int;
cout << "Enter semester hours for this course: ";
cin >> semester_hours;
}
void showData ()
{
cout << course_name<<" : "<< grade_gotten<<endl;
}
};
class student
{
private:
string name;
vector<courses> m_Course;
public:
student(int spaces =1){
m_Course.reserve(spaces);
}
void RollCall()
{
for (vector<courses>::const_iterator iter = m_Course.begin();
iter != m_Course.end(); ++iter)
{
iter->getData () ;
}
}
void RollCall2()
{
for (vector<courses>::const_iterator iter = m_Course.begin();
iter != m_Course.end();
++iter)
{
iter->showData() ;
}
}
};
int main ()
{
int myCourse;
cout << "How many courses did u study this semester";
cin >> myCourse;
student one(myCourse);
one.RollCall();
one.RollCall2();
return 0;
}
|
Add #include <string>
and change the const_iterator
's to iterator
.
Last edited on
Topic archived. No new replies allowed.