Question


Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class
Make sure you include the preprocessor directives (#ifndef, #define, #endif) to prevent a header file from being included (#i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Person.h


#ifndef PERSON
#define PERSON
#include
#include

using namespace std;

class Person{
  
   //Member variables
   private:
      
       string firstName,lastName;
       int personID;
       static int nextID;
  
   //Member functions  
   public:
      
       Person();
       Person(string first,string last);
       void setFirstName(string first);
       string getFirstName();
       void setLastName(string last);
       string getLastName();
       int getID();
       virtual void Print()=0;
          
};

#endif

//Person.cpp

#include "Person.h"

using namespace std;

Person::Person() //constructor
{
   nextID;
   personID=nextID;
  
}

Person::Person(string first,string last) //Parameterised contructor
{
   firstName = first;
   lastName = last;
   nextID;
   personID=nextID;
  
}

void Person::setFirstName(string first)
{
   firstName = first;
}
      
//Accessor Method  
string Person::getFirstName()
{
   return firstName;
}


void Person::setLastName(string last)
{
   lastName = last;
}

//Accessor Method
string Person::getLastName()
{
   return lastName;
}

//Accessor Method
int Person::getID()
{
   return personID;
}


void Person::Print()
{
   cout<<"Name of the person: "<getFirstName()<<" "<getLastName()<    cout<<"Id: "<getID();
}

//Student.h

#ifndef STUDENT
#define STUDENT
#include "person.h"

using namespace std;

//Inheriting Person

class Student : public Person{
  
   //Member variables  
   private:
       float GPA;
       string term;
  
   //Member functions  
   public:
      
       bool setGPA(float);
       float getGPA();
      
       string getTerm();
       void setTerm(string);
      
       void Print();
  
};


#endif

//Student.cpp

#include "student.h"

using namespace std;

bool Student::setGPA(float GPA)
{
   if(GPA>0 && GPA<=4.0)
   {
       this->GPA=GPA;
       return true;
   }
   else{
       this->GPA=0;
       return false;
   }
}
      

//Accessor Method      
float Student::getGPA()
{
   return GPA;
}
  
//Accessor Method  
string Student::getTerm()
{
   return term;
}
      
      
void Student::setTerm(string term)
{
   this->term=term;
}

//Overriding Print()      
void Student::Print()
{
   cout<<"================================================================="<    cout<<"Student First Name: "<    cout<<"Student Last Name: "<    cout<<"Student ID: "<    cout<<"Student GPA: "<    cout<<"Student Admit Term: "<    cout<<"================================================================="< }

//faculty.h

#ifndef FACULTY
#define FACULTY

#include"person.h"

//Inheriting Person

class Faculty : public Person
{
  
   //Member variables  
   private:
       string year;
  
   //Member functions  
   public:
       void setYear(string);
       string getYear();
       void Print();
      
};


#endif

//faculty.cpp

#include "faculty.h"

void Faculty::setYear(string year)
{
   this->year=year;
}


//Accessor Method  
string Faculty::getYear()
{
   return year;
}
      
      
//Overriding Print()      
void Faculty::Print()
{
   cout<<"================================================================="<    cout<<"Faculty First Name: "<    cout<<"Faculty Last Name: "<    cout<<"Faculty ID: "<    cout<<"Faculty Hire Year: "<    cout<<"================================================================="< }

//main.cpp


#include "student.h"
#include "faculty.h"

using namespace std;


//Main() method
int main()
{

   //Creating object of Student
   Student s;
   s.setFirstName("");
   s.setLastName("");
   s.setGPA(4.00);
   s.setTerm("Spring 2019");
   s.Print();
  
   //Creating object of Faculty
   Faculty f;
   f.setFirstName("Mary");
   f.setLastName("Smith");
   f.setYear("2019");
   f.Print();

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Create a class hierarchy to be used in a university setting. The classes are as follows:...
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
  • A class allows a group of one or more member objects to have a series of...

    A class allows a group of one or more member objects to have a series of common characteristics and functions. Create a class (student) that contains the member characteristics: Student ID (string) Student Last Name (string) Student First Name (string) GPA (float) Number of enrolled classes (integer) The class functions are: setID (string passed to function to set Student ID) setLastName (string passed to function to set Student Last Name) setFirstName (string passed to function to set Student First Name)...

  • 2- Write a program that has a Person class, a Student class, that is derived from...

    2- Write a program that has a Person class, a Student class, that is derived from Person, and a Faculty class, derived from Person as well, with the following specifications: The Person class has the following members: a. An integer private member variable named SSN. b. Two string protected member variables named firstName and lastName. C. An integer protected member variable named age. d. A constructor that takes SSN, first name, last name, and age as parameters. e. A constructor...

  • Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee

    In Java(The Person, Student, Employee, Faculty, and Staff classes)Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and date hired. Define a class namedMyDate that contains the fields year, month, and day. A faculty member has office hours and a rank....

  • Use C++ to create a class called Student, which represents the students of a university. A...

    Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...

  • 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...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

  • 2. Write a program named lab3 2.app that contains a class named Student to store student...

    2. Write a program named lab3 2.app that contains a class named Student to store student information Information that will be relevant to store is first name, last name, id number, GPA, and major (1) Define a member function named set0, which allows you to set all member variables. This function has an empty parameter list, and its return type is void. So, within the function you'll prompt for information. Note: For entering major, if you need a space, use...

  • In this laboratory, we are going to build a base class and a collection of derived...

    In this laboratory, we are going to build a base class and a collection of derived classes. Write the code to implement the class Person. A person has a name, address,telephone number and and E-Mail address. Be sure to include accessor functions to return each of these values. Create a derived class Student which has a class status (freshman, sophomore, junior, or senior). Create a derived class Employee which has the attributes office, salary, and date hired. Now define a...

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