-3
我有多重繼承問題。多繼承問題C++
#pragma once
#include <iostream>
#include <list>
class Data {
protected:
int year;
int month;
int day;
public:
Data();
Data(int, int, int);
void show();
};
class Person : virtual public Data {
protected:
std::string Name;
std::string Sur_name;
public:
Person();
Person(std::string, std::string, int, int, int);
void show();
};
class Waiter : public Person {
protected:
int category;
public:
Waiter();
Waiter(std::string, std::string, int d, int m, int y, int c);
void show();
};
class TypeOfDish {
protected:
std::string typeDish;
public:
TypeOfDish();
TypeOfDish(std::string);
void show();
};
class Course : public TypeOfDish {
protected:
double price;
std::string NameofCourse;
public:
Course();
Course(std::string, double, std::string);
void show();
};
class Order : public Course, public Waiter, virtual public Data{
public:
Order();
void show();
};
////////////////////////////////////////
#include "stdafx.h"
#include "Class.h"
#include <string>
Data::Data() {
day = 21;
month = 10;
year = 2017;
}
Data::Data(int d, int m, int y) {
this->day = d;
this->month = m;
this->year = y;
}
void Data::show() {
std::cout << "Hello from Data.Date of birth " << day << " " << month << " " << year << std::endl;
}
Person::Person() : Data() {
day = 22;
month = 10;
year = 2017;
Name = "Ivan";
Sur_name = "Petrov";
}
Person::Person(std::string n, std::string s, int d, int m, int y) : Data(d,m,y) {
this->Name = n;
this->Sur_name = s;
}
void Person::show() {
std::cout << "Hello from Person " << Name << " " << Sur_name << std::endl;
std::cout << "Hello from Person.Date of birth " << day << " " << month << " " << year << std::endl;
}
Waiter::Waiter() : Person() {
category = 3;
}
Waiter::Waiter(std::string n, std::string s, int d, int m, int y, int c) : Person(n,s,d,m,y) {
this->category = c;
}
void Waiter::show() {
std::cout << "Hello from Waiter " << Name << " " << Sur_name << std::endl;
std::cout << "Hello from Waiter.Date of birth " << day << " " << month << " " << year << std::endl;
std::cout << "Hello from Waiter.Category " << category << std::endl;
}
TypeOfDish::TypeOfDish() {
typeDish = "";
}
TypeOfDish::TypeOfDish(std::string type) {
this->typeDish = type;
}
void TypeOfDish::show() {
std::cout << "The type of dish is " << typeDish << std::endl;
}
Course::Course() : TypeOfDish() {
price = 12.32;
NameofCourse = "Borsh";
}
Course::Course(std::string name, double pri, std::string type) : TypeOfDish(type) {
this->NameofCourse = name;
this->price = pri;
}
void Course::show() {
std::cout << typeDish << ":" << NameofCourse << std::endl;
}
Order::Order() : Data(), Course(), Waiter() {
std::cout << ".";
}
void Order::show() {
std::cout << "Hello from Order " << Name << " " << Sur_name << std::endl;
std::cout << "Hello from Order.Date of birth " << Waiter::day << " " << Waiter::month << " " << Waiter::year << std::endl;
std::cout << "Hello from Order.Category " << category << std::endl;
std::cout << "Hello from Order.Date of order " << day << " " << month << " " << year << std::endl;
std::cout << "Hello from Order" << typeDish << ":" << NameofCourse << std::endl;
}
我有3個基本類 - 服務員,課程和數據及派生訂單。 我想從服務員,課程和數據中查看屏幕上的所有字段。 我的意思是姓名,姓氏,類別,出生日期從服務員,所有領域的課程也是最重要的訂單數據。 當我運行程序一切正常,但它不工作,我想要的方式。 出生日期和訂單日期的數據相同。
所以,我想知道我該如何解決這個問題。
任何解決方案將不勝感激。謝謝。
我認爲這將有助於知道究竟是什麼問題。當你說「一切都很好」,然後「不按我想要的方式工作」,除了沒有幫助之外,這是令人困惑的。 – kabanus
一個人是約會嗎?重新思考你的課堂設計。 – 2017-10-21 17:51:36
我同意@ manni66許多課程與其他課程無關,例如訂單**不是**服務員,它**不是**日期。 – HJuls2