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)
--- Objekt Programmierung (http://www.informatikerboard.de/board/thread.php?threadid=3165)


Geschrieben von Windows am 03.08.2016 um 20:48:

  Objekt Programmierung

Hallo alle zusammen ich habe gerade probleme bei dieser programmier Aufgabe.

Habe versucht bei der b) den Konstruktor zu implementieren .

Aber weiss nicht so richtig ob das falsch oder richtig ist großes Grinsen

Kann mir jemand helfen?

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:

 #include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	if(m_contentSize <= 0 || m_contentSize >= 0){

		m_contentSize = contentSize;
	}
		else{

		m_contentSize = 0;
	}
}

 if(m_duration <= 0 || m_duration >= 0){

		m_duration = duration;

		else{

		m_duration = 0;
	}
}


string CTitle::getName() const
{
	return "";
}

string CTitle::getPerformer() const
{
	return "";
}

int CTitle::getDuration() const
{
	return 0;
}








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:
#ifndef CTITLE_H_
#define CTITLE_H_

#include <string>
using namespace std;

/**
 * Diese Klasse beschreibt einen MP3-kodierten Titel (Song).
 */
class CTitle
{
private:
	/** Name (Titel) des Songs */
	string m_name;

	/** Ausführende(r) (Interpret, Gruppe, Orchester o. ä.) */
	string m_performer;

	/** Die Dauer des Titels in Sekunden. */
	int m_duration;

	/** Die Bitrate in bit/s. */
	int m_bitRate;

	/** Die Größe (Anzahl der Bytes) der Audiodaten. */
	int m_contentSize;

public:
	/**
	 * Erzeugt ein neues Objekt, dessen Attribute mit den angegebenen
	 * Werten initialisiert werden.
	 *
	 * Falls Name oder Ausführende(r) (performer) leer sind, werden
	 * die Default-Werte verwendet.
	 *
	 * Die Angabe der Bitrate erfolgt in bit/s.
	 *
	 * Die Bitrate muss zwischen 32000 und 320000 bit/s liegen.
 	 * Falls diese Zusicherung verletzt wird, werden die Attribute
	 * m_bitRate, m_duration und m_contentSize auf 0 gesetzt.
	 */
	CTitle(int contentSize = 0, int duration = 0,
		   string name = "(Untitled)", string performer = "(Unknown)",
		   int bitRate = 128000);

	/**
	 * Diese Methode liefert den Namen des Titels.
	 */
	string getName() const;

	/**
	 * Diese Methode liefert den Ausführenden (Performer).
	 */
	string getPerformer() const;

	/**
	 * Diese Methode liefert die Dauer (Länge) des Titels in Sekunden.
	 */
	int getDuration() const;

};


#endif /* CTITLE_H_ */





Geschrieben von Karlito am 04.08.2016 um 20:32:

 

Hallo,

Du solltest im Konstruktor auch alle anderen Attribute initialisieren.

Gruß,

Karlito



Geschrieben von Windows am 04.08.2016 um 22:55:

 

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:
 #include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	if(m_contentSize <= 0 || m_contentSize >= 0){

		m_contentSize = contentSize;
	}
		else{

		m_contentSize = 0;
	}


 if(m_duration <= 0 || m_duration >= 0){

		m_duration = duration;

		else{

		m_duration = 0;
	}
}

 m_name = name;
 m_performer = performer;

 if(     m_bitRate>=32000 && m_bitRate=< 320000){

	 m_bitRate = bitRate;
	 else{

		 m_bitRate = 0;
		 m_duration = 0;
		 m_contenSize = 0;
	 }
 }

}





Aber leider schon paar Fehler error bei Eclipse verwirrt

Description Resource Path Location Type
'm_name' does not name a type CTitle.cpp /CTitle line 29 C/C++ Problem
Description Resource Path Location Type
'm_performer' does not name a type CTitle.cpp /CTitle line 30 C/C++ Problem
Description Resource Path Location Type
expected '}' before 'else' CTitle.cpp /CTitle line 23 C/C++ Problem
Description Resource Path Location Type
expected unqualified-id before 'if' CTitle.cpp /CTitle line 32 C/C++ Problem


Stimmt wenigstens die Implementierung soweit?



Geschrieben von eulerscheZahl am 05.08.2016 um 05:40:

 

Die Klammer von Zeile 39 sollte eigentlich in Zeile 33 vor das else.

"'m_name' does not name a type"
hast du die Variable im Header definiert?

code:
1:
if(m_contentSize <= 0 || m_contentSize >= 0){

das ist immer true

code:
1:
m_bitRate=< 320000

die Syntax ist falsch.



Geschrieben von Windows am 05.08.2016 um 17:40:

 

Finde den Sytax felher nicht verwirrt

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:
 #include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	if(m_contentSize < 0 || m_contentSize > 0){

		m_contentSize = contentSize;
	}
		else{

		m_contentSize = 0;
	}


 if(m_duration <= 0 || m_duration >= 0){

		m_duration = duration;

		else{

		m_duration = 0;
	}
}

 m_name = name;
 m_performer = performer;

 if(     m_bitRate>=32000 && m_bitRate<= 320000){

	 m_bitRate = bitRate;
	 else{

		 m_bitRate = 0;
		 m_duration = 0;
		 m_contenSize = 0;
	 }
 }

}



string CTitle::getName() const
{
	return "";
}

string CTitle::getPerformer() const
{
	return "";
}

int CTitle::getDuration() const
{
	return 0;
}










Geschrieben von Karlito am 05.08.2016 um 18:12:

 

Schau dir bitte noch mal an, wie if-then-else in C++ funktioniert. Du hast falsch geklammert Außerdem Tippfehler in Zeile 37 (contentSize t vergessen).

Gruß,

Karlito



Geschrieben von Windows am 06.08.2016 um 19:52:

 

so?

Scheint aber auch net zu passen

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:
 #include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	if(m_contentSize < 0 || m_contentSize > 0){

		m_contentSize = contentSize;
	}
		else{

		m_contentSize = 0;
	}


 if(m_duration <= 0 || m_duration >= 0){

		m_duration = duration;

		else(){

		m_duration = 0;
	}
}

 m_name = name;
 m_performer = performer;

 if(    m_bitRate>=32000 && m_bitRate<= 320000){

	 m_bitRate = bitRate;
	 else(){

		 m_bitRate = 0;
		 m_duration = 0;
		 m_contentSize = 0;
	 }
 }

}



string CTitle::getName() const
{
	return "";
}

string CTitle::getPerformer() const
{
	return "";
}

int CTitle::getDuration() const
{
	return 0;
}





Geschrieben von Karlito am 06.08.2016 um 21:28:

 

Nö, so:

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:
#include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	if(m_contentSize < 0 || m_contentSize > 0){

		m_contentSize = contentSize;
	}
	else{

		m_contentSize = 0;
	}


	if(m_duration <= 0 || m_duration >= 0){

		m_duration = duration;

	}else{

		m_duration = 0;
	}

	m_name = name;
	m_performer = performer;

	if(     m_bitRate>=32000 && m_bitRate<= 320000){

		m_bitRate = bitRate;
	} else {

		m_bitRate = 0;
		m_duration = 0;
		m_contentSize = 0;
	}

}



string CTitle::getName() const
{
	return "";
}

string CTitle::getPerformer() const
{
	return "";
}

int CTitle::getDuration() const
{
	return 0;
}


Gruß.

Karlito



Geschrieben von Windows am 06.08.2016 um 21:28:

 

Hat jemand ne Idee?



Geschrieben von Karlito am 06.08.2016 um 21:43:

 

Haben gleichzeitig gepostet. Bitte Beitrag über deinem Anschauen.

Gruß,

Karlito



Geschrieben von Windows am 07.08.2016 um 00:08:

 

Warum werden bei den implementierten get Methoden nch Fehler angezeigt verwirrt

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:
#include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	if(m_contentSize < 0 || m_contentSize > 0){

		m_contentSize = contentSize;
	}
		else{

		m_contentSize = 0;
	}


 if(m_duration <= 0 || m_duration >= 0){

		m_duration = duration;
 }

		else{

		m_duration = 0;
	}


 m_name = name;
 m_performer = performer;

 if(    m_bitRate>=32000 && m_bitRate<= 320000){

	 m_bitRate = bitRate;
 }
	 else{

		 m_bitRate = 0;
		 m_duration = 0;
		 m_contentSize = 0;
	 }






 CTitle::string CTitle::getName() const
{
	return m_name;
}

string CTitle::getPerformer() const
{
	return m_performer;
}

int CTitle::getDuration() const
{
	return m_duration;
}










Description Resource Path Location Type
'string' is not a member of 'CTitle' CTitle.cpp /CTitle line 49 C/C++ Problem
a function-definition is not allowed here before '{' token CTitle.cpp /CTitle line 55 C/C++ Problem
a function-definition is not allowed here before '{' token CTitle.cpp /CTitle line 60 C/C++ Problem
expected ';' before 'CTitle' CTitle.cpp /CTitle line 49 C/C++ Problem
expected '}' at end of input CTitle.cpp /CTitle line 62 C/C++ Problem
Symbol 'string' could not be resolved CTitle.cpp /CTitle line 49 Semantic Error
control reaches end of non-void function [-Wreturn-type] CEvent.cpp /CEvent line 80 C/C++ Problem
Member 'm_bookedSeats' was not initialized in this constructor CEvent.cpp /CEvent line 12 Code Analysis Problem
Member 'm_curEvents' was not initialized in this constructor CEventDB.cpp /CEvent line 14 Code Analysis Problem
No return, in function returning non-void CEvent.cpp /CEvent line 53 Code Analysis Problem
Statement has no effect 'CTitle::string' CTitle.cpp /CTitle line 49 Code Analysis Problem
Statement has no effect 'numSeats*m_pricePerTicket' CEvent.cpp /CEvent line 98 Code Analysis Problem
Statement has no effect 'string' CTitle.cpp /CTitle line 54 Code Analysis Problem
statement has no effect [-Wunused-value] CEvent.cpp /CEvent line 98 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 55 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 60 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 65 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 70 C/C++ Problem
suggest parentheses around assignment used as truth value [-Wparentheses] CEvent.cpp /CEvent line 75 C/C++ Problem



Geschrieben von Karlito am 07.08.2016 um 00:40:

 

Hallo.

Du hast eine Klammer vergessen. Bitte arbeite mit einer sauberen Einrückung, dann sieht man soetwas leichter.

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:
#include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
  if(m_contentSize < 0 || m_contentSize > 0){
    m_contentSize = contentSize;
  } else {
    m_contentSize = 0;
  }


  if(m_duration <= 0 || m_duration >= 0){
    m_duration = duration;
  } else {
    m_duration = 0;
  }

  m_name = name;
  m_performer = performer;

  if(m_bitRate>=32000 && m_bitRate<= 320000){
    m_bitRate = bitRate;
  } else {
    m_bitRate = 0;
    m_duration = 0;
    m_contentSize = 0;
  }
} //Diese Klammer fehlte

string CTitle::getName() const
{
  return m_name;
}

string CTitle::getPerformer() const
{
  return m_performer;
}

int CTitle::getDuration() const
{
  return m_duration;
}



Geschrieben von Windows am 07.08.2016 um 00:43:

 

Hast du paar Tipps für die d) für mich ?

Ist ein wenig schwer zu verstehen was man da genau machen soll.



Geschrieben von Karlito am 07.08.2016 um 01:01:

 

Google nach überladen von Operatoren in C++.

Gruß,

Karlito



Geschrieben von Windows am 07.08.2016 um 09:04:

 

Ich probiere gerade die ostream Ausgabe großes Grinsen

Aber 3 Fehlermelldungen habe ich immer noch.

Wie bekomme ich die weg?

Description Resource Path Location Type
'string' in 'class CTitle' does not name a type CTitle.cpp /CTitle line 50 C/C++ Problem

Description Resource Path Location Type
Member declaration not found CTitle.cpp /CTitle line 50 Semantic Error

Description Resource Path Location Type
Type 'CTitle::string' could not be resolved CTitle.cpp /CTitle line 50 Semantic Error


Hier die cpp nochmals


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:
 #include "CTitle.h"
#include <string>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	if(m_contentSize < 0 || m_contentSize > 0){

		m_contentSize = contentSize;
	}
		else{

		m_contentSize = 0;
	}


 if(m_duration <= 0 || m_duration >= 0){

		m_duration = duration;
 }

		else{

		m_duration = 0;
	}


 m_name = name;
 m_performer = performer;

 if(    m_bitRate>=32000 && m_bitRate<= 320000){

	 m_bitRate = bitRate;
 }
	 else{

		 m_bitRate = 0;
		 m_duration = 0;
		 m_contentSize = 0;
	 }
}






 CTitle::string CTitle::getName() const
{
	return m_name;
}

string CTitle::getPerformer() const
{
	return m_performer;
}

int CTitle::getDuration() const
{
	return m_duration;
}






Forensoftware: Burning Board, entwickelt von WoltLab GmbH