?? 抽象類 車.txt
字號:
# include<iostream.h>
class Vehicle{
public:
virtual void get_data(char *na,char *col,int n)=0;
virtual void display()=0;
};
class Car:public Vehicle{
private:
char *name;
char *color;
int number;
public:
void get_data(char *na,char *col,int n){
name=na;
color=col;
number=n;
}
virtual void display(){
cout<<name<<endl;
cout<<color<<endl;
cout<<number<<endl;
}
};
class Truck:public Vehicle{
private:
char *name;
char *color;
int height;
public:
void get_data(char *na,char *col,int n){
name=na;
color=col;
height=n;
}
virtual void display(){
cout<<name<<endl;
cout<<color<<endl;
cout<<height<<endl;
}
};
void main(){
Vehicle *ptr;
Car car;
Truck truck;
ptr=&car;
ptr->get_data("BIM","red",4);
ptr->display();
ptr=&truck;
ptr->get_data("東風解放牌卡車","blue",30);
ptr->display();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -