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

  • 格式:docx
  • 大小:30.11 KB
  • 文档页数:25

下载文档原格式

  / 25
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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

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

姓名:

学号:

专业:计算机科学与技术

学院:

指导教师:

2018年6月17日

Part 1: 小程序练习

1 类的继承

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

/*

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

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

3.在主函数中定义类的对象c1并初始化r=2。再调用getarea()函数输出面积

*/

#include

using namespace std;

class point //定义point类

{

public:

point() {}point(int x, int y) {

}

void set_x(int x) {

this->x = x;

}

int get_x()

{

return x;

}

void set_y(int y)

{

this->y = y;

}

int get_y()

{

return y;

}

private: //私有对象x y int x;

int y;

};

class circle :public point //circle类公有派生point

{

public:

circle() {}

circle(double r,int x,int y):point(x,y)

{

this->r = r;

}

double get_r() {

return r;

}

double getarea()

{

return(3.14*r*r);

}

private:

int r;

//circle私有对象r

};

int main()

{

circle c1(2,3,6);

cout<<"r="<

cout << "该圆面积

="<

system("pause");

return 0;

}

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

int类型

运行结果分析:

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

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

定义一个计数器类counter,具备自增,自减功能(前后缀);输入输出>>,<<功能。在main函数里测试该类。

/*

1.定义counter类,私有成员数据weight,设置其成员函数(构造函数和析构函数)

2.重载自加自减运算符和<<、>>运算符。

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

4.友元函数需要声明。

*/ #include #include using namespace std; class counter; istream& operator>>(istream& is,counter& a); ostream& operator<<(ostream& os,counter& a); class counter //定义类counter { private: double P; public: counter(){} //无参构造函数 counter(double p):P(p){} //带参构造函数 counter operator ++(); //重载前置++ counter operator ++(int); //重载后置++ counter operator --(); //重载前置-- counter operator --(int); //重载后置-- friend istream& operator>>(istream& is,counter& a); //声明友元,重载输入运算符>> friend ostream& operator<<(ostream& os,counter& a); //同上 }; counter counter::operator ++() //前置++重载实现 { ++P; return *this; } counter counter::operator ++(int) //后置++重载实现 { counter a=*this; ++(*this); return a; } counter counter::operator --() //前置--重载实现 { --P; return *this; } counter counter::operator --(int) //后置--重载实现 { counter a=*this; --(*this); return a; } istream& operator>>(istream& in,counter& a) //运算符>>重载实现 { in>>a.P; if(!in) cerr<<"输入错误!"<