Question: Using C++, Write A Base Class Declare a class named RealProperty that could be used to describe a piece of real property. It should contain
Using C++, Write A Base Class
Declare a class named RealProperty that could be used to describe a piece of real property. It should contain these private fields:
streetAddress (string)
squareFootage (int)
taxes (double)
Each field should have a comment documenting what it is for.
Add public member functions as follows:
The default constructor. The default constructor initializes the fields so that the street address is an empty string and all numeric fields are 0 or 0.0. Implement the default constructor inline using the member initialization list syntax.
The constructor that accepts these data: street address (string), square footage (int), and taxes (double). Implement this constructor inline using the member initialization list syntax and call the mutator function for square footage in the body of the constructor.
Add mutator member functions to set the fields. One member function for each field. Each member function should begin with the word 'set' followed by the field name with the first letter changed to uppercase. Each member function should have a comment above the declaration describing its purpose. Implement the mutator member functions outside of the class.
Add accessor member functions to return the fields. One member function for each field. Each member function should begin with the word 'get' followed by the field name with the first letter changed to uppercase and the function should be marked with the const keyword. Each member function should have a comment above the declaration describing its purpose. Implement the accessor member functions inline.
Write the definition for all member functions not defined inline. Validate the square footage to make sure it is a positive number. If the square footage is not positive, Issue the message,
"Square footage must be a positive number."
and terminate the running of the program.
Write A Derived Class
Declare a class named Apartment that could be used to describe a kind of real property. It is a class derived from RealProperty publicly. It should contain one private field:
monthlyRent (double)
Use the data type in parentheses for the field.
Each field should have a comment documenting what it is for.
Add public member functions as follows:
Add the default constructor. The default constructor initializes the fields through a member initialization list so that the street address is an empty string and all numeric fields are 0 or 0.0. Note you need to use a special syntax to initialize the private fields of the base class. Implement this constructor inline.
Add a constructor that accepts: rent (double), street address (string), square footage (int), and taxes (double). This constructor sets all the fields based on four parameters: street address, square footage, taxes, and monthly rent through a member initialization list. Note you need to use a special syntax to initialize the private fields of the base class.Implement this constructor inline.
Add mutator member functions to set the fields. One member function for each field. Each member function should begin with the word 'set' followed by the field name with the first letter changed to uppercase. Each member function should have a comment above the declaration describing its purpose. Implement the mutator member function inline.
Add accessor member functions to return the fields. One member function for each field. Each member function should begin with the word 'get' followed by the field name with the first letter changed to uppercase and the member function should be a const member function. Each member function should have a comment above the declaration describing its purpose. Implement the accessor member functions inline.
Write the definition for all member functions not implemented inline.
Declare a function named displayPropertyInfo that receives one reference to const parameter representing a real property. The function has no return value.
Declare a function named displayApartmentInfo that receives one reference to const parameter representing an apartment. The function has no return value.
Write the main function as follows:
Define an Apartment variable named lakeside.
Get the info from user by reading a line of user input that contains info in the following format:
Cupertino, 1200, 200, 2550
The line above includes the street address, square footage, taxes and monthly rent in that order.
Note: don't prompt the user in your code.
Store the info in the variable lakeside.
Call displayPropertyInfo and pass the Apartment variable lakeside.
Call displayApartmentInfo and pass the same Apartment variable lakeside.
End of main function.
Write the definition of displayPropertyInfo below the main function. Don't forget the block comment.
Write the definition of displayApartmentInfo below the displayPropertyInfo function. Don't forget the block comment.
Test The Program:
Use the following line as your program input:
Cupertino, 1200, 200, 2550
The output should look exactly as follows:
Property is located at: Cupertino Square footage: 1200 Taxes: 200 Apartment is located at: Cupertino Square footage: 1200 Taxes: 200 Monthly rent: 2550.00
File:
#include
#include
#include
using namespace std;
// Write the code for class RealProperty here . . .
// Write the code for class Apartment here . . .
// Function prototypes
// Declare a function named displayPropertyInfo that receives one reference to const parameter
// representing a real property. The function has no return value.
// Declare a function named displayApartmentInfo that receives one reference to const parameter
// representing an apartment. The function has no return value.
int main() {
// Write code here . . .
return 0;
}
//**********************************************************************
//* Print the real property information.
//* Parameter
//* rp - a reference to const referencing to caller's RealProperty variable.
//* Return void
//**********************************************************************
void displayPropertyInfo(const RealProperty &rp) {
// Write your code here . . .
}
//**********************************************************************
//* Print the apartment information.
//* Parameter
//* rp - a reference to const referencing to caller's Apartment variable.
//* Return
//* void
//**********************************************************************
void displayApartmentInfo(const Apartment &apt) {
// Write your code here . .
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
