Home > Software engineering >  This can change, can't, aye
This can change, can't, aye

Time:09-17

# include
# 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; iN +=mHouse [I]. Getprice ();
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; exit(1);
}
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:

Redefinition of the default parameter, the tip is not very understand

CodePudding user response:

reference 1st floor Xu Wenjun response:
redefinition of the default parameter, the tip is not very understand yao

But I feel function not wrong

CodePudding user response:

CHouse: : CHouse (char * name, float price, float area)
{
If (the name!=NULL) strcpy (mName, name);
MPrice=price;
MArea=area;
}

CodePudding user response:

Don't need the default parameters, why?

CodePudding user response:

The
reference 3 floor Xu Wenjun response:
CHouse: : CHouse (char * name, float price, float area)
{
If (the name!=NULL) strcpy (mName, name);
MPrice=price;
MArea=area;
}

The default parameters do not need?
The following call no and structure

CodePudding user response:

Default arguments specified cannot be repeated

CodePudding user response:

refer to 6th floor Xu Wenjun response:
default parameters cannot be repeated specify

Ok, get, thank you, could you help me put the following wrong also change, file stream command of this aspect is really bad