void test7() { }
void A(doubler) { }
void B(double&b) { }
void C(constdouble&c) { }
//常成员函数的测试********************* classR { public: };
voidR::print() { }
voidR::print() const {
cout<<\调用print()const\< void print() const;//常成员函数 int R1,R2; cout< //c++;//编译错误,常量不能更改 cout< cout< private: } cout< void test8() { } //常数据成员实验**************************** classAB { public: AB(int i); constint&r; constint a; void print(); private: // const int c=9; //只有静态常量数据成员才能在类中初始化,常数据成员只能通过初始化列表获得初值 }; AB::AB(inti):a(i),r(a) { } voidAB::print() { } constintAB::b=10;//静态常数据成员的初始化 void test9() { } #include\ #include AB a1(100),a2(0); a1.print(); a2.print(); cout<<\< usingnamespace std; //多文件结构实验******************** void test10() { } //外部变量与函数的测试********************** int temp=1; void next(); void other(); void test11_12() { } void next() { } //条件编码指令的应用***************** void test13() { int j; cout<<\请输入j:\; cin>>j; cout<<\< cout<<\调用后:\< cout< cout<<\见本程序\< #if j<5 #elif j>5 #else #endif #ifndef NUM #defineNUM } cout<<\没有定义NUM\< //defined操作符的应用*************** #defineNUMM 4 #defineNUMN 3 #undef NUMN int defined(NUMM); //int defined(NUMN); void test14() { } //实验十五********************* void test15() { } #include\ #include //猫的数量************************* intCat::HowManyCats=0;//静态数据成员的定义和初始化 void test16() { } //实验十七,XYZ void test17() { X x1; Y y1; Z z1; int a1; char num[10]; cout<<\请输入现有猫的数量:\; cin>>a1; cout<<\请输入新增猫的的名字(小于10个字符):\; cin>>num; Cat A(num,a1); cout<<\猫的总数为:\< } int i; cout<<\请输入i:\; cin>>i; x1.seti(i); cout<<\< //实验十八,重量和**************************** void test18() { } float a,b; cout<<\请输入boat的重量:\; cin>>a; cout<<\请输入car的重量:\; cin>>b; Boat a1; Car b1; a1.SetBW(a); b1.SetCW(b); cout<<\和car的重量和为:\< #ifndef NUM12 #defineNUM12 classCar;//前向引用声明(注意) classBoat { public: }; classCar { public: void SetCW(floatw){weight=w;} float GetCW(){return weight;} friendfloat totalWeight(Boat&a,Car&b); void SetBW(floatw){weight=w;} float GetBW(){return weight;} friendfloat totalWeight(Boat&a,Car&b); float weight; private: private: 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库南昌大学C++语言程序设计各章实验报告(8)在线全文阅读。
相关推荐: