C++ Assignment: Implementing Person, Student, and Staff Classes in C++

Verified

Added on  2019/09/13

|2
|497
|197
Homework Assignment
AI Summary
This assignment focuses on object-oriented programming in C++ and involves creating three classes: Person, Student, and Staff. The first part of the assignment requires creating a Person class with attributes for name and campus, along with methods to set and display this information. An array of Person objects is initialized, and data is hardcoded for three individuals. The second part extends the Person class through inheritance. The Student class inherits from Person and includes attributes for ID and major. The Staff class also inherits from Person and includes attributes for ID and department. Both Student and Staff classes have methods to set and display their respective data. The program then creates one Student and one Staff object, gathers input from the user for their attributes, and displays the information for both objects. The assignment emphasizes the use of inheritance, encapsulation, and the implementation of methods to manage and display data associated with each class.
Document Page
1.
Create a C++ program
Create a Person class:
o Add the following variables (set access so that only this class can access them):
Name
Campus
o Include the following functions (do not take any user input in the functions. Pass all needed
values in as parameters). Make all functions accessible to classes and programs outside the
Person class:
Set (mutator) functions for all variables
A display function to display the user's name and campus.
In the main function:
o Create an array of Person objects. Set the size to of the array to 5.
o Add three people to the array. Do not gather user input. Instead, hard code the data. Make
sure you include the name and campus for each person.
o Display all information for each person by calling the display() function.
Compile and run your code.
Submit your source code as a plain text file with a .cpp extension. Make sure it compiles without error
before submitting it.
2.
Create a C++ program
Using the Person class from previous one:
o Modify the Person class:
Set all variables so they are accessible by the Person class and all sub classes (not
by any other class or program).
o Create a Student class:
Student inherits from Person
Add variables for ID and major. Set all variables so they are only accessible from the
Student class.
ID should be of type int.
Add set functions for ID and major. Set the accessiblity so they can be accessed
from anywhere.
Add a function to display all information for the Student. This includes information
inherited from Person.
o Create a Staff class:
Staff inherits from Person
Add variables for ID and department. Set all variables so they are only accessible
from the Staff class.
ID should be of type string
Add set functions for ID and department. Set the accessibility so they can be
accessed from anywhere.
Add a function to display all information for the Staff member. This includes
informatino inherited from Person.
o In main:
Create one object of type Student and one object of type Staff.
Gather all input for Student (name, campus, ID, major) from the user and use the set
functions to set the values for the object..
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Display the information for the student.
Gather all input for the staff member (name, campus, ID, department) from the user
and use the set functions to set the values for the object.
Display the information for the staff member.
Compile and run your code.
Submit your source code as a plain text file with a .cpp extension. Make sure it compiles without error
before submitting it.
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]