HELLO GUYS is have I solved the task right so far ?
a) First create the files CParkingLot.h and CParkingLot.cpp and declare the class CParkingLot according to the class diagram shown above. Implement the declared getter and setter methods.
b) Implement the private method void generateId (), which assigns a unique value to the m_id attribute of the CParkingLot objects in the specified value range. Use
a local static variable within this method, which you increment after each assignment.
c) Implement the constructor of the CParkingLot class. Note the assurances and also use the default value if the parameter is not in the value range of m_capacity
lies. To initialize m_id, call the generateId () method in the constructor
b) on.
d) Implement the method bool parkVehicle (), which adds exactly one vehicle to the parking lot. The return value should be true if the vehicle still has a parking space; it returns false if the parking lot is already full.
e) Implement the method int parkVehicles (int numVehicles), which adds several vehicles to the parking lot. The return value should be 0, if there are still parking spaces available for all vehicles; if the parking is already full, the number will be
the vehicles returned for which no more parking space is available.
f) Implement the int getFreeSpots () method, which returns the number of free slots.
g) Implement the float getFreeCapacity () method, which returns the percentage of free spaces.
Header:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#ifndef CPARKINGLOT_H_
#define CPARKINGLOT_H_
#include<iostream>
using namespace std;
class CParkingLot{
private:
int m_id;
int m_capacity;
int m_curOccupancy = 0;
void generateId();
int m_freeSpots;
public:
CParkingLot(int capacity = 80);
int getId();
int getCapacity();
void setCapacity(int capacity);
int getCurOccupancy();
void setCurOccupancy(int curOccupancy);
bool parkVehicle();
int parkVehicles(int numVehicles);
int getFreeSpots();
void print();
friend ostream& operator<< (ostream& lop,const CParkingLot& rop);
};
ostream& operator<< (ostream& lop,const CParkingLot& rop);
#endif /* CPARKINGLOT_H_ */
| |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <iostream>
#include <exception>
#include "CParkingLot.h"
using namespace std;
int m_id;
void generateId()
{
static int id = 100;
if (id >= 100 && id <= 1000)
{
m_id = id;
id++;
}
else
{
throw std::runtime_error("too many ids");
}
}
CParkingLot::CParkingLot(int capacity ){
if(m_capacity <= 200 ){
m_capacity = capacity;
}
else{
int capacity = 80;
}
generateId();
}
bool CParkingLot::parkVehicle(){
if( m_curOccupancy == m_capacity ){
return false;
}
if ( m_curOccupancy < m_capacity){
m_curOccupancy++;
return true;
}
}
int CParkingLot::parkVehicles(int numVehicles){
if (m_capacity -m_curOccupancy < m_capacity){
return 0;
}
if( m_curOccupancy == m_capacity ){
return numVehicles;
}
}
int CParkingLot::getFreeSpots(){
return m_freeSpots;
}
int CParkingLot::getCapacity(){
return m_capacity;
}
int CParkingLot::getCurOccupancy(){
return m_curOccupancy;
}
void CParkingLot::setCurOccupancy(int curOccupancy){
m_curOccupancy = curOccupancy;
}
void CParkingLot::setCapacity(int capacity){
m_capacity = capacity;
}
ostream& CParkingLot::operator<< (ostream& lop,const CParkingLot& rop){
lop << "ID:" << "" << m_id << "" << "Kapazität:" << "" << m_capacity << "" << "frei:" << m_freeSpots << endl;
return rop;
}
void CParkingLot::print(){
cout << " Der Parkplatz hat folgende Eigenschaften :" << endl;
cout << "ID:" << "" << m_id << "" << "Kapazität:" << "" << m_capacity << "" << "frei:" << m_freeSpots << endl;
}
| |
I have also some errors
https://picload.org/view/dcigwcac/bildschirmfoto2019-01-06um22.3.png.html
https://picload.org/view/dcigwcod/bildschirmfoto2019-01-06um15.3.png.html
Please help me ?
Thank you