Objekt Programmierung

Neue Frage »

Auf diesen Beitrag antworten »
Windows 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_ */


 
Auf diesen Beitrag antworten »
Karlito

Hallo,

Du solltest im Konstruktor auch alle anderen Attribute initialisieren.

Gruß,

Karlito
Auf diesen Beitrag antworten »
Windows

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?
Auf diesen Beitrag antworten »
eulerscheZahl

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.
 
Auf diesen Beitrag antworten »
Windows

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







Auf diesen Beitrag antworten »
Karlito

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
Auf diesen Beitrag antworten »
Windows

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


Auf diesen Beitrag antworten »
Karlito

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
Auf diesen Beitrag antworten »
Windows

Hat jemand ne Idee?
Auf diesen Beitrag antworten »
Karlito

Haben gleichzeitig gepostet. Bitte Beitrag über deinem Anschauen.

Gruß,

Karlito
Auf diesen Beitrag antworten »
Windows

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
Auf diesen Beitrag antworten »
Karlito

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;
}
Auf diesen Beitrag antworten »
Windows

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

Ist ein wenig schwer zu verstehen was man da genau machen soll.
Auf diesen Beitrag antworten »
Karlito

Google nach überladen von Operatoren in C++.

Gruß,

Karlito
Auf diesen Beitrag antworten »
Windows

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




Auf diesen Beitrag antworten »
Windows

Habe mal die Ostream ausgabe pobiert .

Aber was ist genau dieses s nache dem duration.

Hier meine Ansätze wenigstens .

Stecke jetzt aber irgendwie fest jetzt auch verwirrt

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:
#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;
}

ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();

}





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:
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:

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


};
ostream& operator<< (ostream& lop, CTitle& rop);


#endif /* CTITLE_H_ */

Auf diesen Beitrag antworten »
Karlito

Hallo,

Was für ein s meinst Du?

Ich habe mal die Fehler korrigiert und kommentiert:
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:
#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 //Hier Fehlerchen
{
	return m_name;
}

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

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

ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();

	return lop; //return-Statement fehlte
}


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

#include <string>
#include <iostream> //Dieses Include fehlte!
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;


};
ostream& operator<< (ostream& lop, CTitle& rop);


#endif /* CTITLE_H_ */
Auf diesen Beitrag antworten »
Windows

Das s nach der duration in der Ausgabe?
Auf diesen Beitrag antworten »
Karlito

ich kann die Ausgabe nicht nachvollziehen.

Gruß,

Karlito
Auf diesen Beitrag antworten »
Windows

Was meinst du genau ?
Auf diesen Beitrag antworten »
Karlito

Mein Test-Programm gibt kein "s" aus.

code:
1:
2:
3:
4:
5:
6:
7:
8:
int main(int argc, char **argv){
	CTitle title = CTitle();
	cout << title << endl;

	return 0;
}


ergibt

code:
1:
2:
3:
0x7fff42086600 (Untitled); (Unknown) ; 0


Gruß,

Karlito
Auf diesen Beitrag antworten »
Windows

Die einzige Hilfe die jetzt noch kommen kann ist von Eulersche Zahl großes Grinsen

Mehr Personal gibt es ja nicht großes Grinsen
Auf diesen Beitrag antworten »
eulerscheZahl

Meinst du das s in der Angabe zu Aufgabe d?
Das steht für die Einheit Sekunden.
code:
1:
2:
3:
4:
5:
6:
7:
ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();
	lop << " s"; //Ausgabe um s erweitert
}
Auf diesen Beitrag antworten »
Windows

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:
#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;
}

ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();
	lop << " s"; //Ausgabe um s erweitert
	
	

}




Warum werden aber so viele Fehler angezeigt?

Und wie kann ich auf das contentSize bei der Ausgabe zugreifen?

Description Resource Path Location Type
'string' in 'class CTitle' does not name a type CTitle.cpp /CTitle line 50 C/C++ Problem
Member declaration not found CTitle.cpp /CTitle line 50 Semantic Error
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const char [3]') CTitle.cpp /CTitle line 68 C/C++ Problem
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const char [3]') CTitle.cpp /CTitle line 70 C/C++ Problem
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const char [4]') CTitle.cpp /CTitle line 69 C/C++ Problem
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'CTitle*') CTitle.cpp /CTitle line 67 C/C++ Problem
Type 'CTitle::string' could not be resolved CTitle.cpp /CTitle line 50 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 statement in function returning non-void [-Wreturn-type] CTitle.cpp /CTitle line 72 C/C++ Problem
No return, in function returning non-void CEvent.cpp /CEvent line 53 Code Analysis Problem
No return, in function returning non-void CTitle.cpp /CTitle line 65 Code Analysis Problem
Statement has no effect 'numSeats*m_pricePerTicket' CEvent.cpp /CEvent line 98 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
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'const char [3]' CTitle.cpp /CTitle line 68 C/C++ Problem
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'const char [3]' CTitle.cpp /CTitle line 70 C/C++ Problem
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'const char [4]' CTitle.cpp /CTitle line 69 C/C++ Problem
mismatched types 'const std::basic_string<_CharT, _Traits, _Alloc>' and 'CTitle*' CTitle.cpp /CTitle line 67 C/C++ Problem
no known conversion for argument 2 from 'const char [3]' to 'CTitle&' CTitle.cpp /CTitle line 65 C/C++ Problem
no known conversion for argument 2 from 'const char [4]' to 'CTitle&' CTitle.cpp /CTitle line 65 C/C++ Problem
no known conversion for argument 2 from 'CTitle*' to 'CTitle&' CTitle.cpp /CTitle line 65 C/C++ Problem
template argument deduction/substitution failed: CTitle line 2753, external location: c:\program files\git\eclipse\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string
.h C/C++ Problem
candidates are: CTitle.cpp /CTitle line 67 C/C++ Problem
candidates are: CTitle.cpp /CTitle line 68 C/C++ Problem
candidates are: CTitle.cpp /CTitle line 69 C/C++ Problem
candidates are: CTitle.cpp /CTitle line 70 C/C++ Problem
std::ostream& operator<<(std::ostream&, CTitle&) CTitle.cpp /CTitle line 65 C/C++ Problem
template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) CTitle line 2753, external location: c:\program files\git\eclipse\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string
.h C/C++ Problem
Auf diesen Beitrag antworten »
Windows

Fehler beseitigt großes Grinsen

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:

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


};
ostream& operator<< (ostream& lop, CTitle& rop);


#endif /* CTITLE_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:
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:


 #include "CTitle.h"
#include <string>
#include<iostream>
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 m_name;
}

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

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

ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();
	lop << " s"; //Ausgabe um s erweitert



}






Was ich jetzt nicht genau an der Aufgabe verstehe wie ich dieses contentSize ausgeben soll?

Wie soll ich dieses präfix verwenden ?
Auf diesen Beitrag antworten »
Windows

Keine Tipps mehr Eulersche Zahl ?
Auf diesen Beitrag antworten »
Windows

Ist jemand da der noch helfen kann ?
Auf diesen Beitrag antworten »
eulerscheZahl

Na schön.
Dann gib mal die komplette Angabe. In deinem Programm steht nämlich noch mehr, was so keinen Sinn macht.
Auf diesen Beitrag antworten »
Windows

Alle angaben stehen im Header .

Die cpp habe ich selber implementiert.

Ist der Konstruktor falsch wie ich den Implementiert hab?

Wir haben nur header bekommen und aufgabenstellung .
Auf diesen Beitrag antworten »
eulerscheZahl

Das hier sieht nicht sinnvoll aus:
code:
1:
2:
3:
4:
5:
if (m_contentSize < 0 || m_contentSize > 0) {
	m_contentSize = contentSize;
} else {
	m_contentSize = 0;
}

Wenn in m_contentSize ein anderer Wert als 0 steht, ersetze ihn durch den, der in contentSize übergeben wird. Sonst setze den Wert auf 0 (er ist in diesem Fall übrigens bereits vorher 0).

Nach der Beschreibung im Header müsste das so aussehen:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
//Die Bitrate muss zwischen 32000 und 320000 bit/s liegen.
if (bitrate >= 32000 && bitrate <= 320000)
{
	m_contentSize = contentSize;
	m_duration = duration;
	m_bitrate = bitrate;
}
else
{
//Falls diese Zusicherung verletzt wird, werden die Attribute
//m_bitRate, m_duration und m_contentSize auf 0 gesetzt.
	m_contentSize = 0;
	m_duration = 0;
	m_bitrate = 0;
}


m_contentSize und m_duration hängen also auch von bitrate ab.


Zu deiner eigentlichen Frage: du musst prüfen, in welchem Intervall die Größe liegt.
code:
1:
2:
3:
4:
5:
6:
if (rop.m_contentSize > 9999 * 1024) // > 9999 KiB
	lop << rop.m_contentSize / (1024 * 1024) << " MiB";
else if (rop.m_contentSize > 9999) // > 9999 B
	lop << rop.m_contentSize / 1024 << " KiB";
else
	lop << rop.m_contentSize << " B"

Problem dabei: du kannst nicht auf m_contentSize zugreifen, da private. Im Header gibt es keinen Getter dafür. Entweder machst du einen rein (falls du das darfst) oder du befreundest den ostream, damit er auf private Member zugreifen kann.
Auf diesen Beitrag antworten »
Windows

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

if (rop.m_contentSize > 9999 * 1024) // > 9999 KiB
	lop << rop.m_contentSize / (1024 * 1024) << " MiB";
else if (rop.m_contentSize > 9999) // > 9999 B
	lop << rop.m_contentSize / 1024 << " KiB";
else
	lop << rop.m_contentSize << " B"




Warum rechnest du 9999*1024 ?

Was bedeuten diese // ?


Warum dann 1024*1024?
Auf diesen Beitrag antworten »
eulerscheZahl

// leitet ein Zeilenkommentar ein.
Ansonsten: probiere ein paar Zahlen aus. Dann siehst du, was passiert.

123456789 Byte = 120563 KiB = 117 MiB (jeweils abgerundet).
Wenn die Zahl größer als 9999 * 1024 ist, ist sie größer als 9999 KiB (1024 ist ja der Faktor für Kilo).
Dann wird sie in MiB angegeben. Also zweimal duch 1024 teilen (einmal für B -> KiB und einmal für KiB -> MiB).
Auf diesen Beitrag antworten »
Windows

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>
#include<iostream>
using namespace std;

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	//Die Bitrate muss zwischen 32000 und 320000 bit/s liegen.
	if (bitRate >= 32000 && bitRate <= 320000)
	{
		m_contentSize = contentSize;
		m_duration = duration;
		m_bitRate = bitRate;
	}
	else
	{
	//Falls diese Zusicherung verletzt wird, werden die Attribute
	//m_bitRate, m_duration und m_contentSize auf 0 gesetzt.
		m_contentSize = 0;
		m_duration = 0;
		m_bitRate = 0;
	}

}



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

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

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

double CTitle::getContentsize(){

	return m_contentSize;
}
ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();
	lop << " s"; //Ausgabe um s erweitert

	if (rop.m_contentSize > 9999 * 1024){ // > 9999 KiB
		lop << rop.m_contentSize / (1024 * 1024) << " MiB";
	else() if (rop.m_contentSize > 9999) // > 9999 B{
		lop << rop.m_contentSize / 1024 << " KiB";
	}
	else{
		lop << rop.m_contentSize << " B"
	}
	}

return lop;

}


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:

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

	double getContentsize();


};
ostream& operator<< (ostream& lop, CTitle& rop);


#endif /* CTITLE_H_ */




Fehler

Description Resource Path Location Type
'int CTitle::m_contentSize' is private CTitle.h /CTitle line 34 C/C++ Problem
Description Resource Path Location Type
expected ';' before 'if' CTitle.cpp /CTitle line 58 C/C++ Problem
Description Resource Path Location Type
expected '}' before 'else' CTitle.cpp /CTitle line 58 C/C++ Problem
Description Resource Path Location Type
expected declaration before '}' token CTitle.cpp /CTitle line 64 C/C++ Problem
Description Resource Path Location Type
expected primary-expression before ')' token CTitle.cpp /CTitle line 58 C/C++ Problem
Description Resource Path Location Type
expected unqualified-id before 'else' CTitle.cpp /CTitle line 61 C/C++ Problem
Description Resource Path Location Type
within this context CTitle.cpp /CTitle line 56 C/C++ Problem
Description Resource Path Location Type
within this context CTitle.cpp /CTitle line 57 C/C++ Problem


Aber das runden muss ich noch irgendwie implementieren oder ?
Auf diesen Beitrag antworten »
eulerscheZahl

Und deshalb habe ich kaum Motivation, dir zu antworten:
in 6 Zeilen hast du es geschafft, 4 Fehler einzubauen, die vorher nicht da waren.
Beim ersten if hast du eine '{' eingefügt, aber keine '}'.
Beim ersten else dann runde Klammern geschrieben, wo keine hinkommen und '{' in den Kommentar geschrieben.
Beim zweiten else gehen dann zwei geschweifte Klammern zu.

Das Semikolon hatte ich vergessen, hättest du anhand der Compilermeldungen aber merken können.
Zur Sichtbarkeit hatte ich mich ja schon geäußert.
Es gibt da eine ziemlich große Lücke zwischen dem, was du kannst und dem, was du können sollst.
Auf diesen Beitrag antworten »
Windows

Ich bekomme die Fehler einfach nicht weg geschockt

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:

#include "CTitle.h" 
#include <string> 
#include<iostream> 
using namespace std; 
  
CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate) 
{ 
    //Die Bitrate muss zwischen 32000 und 320000 bit/s liegen. 
    if (bitRate >= 32000 && bitRate <= 320000) 
    { 
        m_contentSize = contentSize; 
        m_duration = duration; 
        m_bitRate = bitRate; 
    } 
    else 
    { 
    //Falls diese Zusicherung verletzt wird, werden die Attribute 
    //m_bitRate, m_duration und m_contentSize auf 0 gesetzt. 
        m_contentSize = 0; 
        m_duration = 0; 
        m_bitRate = 0; 
    } 
  
} 
  
  
  
 string CTitle::getName() const 
{ 
    return m_name; 
} 
  
string CTitle::getPerformer() const 
{ 
    return m_performer; 
} 
  
int CTitle::getDuration() const 
{ 
    return m_duration; 
} 
  
double CTitle::getContentsize(){ 
  
    return m_contentSize; 
} 
ostream& operator<< (ostream& lop, CTitle& rop){ 
  
    lop<< &rop << " " << rop.getName(); 
    lop<< "; " << rop.getPerformer(); 
    lop<< " ; " << rop.getDuration(); 
    lop << " s"; //Ausgabe um s erweitert 
  
    if (rop.m_contentSize > 9999 * 1024){ // > 9999 KiB 
        lop << rop.m_contentSize / (1024 * 1024) << " MiB"; 
    } 
    else if (rop.m_contentSize > 9999){ // > 9999 B{ 
        lop << rop.m_contentSize / 1024 << " KiB"; 
    } 
    else{ 
        lop << rop.m_contentSize << " B" 
    } 
    } 
  
return lop; 
  
}




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:
#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; 
  
    double getContentsize(); 
  
  
}; 
ostream& operator<< (ostream& lop, CTitle& rop); 

  
#endif /* CTITLE_H_ */



Description Resource Path Location Type
'int CTitle::m_contentSize' is private CTitle.h /CTitle line 34 C/C++ Problem
expected ';' before '}' token CTitle.cpp /CTitle line 64 C/C++ Problem
expected declaration before '}' token CTitle.cpp /CTitle line 69 C/C++ Problem
expected unqualified-id before 'return' CTitle.cpp /CTitle line 67 C/C++ Problem
within this context CTitle.cpp /CTitle line 56 C/C++ Problem
within this context CTitle.cpp /CTitle line 57 C/C++ Problem
within this context CTitle.cpp /CTitle line 59 C/C++ Problem
within this context CTitle.cpp /CTitle line 60 C/C++ Problem
within this context CTitle.cpp /CTitle line 63 C/C++ Problem
Auf diesen Beitrag antworten »
NV21

Habe bei dieser AUfgabe immer noch probleme und habe gedacht das ich mal meinen Code poste.

Im moment scheint das forum sowieso tot zu sein großes Grinsen

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:


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

	double getContentsize();


};
ostream& operator<< (ostream& lop, CTitle& rop);


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

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	//Die Bitrate muss zwischen 32000 und 320000 bit/s liegen.
	if (bitRate >= 32000 && bitRate <= 320000)
	{
		m_contentSize = contentSize;
		m_duration = duration;
		m_bitRate = bitRate;
	}
	else
	{
	//Falls diese Zusicherung verletzt wird, werden die Attribute
	//m_bitRate, m_duration und m_contentSize auf 0 gesetzt.
		m_contentSize = 0;
		m_duration = 0;
		m_bitRate = 0;
	}

}



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

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

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

