第五天练习

复制代码
#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;
复制代码

 

posted @   KuanDong24  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结
点击右上角即可分享
微信分享提示