002
13.11.2017, 22:07 Uhr
Progger33
|
C++: |
#ifndef CEvent_h #define CEvent_h #include<iostream> #include<string> using namespace std; enum eTypes{ NOTYPE,THEATER,ROCKPOP,SCIENCE,NUMTYPES};
class CEvent{ private: eTypes m_type; string m_name; string m_datetime; string m_location; unsigned long m_maxSeats; unsigned long m_bookedSeats = 0.0; float m_pricePerTicket;
public:
CEvent(eTypes type = NOTYPE, string name = "",string datetime ="",string location = "", unsigned long maxSeats = 0, float pricePerTicket =0.0, unsigned long bookedSeats= 0.0); eTypes getType(); string getLocation(); unsigned long getNumAvailSeats(); void print(unsigned long numSeats =0); bool book (unsigned long numSeats ); string getTypeasString(eTypes type);
};
#endif /* CEvent_h */
|
C++: |
#include <stdio.h> #include "CEvent.h" #include<iostream> using namespace std;
CEvent::CEvent(eTypes type,string name,string datetime,string location,unsigned long maxSeats,float pricePerTicket, unsigned long bookedSeats){
m_type = type; m_name = name; m_maxSeats = maxSeats; m_location = location; m_bookedSeats = bookedSeats;
if(m_maxSeats>= m_bookedSeats){
m_bookedSeats = m_maxSeats; } else{
} if(m_pricePerTicket>0.00){
m_pricePerTicket = pricePerTicket; }
} eTypes CEvent::getType(){
return m_type;
} string CEvent::getLocation(){
return m_location; } unsigned long CEvent::getNumAvailSeats(){
return m_maxSeats-m_bookedSeats;
}
void CEvent::print(unsigned long numSeats){
cout << "Objektinfo:" << "" <<getTypeasString(m_type)<< " " << m_name << "/ " << m_location <<":" << m_datetime << " Einzelpreis" << ":" << m_pricePerTicket<< "$";
if(numSeats> 0){
cout << "Buchungsinfo:"<< m_pricePerTicket << "x" << getTypeasString(m_type) <<m_name <<"/" << m_location << ":"<< m_datetime << "Gesamtpreis:" << m_pricePerTicket << "$";
} }
string CEvent::getTypeasString(eTypes type){ switch(type){ case THEATER: return "THEATER"; case ROCKPOP: return "ROCK/POP"; case SCIENCE: return "SCIENCE";
default: return "Unbekannter Typ";
}
} bool CEvent::book (unsigned long numSeats ){ if(m_maxSeats> m_bookedSeats){
m_bookedSeats++; cout << "Buchungsinfo:"<< m_pricePerTicket << "x" << getTypeasString(m_type) <<m_name <<"/" << m_location << ":"<< m_datetime << "Gesamtpreis:" << m_pricePerTicket << "$"; return true;
} if(m_maxSeats < m_bookedSeats){
cout << "Nicht mehr genuegend Plätze verfügbar" << endl; return false; }
}
|
C++: |
/* * CEventDB.h * * Created on: 03.11.2017 * Author: Medion */ #include<iostream> #include<string> #include "CEvent.h" using namespace std;
class CEventDB{
private: CEvent* m_pEvents; int m_maxEvents; int m_curEvents = 0; public: CEventDB(int maxEvents = 10); ~CEventDB(); void print(); bool operator+= (const CEvent& rop); int bookEvent(unsigned long numSeats, int pos); int findEvent(int posStart, eTypes type , string location, CEvent& event);
};
|
C++: |
#include<iostream> #include<string> #include"CEventDB.h"
using namespace std;
CEventDB::CEventDB(int maxEvents ){
m_curEvents = 0;
if(maxEvents >= 10){
m_maxEvents = maxEvents; } else { m_maxEvents = 10; }
m_pEvents = new CEvent[m_maxEvents];
}
CEventDB::~CEventDB(){
delete [] m_pEvents; }
void CEventDB::print(){ if(m_curEvents ==0){ cout << " Leere Datenbank" << endl; } for(int i = 0; i<m_curEvents ; i++){ m_pEvents[i].print() ; cout << endl; } } bool CEventDB::operator+= (const CEvent& rop){ if(m_curEvents <m_maxEvents){ m_pEvents[m_curEvents] = rop; m_curEvents++; return true; }
else{
return false; }
} int CEventDB::bookEvent(unsigned long numSeats, int pos){ m_pEvents[pos].book(numSeats); if(pos>m_maxEvents){ cout << pos << "Ungueltig"<< endl; return false;
}
}
int CEventDB::findEvent(int posStart, eTypes type , string location, CEvent& event){ if(posStart >= 0 && posStart<m_maxEvents){
for(int i =posStart;i<m_maxEvents; i++){ if(m_pEvents[i].getType() == type &&m_pEvents[i].getLocation() == location){ event = m_pEvents[i]; return i;
} }
return -1; } else{
return -1; }
}
|
Wie soll ich die Methode bookEvent genau verändern ?
Das verstehe ich nicht? https://www.pic-upload.de/view-34291073/x.png.html
Was wollen die bei der j) genau von mir?
main:
C++: |
#include<iostream> #include<string> #include "CEvent.h" #include"CEventDB.h" using namespace std;
int main(){
CEvent e1(THEATER,"Aida", "23.7.14 20:00","Orangerie",500.00,25.00); CEvent e2(THEATER,"LLL", "23.7.14 20:00","Orangerie",500.00,25.00);
//e1(THEATER,"Aida", "23.7.14 20:00","Orangerie",500.00,25.00); e1.book(75);
CEventDB DBE(10);
DBE+=e1; DBE+=e2; DBE.print(); CEvent e3(THEATER,"", "","",0.00,0.00);
for(int i =0; i<10;i++){ int wert = DBE.findEvent(0,eTypes::SCIENCE,"h-da", e3);
if(wert == -1){
break; } else{
cout << e3.getType() << endl; }
} cout << "OK"<< endl; }
|
|