c课程设计职工工资管理系统.docx

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多

题目c++面向对象程序设计课程设计

清单:5小题 +职工工资管理系统(类、链表实现)

姓名:学号:

专业:计算机科学与技术

学院:

指导教师:

2018年 6月 17 日

Part1:小程序练习1类的继承

定义一个point类,包含私有数据成员x,y,成员函数包括无参构造函数,带参构造函数,set和get属性函数。定义circle类,从point类公有派生,增加数据成员半径r,成员函数包括无参构造函数,带参构造函数,计算面积函数getarea。在main函

数中定义一个circle的对象,并计算其面积。

/*

定义Point类,设置其成员函数(构造函数,拷贝构造函数和析构函数)以及setx()sety()getx()gety()四个属性函数。

定义circle类,设置其成员函数(构造函数,拷贝构造函数和析构函数)以及获取半径r的函数get_r()计算面积并获取面积的函数getarea()。

*/#includeiostream}voidset_x(intx)usingnamespacestd;classpoint{public:

*/

#includeiostream

}

voidset_x(intx)

usingnamespacestd;classpoint

{

public:

point(){}point(intx,inty)

{

//定义point类

{

this-x=x;

}

intget_x()

{

returnx;

}

voidset_y(inty)

{

this-y=y;

doubleget_r()

{

returnr;

}

intget_y()

{

returny;

}

private:

intx;

//私有对象xy

}

doublegetarea()

{

return(3.14*r*r);

}

private:

intr; //circle私有对象r

inty;

};

};

classcircle:publicpoint

{

public:

//circle类公有派生point

intmain()

{

circlec1(2,3,6);coutr=c1.get_r()endl;

circle(){}circle(doubler,intx,inty):point(x,y)

{

this-r=r; }

cout该圆面积=c1.getarea()endl;system(pause);

return0;

}

运行结果分析:

主函数中r=2,输出圆面积12.56

运算符重载,友元函数和this指针

//发现问题:定义的r好像只显示出int类型

定义一个计数器类counter,具备自增,自减功能(前后缀);输入输出,功能。

在main函数里测试该类。

/*

定义counter类,私有成员数据weight,设置其成员函数

(构造函数和析构函数)

重载自加自减运算符和、运算符。

在主函数中实现运算符重载。

友元函数需要声明。

*/#includeiostream#includecmathusingnamespacestd;classcounter;

istreamoperator(istreamis,countera);ostreamoperator(ostreamos,countera);classcounter//定义类counter

{

private:

doubleP;public:

counter(){}//无参构造函数counter(doublep):P(p){}//带参构造函数counteroperator++();//重载前置++counteroperator++(int);//重载后置++counteroperator--();//重载前置--counteroperator--(int);//重载后置--

friendistreamoperator(istreamis,countera);//声明友元,重载输入运算符

friendostreamoperator(ostreamos,countera);//

同上

};

countercounter::operator++()//前置++重载实现

{

++P;

return*this;

}

countercounter::operator++(int)//后置++重载实现

{

countera=*this;

++(*this);returna;

}

countercounter::operator--()//前置--重载实现

{

--P;

return*this;

}

countercounte

文档评论(0)

mph + 关注
官方认证
内容提供者

该用户很懒,什么也没介绍

认证主体上海谭台科技有限公司
IP属地湖北
统一社会信用代码/组织机构代码
91310115MA7CY11Y3K

1亿VIP精品文档

相关文档