a) Create a class Student that has a constructor that prints “Hello, I am a stud
ID: 3884708 • Letter: A
Question
a) Create a class Student that has a constructor that prints “Hello, I am a student”.
b) In the class Student put a destructor that prints “Good bye, Student out”.
c) Create a class Course that has an array of 10 Students and initialize it
d) Create a class University that has an array of 10 Courses and initialize it
e) Create, in a main () function, one and only one object University.
f) There is NOT inheritance here. Not at all.
g) Add constructors and destructors as needed in the classes Student and University.
h) The program should print 200 messages on the screen – the constructor and the destructor messages for each of the 10 students for each of the 10 courses. Remember that constructors and destructors are called automatically.
Explanation / Answer
#include <iostream>
using namespace std;
class student{
public:
student(){
cout<<" Hello, I am a student";
}
~student(){
cout<<" Good bye, Student out";
}
};
class Course{
student stud[10];
public:
Course(){
for(int i=0;i<10;i++){
stud[i] = student();
}
}
};
class University {
Course courses[10];
public:
University(){
for(int i=0;i<10;i++){
courses[i] = Course();
}
}
};
int main()
{
University uni;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.