Assume you want to model \"house\", which can have attributes, such as address,
ID: 3761068 • Letter: A
Question
Assume you want to model "house", which can have attributes, such as address, owner, lot_size, and year_built. Model your house struct with at least three (3) attributes. Then -Define a function void initHouse (house &) that fills a house struct with some default values. -Define a function bool compareHouse(house, house) that compares two houses and returns true if they are same, or false if they are different. In you main function create two imaginary house variables and show the usage of these two functions in your code.
Explanation / Answer
First we define a structure house as shown below:
struct house {
String address, owner;
int lot_size, year_built;
};
Now we define a function that fills a house struct with some default values:
void initHouse (house &) {
house H[5];
for (int i =1 to 5) {
cout<<" Enter house "<<i<<" 's details : "
cin>>H[i].address>>H[i].owner;
cin>>H[i].lot_size>>H[i].year_built;
}
}
Now we define a function that compares two houses and returns true if they are same, or false if they are different:
bool compareHouse(house H1, house H2) {
if( (H1.address == H2.address) && (H1.owner == H2.owner) &&
(H1.lot_size == H2.lot_size) && (H1.year_built == H2.year_built) ) {
return "True";
}
else {
return "False";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.