Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
-- Praktische Informatik (http://www.informatikerboard.de/board/board.php?boardid=6)
--- Neue Aufgabe c++ (http://www.informatikerboard.de/board/thread.php?threadid=2966)


Geschrieben von progger am 22.04.2016 um 08:42:

  Neue Aufgabe c++

Hallo ich habe eine neue Aufgabe angefangen da mir die alte überhaupt kein Spass macht großes Grinsen

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



Geschrieben von progger am 23.04.2016 um 09:24:

 

Kann mir jemand erklären wie ich das jetzt ausgeben kann ?



Geschrieben von progger am 24.04.2016 um 12:23:

 

Tipps ? Eulersche zahl



Geschrieben von eulerscheZahl am 24.04.2016 um 12:33:

 

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



Geschrieben von progger am 05.05.2016 um 09:45:

 

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);

}



Geschrieben von eulerscheZahl am 05.05.2016 um 11:43:

 

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();
}



Geschrieben von progger am 09.05.2016 um 08:43:

 

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 ?



Geschrieben von eulerscheZahl am 09.05.2016 um 08:50:

 

code:
1:
" Gesamtpreis: " <<  m_pricePerTicket

Merkst du was?



Geschrieben von progger am 09.05.2016 um 12:01:

 

Ich habe dort Einzelpreis stehen .

Soll ich da Gesamtpreis schreiben oder wie ?



Geschrieben von eulerscheZahl am 09.05.2016 um 12:23:

 

Du sollst den Gesamtpreis ausrechnen.



Geschrieben von progger am 09.05.2016 um 12:48:

 

Den Gesamtpreis könnte man doch so ausrechnen :

Anzahl der Tickets *preis pro Ticket

Also :

m_numSeats*m_pricePerTicket;

Stimmt die denkweise so ?



Geschrieben von eulerscheZahl am 09.05.2016 um 12:50:

 

Nur numSeats, das ist die an die Funktion übergebene Variable, keine Klassenvariable.



Geschrieben von progger am 09.05.2016 um 13:42:

 

Meinst du ich soll einfach nur numSeats zurück geben ?



Geschrieben von eulerscheZahl am 10.05.2016 um 06:54:

 

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?



Geschrieben von progger am 14.05.2016 um 22:21:

 

Meinst du das ich mit m_ darstellen soll?

Oder this->getnumAvailSeats()*m_pricePerTicket;
?


Forensoftware: Burning Board, entwickelt von WoltLab GmbH