Question

In: Computer Science

C++ Programming. Create a class hierarchy to be used in a university setting. The classes are...

C++ Programming.

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

The base class isPerson. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The classshould also have a static data member called nextID which is used to assignanID numbertoeach object created(personID). All data members must be private.

Create the following member functions: Accessor functions to allow access to first name and last name (updates and retrieval). These functions should be public. Create a getID function to retrieve the personID of the person. This function should be public. The user oftheclassor any derived class should not have the ability to update personID. Create a constructor with two arguments(first name and last name) with default values.

Create a public member function Print to display information stored in the object. Make this class an abstract class. Create theStudent class as a derived class from the Person class. This class should have two additional data members to keep track of astudent’s GPA (float) and admission term (string –eg. Fall 2019). Create public accessor functions to allow access to the GPA and admission term. The setGPA function should return true if the value of the GPA is between 0 and 4.0(inclusive) and false otherwise. Set the GPA to zero if an invalid value is provided. Override the function Print to print the student information. Create a constructor that takes in four argumentswith default values(first name, last name, admission term, and GPA). Create the Faculty class as a derived class from the Person class. This class should have one additional data member to keep track of the yearthe faculty was hired(string –eg. 2019 ) Create a public accessor functionto allowaccess to the hire year. Override the function Print to print the faculty information. Create a constructor that takes in three argumentswith default values(first name, last name, hire year).

After defining the classes in this hierarchy, write a program that creates objects of each class and tests their member functions. Make sure you include the preprocessor directives (#ifndef, #define, #endif) to prevent a header file from being included (#include) multiple times. Separate the class interface from the class implementation.

Output Sample:

Faculty First Name: John

Faculty Last Name:Smith

Faculty ID:5

Faculty Hire Year:2019

******************************************************

******************************************************

Student First Name: Sarah

Student Last Name: Smith

Student ID: 3

Student GPA: 3.75

Student Admit Term: Fall 2019

Solutions

Expert Solution

CODE:

//Tester program for Person, Student and Faculty classes
//main.cpp
#include<iostream>
//include Student and Faculty header files
#include "Student.h"
#include "Faculty.h"
using namespace std;

int main()
{
   //Create Student and faculty class objects
   Student std("John","Smith",3.75,"Spring 2019");
   Faculty faculty("Mary","Smith","2019");


   cout<<"*******************************************\n";
   //calling Print method on faculty
   faculty.Print();
   cout<<"*******************************************\n";
   cout<<"\n\n\n";
   cout<<"*******************************************\n";
   //calling Print method on Student object
   std.Print();
   cout<<"*******************************************\n";
   return 0;
}

-----------------------------------------------------------------------------------------

//Person.h
#ifndef PERSON_H
#define PERSON_H
#include<iostream>
#include<string>
using namespace std;
class Person
{
private:
   int personID;
   string firstName;
   string lastName;
public:
   //Constructor and methods
   Person(string fName, string lName);
   string getFirstName();
   string getLastName();
   int getID();
   virtual void Print() = 0;
   static int nextID;
};

#endif //PERSON_H

-----------------------------------------------------------------------------------------

//Person.cpp
#include<iostream>
#include "Person.h"
using namespace std;
//Set static variable value nextID to 0
int Person::nextID = 0;
//Implementation of methods of Person class
Person::Person(string fName, string lName)
{
   nextID=nextID+1;
   personID=nextID;
   this->firstName=fName;
   this->lastName=lName;
}
string Person::getFirstName()
{
   return firstName;
}
string Person::getLastName()
{
   return lastName;
}
int Person::getID()
{
   return personID;
}

-----------------------------------------------------------------------------------------

//Student.h
#ifndef STUDENT_H
#define STUDENT_H
#include<iostream>
#include<string>
#include "Person.h"
using namespace std;
class Student : public Person
{
private:
   float gpa;
   string admissionTerm;
public:
   Student(string fName, string lName, float gpa, string adTerm);
   bool setGPA(float gpa);
   float getGPA();
   string getAdmissionTerm();
   void Print();

};

#endif //STUDENT_H

-----------------------------------------------------------------------------------------


//Student.cpp
#include<iostream>
#include<iomanip>
#include "Student.h"
#include<string>
using namespace std;
Student::Student(string fName, string lName, float gpa, string adTerm): Person(fName, lName)
{
   setGPA(gpa);
   admissionTerm=adTerm;
}
bool Student::setGPA(float gpa)
{
   if(gpa<0 || gpa>4)
   {
       gpa=0;
       return false;
   }
   else
       this->gpa=gpa;
}
float Student::getGPA()
{
   return gpa;
}
string Student::getAdmissionTerm()
{
   return admissionTerm;
}

void Student::Print()
{
   cout<<fixed<<setprecision(2);
   cout<<left<<setw(20)<<"Student First Name "
                   <<":"<<setw(20)<<getFirstName()<<endl;
   cout<<left<<setw(20)<<"Student Last Name "
                   <<":"<<setw(20)<<getLastName()<<endl;
   cout<<left<<setw(20)<<"Student ID "
                   <<":"<<setw(20)<<getID()<<endl;
   cout<<left<<setw(20)<<"Student GPA "
                   <<":"<<setw(20)<<getGPA()<<endl;
   cout<<left<<setw(20)<<"Student Admit Term "
                   <<":"<<setw(20)<<getAdmissionTerm()<<endl;
}

-----------------------------------------------------------------------------------------

//Faculty.h
#ifndef FACULTY_H
#define FACULTY_H
#include<iostream>
#include<string>
#include "Person.h"
using namespace std;
class Faculty : public Person
{
private:
   string year;
public:
   Faculty(string fName, string lName,string year);
   string getYear();
   void Print();
};

#endif //FACULTY_H

-----------------------------------------------------------------------------------------

//Faculty.cpp
#include<iostream>
#include<iomanip>
#include "Faculty.h"
#include<string>
using namespace std;
//Implementation of methods of Person class
Faculty::Faculty(string fName, string lName, string year) : Person(fName, lName)
{
   this->year=year;
}
string Faculty::getYear()
{
   return year;
}
void Faculty::Print()
{
   cout<<fixed<<setprecision(2);
   cout<<left<<setw(20)<<"Faculty First Name "
                   <<":"<<setw(20)<<getFirstName()<<endl;
   cout<<left<<setw(20)<<"Faculty Last Name "
                   <<":"<<setw(20)<<getLastName()<<endl;
   cout<<left<<setw(20)<<"Faculty ID "
                   <<":"<<setw(20)<<getID()<<endl;
   cout<<left<<setw(20)<<"Faculty Hire Year "
                   <<":"<<setw(20)<<getYear()<<endl;
}

-----------------------------------------------------------------------------------------

OUTPUT:


Related Solutions

Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape,...
Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape, Two Dimensional Shape, Three Dimensional Shape, Square, Circle, Cube, Rectangular Prism, and Sphere. Cube should inherit from Rectangular Prism. The two dimensional shapes should include methods to calculate Area. The three dimensional shapes should include methods to calculate surface area and volume. Use as little methods as possible (total, across all classes) to accomplish this, think about what logic should be written at which...
For this assignment, you will create a hierarchy of five classes to describe various elements of...
For this assignment, you will create a hierarchy of five classes to describe various elements of a school setting. The classes you will write are: Person, Student,Teacher, HighSchoolStudent, and School. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task with this assignment. Person Variables: String firstName - Holds the person's first name String lastName -...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
C# programming Create a classes called AlphabetDice that simulates a multi-sided dices with alphabet characters on...
C# programming Create a classes called AlphabetDice that simulates a multi-sided dices with alphabet characters on each side. For instance, a 10-sided AlphabetDice will random return 'a','b','c','d','e','f','g','h','i' or 'j'. The custom constructor should require a random seed and the number of sides. It should also have the following: A read-only property Sides that give us the number of sides A method char Next() that returns an appropriate random character (char) On a side note, to cast an integer to a...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
Assume that the Student class is part of a generalization/specialization hierarchy, with University Person as a...
Assume that the Student class is part of a generalization/specialization hierarchy, with University Person as a general class. What attributes would Student inherit from University Person? What are attributes are unique to the Student class, which all University Persons would not have?
C++ programming Instructions Create a ShopCart class that allows you to add items to a shopping...
C++ programming Instructions Create a ShopCart class that allows you to add items to a shopping cart and get the total price of purchases made. Items are simply described by an Item class as follows: class Item {   public:      std :: String description;      float price; }; The ShopCart class must be able to add and remove items and display an invoice. This class must use a dynamically allocated array of items whose capacity is fixed in advance to the build....
Define the classes to complete dynamic array hierarchy with a concrete, abstract and interface class. public...
Define the classes to complete dynamic array hierarchy with a concrete, abstract and interface class. public class DArray { private int array[]; public DArray() { } private void expandArray() { } private void shrinkArray() { } } --------------------------------------------------------------- public abstract class ArrayBP { protected int numElements; protected int numAllocations; public abstract void storeAt(int item, int index) { } public abstract getFrom(int index) { } public abstract int len() { } public abstract void remove();{ } public abstract void removeAt(int index)...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the opportunity to overload or override an inherited member function. What is the difference? and which one is the better?
C# Programming create a Hash Function
C# Programming create a Hash Function
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT