Write a program in C++ with comments!
Create an abstract class Property, containing the
data items owner, address and
price. Add an abstract method
showOwner().
Also provide getter/setters for all the data items. Make
validations if necessary in the setter so that
no invalid values are entered.
Create a class House, to inherit the Property class. This class should contain additional data item – yardSize – an integer – the size of the yard of the house, getter and setter for the additional data item, constructors and implementation of showOwner() method to print “The owner of the house is xxx”, where xxx is the name of the owner.
Create a class Apartment to inherit Property class. This class should contain one additional data item – typeOfAparment that should be enum with values oneroom, onebedroom, twobedrooms, multibedrooms. Implement showOwner() to print “The xxx aparment’s owner is yyy”, where xxx is the type of the apartment (convert the enum value to proper string) and yyy is the name of the owner.
Create a main function that declares a vector of pointers to Property objects and initialize it with some instances of the House and Apartment classes. Write a for loop to iterate through all elements of that vector and show information about the owner of the properties on a separate line each.
#include<iostream>
#include<string>
#include<vector>
using namespace std;
//Abstract class Proprty
class Property
{
public:
Property(string,string,double);
void setOwner(string);
void setAddress(string);
void setPrice(double);
string getOwner();
string getAddress();
double getPrice();
//abstract method
virtual void showOwner() = 0;
private:
//instance vatibals
string owner, address;
double price;
};
//constructore with perameter
Property::Property(string owner, string address, double
price)
{
setAddress(address);
setOwner(owner);
setPrice(price);
}
//setter method with validations
void Property::setOwner(string owner)
{
if (owner != "")
{
this->owner = owner;
}
else
this->owner = "Unknown";
}
void Property::setAddress(string adderss)
{
if (address != "")
this->address = address;
else
this->address = "Unknown";
}
void Property::setPrice(double price)
{
if (price > 0)
this->price = price;
else
this->price = 0;
}
//getter methods
string Property::getOwner()
{
return owner;
}
string Property::getAddress()
{
return address;
}
double Property::getPrice()
{
return price;
}
//Class House that inherites the Property
class House:public Property
{
public:
House(string,string,double,int);
void setYardSize(int);
int getYardSize(int);
void showOwner();
private:
//instance variable
int yardSize;
};
//Constructor that called parent class constructor
House::House(string owner, string address, double price, int
size):Property(owner,address,price)
{
setYardSize(size);
}
void House::setYardSize(int size)
{
if (size > 0)
yardSize = size;
else
yardSize = 0;
}
int House::getYardSize(int)
{
return yardSize;
}
//implements the showOwner abstracr method here
void House::showOwner()
{
cout << "The owner of the house is " <<
this->getOwner() << endl;
}
//Apartment class that inheritce the Property class
class Apartment :public Property
{
public:
//enum type varibale ApartmentType
enum ApartmentType { oneroom , onebedroom,twobedrooms,
multibedrooms};
Apartment(string,string,double, ApartmentType);
void showOwner();
private:
ApartmentType typeOfAparment;
};
Apartment::Apartment(string owner, string address, double price,
ApartmentType type) :Property(owner, address, price)
{
typeOfAparment = type;
}
//implements the showOwner abstracr method here
void Apartment::showOwner()
{
string type;
if (typeOfAparment == oneroom)
type = "one room";
else if (typeOfAparment == onebedroom)
type = "one bed room";
else if (typeOfAparment == twobedrooms)
type = "two bed room";
else
type = "multi bed room";
cout << "The "<<type<<"
aparment's owner is " << this->getOwner() <<
endl;
}
int main()
{
vector<Property*>properties;
properties.push_back(new House("Bob Smith", "America",
2000,25));
properties.push_back(new Apartment("Alice smith",
"London", 23500, Apartment::oneroom));
properties.push_back(new House("Johan Cena",
"Jamnagar", 23000, 200));
properties.push_back(new House("Arth Vyas", "Bhuj",
20040, 100));
properties.push_back(new Apartment("John smith",
"Australia", 23500, Apartment::twobedrooms));
properties.push_back(new Apartment("Will smith",
"India", 23500, Apartment::multibedrooms));
for (int i = 0; i < properties.size(); i++)
{
properties.at(i)->showOwner();
cout << endl;
}
system("pause");
return 0;
}
output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
Write a program in C++ with comments! Create an abstract class Property, containing the data items...
Create a class named Date in C++ Class has 3 private data items (name the data items month, day, year) int month int day int year Member functions ‘getters’ a getter for each data item Use ‘get’ and the data items name The data item name must be capitalized Return the data item Example: int getMonth() {return month;} ‘setters’ a setter for each data item Use ‘set’ and the data items name The data item name must be capitalized Change...
Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student and “PostGraduate” that inherits form “Graduate”. Write the class definition for the abstract class “Student”. The class definition should include private instance variables of type String to hold the student’s first name, a string for his/her major and an int to hold the number of units taken. Getter and setter methods for each of the variables should be included in the class definition. Also...
Create a Java program for a school. Create a report containing information for a classroom. For each classroom, the report will contain: the room number, the teacher and subject to the class, and a list of students assigned to the class and their grade. Create a directory called “SchoolInfo". Create Displayable interface. The interface should declare one method Create Person (abstract) class String firstName String lastName. (other classes will implement this one) Create the Teacher class, name and subject Create...
Need help to create general
class
Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...
Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...
Write the following program in Java. Create an abstract Vehicle class - Vehicle should have a float Speed and string Name, an abstract method Drive, and include a constructor. Create a Tesla class - Tesla inherits from Vehicle. - Tesla has an int Capacity. - Include a constructor with the variables, and use super to set the parent class members. - Override Drive to increase the speed by 1 each time. - Add a toString to print the name, speed,...
JAVA Problem: Coffee Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...
In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...
Create an Item class, which is the abstract super class of all Items. Item class includes an attribute, description of type String for every item. [for eg. Book] A constructor to initialize its data member of Item class. Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details. Declare a constant RATE with value 0.25 Declare a method called calculateExtraCharge(), which returns a double value. Create the...
IN JAVA For the following questions, “define a class” means the following: • Create an appropriately-named file containing the Java class definition, including the following: – A block comment describing the file (and hence the class), as always – Any instance variables, as required by the question – Accessor (getter) and mutator (setter) methods for any instance variables – Constructors as appropriate or as required by the question – A toString method that prints instances of the class informatively –...