C++ Programming Assignment: Object-Oriented Programming in C++

Verified

Added on  2019/09/18

|3
|781
|323
Homework Assignment
AI Summary
This C++ programming assignment comprises three distinct problems designed to reinforce object-oriented programming concepts. The first problem involves creating a `VehicleWarranty` class, incorporating private variables for vehicle details, warranty length, and a constant for the current year. Students are tasked with implementing public getter and setter functions, along with a function to calculate warranty validity. The second problem centers on a `Person` class with private variables for name and campus, along with public getter and setter functions and a display function. An array of `Person` objects is created and populated with hardcoded data. The final problem extends the `Person` class, introducing `Student` and `Staff` classes through inheritance. Students are required to add specific variables (ID, major, department) to the derived classes and implement appropriate getter, setter, and display functions. In the `main` function, one `Student` object and one `Staff` object are created, with user input gathered to populate their respective data, which is then displayed using the display functions. The objective is to demonstrate understanding of classes, objects, inheritance, and polymorphism in C++ programming.
Document Page
1.
Create a C++ program:
Create a vehicle warranty class:
o Add the following variables (make all variables private):
Vehicle Make
Vehicle Model
Year manufactured
Length of warranty
o Add the following constant (make it private):
Current year
o Include the following functions (do not take any user input in the functions. Pass all
needed values in as parameters):
Public set (mutator) functions for all variables (not the constant)
Public get (accessor) functions for all variables (including the constant)
Public function used to calculate the warranty validity. Use this formula:
Year manufactured + length of warranty - Current Year
If the result is negative the warranty is not valid. Otherwise it is
valid.
This function will return a boolean value (0 or 1) indicating if the
warranty is valid. If it is valid return 1. If not then return 0.
In the main function:
o Create an object using the vehicle warranty class as the type.
o Gather user input and pass to the object:
Make
Model
Year manufactured
Length of warranty
o Call the function to calculate if the warranty is valid.
o Display all information the user entered, plus the current year (use the get
functions).
o Display if the warranty is valid or not.
o Include appropriate output messages.
o Repeat until the user chooses to quit.
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.
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
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.
3.
Create a C++ program ):
Using the Person class from previous problem:
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.
Document Page
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 ojbect 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..
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 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]