欢迎来到天天文库
浏览记录
ID:12047403
大小:19.17 KB
页数:11页
时间:2018-07-15
《c++程序设计实验辅导及习题解答-实验》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验十一任务1:程序调试。类静态数据的应用。下列程序设计了一个职工类,职工类中包括职工姓名、薪水和所有职工的薪水总和allSalary。薪水总和员是所有职工对象薪水的统计和,它属于类而不属于某个对象,因而设置为static数据。程序为:#include"stdafx.h"#includeusingnamespacestd;#includeclassEmployee{private:charname[30];floatsalary;staticfloatallSalary;publi
2、c:Employee(char*n,floats){strcpy(name,n);salary=s;allSalary=allSalary+salary;}~Employee(void){}staticfloatGetAllSalary(void){returnallSalary;}};floatEmployee::allSalary=0;voidmain(void){Employeee1("张三",4500);Employeee2("王五",5200);Employeee3("李四",2450);floatall;al
3、l=Employee::GetAllSalary();cout<<"AllSalary="<usingnamespacestd
4、;#includeclasspeople{private:charname[30];floatsalary;staticfloatallSalary;public:people(char*n,floats){strcpy(name,n);salary=s;allSalary=allSalary-salary;}~people(void){}staticfloatGetAllSalary(void){returnallSalary;}};floatpeople::allSalary=10000;void
5、main(void){peoplee1("A",1000);peoplee2("B",500);peoplee3("C",2000);peoplee4("D",1800);floatall;all=people::GetAllSalary();cout<<"访问一次后还剩现金为:"<usingnamespacestd;#includeclassPoint{publi
6、c:Point(doublexx,doubleyy){x=xx;y=yy;}voidGetxy();frienddoubleDistance(Point&a,Point&b);private:doublex,y;};voidPoint::Getxy(){cout<<"("<7、ointp1(3.0,4.0),p2(6.0,8.0);p1.Getxy();p2.Getxy();doubled=Distance(p1,p2);cout<<"Distanceis"<8、:#include#includeclassvector{private:doublex,y;public:vector(doublea,doubleb){x=a;y=b;}frienddoubleb(constvector&s,constvector&s1);frienddo
7、ointp1(3.0,4.0),p2(6.0,8.0);p1.Getxy();p2.Getxy();doubled=Distance(p1,p2);cout<<"Distanceis"<8、:#include#includeclassvector{private:doublex,y;public:vector(doublea,doubleb){x=a;y=b;}frienddoubleb(constvector&s,constvector&s1);frienddo
8、:#include#includeclassvector{private:doublex,y;public:vector(doublea,doubleb){x=a;y=b;}frienddoubleb(constvector&s,constvector&s1);frienddo
此文档下载收益归作者所有