c课程设计职工工资管理系统
- 格式:docx
- 大小:30.11 KB
- 文档页数:25
题目 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