double CTitle::getContentsize(){

	return m_contentSize;
}
ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();
	lop << " s"; //Ausgabe um s erweitert

	if (rop.m_contentSize > 9999 * 1024){ // > 9999 KiB
		lop << rop.m_contentSize / (1024 * 1024) << " MiB";
	}
	else if (rop.m_contentSize > 9999){ // > 9999 B
		lop << rop.m_contentSize / 1024 << " KiB";
	}

	else{
		lop << rop.m_contentSize << " B"
	}


return lop;

}


Auf diesen Beitrag antworten »
Windows

Wo liegen den die Feheler damit ich irgendwie ans Proggen komme großes Grinsen
Auf diesen Beitrag antworten »
eulerscheZahl

Wie vor knapp 2 Monaten schon geschrieben:
Zitat:
Original von eulerscheZahl
du kannst nicht auf m_contentSize zugreifen, da private. Im Header gibt es keinen Getter dafür. Entweder machst du einen rein (falls du das darfst) oder du befreundest den ostream, damit er auf private Member zugreifen kann.

friend ostream& operator<< (ostream& lop, CTitle& rop); (im Header, innerhalb der Klasse).
In der .cpp fehlt bei lop << rop.m_contentSize << " B"; das Semikolon am Ende.
Auf diesen Beitrag antworten »
Windows

Doch ich habe ein getter eingebaut:

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:
CTitle.h
 *
 *  Created on: 03.08.2016
 *      Author: VAIO
 */


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

	double getContentsize();  hier eingebaut 

	ostream& operator<< (ostream& lop, CTitle& rop);
};











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:


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

CTitle::CTitle(int contentSize, int duration, string name, string performer, int bitRate)
{
	//Die Bitrate muss zwischen 32000 und 320000 bit/s liegen.
	if (bitRate >= 32000 && bitRate <= 320000)
	{
		m_contentSize = contentSize;
		m_duration = duration;
		m_bitRate = bitRate;
	}
	else
	{
	//Falls diese Zusicherung verletzt wird, werden die Attribute
	//m_bitRate, m_duration und m_contentSize auf 0 gesetzt.
		m_contentSize = 0;
		m_duration = 0;
		m_bitRate = 0;
	}

}



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

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

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

double CTitle::getContentsize(){

	return m_contentSize;       hierrrrrrrrrr
}
ostream& operator<< (ostream& lop, CTitle& rop){

	lop<< &rop << " " << rop.getName();
	lop<< "; " << rop.getPerformer();
	lop<< " ; " << rop.getDuration();
	lop << " s"; //Ausgabe um s erweitert

	if (rop.m_contentSize > 9999 * 1024){ // > 9999 KiB
		lop << rop.m_contentSize / (1024 * 1024) << " MiB";
	}
	else if (rop.m_contentSize > 9999){ // > 9999 B
		lop << rop.m_contentSize / 1024 << " KiB";
	}

	else{
		lop << rop.m_contentSize << " B";
	}


return lop;

}



Ich habe es im code geschrieben


Description Resource Path Location Type
'int CTitle::m_contentSize' is private CTitle.h /CTitle line 34 C/C++ Problem
'std::ostream& CTitle::operator<<(std::ostream&, CTitle&)' must take exactly one argument CTitle.h /CTitle line 71 C/C++ Problem
within this context CTitle.cpp /CTitle line 56 C/C++ Problem
within this context CTitle.cpp /CTitle line 57 C/C++ Problem
within this context CTitle.cpp /CTitle line 59 C/C++ Problem
within this context CTitle.cpp /CTitle line 60 C/C++ Problem
within this context CTitle.cpp /CTitle line 64 C/C++ Problem
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 'numSeats*m_pricePerTicket' CEvent.cpp /CEvent line 98 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
Auf diesen Beitrag antworten »
eulerscheZahl

Dann solltest du aber auch getContentsize aufrufen und nicht über m_contentSize darauf zugreifen.
Ich weiß wieder, warum ich keine Lust mehr hatte zu antworten.
 
Neue Frage »
Antworten »


Verwandte Themen

Die Beliebtesten »
Die Größten »
Die Neuesten »