Die letzten 10 Beiträge |
eulerscheZahl |
Damit auch spätere Leser etwas davon haben, hier das Ergebnis des Chats:
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:
|
---------- main.cpp ----------
#include <iostream>
#include "CStudent.h"
using namespace std;
int main()
{
//Testfall 1
CStudent student1("Muster", "Fritz", 123456);
cout << student1 << endl;
//Testfall 2
CStudent student2("Muster", "Luise");
cout << student2 << endl;
//Testfall 3
CStudent student3("Mayer", "Hans", 12);
cout << student3 << endl;
//Testfall 4
CStudent student4;
cout << student4 << endl;
//Testfall 5
CStudent student5(student1);
cout << student5 << endl;
//Testfall 6
student4.setName("Nachname", "Vorname");
cout << student4 << endl;
//Testfall 7
student4.setNumMatr(234567);
cout << student4 << endl;
//Testfall 8
student4.setNumMatr(12345678);
cout << student4 << endl;
return 0;
}
---------- CStudent.h ----------
#pragma once
#include <string>
#include <iostream>
class CStudent {
private:
int m_numMatr;
std::string m_firstname;
std::string m_surname;
public:
CStudent(std::string surname = "NoName", std::string firstname = "NoName", int numMatr = -1);
CStudent(CStudent& orig);
void print();
void setName(std::string firstname, std::string surname);
bool setNumMatr(int matr);
friend std::ostream& operator << (std::ostream& stream, CStudent& s);
};
std::ostream& operator << (std::ostream& stream, CStudent& s);
---------- CStudent.cpp ----------
#include <string>
#include "CStudent.h"
#include<iostream>
using namespace std;
CStudent::CStudent(string surname, string firstname, int numMatr)
{
m_surname = surname;
m_firstname = firstname;
m_numMatr = -1;
if(100000 <= numMatr && numMatr <= 999999)
m_numMatr = numMatr;
}
CStudent::CStudent(CStudent& orig)
{
m_surname = orig.m_surname;
m_firstname = orig.m_firstname;
m_numMatr = -1;
if(100000 <= orig.m_numMatr && orig.m_numMatr <= 999999)
m_numMatr = orig.m_numMatr;
}
void CStudent::setName( std::string firstname, std::string surname)
{
m_firstname = firstname;
m_surname = surname;
}
void CStudent::print()
{
cout << "CStudent@" << this << ": " << m_surname << ", " << m_firstname << " " << "(" << m_numMatr << ")" << endl;
}
bool CStudent::setNumMatr(int matr)
{
if(100000 <= matr && matr <= 999999)
m_numMatr = matr;
}
ostream& operator << (ostream& stream, CStudent& s)
{
stream << "CStudent@" << &s << ": " << s.m_surname << ", " << s.m_firstname << " " << "(" << s.m_numMatr << ")";
return stream;
} |
|
|
tany |
Kannst mir dann ja mail nennen.
Können bei skype chatten. |
eulerscheZahl |
Download läuft... |
tany |
Keine Ahnung die nachrichten scheinen nicht anzukommen.
Hast du msn messenger? |
eulerscheZahl |
Sieht gut aus.
Was ist aus icq geworden? Ich hatte eine Anfrage von ******525, da antwortet aber keiner mehr. |
Tany |
Würde das für den 2testfall so gehen ?
#include "CStudent.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
CStudent z1("Muster", "Fritz", 123456);
CStudent z2; //Variable anlegen
z2 = CStudent(z1);
CStudent z3("Meyer","Hans",12);
CStudent z4(z3);
} |
Tany |
ok .
Ich mache mir einen account bei icq und meld mich dann . |
eulerscheZahl |
Du hast den Konstruktor schon, du hast ihn sogar doppelt.
Den Teil, den ich im letzten Beitrag zitiert habe, musst du löschen.
ICQ: 418863782, schon ewig nicht mehr genutzt
|
Tany |
Meinst du das ich einen default konstruktor anlegen soll?
P:S
Hast du irgendwie ICQ oder so ?
Oder kannst du dir anlegen ? |
eulerscheZahl |
Ach ja, das hatte ich dir zwar gelöscht, aber vergessen zu erwähnen:
code: |
1:
2:
3:
|
CStudent::CStudent(){
} |
|
Du hast schon
CStudent(std::string surname = "NoName", std::string firstname = "NoName", int numMatr = -1);
durch die Defaultwerte ist der andere Konstruktor darin enthalten, du schreibst also zweimal die selbe Funktion. Jetzt weiß der Compiler nicht, welche der beiden er nehmen soll.
Das zieht sich wirklich, über Skype oder ähnliches ginge es schneller. |
Es sind weitere Beiträge zu diesem Thema vorhanden. Klicken Sie hier, um sich alle Beiträge anzusehen. |
|
|