Split statements and comments longer than 80 characters into multiple lines and
ID: 3904984 • Letter: S
Question
Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions.
Read the entire instructions before writing code. In order to get 100%, the entire instructions must be followed.
Write a program that is composed of one source file named Lab4a.cpp. The program instantiates and uses instances of a derived class with default and non-default constructors. The program must be written in accordance to the following plan:
Description
You should include a program description at the top of the main program according to the template. You may simply use this sentence, "The program instantiates and uses instances of a derived class with default and non-default constructors."
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)
Use the data types in parentheses for the fields.
Each field should have a comment documenting what it is for.
Add the default constructor.
Add a constructor that accepts these data: street address (string), square footage (int), and taxes (double) .
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.
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. Each member function should have a comment above the declaration describing its purpose.
Write the definition for 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.
Write the definition for the other constructor which sets all the fields based on three parameters: street address, square footage, and taxes.
Write the definition for every member function.
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 the default constructor.
Add a constructor that accepts: rent (double) .
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.
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. Each member function should have a comment above the declaration describing its purpose.
Write the definition for 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. Note you need to use a special syntax to initialize the private fields of the base class.
Write the definition for the other constructor which sets all the fields based on four parameters: street address, square footage, taxes, and monthly rent. Note you need to use a special syntax to initialize the private fields of the base class.
Write the definition for every member function.
Declare a function named displayPropertyInfo that receives one reference parameter representing a real property. The function has no return value.
Declare a function named displayApartmentInfo that receives one reference parameter representing an apartment. The function has no return value.
Write the main function as follows:
Define and initialize an Apartment variable using the following data:
street address: Cupertino
square footage: 1200
taxes: 200
monthly rent: 2550.0
Call displayPropertyInfo and pass the Apartment variable.
Call displayApartmentInfo and pass the Apartment variable.
Write the definition of displayPropertyInfo below the main function.
Write the definition of displayApartmentInfo below the displayPropertyInfo function.
Test The Program
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
Explanation / Answer
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class RealProperty{
private:
string streetAddress;
int squareFootage;
double taxes;
public:
RealProperty(string s, int f, double t){
streetAddress = s;
squareFootage = f;
taxes = t;
}
RealProperty(){
streetAddress = "";
squareFootage = 0;
taxes = 0.0;
}
string getStreetAddress(){
return streetAddress;
}
int getSquareFootage(){
return squareFootage;
}
int getTaxes(){
return taxes;
}
void setStreetAddress(string a){
streetAddress = a;
}
void setSquareFootage(int a){
squareFootage = a;
}
void setTaxes(double a){
taxes = a;
}
};
class Apartment : public RealProperty{
private:
double monthlyRent;
public:
Apartment(string s, int f, double t, double m): RealProperty(s,f,t){
monthlyRent = m;
}
Apartment() : RealProperty(){
monthlyRent = 0;
}
double getMonthlyRent(){
return monthlyRent;
}
double setMonthlyRent(double a){
monthlyRent = a;
}
};
void displayPropertyInfo(RealProperty &a){
cout << "The property is located at:" << a.getStreetAddress() << endl;
cout << "Square footage:" << a.getSquareFootage() << endl;
cout << "taxes:" << fixed << setprecision(2) << a.getTaxes() << endl;
}
void displayApartmentInfo(Apartment &a){
cout << "The apartment is located at::" << a.getStreetAddress() << endl;
cout << "Square footage:" << a.getSquareFootage() << endl;
cout << "Taxes:" << fixed << setprecision(2) << a.getTaxes() << endl;
cout << "Monthly rent:" << fixed << setprecision(2) << a.getMonthlyRent() << endl;
}
void displayIntro(){
cout << "The program instantiates and uses instances of a derived class with default and non-default constructors. ";
}
int main(){
displayIntro();
RealProperty r("Cupertino",1200,200);
displayPropertyInfo(r);
Apartment a("Cupertino",1200,200,2500);
displayApartmentInfo(a);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.