Cube
#include<bits/stdc++.h>
using namespace std;
class Rectangle{
protected:
double length , width ;
public:
void showSize(){
cout << "length is " << length << " width is " << width << endl;
}
};
class Cube : public Rectangle{
private:
double height;
public:
void input(){
cout << "input length , width and height please:\n ";
cin >> length >> width >> height;
}
void displaySize(){
cout << "length is " << length << " width is " << width << " height is " << height<< endl;
}
void volume(){
double S = length * width * height;
cout << " S is : " << S << endl;
}
};
int main(){
Cube c1;
c1.input();
c1.displaySize();
c1.volume();
return 0;
}
Student
#include<bits/stdc++.h>
using namespace std;
class Person{
protected:
string name;
int age;
public:
void input(){
cout << "input name and age please:\n ";
cin >> name >> age;
}
void display(){
cout << "name is " << name << " age is " << age << endl;
}
};
class Student :public Person{
private:
string xuehao , zhuanye;
public:
void input_s(){
cout << "input xuehao and zhuanye please:\n ";
cin >> xuehao >> zhuanye;
}
void display_s(){
cout << "xuehao is " << xuehao << " zhuanye is " << zhuanye << endl;
}
};
int main(){
Student stu;
stu.input();
stu.input_s();
stu.display();
stu.display_s();
return 0;
}
xigou
#include<iostream>
using namespace std;
class A{
public:
A(){cout << "constructing A" << endl;
}
~A(){
cout << "destructing A" << endl;
}
};
class B:public A{
public:
B(){cout << "constructing B" << endl;
}
~B(){
cout << "destructing B" << endl;
}
};
class C :public B{
public:
C(){cout << "constructing C" << endl;
}
~C(){
cout << "destructing C" << endl;
}
};
int main(){
C c1;
return 0;
}