1、http:/ 08 级 C+(下)上机试卷 B-答案一改错题(50 分)/*冒泡排序*/1. #include 2 ;3 int* slist 或者 int slist4 n-15 noswap6 const int h =10;7 改成 #include #include #include using namespace std;class inventorypublic:inventory();inventory();void SetParam(string ,string,int,double,double);protected:private:string Description;st
2、ring No;int Quantity;double Cost;double Retail;fstream datafile;inventory:inventory()Description=“#“;No=“#“;Quantity=0;Cost=0;http:/ 为文件所在的磁盘if (!datafile.fail()while (!datafile.eof()datafileDescription;datafileNo;datafileQuantity;datafileCost;datafileRetail;break;datafile.close();datafile.clear();
3、/ clear应放在close之后,因为如果文件打开失败,关闭时也会失败inventory:inventory()datafile.open(“mydatafile.txt“,ios:out);datafilesetw(8)Descriptionsetw(8)Nosetw(8)Quantitysetw(8)Costsetw(8)Retail;datafile.close();void inventory:SetParam(string description ,string number,int quantity,double cost,double retail)Description=description;No=number;Quantity=quantity;Cost=cost;Retail=retail;int main()inventory goods;goods.SetParam(“家电“,“10“,100,2000,3500);return 0;