Classcode 9- struct houseInfo { int noBedRoom; int noBathRoom; int noGarage; int
ID: 3721151 • Letter: C
Question
Classcode 9- struct houseInfo { int noBedRoom; int noBathRoom; int noGarage; int yearBuilt; double housePrice; string style; }; void readIN(houseInfo x[], int size); void print(houseInfo x[], int size);int main() { houseInfo house[3];
readIN(house, 3); print(house, 3);
system("pause"); return 0; }
void readIN(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"Enter in the no of Bathrooms for house "<<i+1<<endl; cin>>x[i].noBathRoom; cout<<"Enter in the no of Bedrooms for house "<<i+1<<endl; cin>>x[i].noBedRoom; cout<<"Enter in the no of Garages for house "<<i+1<<endl; cin>>x[i].noGarage; cout<<"Enter in the year the house "<<i+1<<" was built"<<endl; cin>>x[i].yearBuilt; cout<<"Enter in the price of house "<<i+1<<endl; cin>>x[i].housePrice; cout<<"Enter in the style of house "<<i+1<<endl; cin>>x[i].style; }
}
void print(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"House "<<i+1<<endl;
cout<<x[i].noBathRoom<<" "<<x[i].noBedRoom<<" "<<x[i].noGarage<<" " <<x[i].yearBuilt<<" "<<x[i].housePrice<<" "<<x[i].style<<endl<<endl; }
} ————————
2. Using the structure given in classcode9, write a C++ program that adds the following functions. Also increase the maximum number of houses to 20.
a) Rewrite the readin function to read in the house details from a file. (Have a minimum of 10 houses and maximum of 15 houses). Style could be switched between apartment, townhouse, bungalow, mansion, duplex.
b) A function that takes in a year as an integer input and the list of houses, and outputs all the styles built after that year
c) A function that takes in a year and the house list and returns true if a house was built that year and false otherwise
d) A function that takes in a year as an integer input and the list of houses, and outputs the the name of the most frequent house style built before that year.
e) A function that takes in two houses and returns true if the are of the same size. Two houses are of the same size if the have the same no of bathrooms, bedrooms and garages
f) A function that takes in the house list and a house style and returns the average price of houses of that style.
g) A function that takes in a house and adds it to the house list
h) A function that takes in the house list and returns the number of houses with the similar sizes (Hint a nested loop will be needed) Classcode 9- struct houseInfo { int noBedRoom; int noBathRoom; int noGarage; int yearBuilt; double housePrice; string style; }; void readIN(houseInfo x[], int size); void print(houseInfo x[], int size);
int main() { houseInfo house[3];
readIN(house, 3); print(house, 3);
system("pause"); return 0; }
void readIN(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"Enter in the no of Bathrooms for house "<<i+1<<endl; cin>>x[i].noBathRoom; cout<<"Enter in the no of Bedrooms for house "<<i+1<<endl; cin>>x[i].noBedRoom; cout<<"Enter in the no of Garages for house "<<i+1<<endl; cin>>x[i].noGarage; cout<<"Enter in the year the house "<<i+1<<" was built"<<endl; cin>>x[i].yearBuilt; cout<<"Enter in the price of house "<<i+1<<endl; cin>>x[i].housePrice; cout<<"Enter in the style of house "<<i+1<<endl; cin>>x[i].style; }
}
void print(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"House "<<i+1<<endl;
cout<<x[i].noBathRoom<<" "<<x[i].noBedRoom<<" "<<x[i].noGarage<<" " <<x[i].yearBuilt<<" "<<x[i].housePrice<<" "<<x[i].style<<endl<<endl; }
} ————————
2. Using the structure given in classcode9, write a C++ program that adds the following functions. Also increase the maximum number of houses to 20.
a) Rewrite the readin function to read in the house details from a file. (Have a minimum of 10 houses and maximum of 15 houses). Style could be switched between apartment, townhouse, bungalow, mansion, duplex.
b) A function that takes in a year as an integer input and the list of houses, and outputs all the styles built after that year
c) A function that takes in a year and the house list and returns true if a house was built that year and false otherwise
d) A function that takes in a year as an integer input and the list of houses, and outputs the the name of the most frequent house style built before that year.
e) A function that takes in two houses and returns true if the are of the same size. Two houses are of the same size if the have the same no of bathrooms, bedrooms and garages
f) A function that takes in the house list and a house style and returns the average price of houses of that style.
g) A function that takes in a house and adds it to the house list
h) A function that takes in the house list and returns the number of houses with the similar sizes (Hint a nested loop will be needed) Classcode 9- struct houseInfo { int noBedRoom; int noBathRoom; int noGarage; int yearBuilt; double housePrice; string style; }; void readIN(houseInfo x[], int size); void print(houseInfo x[], int size);
int main() { houseInfo house[3];
readIN(house, 3); print(house, 3);
system("pause"); return 0; }
void readIN(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"Enter in the no of Bathrooms for house "<<i+1<<endl; cin>>x[i].noBathRoom; cout<<"Enter in the no of Bedrooms for house "<<i+1<<endl; cin>>x[i].noBedRoom; cout<<"Enter in the no of Garages for house "<<i+1<<endl; cin>>x[i].noGarage; cout<<"Enter in the year the house "<<i+1<<" was built"<<endl; cin>>x[i].yearBuilt; cout<<"Enter in the price of house "<<i+1<<endl; cin>>x[i].housePrice; cout<<"Enter in the style of house "<<i+1<<endl; cin>>x[i].style; }
}
void print(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"House "<<i+1<<endl;
cout<<x[i].noBathRoom<<" "<<x[i].noBedRoom<<" "<<x[i].noGarage<<" " <<x[i].yearBuilt<<" "<<x[i].housePrice<<" "<<x[i].style<<endl<<endl; }
} ————————
2. Using the structure given in classcode9, write a C++ program that adds the following functions. Also increase the maximum number of houses to 20.
a) Rewrite the readin function to read in the house details from a file. (Have a minimum of 10 houses and maximum of 15 houses). Style could be switched between apartment, townhouse, bungalow, mansion, duplex.
b) A function that takes in a year as an integer input and the list of houses, and outputs all the styles built after that year
c) A function that takes in a year and the house list and returns true if a house was built that year and false otherwise
d) A function that takes in a year as an integer input and the list of houses, and outputs the the name of the most frequent house style built before that year.
e) A function that takes in two houses and returns true if the are of the same size. Two houses are of the same size if the have the same no of bathrooms, bedrooms and garages
f) A function that takes in the house list and a house style and returns the average price of houses of that style.
g) A function that takes in a house and adds it to the house list
h) A function that takes in the house list and returns the number of houses with the similar sizes (Hint a nested loop will be needed) Classcode 9- struct houseInfo { int noBedRoom; int noBathRoom; int noGarage; int yearBuilt; double housePrice; string style; }; void readIN(houseInfo x[], int size); void print(houseInfo x[], int size);
int main() { houseInfo house[3];
readIN(house, 3); print(house, 3);
system("pause"); return 0; }
void readIN(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"Enter in the no of Bathrooms for house "<<i+1<<endl; cin>>x[i].noBathRoom; cout<<"Enter in the no of Bedrooms for house "<<i+1<<endl; cin>>x[i].noBedRoom; cout<<"Enter in the no of Garages for house "<<i+1<<endl; cin>>x[i].noGarage; cout<<"Enter in the year the house "<<i+1<<" was built"<<endl; cin>>x[i].yearBuilt; cout<<"Enter in the price of house "<<i+1<<endl; cin>>x[i].housePrice; cout<<"Enter in the style of house "<<i+1<<endl; cin>>x[i].style; }
}
void print(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"House "<<i+1<<endl;
cout<<x[i].noBathRoom<<" "<<x[i].noBedRoom<<" "<<x[i].noGarage<<" " <<x[i].yearBuilt<<" "<<x[i].housePrice<<" "<<x[i].style<<endl<<endl; }
} void readIN(houseInfo x[], int size); void print(houseInfo x[], int size);
int main() { houseInfo house[3];
readIN(house, 3); print(house, 3);
system("pause"); return 0; }
void readIN(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"Enter in the no of Bathrooms for house "<<i+1<<endl; cin>>x[i].noBathRoom; cout<<"Enter in the no of Bedrooms for house "<<i+1<<endl; cin>>x[i].noBedRoom; cout<<"Enter in the no of Garages for house "<<i+1<<endl; cin>>x[i].noGarage; cout<<"Enter in the year the house "<<i+1<<" was built"<<endl; cin>>x[i].yearBuilt; cout<<"Enter in the price of house "<<i+1<<endl; cin>>x[i].housePrice; cout<<"Enter in the style of house "<<i+1<<endl; cin>>x[i].style; }
}
void print(houseInfo x[], int size) { for(int i = 0; i < size; i++) { cout<<"House "<<i+1<<endl;
cout<<x[i].noBathRoom<<" "<<x[i].noBedRoom<<" "<<x[i].noGarage<<" " <<x[i].yearBuilt<<" "<<x[i].housePrice<<" "<<x[i].style<<endl<<endl; }
} ————————
2. Using the structure given in classcode9, write a C++ program that adds the following functions. Also increase the maximum number of houses to 20.
a) Rewrite the readin function to read in the house details from a file. (Have a minimum of 10 houses and maximum of 15 houses). Style could be switched between apartment, townhouse, bungalow, mansion, duplex.
b) A function that takes in a year as an integer input and the list of houses, and outputs all the styles built after that year
c) A function that takes in a year and the house list and returns true if a house was built that year and false otherwise
d) A function that takes in a year as an integer input and the list of houses, and outputs the the name of the most frequent house style built before that year.
e) A function that takes in two houses and returns true if the are of the same size. Two houses are of the same size if the have the same no of bathrooms, bedrooms and garages
f) A function that takes in the house list and a house style and returns the average price of houses of that style.
g) A function that takes in a house and adds it to the house list
h) A function that takes in the house list and returns the number of houses with the similar sizes (Hint a nested loop will be needed)
Explanation / Answer
As per the policy i have done 4 parts, if i get answers to other ones i will definitly post it.
void partb(int year, houseInfo x[], int size)
{
for(int i = 0; i < size; i++)
{
if(x[i].yearBuilt>year)
cout<<x[i].style<<endl;
}
}
bool partc(int year, houseInfo x[], int size)
{
for(int i = 0; i < size; i++)
{
if(x[i].yearBuilt==year)
return true;
}
return false;
}
bool parte(houseInfo a, houseInfo b)
{
if(a.noBedRoom==b.noBedRoom && a.noGarage==b.noGarage && a.noBathRoom==b.noBathRoom)
return true;
return false;
}
double partf(houseInfo x[], string style)
{
double sum=0;
int cnt=0;
for(int i = 0; i < size; i++)
{
if(x[i].style==style)
{
sum+=(1.0*x[i].housePrice);
cnt++;
}
}
return sum/(cnt*1.0);
}