第五天练习
#include<iostream> using namespace std; class CPolygon{ protected: int width,height; public: void set_values(int a,int b) {width=a;height=b;} }; class CRectangle:public CPolygon{ public: int area() {return (width*height);} }; class CTriangle:public CPolygon{ public: int area() {return(width*height/2);} }; int main() { CRectangle rect; CTriangle trgl; rect.set_values (4,5); trgl.set_values (4,5); cout<<rect.area()<<endl; cout<<trgl.area()<<endl; return 0; }
//DateTime.h #pragma once #include"date.h" #include"time.h" class dateTime:public date,public time{public: dateTime(void); dateTime(int y,int mon,int d,int h,int m,int s); date(y,mon,d),time(h,m,s){} ~dateTime(void) void displayDateAndTime();}; /main.cpp #include<iostream> using namespace std; class mother{ public: mother() {cout<<"mother\n";} }; class daughter:public mother{ public: daughter() {cout<<"daughter\n";} }; class son:public mother{public: son(){cout<<"son\n";}}; int main(void){ daughter cymthial; son daniel; return 0;