# include
# include
The class CHouse
{
Private:
Char mName [20].//address
Float mPrice;//unit price
Float mArea.//area
Public:
Float getprice ()
{
Return mPrice;
}
Float getarea ()
{
Return mArea.
}
Void the set (char * name, float price, float area);//modify housing parameter
CHouse (char * name=0, float price=0, float area=0).//the constructor
Friend ifstream& Operator> (ifstream& Is and CHouse & amp; House);//read from the file a house parameter
};
Void CHouse: : set (char * name, float price, float area)
{
Strcpy (mName, name);
MPrice=price;
MArea=area;
}
CHouse: : CHouse (char * name=0, float price=0, float area=0)
{
If (the name!=NULL) strcpy (mName, name);
MPrice=price;
MArea=area;
}
Ifstream& Operator> (ifstream& Is and CHouse & amp; House)
{
Is> House. MName> House. MPrice> House.
MArea.
The return is;
}
The class CBuilding//building
{
Private:
CHouse mHouse [20].
Int mNums;
Public:
CBuilding ()
{
MNums=0;
}
Float Total ();//calculate the total value of all home building
Void AddHouse (char * name, float price, float area);//add to the building to the building
Void ReadData (char * filename);//the building information read from the file
};
Float CBuilding: : Total ()
{
Float n;
for(int i=0; i
return n;
}
Void CBuilding: : AddHouse (char * name, float price, float area)
{
MHouse [mNums]=CHouse (name, price, area);
MNums++;
}
Void CBuilding: : ReadData (char * filename)
{
Char buff [20].
Ifstream infile (filename);
if(! Infile)
{
Cout<& lt;" Cannot open input file: "& lt;
}
int i=0;
While (infile. Getline (buff, 20)) {
If (I==0) cin> MNums;
The else {
Cin> MHouse [mNums];
i++;
MNums++; }}
Infile. Close ();
}
Void main ()
{
CBuilding Building;
Building. ReadData (" data. TXT ");
Building. AddHouse (" 507 ", 23000);
Cout<& lt;" Total housing: "& lt;
CodePudding user response:
For bosses to give directions rookieCodePudding user response:
https://docs.microsoft.com/zh-cn/previous-versions/00hh13h0%28v%3dvs.110%29CodePudding user response: