Question

{C++} Create a base class called Person with a public member function called sayHi which outputs “Hi, I am a person.” Create a derived class called Student which inherits from the Person class (public inheritance) and overwrites the sayHi function and outputs “Hi, I am a student.” Create another derived class called EngineeringStudent which inherits from the Student class (public inheritance) and overwrites the sayHi function and outputs “Hi, I am an engineering student.” In the main program, create a Person object, a Student object, and a EngineeringStudent object. Call the sayHi function on Person, Student, and EngineeringStudent objects to test classes.

Hi, I am a person. Hi, I am a student. Hi, I am an engineering student.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream> using namespace std; class Person { public: void sayHi() { cout<<Hi, I am a person.<<endl; 1 class StudHi, I am a person. Hi, I am a Student. Hi, I am an EngineeringStudent.

#include <iostream>

using namespace std;

class Person {  
public:  
void sayHi(){   
cout<<"Hi, I am a person."<<endl;
}   
};
class Student: public Person   
{   
public:  
void sayHi()   
{   
cout<<"Hi, I am a Student."<<endl;   
}   
};
class EngineeringStudent: public Person   
{   
public:  
void sayHi()   
{   
cout<<"Hi, I am an EngineeringStudent."<<endl;   
}   
};
int main(void) {  
Person p;
Student s;
EngineeringStudent es;
p.sayHi();
s.sayHi();
es.sayHi();
return 0;  
}

Anything doubtful or not understand just comment I will touch with you. Please thumsup for my effort thank you and all the best

Add a comment
Know the answer?
Add Answer to:
{C++} Create a base class called Person with a public member function called sayHi which outputs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 27. Suppose the unary ! operator is an overloaded member function of class String. For a...

    27. Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression Is? a. s.operator!0 b. s.operator!(default valuel, default value?,...) c. operator!(s d. A compiler error results because no arguments are given 28. Select the false statement regarding inheritance. a. A derived class can contain more attributes and behaviors than its base class b. A derived class can be the...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • Suppose the base class and the derived class each have a member function with the same...

    Suppose the base class and the derived class each have a member function with the same signature. When you have a pointer to a base class object and call a function member through the pointer, discuss what determines which function is actually called—the base class member function or the derived-class function.

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • If the derived class overrides a public member function of the base class, then to specify...

    If the derived class overrides a public member function of the base class, then to specify a call to that public member function of the base class you use the name of the base class, followed by the ____ operator, followed by the function name with the appropriate parameter list. Question 16 options: 1) : 2) . 3) :: 4) $

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Design class Person with private fields name and social security number, and a public virtual member...

    Design class Person with private fields name and social security number, and a public virtual member Design class Person with private fields name and social security number, and a public virtual member function print(). Derive classes Employee and Student from Person. An employee has a private field salary and a student has a private field grade in addition to the data fields in person. Derive classes Professor and Secretary from Employee. A professor has a private field research area and...

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

  • Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The clas...

    Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...

  • A) Suppose you have a class called base which has been inherited by a class called...

    A) Suppose you have a class called base which has been inherited by a class called derived.     ( both classes have public, protected and private members )     What can a client of derived access within the class base ?     What can the class derived access within the class base ? B) Suppose you have a class called more which has a private object of a class called simple. ( both classes have public, protected and private members...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT