22.04.2016, 08:42 |
Auf diesen Beitrag antworten » |
progger |
Neue Aufgabe c++
Hallo ich habe eine neue Aufgabe angefangen da mir die alte überhaupt kein Spass macht
Aber ich bin bei der e) wiedermal überfragt ?
Soll ich da was mittels cout einfach ausgeben ?
Ich habe wieder sau probleme damit.
CEvent.h
code: |
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:
|
#ifndef CEVENT_H_
#define CEVENT_H_
#include<iostream>
using namespace std;
#include<string>
class CEvent{
public:
enum eType {
NOTYPE, THEATER,ROCKPOP,SCIENCE, NUMTYPES
};
private:
eType m_type;
string m_name;
string m_datetime;
string m_location;
unsigned long m_maxSeats;
unsigned long m_bookedSeats;
float m_pricePerTicket;
public:
CEvent( eType type = NOTYPE, string name = "",string datetime = "", string location = "",unsigned long maxSeats = 0 );
eType getType();
string getLocation();
unsigned long getNumAvailSeats();
void pint(unsigned long numSeats = 0);
bool book( unsigned long numSeats);
string getTypeAsString(eType type);
};
|
|
cpp
code: |
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:
|
#include <iostream>
using namespace std;
#include "CEvent.h"
CEvent::CEvent( eType type , string name ,string datetime , string location ,unsigned long maxSeats ){
m_type = type;
m_name = name;
m_datetime = datetime;
m_location = location;
if(m_maxSeats >=0 ){
m_maxSeats = maxSeats;
}
if(m_maxSeats <= 0){
m_maxSeats = 0;
}
}
CEvent::eType CEvent::getType(){
return m_type;
}
string CEvent::getLocation(){
return m_location;
}
unsigned long CEvent::getNumAvailSeats(){
return m_maxSeats;
}
string CEvent::getTypeAsString(eType type){
if(m_type = NOTYPE){
return "Unbekannter Typ";
}
if(m_type = THEATER){
return "THEATER";
}
if(m_type = ROCKPOP){
return "ROCKPOP";
}
if(m_type = SCIENCE){
return "SCIENCE";
}
if(m_type = NUMTYPES){
return "Unbekannter Typ";
}
}
void CEvent::print(unsigned long numSeats){
}
|
|
Fehlermeldungen
Description Resource Path Location Type
Member declaration not found CEvent.cpp /CEvent/src line 82 Semantic Error
control reaches end of non-void function [-Wreturn-type] CEvent.cpp /CEvent/src line 80 C/C++ Problem
Member 'm_bookedSeats' was not initialized in this constructor CEvent.cpp /CEvent/src line 13 Code Analysis Problem
Member 'm_pricePerTicket' was not initialized in this constructor CEvent.cpp /CEvent/src line 13 Code Analysis Problem
No return, in function returning non-void CEvent.cpp /CEvent/src line 53 Code Analysis Problem
Possible assignment in condition 'm_type = NOTYPE' CEvent.cpp /CEvent/src line 55 Semantic Error
Possible assignment in condition 'm_type = NUMTYPES' CEvent.cpp /CEvent/src line 75 Semantic Error
Possible assignment in condition 'm_type = ROCKPOP' CEvent.cpp /CEvent/src line 65 Semantic Error
Possible assignment in condition 'm_type = SCIENCE' CEvent.cpp /CEvent/src line 70 Semantic Error
Possible assignment in condition 'm_type = THEATER' CEvent.cpp /CEvent/src line 60 Semantic Error
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent/src line 55 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent/src line 60 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent/src line 65 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent/src line 70 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent/src line 75 C/C++ Problem
Sind hauptsächlich warnungen |
|
|
|
23.04.2016, 09:24 |
Auf diesen Beitrag antworten » |
progger |
Kann mir jemand erklären wie ich das jetzt ausgeben kann ? |
24.04.2016, 12:23 |
Auf diesen Beitrag antworten » |
progger |
Tipps ? Eulersche zahl |
24.04.2016, 12:33 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Die Aufgabenstellung verrät doch schon, was zu tun ist. Du musst das nur noch abtippen.
Die grobe Struktur ist:
code: |
1:
2:
3:
4:
|
if (seatNumbers == 0)
cout << "foo" << endl;
else
cout << "bar" << endl; |
|
Jetzt musst du nur noch die Ausgabe mit dem füllen, was du ausgeben sollst.
Und auch Warnungen wie die hier solltest du ernst nehmen:
Possible assignment in condition 'm_type = NOTYPE' CEvent.cpp /CEvent/src line 55 Semantic Error |
Anzeige |
|
|
05.05.2016, 09:45 |
Auf diesen Beitrag antworten » |
progger |
Stimmt meine Lösung jetzt soweit ?
Ich habe nur noch probleme mit der h)?
Hat jemand tipps für die h)?
Header :
code: |
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:
|
#define CEVENT_H_
#include<iostream>
using namespace std;
#include<string>
enum eType {
NOTYPE, THEATER,ROCKPOP,SCIENCE, NUMTYPES
};
class CEvent{
private:
eType m_type;
string m_name;
string m_datetime;
string m_location;
unsigned long m_maxSeats;
unsigned long m_bookedSeats;
float m_pricePerTicket;
public:
CEvent( eType type = NOTYPE, string name = "",string datetime = "", string location = "",unsigned long int maxSeats = 0, float pricePerTicket = 0.0);
eType getType();
string getLocation();
unsigned long getNumAvailSeats();
void print(unsigned long numSeats = 0);
bool book( unsigned long numSeats);
string getTypeAsString(eType type);
};
#endif
|
|
cpp:
code: |
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:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
|
#include <iostream>
using namespace std;
#include "CEvent.h"
CEvent::CEvent( eType type , string name ,string datetime , string location ,unsigned long int maxSeats, float pricePerTicket){
m_type = type;
m_name = name;
m_datetime = datetime;
m_location = location;
if(m_maxSeats >=0 ){
m_maxSeats = maxSeats;
}
if(m_maxSeats <= 0){
m_maxSeats = 0;
}
}
eType CEvent::getType(){
return m_type;
}
string CEvent::getLocation(){
return m_location;
}
unsigned long CEvent::getNumAvailSeats(){
return m_maxSeats-m_bookedSeats;
}
string CEvent::getTypeAsString(eType type){
if(m_type = NOTYPE){
return "Unbekannter Typ";
}
if(m_type = THEATER){
return "THEATER";
}
if(m_type = ROCKPOP){
return "ROCKPOP";
}
if(m_type = SCIENCE){
return "SCIENCE";
}
if(m_type = NUMTYPES){
return "Unbekannter Typ";
}
}
void CEvent::print(unsigned long numSeats){
if (numSeats == 0){
cout << " Objektinfo: " << m_location << " " << m_type << " : " << m_datetime << " Einzelpreis : " << m_pricePerTicket << endl;
}
if (numSeats != 0){
cout << m_type << " 25x " << m_name << m_location << " : " << m_datetime << " Gesamtpreis: " << m_pricePerTicket << endl;
}
}
bool CEvent::book(unsigned long numSeats){
this->getNumAvailSeats();
if(this->getNumAvailSeats()== 0){
cout<< "Keine Plätze vorhanden "<< endl;
return false;} else {
m_bookedSeats += numSeats;
this->print(numSeats);
return true;
}
}
|
|
main cpp
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
|
#include <iostream>
#include "CEvent.h"
using namespace std;
int main(){
CEvent test(THEATER, "Aida","23.7.14 20:00", "Orangerie", 500,25.00);
CEvent test2(ROCKPOP, "Blitze","23.7.14 20:00", "h-da", 200, 0.00);
}
|
|
|
05.05.2016, 11:43 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Ich habe im Header noch ein #ifndef voranstellen müssen.
Im Konstruktor fehlt m_pricePerTicket = pricePerTicket;.
Bei der Preisausgabe hast du einen Fehler, wenn mehrere Tickets gebucht werden.
Kann gut sein, dass da noch mehr Fehler drin sind. Ich habe nicht wirklich nach Fehler gesucht, sie sind mir praktisch über den Weg gelaufen.
Die Main sieht jetzt so aus:
code: |
1:
2:
3:
4:
5:
6:
7:
|
int main(){
CEvent e1(THEATER, "Aida", "23.7.14 20:00", "Orangerie" , 500,25.00);
CEvent e2(SCIENCE, "Blitze", "17.7.14 20:00", "h-da" , 200, 0.00);
CEvent e3(ROCKPOP, "The Rockers", "1.7.14 22:00", "Musikkneipe", 50, 5.00);
if (!e3.book(75)) e3.book(25);
e3.print();
} |
|
|
09.05.2016, 08:43 |
Auf diesen Beitrag antworten » |
progger |
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
|
void CEvent::print(unsigned long numSeats){
if (numSeats == 0){
cout << " Objektinfo: " << m_location << " " << m_type << " : " << m_datetime << " Einzelpreis : " << m_pricePerTicket << endl;
}
if (numSeats != 0){
cout << m_type << " 25x " << m_name << m_location << " : " << m_datetime << " Gesamtpreis: " << m_pricePerTicket << endl;
}
}
|
|
Meinst du das hier ein Fehler steckt ?
Aber es ist doch gar nicht hier nach mehreren Tickets gefragt worden ? |
09.05.2016, 08:50 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
code: |
1:
|
" Gesamtpreis: " << m_pricePerTicket |
|
Merkst du was? |
09.05.2016, 12:01 |
Auf diesen Beitrag antworten » |
progger |
Ich habe dort Einzelpreis stehen .
Soll ich da Gesamtpreis schreiben oder wie ? |
09.05.2016, 12:23 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Du sollst den Gesamtpreis ausrechnen. |
09.05.2016, 12:48 |
Auf diesen Beitrag antworten » |
progger |
Den Gesamtpreis könnte man doch so ausrechnen :
Anzahl der Tickets *preis pro Ticket
Also :
m_numSeats*m_pricePerTicket;
Stimmt die denkweise so ? |
09.05.2016, 12:50 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Nur numSeats, das ist die an die Funktion übergebene Variable, keine Klassenvariable. |
09.05.2016, 13:42 |
Auf diesen Beitrag antworten » |
progger |
Meinst du ich soll einfach nur numSeats zurück geben ? |
10.05.2016, 06:54 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Du sollst da eine Formel hinschreiben, die den Gesamtpreis berechnet.
Zitat: |
Anzahl der Tickets *preis pro Ticket
Also :
m_numSeats*m_pricePerTicket; |
ist nah dran, aber die Variable m_numSeats existiert nicht. Wie heißt sie wirklich? |
14.05.2016, 22:21 |
Auf diesen Beitrag antworten » |
progger |
Meinst du das ich mit m_ darstellen soll?
Oder this->getnumAvailSeats()*m_pricePerTicket;
? |
15.05.2016, 08:01 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Nein
numSeats ist eine lokale Variable. Verwende sie auch!
code: |
1:
|
numSeats*m_pricePerTicket |
|
|
15.05.2016, 10:49 |
Auf diesen Beitrag antworten » |
progger |
Warum lässt man das m_ weg?
Warum wird der Spamschutz Code nicht mehr angezeigt? |
15.05.2016, 11:50 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Weil die Variable nicht m_numSeats heißt.
Du schreibst bei der Deklaration
code: |
1:
|
void CEvent::print(unsigned long numSeats){ |
|
das m_ steht für member und deutet an, dass es sich um eine Klassenvariable handelt (ich persönlich mag die ungarische Notation nicht). |
15.05.2016, 20:22 |
Auf diesen Beitrag antworten » |
progger |
code: |
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:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
|
#include <iostream>
using namespace std;
#include "CEvent.h"
CEvent::CEvent( eType type , string name ,string datetime , string location ,unsigned long int maxSeats, float pricePerTicket){
m_type = type;
m_name = name;
m_datetime = datetime;
m_location = location;
m_pricePerTicket = pricePerTicket;
if(m_maxSeats >=0 ){
m_maxSeats = maxSeats;
}
if(m_maxSeats <= 0){
m_maxSeats = 0;
}
}
eType CEvent::getType(){
return m_type;
}
string CEvent::getLocation(){
return m_location;
}
unsigned long CEvent::getNumAvailSeats(){
return m_maxSeats-m_bookedSeats;
}
string CEvent::getTypeAsString(eType type){
if(m_type = NOTYPE){
return "Unbekannter Typ";
}
if(m_type = THEATER){
return "THEATER";
}
if(m_type = ROCKPOP){
return "ROCKPOP";
}
if(m_type = SCIENCE){
return "SCIENCE";
}
if(m_type = NUMTYPES){
return "Unbekannter Typ";
}
}
void CEvent::print(unsigned long numSeats){
if (numSeats == 0){
cout << " Objektinfo: " << m_location << " " << m_type << " : " << m_datetime << " Einzelpreis : " << m_pricePerTicket << endl;
}
if (numSeats != 0){
cout << m_type << " 25x " << m_name << m_location << " : " << m_datetime << " Gesamtpreis: " << m_pricePerTicket << endl;
}
numSeats*m_pricePerTicket;
}
bool CEvent::book(unsigned long numSeats){
this->getNumAvailSeats();
if(this->getNumAvailSeats()== 0){
cout<< "Keine Plätze vorhanden "<< endl;
return false;} else {
m_bookedSeats += numSeats;
this->print(numSeats);
return true;
}
}
|
|
Stimmt der eingebaute Code so ? |
15.05.2016, 20:28 |
Auf diesen Beitrag antworten » |
progger |
Wie soll ich hier die freie position im Array einbauen?
code: |
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:
|
#include <iostream>
using namespace std;
#include "CEvent.h"
#include"CEventDB.h"
CEventDB::CEventDB(int maxEvents ){
if(m_maxEvents >= 10 ){
m_maxEvents = maxEvents;
}
if(m_maxEvents <= 10 ){
m_maxEvents = 10;
}
m_pEvents = new CEvent[maxEvents];
}
|
|
|
17.05.2016, 20:00 |
Auf diesen Beitrag antworten » |
progger |
Weisst du was ich genau bei der b) machen soll ? |