- 博客(29)
- 收藏
- 关注
原创 7.31友元成员函数
友元成员函数#include using namespace std;class Date; class Clock {public:Clock(int, int, int);void display(Date &); private:int hour;int minute;int second;};class Date
2014-08-29 18:48:36 353
原创 7.31友元普通函数
友元普通函数#include using namespace std;class Clock {public:Clock(int, int, int); friend void display(Clock &); private:int hour;int minute;int second;};Clock::Clock(int h,int m,
2014-08-29 18:47:51 337
原创 8.1~8.7综合程序代码 未完待续。。。。。。。
访问静态数据成员。#include using namespace std;#include class Student{public:Student(char *Id = "uncertain", char *Name = "uncertain", char Sex = 'M');~Student( );static int stu_count; p
2014-08-29 18:47:32 535
原创 7.30定义一个公共基类Shape,实现运行时的多态性
定义一个公共基类Shape,它表示一个封闭平面几何图形。然后,从Shape类派生出三角形类Triangle、矩形类Rectangle和圆类Circle,在基类中定义纯虚函数show和area,分别用于显示图形信息和求相应图形的面积,并在派生类中根据不同的图形实现相应的函数。要求实现运行时的多态性。#include #includeusing namespace std;
2014-08-29 18:46:48 2450
原创 7.29交通工具类
有一个交通工具类vehicle,将它作为基类派生出汽车类motor_ vehicle,再将汽车类motor_ vehicle 作为基类派生出小汽车类car和卡车类truck,声明这些类并定义一个虚函数用来显示各类信息。#include using namespace std;class vehicle{public: virtual void message( )
2014-08-29 18:44:30 1239
原创 7.29虚函数的作用
虚函数的作用#include using namespace std;class Point{public:Point(double a = 0, double b = 0) { x = a; y = b; }virtual double Area( ) { cout return 0.0; } protected:double x, y;
2014-08-29 18:43:56 377
原创 7.30在交通工具类vehicle中使用虚析构函数。
在交通工具类vehicle中使用虚析构函数。#include using namespace std;class vehicle {public:vehicle( ){} virtual ~vehicle( ) { cout private:int wheels;float weight;};class motor_vehicl
2014-08-29 18:42:57 584
原创 7.27多重继承派生类的构造函数
多重继承派生类的构造函数#includeusing namespace std;class Employee: public Person {public:Employee(char *Name, char Sex, int Age, char *Num, char *Clerk, char *Depart, char *Timer): Person(Name, Sex, A
2014-08-29 18:40:46 471
原创 7.28组合
组合class Student {public: Student(string num, string name, char sex, int age): num(num),name(name), sex(sex), age(age){ }private: string num; string name;
2014-08-29 18:40:00 380
原创 7.28基类对象的指针指向公用派生类对象的应用。
基类对象的指针指向公用派生类对象的应用。#include using namespace std;class Point {public:Point(double a = 0, double b = 0) { x = a; y = b; }void Show( ) { cout protected:double x, y; };class
2014-08-29 18:39:32 387
原创 7.27派生类的析构函数
派生类的析构函数#includeusing namespace std;# includeclass Person {public:Person(char *Name, char Sex, int Age ) { name = new char[strlen(Name)+1];strcpy(name, Name); sex = Sex; age =
2014-08-29 18:37:27 303
原创 7.26派生类的构造函数
/*派生类的构造函数*/ #include using namespace std; # includeclass Person {public:Person(char *Name, char Sex, int Age ) { strcpy(name, Name); sex = Sex; age = Age;cout }~Pers
2014-08-09 12:41:10 356
原创 7.26派生类成员函数与基类成员函数同名
/*派生类成员函数与基类成员函数同名*/#include using namespace std;class Circle {public: void Set(int r){ radius = r; } void Show( ){ cout private: int radius; };class Cy
2014-08-09 12:38:49 879
原创 7.25私有继承、保护继承
私有继承、保护继承#includeusing namespace std;class Cylinder: private Circle {public: void SetHeight(int h){ height = h; } int GetHeight( ){ return height; } void ShowHeig
2014-08-09 00:36:14 302
原创 7.25公用继承
公用继承#include using namespace std;class Circle {public: void SetRadius(int r){ radius = r; } int GetRadius( ){ return radius; } void ShowRadius( )
2014-08-09 00:31:24 306
原创 7.24常指针 常对象 常引用
常对象一般形式const 类名 对象名(实参表)类名 const 对象名(实参表)指向对象的常指针类名 *const 指针名=&类的对象Box box(1,2,3);Box *const pbox=&box;指向常对象的指针const 类名 *指针名const Clock clock1(1,2,3);const Clock *p1=&cloc
2014-08-08 23:53:13 343
原创 7.24定义对象数组,并初始化
/*定义对象数组,并初始化*/#includeusing namespace std;class Box{public:Box(){length=1;width=2;height=3;coutcout}Box(float L,float W,float H){length=L;width=W;height=Hcoutfloat Volume(){
2014-08-08 23:33:16 415
原创 7.23构造函数和析构函数的调用次序
/*构造函数和析构函数的调用次序*/#includeusing namespace std;class Box{public:Box(){length=1;width=2;height=3;coutcout}Box(float L,float W,float H){length=L;width=W;height=Hcoutfloat Volume
2014-08-08 23:19:29 346
原创 7.23带参数的构造函数
/*带参数的构造函数*/#includeusing namespace std;class Box{public:Box(float L,float W,float H){length=L;width=W;height=H;}float volume(){return length*width*height;}private:float length;float
2014-08-08 00:13:06 348
原创 7.23构造函数
/*构造函数*/#includeusing namespace std;class Box{public:Box{length=1;width=2;height=3;}void Show(){cout}private:{ float length,width,height;};int main(){Box b
2014-08-07 23:39:52 290
原创 7.22通过对象的引用访问对象中的成员
/*通过对象的引用访问对象中的成员*/#includeusing namespace std;class Test{public:void Set(char ch){c=ch;}void Show(){coutprivate:char c;};int main(){Test test;test1.Set('a');Test &re
2014-08-07 23:25:18 503
原创 7.22通过指向对象的指针访问对象中的成员
/*通过指向对象的指针访问对象中的成员pTest->Show(),(*pTest).Show(),test1.Show等价*/#includeusing namespace std;class Test{public:void Set(char ch){c=ch;}void Show(){coutprivate:char c;};int main()
2014-08-07 23:23:00 971
原创 7.22相同类的不同对象执行相同成员函数输出不同结果
相同类的不同对象执行相同成员函数输出不同结果#includeusing namespace std;class Test{public:void Set(char ch){c=ch;}void Show(){coutprivate:char c;};int main(){Test test1,test2;test1.Set('a');test
2014-08-07 23:13:26 516
原创 7.21类外定义成员函数
类外定义成员函数#includeusing namespace std;class Student{public:void show();private:{ string stuNO; string stuName; string stuSex;};void Student::Show(){coutcoutcout
2014-08-07 00:06:59 392
原创 7.20在学生类student和教师类teacher 基础上再派生出一个助教类
/*在学生类student和教师类teacher基础上再派生出一个助教类TeachAssistant,一个助教既具有教师的特征,又具有学生的特征,还有自己的新特征:工资(wage)。要求将助教类的间接共同基类声明为虚基类。*/#include#includeusing namespace std;class Person{public:void input(){
2014-08-06 23:58:24 5130
原创 7.20学生和教师数据输入和显示的程序
/*编写一个用于学生和教师数据输入和显示的程序,学生数据要求有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名的输入和显示设计成一个类person,并作为学生类student和教师类teacher的基类,学生数据中的班号和成绩的输入和显示在student类中实现,教师数据中的职称和部门的输入和显示在teacher类中实现。最后在main函数中进行该
2014-08-06 23:58:05 1733
原创 7.21声明一个学生类(学号,姓名,性别)同时定义对象
#includeusing namespace std;class Student{public:void show(){coutcoutcout}private:{ string stuNO; string stuName; string stuSex;}zhang,wang;
2014-08-06 23:54:08 1290
原创 1
#includeint main(){ int *p; /*p是变量的名字,int * 表示p变量存放的是int类型变量的地址*/ int i=3; p=&i; /*ok,p=i; error,因为类型不一致,p只能存放int类型的变量地址,不能存放int类型变量的值。p=55错误的原因也为此*/ return 0;}
2014-02-08 22:27:58 680
原创 c语言期末编程题
1 .设N是一个四位数,它的9倍恰好是其反序数(例如:123的反序数是321),求N的值。#includeint main (){ int n; int a,b,c,d; for(n=1000;n { a=n/1000; b=n100%10; c=n/10%10; d=n%10; if
2014-01-19 20:00:08 1315
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人