Question
hi, i want the program written in C++. ================================ Define a class Course with a print function (that prints I am a generic course). Define
hi, i want the program written in C++.
================================
Define a class Course with a print function (that prints I am a generic course).
Define a class Programming that publicly inherits the class Course with a print function (that prints I am Programming).
Define a class Physics that publicly inherits the class Course with a print function (that prints I am Physics).
Define a class Chemistry that publicly inherits the class Course with a print function (that prints I am Chemistry).
Define a class Mathematics that publicly inherits the class Course with a print function (that prints I am Mathematics).
Define a class NewCourse that publicly inherits the class Course with no member functions.
Run the program with the print function being a non-virtual function
Run the program with the print function being a virtual function
The following driver produces the given sample of output:
int main()
{
Course *aCourse[6];
aCourse[0] = new Course;
aCourse[1] = new Programming;
aCourse[2] = new Physics;
aCourse[3] = new Chemistry;
aCourse[4] = new Mathematics;
aCourse[5] = new newCourse;
for(int i = 0; i < 6; i++)
aCourse[i] -> print();
return 0;
}
Sample output:
With non-virtual print():
I am a generic course.
I am a generic course.
I am a generic course.
I am a generic course.
I am a generic course.
I am a generic course.
With virtual print()
I am a generic course.
I am Programming.
I am Physics.
I am Chemistry.
I am Mathematics.
I am a generic course.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started