首页 > TAG信息列表 > Machinepets
实验4 继承
实验任务二 source code : 1 #include <iostream> 2 #include <typeinfo> 3 4 // definitation of Graph 5 class Graph 6 { 7 public: 8 void draw() { std::cout << "Graph::draw() : just as an interface\n"; } 9 }; 10 11 12实验4
task3 Battery.hpp #ifndef BATTERY_HPP #define BATTERY_HPP #include<bits/stdc++.h> using namespace std; class Battery { public: Battery(int a=70):capacity(a){} int get_capacity(){ return this->capacity; }11.24
#include<iostream> #include<iomanip> #include<string> using namespace std; class Car { public: Car(string maker, string model, int year) { this->maker = maker; this->model = model; this->year =实验四 继承
#include <iostream> #include <typeinfo> // definitation of Graph class Graph { public: virtual void draw() { std::cout << "Graph::draw() : just as an interface\n"; } }; // definition of Rectangle, derived from Graph cla实验四 继承
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 class Car{ 5 public: 6 Car(string maker0,string model0,int year0,int odometers0=0):maker(maker0),model(model0),year(year0),odometers(odometers0){}; 7 void info()co实验四
任务三 Battery.hpp #pragma once #include<iostream> using namespace std; class Battery { public: Battery(float n=70) :capacity{ n } {} float get_capacity() { return capacity; } ~Battery() = default; private: float capacity;实验4
#include <iostream> #include <typeinfo> // definitation of Graph class Graph { public: void draw() { std::cout << "Graph::draw() : just as an interface\n"; } }; // definition of Rectangle, derived from Graph class Recta【实验四】继承
目录任务2任务3任务4 任务2 task2.cpp #include <iostream> #include <typeinfo> // definitation of Graph class Graph { public: void draw() { std::cout << "Graph::draw() : just as an interface\n"; } }; // definition of Rectangle, deri面向对象->实验报告四(C++)
task3 题目要求 源码 main.cpp #include <iostream> #include "electricCar.hpp" int main() { using namespace std; // test class of Car Car oldcar("Audi", "a4", 2016); cout << "--------oldcar's info实验四 继承
------------恢复内容开始------------ //task2.cpp #include <iostream> #include <typeinfo> // definitation of Graph class Graph { public: void draw() { std::cout << "Graph::draw() : just as an interface\n"; } }; // definition实验四 继承
实验任务三 1、Battery类: #include <iostream> #include <string> using namespace std; class Battery { private: int capacity; public: Battery(int capacity); ~Battery(); int get_capacity(); }; Battery::Battery(int capacity = 70) {实验4 继承
实验任务3 "battery.hpp" 1 #ifndef TEST01_BATTERY_HPP 2 #define TEST01_BATTERY_HPP 3 4 #include <iostream> 5 using namespace std; 6 7 class Battery { 8 public: 9 Battery (int cap = 70): capacity(cap) {}; 10 int get_capacity(实验五
1 2 3 #include<iostream>#include<string>#include<cstdlib>using namespace std;class MachinePets{public: MachinePets(const string s); virtual string talk() const=0; string getNickname(); virtual ~MachinePets(); private:实验五
#include <iostream>#include<string>#include"MachinePets.h"#include "PetCats.h"#include "PetDogs.h"using namespace std;void play(MachinePets *p){ cout<<p->getNickname()<<" says "<<p-实验5
一 机械宠物 #include <iostream>#include "MachinePets.h"#include "Petcats.h"#include "Petdogs.h"using namespace std;void play(MachinePets *m){ cout<<m->getnickname()<<" say "<<m->talk()&实验五
#include<string>#include<iostream>using namespace std;class MachinePets {public: MachinePets(const string s); virtual string talk()=0; string getNickname() { return nickname; }private: string nickname;};class PetCats:publ实验5
#include <iostream>#include <string>using namespace std;class MachinePets {public: MachinePets(const string s) :nickname(s) {} ; string getNickname(); virtual string talk() = 0;private: string nickname;};string MachinePets::getN实验5
#include<iostream>#include<string>using namespace std;class MachinePets{ public: MachinePets(){} MachinePets(const string s){ nikname=s; } string getNikname()const{return nikname;} virtual strin实验五
//MachinePets.h#include<iostream>#include<string>using namespace std;#ifndef MACHINEPETS_H#define MACHINEPETS_Hclass MachinePets{public: MachinePets(const string s); virtual string talk() const=0; string getNickname();private: stri实验5
#include <iostream>#include <string>using namespace std;class MachinePets{public: MachinePets(const string s):nickname(s){}; string getNickname() {return nickname;}; virtual string talk()=0;private: string nickname; };class P实验五 类的继承、派生和多态(2)
一、验证性实验1. 在多层继承中,派生类中出现与基类同名成员时,通过对象名.成员名的方式,访问的成员什么? 对象名.成员名:派生类对象2. 通过基类指针访问派生类对象时,基类中成员函数有无关键字virtual,访问的成员分别是什么? 基类指针:有关键字时访问派生类,无关键实验五
1 main.cpp #include <iostream>#include <string>using namespace std;#include "MachinePets.h"#include "PetCats.h"#include "PetDogs.h"void play(MachinePets *x){ cout<<x->getNickname()<<"says&qu实验5 类的继承、派生和多态(2)
设计并实现一个机器宠物类MachinePets。 #include"petcats.h"#include"petdogs.h"#include"machinepets.h"#include<iostream>#include<string>using namespace std;void play(MachinePets *p){ cout<<p -> getNickname()<<实验五
设计并实现一个机器宠物类MachinePets。 #include <iostream>#include <string>using namespace std;class MachinePets{ public: MachinePets(const string s):nickname(s){ } virtual string talk()=0; string getNickname(){ rc++第五次实验
part 1 两个问题: 1、派生类中出现与基类同名成员,通过对象名.成员名的方式,即代码中base2.display(),访问的成员是派生类中的成员 2、通过基类指针访问派生类对象时,在ex1_1.cpp中没有virtual,得到的结果全是基类成员函数的调用,在ex1_2.cpp中基类成员函数有virtual,结果基类派生类都依次