Write the definition of the member function set so that private members are set
ID: 3765726 • Letter: W
Question
Write the definition of the member function set so that private members are set according to the parameters. Write the definition of the member function print that prints the values of the data members. Write the definition of the constructor of the class houseType so that the private member variables arc initialized according to the parameters. Write a C + + statement that prints the value of the object newHouse. Write a C++ statement that declares an object house of type newHouse, and initializes the member variables of house to "Ranch", 3. 2. 2, 2005, 1300, 185000. and 3600.0. respectively. Which function members are accessors and which are mutators?Explanation / Answer
As per the given C++ class definition and problem statement
I have define definition of all the methods including setters and getters and constructor
and print function also. I removed the const keyword for print function because it will not access the non
const data members of class. so it is not applicable.. see the below c++ code and i have written the good commnets
to understand the what code is doing
#include <iostream>
using namespace std;
class houseType
{
public:
// Answer for Question c) is houseType constructor definition to initialize the class private
//data members
houseType(string style1 = " ", int bedRooms = 0, int bathRooms = 0, int carGarage = 0, int year = 0, int footage = 0, double cost = 0, double tax1 = 0)
{
style = style1;
numOfBedRooms = bedRooms;
numofBathRoooms = bathRooms;
numofCarsGarage = carGarage;
yearBuilt = year;
finishedSqaureFootage = footage;
price = cost;
tax = tax1;
}
// Answer for Question B is below
// Print the private data members of houseType class.
// Here Removed the const key workd because it is access the const data members..
void print()
{
cout<<"House Style is :"<<style<<endl;
cout<<"House Num of BedRooms are :"<<numOfBedRooms<<endl;
cout<<"House Num of BathRooms are :"<<numofBathRoooms<<endl;
cout<<"House Num of CarGarage are :"<<numofBathRoooms<<endl;
cout<<"House Year of Construction is :"<<yearBuilt;
cout<<"House Num of FinishedFootage is :"<<finishedSqaureFootage<<endl;
cout<<"House Price is :"<<price<<endl;
cout<<"House Tax is :"<<tax<<endl;
}
// Answer for Question A is below
// Set the Values to private data members of a houseType class
void set(string style1, int bedRooms, int bathRooms, int carGarage, int year, int footage, double cost, double tax1)
{
style = style1;
numOfBedRooms = bedRooms;
numofBathRoooms = bathRooms;
numofCarsGarage = carGarage;
yearBuilt = year;
finishedSqaureFootage = footage;
price = cost;
tax = tax1;
}
// Set the House Style Model
void setStyle(string style1)
{
style = style1;
}
// Return the House Style Model
string getStyle() const
{
return style;
}
// Set the Num of BedRooms
void setNumofBedRooms(int bedRooms)
{
numOfBedRooms = bedRooms;
}
// Return the Num of BedRooms
int getNumofBedRooms() const
{
return numOfBedRooms;
}
// Set the Num of BathRooms
void setNumofBathRooms(int bathRooms)
{
numofBathRoooms = bathRooms;
}
// Return the Num of BathRooms
int getNumofBathRooms(int ) const
{
return numofBathRoooms;
}
// Set the Num of Car Garages
void setNumofCarsGarage(int carGarage)
{
numofCarsGarage = carGarage;
}
// Return the Num of Car Garages
int getNumofCardGarage() const
{
return numofCarsGarage;
}
// Set the house built year
void setYearBuilt(int year)
{
yearBuilt = year;
}
// Return the house built year
int getYearBuillt() const
{
return yearBuilt;
}
// Set the FinishedSqaureFootage
void setFinishedSqaureFootage(int footage)
{
finishedSqaureFootage = footage;
}
// Return the FinishedSqaureFootage
int getFinishedSqaureFootage(int ) const
{
return finishedSqaureFootage;
}
// Set the House price
void setPrice(double cost)
{
price = cost;
}
// Return the House price
double getPrice(double ) const
{
return price;
}
// Set the House Tax
void setTax(double tax1)
{
tax = tax1;
}
// Return the House Tax
double getTax() const
{
return tax;
}
private:
string style;
int numOfBedRooms;
int numofBathRoooms;
int numofCarsGarage;
int yearBuilt;
int finishedSqaureFootage;
double price;
double tax;
};
int main()
{
// Answer for Question D is below
// Defined newHouse object of houseType class
houseType newHouse;
newHouse.print(); // Print the newHouse Data members through the print method
// Answer for Question E is below
// Defined house object of houseType class
houseType house("Raneh",3,2,2,2005,1300,185000.0,3600.0);
house.print(); // Print the house data members through the print method
return 1;
}
Answer for Question E is below:
Setters: Below list of functions are setters
setStyle()
setNumofBedRooms()
setNumofBathRooms()
setNumofCardGarage()
setFinishedSqaureFootage()
setPrice()
setTax()
Mutors: Below list of functions are Mutors
getStyle()
getNumofBedRooms()
getNumofBathRooms()
getNumofCardGarage()
getFinishedSqaureFootage()
getPrice()
getTax()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.