Consider the declaration of the struct house type given below: struct house Type
ID: 3673592 • Letter: C
Question
Consider the declaration of the struct house type given below: struct house Type {string style; int numOfBcdrooms; int numOfBathrooms; int numOfCarsGarage; double price; } write C++ statements to do the following: Declare variables oldHouse and newHouse of type housetype. Store the following infomlation into oldHouse: Style-Two-story, number of bedrooms-5, number of bathrooms-3, number of cars garage-4, price 675000, and Copy the values of the components of oldHouse into the corresponding components of newHouse. Write a C++ function, getHouselnput to read and store data into a variable of houseType. Write a C++ function, printHouselnfo to output data stored into a variable of houseType. Use appropriate labels to identify each component.Explanation / Answer
a. We can create an objects of the given names in the main() method of C++ . The syntax is as follows :
struct houseType oldHouse,newHouse ;
b. We can use following syntax :
oldHouse.style = "Two-story";
oldHouse.noOfBedrooms = 5;
oldHouse.noOfBathrooms= 3;
oldHouse.noOfGarageCar= 4;
oldHouse.price = 675000;
C. The following syntax will copy the value of two objects :
newHouse=oldHouse ;
D. Following is the function :
Void getHouseInput ()
{
Cout << " enter house style , number of bedrooms , no of bathrooms , price , no of cars garage " << endl ;
Cin >> newHouse.style;
Cin >> newHouse.noOfBedrooms:
Cin>> newHouse.noOfBathrooms;
Cin >> newHouse.price;
Cin >> newHouse.noOfGarageCars:
}
E. Following is the function :
void printHouseInfo()
{
Cout << " enter house style , number of bedrooms , no of bathrooms , price , no of cars garage " << endl ;
Cout<< newHouse.style;
Cout << newHouse.noOfBedrooms:
cout << newHouse.noOfBathrooms;
cout <<newHouse.price;
cout <<newHouse.noOfGarageCars:
}