"The program instantiates and uses instances of a derived class with default and parameterized 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) 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. First in the picture is program input and second is output
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
"The program instantiates and uses instances of a derived class with default and parameterized 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)
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.
First in the picture is program input and second is output.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps