我在这里遇到了一些麻烦。我不知道我做错了什么。我的bike.cpp类很好。但我认为问题出在bike_shed类,我遇到了“park”和“checklegal”方法的问题。我们被要求做这样的事情:“有10个默认构造的自行车对象的私有数组BikeShed该类的类应该具有以下公共方法:由编译器提供Objects Array - C++
- 一个默认的构造BikeShed() 。
函数布尔公园(常量自行车&)增加了一个自行车可用 现场并返回true,如果BikeShed已满,则函数返回 假。
函数自行车删除(常量字符串& int),重新移动并返回 与给定名称的所有者的第一辆自行车。如果找到这样的自行车不是 ,则该功能返回一辆自行车“无”。
一个函数bool checkLegal(),如果所有非“None”的自行车 合法,它将返回true。如果发现一辆自行车违章 打印一条信息打印自行车。 。
一个函数void print()函数,打印所有的自行车与业主 不是 “无” 等”
这里是我的代码:
这里是bike_shed.cpp文件
#include <iostream>
#include "bike_shed.h"
#include "Bike.h"
using namespace std;
void bike_shed::print(){
cout<< "Bike: " << sizeof(Bike) <<endl;
}
bool bike_shed::checkLegal() {
Bike bike1;
if(bike1.getOwner() == "None"){
return false;
}
else{
return true;
}
}
//Bike bike_shed::remove(const string&, int) {
//
//
//}
bool bike_shed::park(const Bike&) {
if (sizeof(Bike) > 10) {
return false;
}
}
这里是Bike.cpp文件
#include "Bike.h"
#include <iostream>
using namespace std;
void Bike::setNLight(int _light) {
d_nLight = _light;
}
void Bike::setBell(bool _bell) {
d_bell = _bell;
}
void Bike::setOwner(string _owner) {
d_owner = _owner;
}
void Bike::setReflector(bool _reflector) {
d_reflector = _reflector;
}
int Bike::getNLight() {
return d_nLight;
}
string Bike::getOwner() {
return d_owner;
}
bool Bike:: hasReflector() {
if (d_reflector == true) {
return true;
}
else {
return false;
}
}
bool Bike:: hasBell(){
if(d_bell == true) {
return true;
}
else{
return false;
}
}
bool Bike::isLegal() {
if (d_nLight >= 1 && d_reflector && d_bell) {
return true;
}
else {
return false;
}
}
void Bike::print() {
cout << "Owner: " << d_owner << " Color: " << d_color.Red << " " << d_color.Green << " " << d_color.Blue
<< " " << " Lights: " << d_nLight << " Bell: " << d_bell << " Reflector: " <<d_reflector << endl;
}
Bike::Bike(string name, Color color){
d_owner = name;
d_color = color;
}
这里是bike_shed.h文件
#include "Bike.h"
class bike_shed {
public:
bike_shed();
bool park(const Bike&);
Bike remove(const string&, int);
bool checkLegal();
void print();
public:
Bike bike[10];};
我会很感激,如果有人能帮助我。谢谢:)
您可能想要澄清remove方法的签名。 int是什么?在顶部的描述中,你没有在'string'和'int'之间加逗号。 –