- 博客(83)
- 收藏
- 关注
原创 11.4.3
#include using namespace std;class Point{public: Point(double x=0,double y=0); //构造函数 void setPoint(double,double); //设置坐标值 double getX( ) const {return x;}
2014-06-08 12:49:17 461
原创 11.4.2
#include using namespace std;class Point{ public: Point(double xx=0,double yy=0):x(xx),y(yy){} friend ostream&operator<<(ostream &,const Point &); protected: double x,
2014-06-08 12:48:47 529
原创 11.4.1
/*由基类的设计和测试开始,逐渐地完成各个类的设计,求出圆格柱体的表面积、体积并输出并且完成要求的计算任务: (1)先建立一个Point(点)类,包含数据成员x,y(坐标点), 实现需要的成员函数,并设计main函数完成测试;*/#include using namespace std;class Point{public: Poi
2014-06-08 12:48:18 666
原创 15.2
/*文件score.dat中保存的是若干名学生的姓名和C++课、高数和英语成绩。(1)定义学生类,其中包含姓名、C++课、高数和英语成绩及总分数据成员,成员函数根据需要确定。2)用对象数组进行存储学生的成绩,读入成绩并计算总分;将总分高于平均总分且没挂科的同学的信息保存到文件pass_score.dat中*/#include #include using n
2014-06-08 12:44:22 737
原创 15.1.3
#include #include #include using namespace std;int main(){ double salarys[500]; ifstream infile("salary.txt",ios::in); if(!infile) { cerr<<"open error!"<<end
2014-06-06 17:07:35 537
原创 15.1.2
#include #include #include //支持freopen的头文件#include using namespace std;int main( ){ freopen("a.txt","r",stdin); double salarys[500]; int n=0; while(cin>>salarys[n])
2014-06-04 18:38:33 640
原创 15.1.1
#include #include using namespace std;int main( ){ double salarys[500]; int n=0; while(cin>>salarys[n]) { n++; //从cin流读取数据 } //将n名职工的工资排序后输出 for(i
2014-06-03 18:44:04 561
原创 14.3
/*设计一个抽象类CSolid,含有两个求表面积及体积的纯虚函数。设计个派生类CCube、CBall、CCylinder,分别表示正方体、球体及圆柱体。在main()函数中,定义基类的指针p(CSolid *p;),利用p指针,输出正方体、球体及圆柱体对象的表面积及体积。*/#include using namespace std;class CSolid{
2014-05-29 20:11:56 798
原创 14.2
#include using namespace std;class Shape{ public: virtual double area()=0;};class Circle:public Shape{ public: Circle(double r):R(r){} virtual double area();
2014-05-29 19:32:51 1184
原创 14.1
#include #include using namespace std;class Animal{public: Animal(string nam):name(nam){} virtual void cry()=0; protected: string name;};class Mouse:public Animal{
2014-05-29 19:08:31 685
原创 14.1
#include #include using namespace std;class Animal{public: virtual void cry()=0;};class Mouse:public Animal{ public: Mouse(string nam,char s):name(nam),sex(s){} vir
2014-05-29 18:58:05 654
原创 14.1
#include using namespace std;class Animal{public: Animal(string nam):name(nam){} virtual void cry() { cout<<"不知哪种动物,让我如何学叫?"<<endl; }protected: string name;};c
2014-05-29 18:52:07 788
原创 13.3
#include #includeusing namespace std;class Circle; //由于在Point中声明友元函数crossover_point中参数中用了Circle,需要提前声明class Point{ public: Circle(double xx,double yy):x(xx),y(yy){} friend os
2014-05-28 17:22:42 668
原创 13.2
/*(1)先建立一个Point(点)类,包含数据成员x,y(坐标点);(2)以Point为基类,派生出一个Circle(圆)类,增加数据成员(半径),基类的成员表示圆心;(3)编写上述两类中的构造、析构函数及必要运算符重载函数(本项目主要是输入输出);(4)定义友元函数int locate,判断点p与圆的位置关系(返回值0 圆外); 在项目1的基础上,在圆类上重载关系运算符(
2014-05-27 14:56:04 759
原创 acm.2
#include #include using namespace std;class Complex{public:Complex():real(0),imag(0) {}Complex(double r,double i):real(r),imag(i) {}Complex operator+(Complex &);Complex operator+(d
2014-05-27 09:14:07 470
原创 13.1
#include using namespace std;class Point{ public: Point(double xx,double yy):x(xx),y(yy){} void display() { cout<<"("<<x<<","<<y<<")"; } protected: d
2014-05-27 09:12:41 715
原创 12.3
#include #include#include using namespace std;enum vehicleStaus {rest, running}; //车辆状态:泊车、行进class vehicle //车辆类{protected: int maxSpeed; //最大车速 int currentSpeed; //当前速度
2014-05-19 18:22:37 440
原创 12.2
#include using namespace std;class Teacher{public:Teacher(string nam,int a,char s,string ad,string c,string t);void display();protected: string name; int age; char sex;
2014-05-19 10:26:20 632
原创 12.1.3
#include using namespace std;class Animal{public: Animal() {} void eat() { cout << "eat\n"; }protected: void play() { cout << "play\n"; }
2014-05-13 15:27:51 702
原创 12.1.2
#include using namespace std;class Animal{public: Animal() {} void eat() { cout << "eat\n"; }protected: void play() { cout << "play\n"; }
2014-05-13 15:22:52 890
原创 12.1.1
#include using namespace std;class Animal //动物类{public: Animal() {} void eat(){ cout << "eat\n"; }protected: void play() { cout << "play\n";
2014-05-13 15:18:28 403
原创 点派生类直线
#include#includeusing namespace std;class Point //定义坐标点类{public: Point():x(0),y(0) {}; Point(double x0, double y0):x(x0), y(y0) {}; void PrintPoint(); //输出点的信息 double get
2014-05-13 15:01:28 454
原创 职员有薪水了
#include using namespace std;class CPerson{protected: string m_szName; string m_szId; int m_nSex;//0:women,1:man int m_nAge;public: CPerson(string name,string id,i
2014-05-13 09:40:37 473
原创 11.1
#include using namespace std;class Stu //声明基类{public: Stu(int n, string nam ); //基类构造函数 void display( ); //成员函数,输出基类数据成员protected: //(*)访问权限为保护型的数据成员 int num;
2014-05-11 22:10:30 443
原创 9.2
#include using namespace std;class CTime{private: unsigned short int hour; // 时 unsigned short int minute; // 分 unsigned short int second; // 秒public: CTime(int h=0,int m=0,
2014-05-11 21:10:48 514
原创 9.1
#include using namespace std;class Complex{public: Complex() { real=0; imag=0; } Complex(double r,double i) { real=r; imag=i;
2014-05-11 21:10:10 400
原创 8.3
#include using namespace std;class CFraction{private: int nume; // 分子 int deno; // 分母public: //构造函数及运算符重载的函数声明 CFraction(int nu=0,int de=1):nume(nu),deno(de) {}
2014-04-22 16:31:19 418
原创 8.2
#include using namespace std;class CTime{private: unsigned short int hour; // 时 unsigned short int minute; // 分 unsigned short int second; // 秒public: CTime(int h=0,
2014-04-21 11:13:28 553
原创 8.1.1
#include using namespace std;//请用类的成员函数,定义复数类重载运算符+、-、*、/,使之能用于复数的加减乘除class Complex{public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r; imag=i;} Complex
2014-04-21 10:30:05 405
原创 8.1.2友元函数
#include using namespace std;class Complex{public: Complex() { real=0; imag=0; } Complex(double r,double i) { real=r; imag=i;
2014-04-21 10:25:10 392
原创 7.2
#includeusing namespace std;class A{private: int *arrayAddr;//保存一个有len个整型元素的数组的首地址 int len; //记录动态数组的长度 int max; //动态数组中的最大值(并非动态数组中必须要的数据成员)public: A(int *a,
2014-04-21 10:17:50 416
原创 成员函数友元函数和一般函数区别
/* * 作 者: 丁露* 完成日期:2014 年4月15日 * 版 本 号:v1.0 * 问题描述:成员函数、友元函数和一般函数有区别。 * 样例输入: * 样例输出: * 问题分析:利用成员函数、友元函数和一般函数,实现三个版本的求两点间距离的函数,并设计main()函数完成测试。 */ #include #include using na
2014-04-15 15:03:54 819
原创 深复制体验
#include#includeusing namespace std;class A{private: char *a;public: A(char *aa) { a = new char[strlen(aa)+1];//(1)这样处理的意义在于:\0要占用空间 strcpy(a,aa);//(2)数据成员
2014-04-12 18:09:20 382
原创 对象作为数据成员
#include #include #include using namespace std;class CPoint{private: double x; // 横坐标 double y; // 纵坐标public: CPoint(double xx=0,double yy=0):x(xx),y(yy) {};//构造函数初始化;
2014-04-08 18:58:21 429
原创 体验常成员函数
* Copyright (c) 2014, 烟台大学计算机学院 All rights reserved. 作 者:丁露 完成日期:2014 年 4 月 6 日 版 本 号:v1.0 输入描述: 无 问题描述:体验常成员函数。 设计平面坐标点类,计算两点之间距离、到原点距离、 关于坐标轴和原点的对称点等。在设计中,由于求距 离、求对称点等操作对原对象不能
2014-04-07 10:22:24 397
原创 三角形类的构造函数
/** 作 者: 丁露* 完成日期:2014 年3月30日* 版 本 号:v1.0* 问题描述:面向对象。* 样例输入:* 样例输出:* 问题分析:设计一个三角形类,完成各成员函数的定义。*/#include #include using namespace std;class Triangle{public: double
2014-03-30 15:38:16 499
原创 三角形类的构造函数
/** 作 者: 丁露* 完成日期:2014 年3月30日* 版 本 号:v1.0* 问题描述:面向对象。* 样例输入:* 样例输出:* 问题分析:设计一个三角形类,完成各成员函数的定义。*/#include #include using namespace std;class Triangle{public: double
2014-03-30 15:34:28 466
原创 三角形类的构造函数
/** 作 者: 丁露* 完成日期:2014 年3月30日* 版 本 号:v1.0* 问题描述:面向对象。* 样例输入:* 样例输出:* 问题分析:设计一个三角形类,完成各成员函数的定义。*/#include #include using namespace std;class Triangle{public: doubl
2014-03-30 15:31:12 513
原创 三角形类2
/** 作 者: 丁露* 完成日期:2014 年3月18日* 版 本 号:v1.0* 问题描述:面向对象。* 样例输入:* 样例输出:* 问题分析:设计一个三角形类,完成各成员函数的定义。*/#include #include using namespace std;class Triangle{public: v
2014-03-18 18:19:00 523 1
原创 三角形类
/** 作 者: 丁露* 完成日期:2014 年3月18日* 版 本 号:v1.0* 问题描述:面向对象。* 样例输入:* 样例输出:* 问题分析:设计一个三角形类,完成各成员函数的定义。*/#include#includeusing namespace std;class Triangle{public: void setAB
2014-03-18 16:46:59 547
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人