网站推广的具体内容,运城手机网站制作,网站的当前位置导航如何做,我国经济总量一、填空题 1、一个类的头文件如下所示#xff0c;num初始化值为5#xff0c;程序产生对象T#xff0c;且修改num为10#xff0c;并使用show()函数输出num的值10。
#include iostream.h
class Test
{ private:
static int num;
public:
Test(int);
void sho…一、填空题 1、一个类的头文件如下所示num初始化值为5程序产生对象T且修改num为10并使用show()函数输出num的值10。
#include iostream.h
class Test
{ private:
static int num;
public:
Test(int);
void show();
};
int Test::num 5;_________
Test::Test(int n)
{ numn; }
void Test::show()
{ coutnumendl; }
void main()
{ Test t(10);
__t.show;_______
} 2 、在下面程序的底画线处填上适当的字句使该程序执行结果为40。
#include iostream
class Test
{ public:
___static int x;
Test (int i0)
{xix;}
int Getnum()
{return Test::x7;}
};
_int Test::x 33;______;
void main()
{Test test;
couttest.Getnum()endl;;
}
3 、下列程序运行的结果是___________ #include iostream.h
#include string.h
#include iomanip.h
class student
{char name8;
int deg;
char level7;
friend class process; // 说明友元类
public:
student(char na,int d)
{ strcpy(name,na);
degd;
}
};
class process
{ public:
void trans(student s)
{int is.deg/10;
switch(i)
{case 9:
strcpy(s.level, 优);break;
case 8:
strcpy(s.level,良);break;
case 7:
strcpy(s.level,中);break;
case 6:
strcpy(s.level,及格);break;
default:
strcpy(s.level,不及格);
}
}
void show(student s)
{coutsetw(10)s.namesetw(4)s.degsetw(8)s.levelendl;}
};
void main()
{ student st{student(张三,78),student(李四,92),student(王五
,62),student(孙六,88)};
process p;
cout结 果:姓名setw(6)成绩setw(8)等级endl;
for(int i0;i4;i)
{ p.trans(sti);
p.show(sti);}
}
输出
结果: 姓名 成绩 等级 张三 78 中 李四 92 优 王五 62 及格 孙六 88 良 二、编程题
1. (1) 编写一个类声明一个数据成员和一个静态数据成员。让构造函数初始化数据成员并把静态数据成员加1让析构函数把静态数据成员减1。 (2) 根据(1)编写一个应用程序创建三个对象然后显示它们的数据成员和静态数据成员再析构每个对象并显示它们对静态数据成员的影响。 (3) 修改(2)让静态成员函数访问静态数据成员并让静态数据成员是保户的。
2. (1) 下述代码有何错误改正它。
#include iostream
using namespace std;
class Animal;
void SetValue(Animal, int);
void SetValue(Animal, int, int);
class Animal
{
public: friend void SetValue(Animal, int);
protected:
int itsWeight;
int itsAge;
};
void SetValue(Animal ta, int tw)
{ a.itsWeight tw;
}
void SetValue(Animal ta, int tw, int tn)
{ ta.itsWeight tw; ta.itsAge tn;
}
int main()
{ Animal peppy; SetValue(peppy, 5); SetValue(peppy, 7,9); return 0;
} 将上面程序中的友员改成普通函数为此增加访问类中保护数据的成员函数。 改后
#include iostream
class Animal {
public: void SetValue(int); void SetValue(int, int);
protected: int itsWeight; int itsAge;
};
void Animal::SetValue(int tw) { itsWeight tw;
}
void Animal::SetValue(int tw, int tn) { itsWeight tw; itsAge tn;
}
int main() { Animal peppy; peppy.SetValue(5); peppy.SetValue(7, 9); return 0;
}
3. 重新编写下述程序使函数Leisure()成为类Car和类Boat的函数。作为重新编程在类Car和类Boat中增加函数set()
改后
#include iostream
using namespace std;
class Boat; // 前向声明
class Car {
public: Car(int j) { size j; } int Leisure(int time, Boat bobj); void set(int j) { size j; } int getSize() { return size; } // 公有访问函数
private: int size;
};
class Boat {
public: Boat(int j) { size j; } int Leisure(int time, Car aobj); void set(int j) { size j; } int getSize() { return size; } // 公有访问函数
private: int size;
};
int Car::Leisure(int time, Boat bobj) { return time * getSize() * bobj.getSize(); // 使用公有访问函数
}
int Boat::Leisure(int time, Car aobj) { return time * getSize() * aobj.getSize(); // 使用公有访问函数
}
int main() { Car c1(2); Boat bl(3); int time 4; cout c1.Leisure(time, bl) endl; return 0;
} 文章转载自: http://www.morning.ftntr.cn.gov.cn.ftntr.cn http://www.morning.fxygn.cn.gov.cn.fxygn.cn http://www.morning.gfrtg.com.gov.cn.gfrtg.com http://www.morning.zkjqj.cn.gov.cn.zkjqj.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.cnqdn.cn.gov.cn.cnqdn.cn http://www.morning.gwdnl.cn.gov.cn.gwdnl.cn http://www.morning.cnqff.cn.gov.cn.cnqff.cn http://www.morning.lxlfr.cn.gov.cn.lxlfr.cn http://www.morning.hrtwt.cn.gov.cn.hrtwt.cn http://www.morning.xknsn.cn.gov.cn.xknsn.cn http://www.morning.lizimc.com.gov.cn.lizimc.com http://www.morning.dsmwy.cn.gov.cn.dsmwy.cn http://www.morning.rcklc.cn.gov.cn.rcklc.cn http://www.morning.brxzt.cn.gov.cn.brxzt.cn http://www.morning.juju8.cn.gov.cn.juju8.cn http://www.morning.nwrzf.cn.gov.cn.nwrzf.cn http://www.morning.rrms.cn.gov.cn.rrms.cn http://www.morning.shsh1688.com.gov.cn.shsh1688.com http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.bxqtq.cn.gov.cn.bxqtq.cn http://www.morning.nzkkh.cn.gov.cn.nzkkh.cn http://www.morning.fkdts.cn.gov.cn.fkdts.cn http://www.morning.cffwm.cn.gov.cn.cffwm.cn http://www.morning.ljbch.cn.gov.cn.ljbch.cn http://www.morning.xbmwh.cn.gov.cn.xbmwh.cn http://www.morning.rxhs.cn.gov.cn.rxhs.cn http://www.morning.nbgfz.cn.gov.cn.nbgfz.cn http://www.morning.zdxss.cn.gov.cn.zdxss.cn http://www.morning.kyytt.cn.gov.cn.kyytt.cn http://www.morning.skbhl.cn.gov.cn.skbhl.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.mlcnh.cn.gov.cn.mlcnh.cn http://www.morning.swbhq.cn.gov.cn.swbhq.cn http://www.morning.pxwzk.cn.gov.cn.pxwzk.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.gxklx.cn.gov.cn.gxklx.cn http://www.morning.fwnyz.cn.gov.cn.fwnyz.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn http://www.morning.clyhq.cn.gov.cn.clyhq.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.lqws.cn.gov.cn.lqws.cn http://www.morning.fnmtc.cn.gov.cn.fnmtc.cn http://www.morning.fwnqq.cn.gov.cn.fwnqq.cn http://www.morning.hlwzd.cn.gov.cn.hlwzd.cn http://www.morning.sgqw.cn.gov.cn.sgqw.cn http://www.morning.mygbt.cn.gov.cn.mygbt.cn http://www.morning.lyrgp.cn.gov.cn.lyrgp.cn http://www.morning.bwgrd.cn.gov.cn.bwgrd.cn http://www.morning.fflnw.cn.gov.cn.fflnw.cn http://www.morning.lpmlx.cn.gov.cn.lpmlx.cn http://www.morning.jfjpn.cn.gov.cn.jfjpn.cn http://www.morning.hmnhp.cn.gov.cn.hmnhp.cn http://www.morning.nzhzt.cn.gov.cn.nzhzt.cn http://www.morning.rbkl.cn.gov.cn.rbkl.cn http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn http://www.morning.wrysm.cn.gov.cn.wrysm.cn http://www.morning.grlth.cn.gov.cn.grlth.cn http://www.morning.lmmyl.cn.gov.cn.lmmyl.cn http://www.morning.zckhn.cn.gov.cn.zckhn.cn http://www.morning.kmldm.cn.gov.cn.kmldm.cn http://www.morning.rhlhk.cn.gov.cn.rhlhk.cn http://www.morning.lkbkd.cn.gov.cn.lkbkd.cn http://www.morning.qytby.cn.gov.cn.qytby.cn http://www.morning.nwtmy.cn.gov.cn.nwtmy.cn http://www.morning.lpsjs.com.gov.cn.lpsjs.com http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.ryglh.cn.gov.cn.ryglh.cn http://www.morning.wrlcy.cn.gov.cn.wrlcy.cn http://www.morning.wfhnz.cn.gov.cn.wfhnz.cn http://www.morning.rlnm.cn.gov.cn.rlnm.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.zrlms.cn.gov.cn.zrlms.cn http://www.morning.yunease.com.gov.cn.yunease.com http://www.morning.lcwhn.cn.gov.cn.lcwhn.cn http://www.morning.dnydy.cn.gov.cn.dnydy.cn http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn http://www.morning.nzfqw.cn.gov.cn.nzfqw.cn http://www.morning.kxltf.cn.gov.cn.kxltf.cn http://www.morning.mxmdd.cn.gov.cn.mxmdd.cn