测试代码:

Animals.h:

 #pragma once
#include<string>
class Animals
{
protected:
std::string Food;
int Weight;
int Intake;
double Velocity;
public:
Animals(const std::string &fd="none",int w=,int n=,double v=0.0);
virtual void Speaking();
void Swimming();
void show(int)const;
virtual ~Animals();
}; class Fish :Animals
{
private:
std::string Colour;
public:
Fish(const std::string &cr = "none", const std::string &fd = "none", int w = , int n = , double v = 0.0);
Fish(const std::string &cr, Animals &tp);
void Appear()const;
void show()const;
void Speaking(); };

Animals.cpp:

 #include "stdafx.h"
#include "Animals.h"
#include<iostream> Animals::Animals(const std::string &fd, int w, int n,double v):Food(fd),Weight(w),Intake(n), Velocity(v)
{} void Animals::Speaking()
{
std::cout << "......" << std::endl;
} void Animals::Swimming()
{
std::cout <<"++++++"<< Velocity << "m/s" <<"++++++"<< std::endl;
} void Animals::show(int p) const
{
std::cout << "I want eatting ";
for (int i = ; i < p; i++)
std::cout << Food<<"! ";
std::cout << std::endl;
} Animals::~Animals()
{
} Fish::Fish(const std::string & cr, const std::string & fd, int w, int n, double v) :Animals(fd,w,n,v)
{
Colour = cr;
} Fish::Fish(const std::string & cr, Animals & tp):Animals(tp),Colour(cr)
{} void Fish::Speaking()
{
std::cout << "Booo Booo!" << std::endl;
} void Fish::Appear() const
{
std::cout << Colour << std::endl;
} void Fish::show() const
{
std::cout << "Food: " << Food << std::endl;
std::cout << "Weight: " << Weight << std::endl;
std::cout << "Intake: " << Intake << std::endl;
std::cout << "Velocity: " << Velocity <<" m/s"<< std::endl;
std::cout << "Colour: " << Colour << std::endl;
}

ConsoleApplication.cpp:

 #include "stdafx.h"
#include "Animals.h"
#include<iostream>
using namespace std;
int main()
{
Animals p0("shrimp", , , 1.0);
Fish b0("Red and White", "Coral", , , 0.5);
p0.show();
p0.Speaking();
p0.Swimming();
cout << endl ;
b0.show();
cout << "Now I must speaking: ";
b0.Speaking();
cout << endl ;
Fish b1("Blue", p0);
b1.show();
cout << "Now I must speaking: ";
b1.Speaking();
return ;
}

运行结果:

最新文章

  1. 用RMAN备份EBS数据库的脚本
  2. SSH三大框架笔面试总结
  3. 基于 jQuery 实现垂直滑动的手风琴效果
  4. 【英语】Bingo口语笔记(6) - 表示“迷茫”
  5. jquery实现ajax,返回json数据
  6. 用生活例子来解释Java synchronized块
  7. 学习java随笔第二篇:java开发工具——Eclipse
  8. Mongodb数据库命令端经常使用操作
  9. krpano音量控制(我们已经转移到krpano中国网站 krpano360.com)
  10. redis缓存雪崩、缓存穿透、数据库和redis数据一致性
  11. Codeforces 461D. Appleman and Complicated Task 构造,计数
  12. Using 1-Wire device with Intel Galileo
  13. Hibernate的使用技巧②
  14. BZOJ 3483 SGU505 Prefixes and suffixes(字典树+可持久化线段树)
  15. 算法(第四版)学习笔记之java实现希尔排序
  16. IOS企业开发者帐号申请
  17. python-创建进程的三种方式
  18. java - day13 - ImplementDemo
  19. oracle数据结构
  20. SpringMVC_基本配置 --跟海涛学SpringMVC(和自己在项目中的实际使用的对比)

热门文章

  1. CERC2017 Gambling Guide,最短路变形,期望dp
  2. 让Dreamweaver支持cshtml (MVC Razor环境)
  3. .NET中调用不安全代码
  4. 初探Qt Opengl【1】
  5. 《python机器学习—预测分析核心算法》:理解数据
  6. AGV小车典型设计算法及应用
  7. Long Short-Term Memory (LSTM)
  8. php+Mysql中网页出现乱码的解决办法详解
  9. C#中System.DBNull的问题
  10. 有关于PHP的基础知识