- 博客(50)
- 资源 (6)
- 收藏
- 关注
原创 添加一个三角类
//扩展程序:创建一个三角形类 //修改create_object函数,使得程序支持三角形的创建 //和求面积、打印等操作 #include #include using namespace std; class Shape { public: virtual double getArea() const =0; v
2015-05-25 21:30:26
605
原创 在程序中使用继承和组合 第五章第十题
#include #include using namespace std; class Teacher //教师类 {public: Teacher(int,char [],char); //声明构造函数 void display();
2015-05-17 23:27:15
662
原创 分别定义教师类和干部类 采用多重继承方式 第五章第九题
#include #include using namespace std; class Teacher {public: Teacher(string nam,int a,char s,string tit,string ad,string t); void display(); protected: string name; int ag
2015-05-17 23:25:28
1406
原创 改为公用继承方式 第五章第四题
#include using namespace std; class Student //声明基类 {public: //基类公用成员 void get_value(); void display( ); protected :
2015-05-17 23:22:51
1059
原创 保护继承方式 第五章第三题
#include using namespace std; class Student //声明基类 {public: //基类公用成员 void get_value(); void display( ); protected :
2015-05-17 23:21:36
559
原创 用私有继承方式 第五章第二题
#include using namespace std; class Student {public: void get_value() {cin>>num>>name>>sex;} void display( ) {cout<<"num: "<<num<<endl; cout<<"name: "<<name<<endl; cout<
2015-05-17 23:19:36
492
原创 用公用继承方式 第五章第一题
#include using namespace std; class Student {public: void get_value() {cin>>num>>name>>sex;} void display( ) {cout<<"num: "<<num<<endl; cout<<"name: "<<name<<endl; cout<
2015-05-17 23:10:46
506
原创 第六题
#include using namespace std; class Complex {public: Complex(){real=0;imag=0;} Complex(double r){real=r;imag=0;} Complex(double r,double i){real=r;imag=i;} operator double(){retur
2015-05-11 23:40:07
695
原创 定义一个教师类和一个学生类 第七题
#include using namespace std; class Student {public: Student(int,char[],char,float); int get_num(){return num;} char * get_name(){return name;} char get_sex(){return sex;} void disp
2015-05-11 23:39:26
3085
原创 重载流插入运算符《和流提取运算符》 第五题
#include //using namespace std; class Matrix {public: Matrix(); friend Matrix operator+(Matrix &,Matrix &); friend ostream& operator<<(ostream&,Matrix&); friend istream& operator>
2015-05-11 23:38:21
1815
原创 有两个矩阵a和b 均为2行3列 求两个矩阵之和第四题
#include using namespace std; class Matrix //定义 Matrix 类 {public: Matrix(); //默认构造函数 friend Matrix oper
2015-05-11 23:37:13
18897
1
原创 定义一个复数类Coplex 使之能用于复数的加法运算 第三题
#include using namespace std; class Complex {public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r;imag=i;} Complex operator+(Complex &c2); Complex ope
2015-05-11 23:35:33
1736
原创 定义一个复数类Complex 第一题
#include using namespace std; class Complex {public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r;imag=i;} double get_real(); double get_imag(); void display();
2015-05-11 23:32:56
16266
原创 定义一个复数类Complex 重载运算符 第二题
#include using namespace std; class Complex {public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r;imag=i;} Complex operator+(Complex &c2); Complex operator-(Complex
2015-05-11 23:32:27
8422
1
原创 用重载时间相加
#include #include using namespace std; class Time { public: void display(){cout<<hour<<":"<<minute<<":"<<sec<<endl;} protected: int hour; int minute; int sec; };
2015-05-11 22:58:08
438
原创 将例3.14改写为在类模版外定义各成员函数(第三章第十二题)
#include using namespace std;templateclass Compare{public:Compare(numtype a,numtype b);numtype max();numtype min();private:numtype x,y;};template Compare::Compare(numtype a,numtype b){x=a
2015-04-20 15:57:31
4663
原创 将例3.13中的Time类声明为Date类的友元类(第三章第十一题)
#include using namespace std;class Time;class Date{public:Date(int,int,int);friend Time;private:int month;int day;int year;};Date::Date(int m,int d,int y):month(m),day(d),year(y){ }class
2015-04-20 15:56:23
5578
原创 将例3.13中程序中的display函数不放在Time类中(第三章第10题)
#include using namespace std;class Date;class Time{public:Time(int,int,int);friend void display(const Date &,const Time &);private:int hour;int minute;int sec;};Time::Time(int h,int m,int
2015-04-20 15:50:26
8271
原创 商店销售某一商品,商店每天公布统一的折扣(第三章第9题)
#include using namespace std;class Product{public:Product(int n,int q,float p):num(n),quantity(q),price(p){};void total();static float average();static void display();private:int num
2015-04-20 15:45:46
14680
2
原创 增加一个fun函数,使用对象的引用作为形参(第三章第八题)
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}void change(int n,float s) {num=n;score=s;}void display() {cout<<num<<" "<<score<<endl;}private:int nu
2015-04-20 15:38:29
1886
原创 第三章第七题(5)
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}void change(int n,float s) {num=n;score=s;}void display() {cout<<num<<" "<<score<<endl;}private:int nu
2015-04-20 15:34:45
414
原创 第三章第七题(4)
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}void change(int n,float s) {num=n;score=s;}void display() const{cout<<num<<" "<<score<<endl;}private:i
2015-04-20 15:30:33
430
原创 第三章第七题(3)
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}void change(int n,float s) {num=n;score=s;}void display() {cout<<num<<" "<<score<<endl;}private:int nu
2015-04-20 15:24:32
453
原创 第三章第七题(2)
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}void change(int n,float s) const {num=n;score=s;}void display() const {cout<<num<<" "<<score<<endl;}pri
2015-04-20 15:21:44
496
原创 输出成绩(第三章第六题0
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}void change(int n,float s) {num=n;score=s;}void display(){cout<<num<<" "<<score<<endl;}private:int num
2015-04-20 14:42:56
436
原创 建立一个对象数组,设立一个函数max,选出成绩最高的(第三章第五题)
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}int num;float score;};void main(){Student stud[5]={Student(101,78.5),Student(102,85.5),Student(103,9
2015-04-20 14:30:55
974
原创 建立一个数组,从五个数据选出三个(第三章第四题)
#include using namespace std;class Student{public:Student(int n,float s):num(n),score(s){}void display();private:int num;float score;};void Student::display(){cout<<num<<" "<<score<<endl;}
2015-04-20 14:27:13
685
原创 将输出的年月日修改为默认参数(第三章第三题)
#include using namespace std;class Date{public:Date(int=1,int=1,int=2005);void display();private:int month;int day;int year;};Date::Date(int m,int d,int y):month(m),day(d),year(y){ }void
2015-04-20 14:25:25
471
原创 显示年月日(第三章第二题)
#include using namespace std;class Date{public:Date(int,int,int);Date(int,int);Date(int);Date();void display();private:int month;int day;int year;};Date::Date(int m,int d,int y):month(m)
2015-04-20 14:21:22
397
原创 将类定义放在头文件arraymax.h中(第二章第五题)
#include#include"xt8-5.h"int main(){Array_max arrmax;arrmax.set_value();arrmax.max_value();arrmax.show_value();return 0;}#includeusing namespace std;#includ
2015-04-07 19:32:36
2952
原创 在类体内申明成员函数(第二章第三题)
#includeusing namespace std;class Time{public:void set_time(void);void show_time(void);private:int hour;int minute;int sec;};void Time::set_time(void){c
2015-04-07 19:01:48
671
原创 在类中增加一个对数据成员赋初值的成员函数(第二章第四题)
#includeusing namespace std;#include "xt8-4.h"int main(){Student stud;stud.set_value();stud.display();return 0;}或:#include using namespace std;void Stud
2015-04-07 18:55:37
3048
原创 将数据成员改为私人的(第二章第二题)
#includeusing namespace std;class Time{public:void set_time(void){cin>>hour;cin>>minute;cin>>sec;}void show_time(void){cout<<hour<<":"<<minute<<":"<<sec<<endl;}private:int hour;int minut
2015-04-07 18:03:26
2232
原创 从键盘输入时.分.秒(第二章第一题)
#includeusing namespace std;class Time{public:int hour;int minute;int sec;};Time t;void set_time(void){cin>>t.hour;cin>>t.minute;cin>>t.sec;}void show_time(void){cout<<t.hour<<":"<<t.mi
2015-04-07 17:44:19
884
原创 修改文章2
原:#includeusing namespace std;int main(){int a, b;c=add(a,b)cout<<"a+b"<<c<<endl;return 0; }int add(int x,int y);{z=x+y;return(z);}改:#includeusing namespace std;int main(){int a,
2015-04-07 17:28:42
390
原创 代码
#includeusing namespace std;class A{ double lengh,width,height;public: A(){lengh=width=height=0;} void input(); void output();} A::void input() { cout cin>>lengh;
2015-03-29 13:20:15
306
原创 用同一个函数名对n个数据进行从小到大排序 用函数模板
#include using namespace std;template void sort(T* a, int n){ int t; T temp; for (int i=0; i { t=i; for (int j=i+1; j { if (*(a+t)>*(a+j)) t=j; } temp=*(a+
2015-03-29 12:55:49
11140
原创 用同一个函数名对n个数据进行从小到大排序
#include using namespace std;template void sort(T* a, int n){ int t; T temp; for (int i=0; i { t=i; for (int j=i+1; j { if (*(a+t)>*(a+j)) t=j; } temp=
2015-03-29 12:51:47
6467
原创 有5个字符串,要求对他们按由小到大 string
#include #include using namespace std;int main(){ int i; string str[5]; void sort(string s[]); cout for(i=0;i cin>>str[i]; sort(str); cout for(i=0;i
2015-03-29 12:46:43
5120
尚硅谷SSM整合视频(SSM整合开发是目前企业流行使用的框架整合方案)
2017-08-09
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人