Objekt Programmierung |
Windows unregistriert
|
|
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?
|
|
14.08.2016 11:27 |
|
|
|
// 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).
__________________ Syntax Highlighting fürs Board (Link)
|
|
14.08.2016 11:32 |
|
|
Windows unregistriert
|
|
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 ?
|
|
15.08.2016 16:11 |
|
|
|
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.
__________________ Syntax Highlighting fürs Board (Link)
|
|
15.08.2016 16:28 |
|
|
Windows unregistriert
|
|
Ich bekomme die Fehler einfach nicht weg
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
|
|
16.08.2016 18:38 |
|
|
NV21 unregistriert
|
|
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
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;
}
|
|
|
|
06.10.2016 18:39 |
|
|
Windows unregistriert
|
|
Wo liegen den die Feheler damit ich irgendwie ans Proggen komme
|
|
08.10.2016 10:32 |
|
|
|
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.
__________________ Syntax Highlighting fürs Board (Link)
|
|
08.10.2016 10:43 |
|
|
Windows unregistriert
|
|
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
|
|
11.10.2016 10:17 |
|
|
|
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.
__________________ Syntax Highlighting fürs Board (Link)
|
|
11.10.2016 11:52 |
|
|
Windows unregistriert
|
|
Wie greife ich darauf zu ?
|
|
11.10.2016 18:04 |
|
|
Windows unregistriert
|
|
ok habe jetzt zumindest die Fehler weg
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:
|
#ifndef CTITLE_H_
#define CTITLE_H_
#include <string>
#include <iostream>
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. */
double 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:
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;
}
ostream& operator<< (ostream& lop, CTitle& rop){
lop<< &rop << " " << rop.getName();
lop<< "; " << rop.getPerformer();
lop<< " ; " << rop.getDuration();
lop << " s"; //Ausgabe um s erweitert
if (rop.getContentsize() > 9999 * 1024){ // > 9999 KiB
lop << rop.getContentsize() / (1024 * 1024) << " MiB";
}
else if (rop. getContentsize() > 9999){ // > 9999 B
lop << rop.getContentsize() / 1024 << " KiB";
}
else{
lop << rop.getContentsize() << " B";
}
return lop;
}
|
|
main
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
|
#include "CTitle.h"
#include <string>
#include<iostream>
using namespace std;
int main(){
CTitle a(0,2,"titlel","0",23456);
cout<< a <<endl;
}
|
|
Frage zu f)
Ich habe erst einmal jetzt ein Operator erstellt im Header:
CTitle operator+( CTitle right);
main 2 Titel erstellt
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
|
#include "CTitle.h"
#include <string>
#include<iostream>
using namespace std;
int main(){
CTitle a(0,2,"titlel","0",23456);
cout<< a <<endl;
CTitle b(0,3," BadBoy", "text", 66666);
|
|
Muss ich rgendwie auch den linken Operand erstellen ?
Wie ?
In der Aufgabe steht wenn die Bitrate nicht übereinstimmt ,den linken Operanden ausgeben .
WIe soll ich Bitrate vergleichen ?
So?
If( this.Bitrate != bitrate ????
|
|
15.10.2016 11:09 |
|
|
Karlito
Kaiser
Dabei seit: 11.04.2011
Beiträge: 1.461
|
|
Aufgabenteil f hast du nicht mit gepostet.
Gruß,
Karlito
|
|
15.10.2016 16:47 |
|
|
Karlito
Kaiser
Dabei seit: 11.04.2011
Beiträge: 1.461
|
|
Zitat: |
Original von Windows
Frage zu f)
Ich habe erst einmal jetzt ein Operator erstellt im Header:
CTitle operator+( CTitle right);
|
Schau dir noch mal an, wie Operatoren definiert sind und wie sie überladen werden. Teilweise kannst du bei "<<" spicken. Verstehe was lop und rop sind und wie Du das bei dem Operator + anwenden musst.
Zitat: |
Original von Windows
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
|
#include "CTitle.h"
#include <string>
#include<iostream>
using namespace std;
int main(){
CTitle a(0,2,"titlel","0",23456);
cout<< a <<endl;
CTitle b(0,3," BadBoy", "text", 66666);
|
|
Muss ich rgendwie auch den linken Operand erstellen ?
Wie ?
In der Aufgabe steht wenn die Bitrate nicht übereinstimmt ,den linken Operanden ausgeben .
WIe soll ich Bitrate vergleichen ?
So?
If( this.Bitrate != bitrate ???? |
Der Operator "+" hat zwei Operanden. Du musst die Bitraten der beiden Operanden auslesen und vergleichen. Dazu zuerst, wie oben beschrieben, verstehen, wie Operatoren in C++ aufgebaut sind und wie man Operatoren überläd.
Gruß,
Karlito
|
|
15.10.2016 20:51 |
|
|
|