#include <iostream>
using namespace std;
//To know the car's make, model, color, license number, and the number of minutes the car has been parked
class ParkedCar
{
string make, model, color, license_number;
int minutes;
public:
ParkedCar(string make = "...", string model = "...", string color = "...",
string license_number = "...", int minutes = 0) : make{ make }, model{model},
color{color}, license_number{license_number}, minutes{minutes} { this->make = make; }
};
//To know the number of minutes of parking time that has been purchased
class ParkingMeter
{
int purchased_minutes;
public:
ParkingMeter(int purchased_minutes) { this->purchased_minutes = purchased_minutes; }
};
//To report the make, model, color, and license number of the illegally parked car
//To report the amount of the fine, which is $25 for the first hour, or part of an
//hour that the car is illegally parked, plus $10 for every additional hour or
//part of an hour that the car is illegally parked
//To report the name and badge number of the police officer issuing the ticket
class ParkingTicket
{
ParkedCar car;
ParkingMeter meter;
PoliceOfficer officer;
public:
ParkingTicket(const ParkedCar &car, const ParkingMeter &meter, const PoliceOfficer &officer)
{
this->car = car;
this->meter = meter;
this->officer = officer;
}
};
//To know the officer's name and badge number
//To examine a ParkedCar object and a ParkingMeter object, and determine whether the car's time has expired
//To issue a prking ticket (generate a ParkingTicket object) if the car's time has expired
class PoliceOfficer
{
string name;
int badge_number;
ParkedCar car;
ParkingMeter meter;
public:
PoliceOfficer(const ParkedCar &car, const ParkingMeter &meter, string name = "...", int badge_number = 000000)
{
this->car = car;
this->meter = meter;
}
};
Bu dosyayı okul için yapıyorum ve her şey Park Etme ve Polis Görevlisi sınıflarına ulaşana kadar iyi gidiyor. Bu kurucuları tanımlamaya çalışıyorum ve ikisi de diğer sınıfın varsayılan kurucusu olmadığını söylüyorlar. Bunu nasıl düzeltirim? Teşekkür ederim! :) Yapıcınızda yanaVarsayılan kurucu yok mu?
_ "Bunu nasıl düzeltirim?" _ Varsayılan parametreler sağlayın, bunlar hiçbir parametre almaz veya bunların tümünü varsayılan değere ayarlamalıdır. –
ParkedCar ve ParkingMeter gerçekten bir Polis Görevlisinden _members_? Bir Polis Yetkilisi gerçekten bir isim, rozet, araba ve sayaçtan mı oluşuyor? – kfsone
Evet, 'ParkedCar' ve' ParkingMeter' gerçekten bir PoliceOfficer üyesini _are_. İsim ve rozeti PolisOfisyerine özgü attrbutes, kurucudan alınan 'araba' ve 'metre' nesnelerinin sınıf içi kopyalarını kullanarak değerlerini ve işlevlerini [sonra yapacağım] PolisOfisörü, aksi takdirde mevcut olmayan bilgileri bildirebilmek için. –