实验任务三
源码如下:
1 #pragma once 2 #include<iostream> 3 #include<string> 4 using std::string; 5 using std::cout; 6 using std::endl; 7 class MachinePets { 8 private: 9 string nickname; 10 public: 11 MachinePets(const string & s = ""); 12 string get_nickname() const; 13 virtual string talk() = 0; 14 }; 15 MachinePets::MachinePets(const string & s) :nickname{ s } { 16 } 17 string MachinePets::get_nickname() const { 18 return nickname; 19 } 20 class PetCats :public MachinePets { 21 public: 22 PetCats(const string & s = ""); 23 string talk(); 24 }; 25 PetCats::PetCats(const string & s) :MachinePets{ s } { 26 } 27 string PetCats::talk() { 28 return "miao wu~"; 29 } 30 class PetDogs :public MachinePets { 31 public: 32 PetDogs(const string & s = ""); 33 string talk(); 34 }; 35 PetDogs::PetDogs(const string & s) :MachinePets{ s } { 36 } 37 string PetDogs::talk() { 38 return "wang wang~"; 39 }
task3.cpp
运行测试截图如下:
实验任务四
源码如下:
film.hpp
task4.cpp
运行测试截图如下:
实验任务五
源码如下:
Complex.hpp
task5.cpp
运行测试截图如下:
实验任务六
源码如下:
date.h
date.cpp
accumulator.h
account.h
account.cpp
task6.cpp
运行测试截图如下:
实验任务七
源码如下:
运行测试截图如下: