#include<iostream> #include<iomanip> using namespace std; class table{ public: table (int p){ i=p; } void ascii(void); protected: int i; }; void table ::ascii(){ int k=1; for(;i<97 26;i ){ cout<<setw(4)<<i<<(char)i; if(k%6==0){ cout<<endl; } k ; } } class der_table:public table{//继承 public: der_table(int p,char *m):table(p){c=m;} void print(void); protected: char *c; }; void der_table::print(){ cout<<c<<endl; table::ascii(); } int main(){ der_table ob1(97,"ASCII value-char");ob1.print(); }
5522、
#include <iostream> #include <string.h> using namespace std; class Time { public: Time(int h, int m, int s) { hours = h; minutes = m; seconds = s; } void display() { cout << hours << ":" << minutes << ":" << seconds << endl; } protected: int hours, minutes, seconds; }; class Date { public: Date(int m, int d, int y) { month = m; day = d; year = y; } void display() { cout << month << "/" << day << "/" << year << endl; } protected: int month, day, year; }; class Birthtime : public Date,public Time { public: Birthtime(char *m, int mon, int d, int y, int h, int min, int s) : Date(mon, d, y), Time(h, min, s) { Childname = m; } void display() { cout << Childname <<endl; Time::display(); Date::display(); } protected: char *Childname; }; int main(){ Birthtime ob1("dcc",11、22、2007、9、18、18); ob1.display(); }
5531、
#include <iostream> using namespace std; class building { protected: int floor, house; double squre; public: building(int floor, int house, double squre) { this->floor = floor; this->house = house; this->squre = squre; } void display() { cout << "floor is" << floor << "house is" << house << "square is" << squre << endl; } }; class house1 : public building { protected: int beedroom, bathroom; public: house1(int floor, int house, double squre, int beedroom, int bathroom): building(floor, house, squre) { this->bathroom = bathroom; this->beedroom = beedroom; } void display() { cout << "floor is " << floor << " house is " << house << " square is " << squre << endl; cout << "bedroom is " << beedroom << " bathroom is " << bathroom << endl; } }; class office : public building { protected: int extinguisher, telephone; public: office(int floor, int house, double squre,int extinguisher,int telephone):building(floor,house,squre){ this->extinguisher=extinguisher; this->telephone=telephone; } void display(){ cout << "floor is " << floor << " house is " << house << " square is " << squre << endl; cout <<"extinguisher is " <<extinguisher<< " telephone is "<<telephone <<endl; } }; int main() { house1 ob1(32, 4, 600.0,8,4); ob1.display(); office ob2(15, 40,2000.0, 40, 40 ); ob.display();
}
5532、
#include<iostream>
using namespace std;
class person{
protected:
string name;
string id;
public:
person(string name,string id){
this->name=name;
this->id=id;
}
void output(){
cout<<"name is "<<name<<" id is "<<id<<endl;
}
};
class teacher: public person{
protected:
string degree,dep;
public:
teacher(string name,string id,string degree,string dep):person(name,id){
this->degree=degree;
this->dep=dep;
}
void output(){
person::output();
cout<<"degree is "<<degree<<" dep is "<<dep<<endl;
}
};
class student: public person{
protected:
int old,sno;
public:
student(string name,string id,int old,int sno):person(name,id){
this->old=old;
this->sno=sno;
}
void output(){
person::output();
cout<<"old is "<<old<<" sno is "<<sno<<endl;
}
};
class stud{
protected:
string addr ,tel;
public:
stud(string addr,string tel){
this->tel=tel;
this->addr=addr;
}
void output(){
cout<<"addr is "<<addr<<" tel is "<<tel<<endl;
}
};
class score:public stud,public student{
protected:
int math,eng;
public:
score(string name,string id,int old,int sno,string addr,string tel,int math,int eng):student(name,id,old,sno),stud(addr,tel){
this->math=math;
this->eng=eng;
}
void output(){
student::output();
stud::output();
cout<<"math is "<<math<<" eng is "<<eng<<endl;
}
};
int main(){
score c1("dcc","23010620071122",10,201304,"Haping Road","13804582160",94,100);
c1.output();
teacher t1("dbz","23010719750412","Ph.D","Computer");
t1.output();
}