Answer to Question #214445 in C++ for Hemambar

Question #214445

Create a person class with name as data member provide four functions in getname() to get input from user and put name to display output write two virtual functions getdata() and outstanding() where both these functions takes no argument and getdata() returns no value but outstanding() returns Boolean value . Derive student and professor from person. student class should contain gpa as its float type and overrides the virtual functions appropriately . In professor class provide number of applications as data members and override the virtual functions appropriately . Write a main program to declare a array of pointers to person object and depending on the choice from user create either a student object or professor object and store it in person array for n persons and display the details along with whether the person is outstanding or not


1
Expert's answer
2021-07-11T14:35:47-0400
#include <iostream>

using namespace std;

class Person {
private:
  string name;

public:
  void getname(string name) {
    this->name = name;
  }

  virtual void getdata();
  virtual bool outstanding();
};

class Student : public Person {
private:
  float gpa;

public:
  void getgpa(float gpa) {
    this->gpa = gpa;
  }
  
  // todo impl.
  void getdata() {
  }

  // todo impl.
  bool outstanding() {
    return false;
  }
};

class Professor : public Person {
private:
  int numberofapps;

public:
  void getnumberofapps(int numberofapps) {
    this->numberofapps = numberofapps;
  }

  // todo impl.
  void getdata() {
  }
  
  // todo impl.
  bool outstanding() {
    return false;
  }
};

int main() 
{
  Person *person;
  
  int n; cin >> n;

  cout << "1) Student" << endl;
  cout << "2) Professor" << endl;

  switch (n) {
    case 1:
      person = new Student();
    case 2:
      person = new Professor();
    default:
      cout << "Invalid choice!" << endl;
  }

  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS