Write a C++ program named final.cpp. When you're done, upload the final.cpp file and press the Submit Quiz button to complete this part of the exam.
Your code must be done in accordance with the following plan.
Copy and paste the following abstract base class Person into your source file.
// Person is an abstract base class.
class Person {
private:
string myName; // Name of this person
public:
Person(string name) : myName(name) {}
// A pure virtual function with a function body
virtual void hello() const = 0 {
cout << "Hello, my name is " << myName
<< ". ";
}
};
The Person class must be used “as is” and not be modified.
Derive two classes, CustomerServiceAgent and CollegeStudent from the given Person class using public inheritance. CustomerServiceAgent does not add new properties. CollegeStudent adds a new property called yearInSchool which can assume one of the values from the enum type CollegeYear = {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}. Declare the enum type within the CollegeStudentclass.
Derive two classes, CSStudent and BUSStudent, from the CollegeStudent class using public inheritance.
In the derived classes, write appropriate constructors and override the virtual function hello.
In the main function, create an array of pointers and initialize them with the following pointers.
new CustomerServiceAgent("Jacqueline")
new CollegeStudent("Jackson", CollegeStudent::FRESHMAN)
new CSStudent("Jack", CollegeStudent::SOPHOMORE)
new BUSStudent("Jacky", CollegeStudent::JUNIOR)
new BUSStudent("Joyce", CollegeStudent::SENIOR)
Write a range-based for loop to iterate through the array and use each pointer to call the hello virtual function.
Write another range-based for loop to delete the pointers returned by the new operations.
The output should be exactly the same as the following:
Hello, my name is Jacqueline. I'm a customer service representative. How may I help you? --- Hello, my name is Jackson. I'm a college freshman. --- Hello, my name is Jack. I'm a college sophomore. I'm a computer science major. --- Hello, my name is Jacky. I'm a college junior. I'm a business major. --- Hello, my name is Joyce. I'm a college senior. I'm a business major. ---
The grading criteria are the same as the labs. For one thing, make sure the lines are not too wide. If a statement is too long, split it into multiple lines and use proper indentations. You should try to limit the line width to about 80 characters for the ease of reading. Among other things, the grading will look at specific aspects such as the structure (every major step is clearly seen), documentation/comments, indentations, identifier naming of variables and constants, usage of named constants.
Here is the program
#include <string>
#include <iostream>
using namespace std;
// Person is an abstract base class.
class Person {
private:
string myName; // Name of this person
public:
Person(string name): myName(name) {}
// A pure virtual function with a function body
virtual void hello() =0; //const = 0 {
//cout << "Hello, my name is " << myName
//<< ". ";
//}
};
// Sub class inheriting from Base Class(Person)
class CollegeStudent : public Person
{
public:
string myName; // Name of this person
int yearInSchool;
CollegeStudent(string name, int yr) :Person(name),
yearInSchool(yr){myName=name;}
string getYear() {
string yrstr ="";
if(yearInSchool == 1)
return "freshman";
if(yearInSchool == 2)
return "sophomore";
if(yearInSchool == 3)
return "junior";
if(yearInSchool == 4)
return "senior";
return "";
}
void hello(){
cout << "Hello, my name is " << myName
<< ".\nI am a college "<< getYear()
<< ".";
}
};
// Sub class inheriting from Base Class(Person)
class CustomerServiceAgent : public Person
{
public:
string myName; // Name of this person
CustomerServiceAgent(string name):Person(name)
{myName=name;}
void hello(){
cout << "Hello, my name is " << myName
<< ".\nI'm a customer service representative. How may I help
you?";
}
};
// Sub class inheriting from Base Class(CollegeStudent)
class CSStudent : public CollegeStudent
{
private:
int yearInSchool;
public:
string myName; // Name of this person
CSStudent(string name, int yr) :CollegeStudent(name,yr)
{myName=name;}
void hello(){
cout << "Hello, my name is " << myName
<< ".\nI am a college "<< getYear()
<< "\nI'm a computer science major.";
}
};
// Sub class inheriting from Base Class(CollegeStudent)
class BUSStudent : public CollegeStudent
{
private:
int yearInSchool;
public:
string myName; // Name of this person
BUSStudent(string name, int yr) :CollegeStudent(name,yr)
{myName=name;}
void hello(){
cout << "Hello, my name is " << myName
<< ".\nI am a college "<< getYear()
<< "\nI'm a business major.";
}
};
// The main driver function
int main() {
enum CollegeYear {FRESHMAN=1, SOPHOMORE=2, JUNIOR=3,
SENIOR=4};
Person **persons;
persons = new Person*[5];
persons[0] = new CustomerServiceAgent("Jacqueline");
persons[1] = new CollegeStudent("Jackson",
CollegeYear::FRESHMAN);
persons[2] = new CSStudent("Jack", CollegeYear::SOPHOMORE);
persons[3] = new BUSStudent("Jacky", CollegeYear::JUNIOR);
persons[4] = new BUSStudent("Joyce", CollegeYear::SENIOR);
for (int i=0; i < 5; i++) {
persons[i]->hello();
cout <<endl<< "--------------------"<<endl;
}
for (int i=0; i < 5; i++) {
delete persons[i];
}
return 0;
}
Here is program output
Hello, my name is Jacqueline.
I'm a customer service representative. How may I help you?
--------------------
Hello, my name is Jackson.
I am a college freshman.
--------------------
Hello, my name is Jack.
I am a college sophomore
I'm a computer science major.
--------------------
Hello, my name is Jacky.
I am a college junior
I'm a business major.
--------------------
Hello, my name is Joyce.
I am a college senior
I'm a business major.
--------------------
Write a C++ program named final.cpp. When you're done, upload the final.cpp file and press the...
Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...
a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...
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....
Please provide the code for the last part(client side
program).
yes i have all the class implementations.
``` person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;
class person
{
public:
person();
string getname() const;
string getadd() const;
string getemail() const;
string getphno() const;
string toString() const;
private:
string name;
string add;
string email;
string phno;
};
```person.cpp
#include "person.h"
person::person()
{
name = "XYZ";
add="IIT ";
email="%%%%";
phno="!!!!!";
}
string person::getname() const
{
return name;
}
string person::getadd()...
Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program: Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...
please help
Write a simple program with Student class having STL list of Record's structure as a member. 1. Records of the Students are not accessible to the outside world. 2. Student shall output its standing (Freshman, Sophomore etc). 3. A Student can only be created with the name 4. A class can only be added if there is a class name and the passing grade. Driver program creates a Student, adds few classes to the Student's records, then prints...
A Java Program Purpose: Work with Abstract classes. Purpose: Abstract classes are import because they ensure than any children which inherit from it must implement certain methods. This is done to enforce consistency across many different classes. Problem: Implement a class called Student. This class needs to be abstract and should contain a String for the name, and a String for the major (and they should be private). The class must have a constructor to set the name and major....
Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....
PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...
Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...