ik heb op de hcc beurs een boek gekocht over c++, namelijk
"Teach yourself c++ in 21 days 3rd ed". Aangezien bij dit boek geen source code is toegevoegd, en ik de site www.samspublishing.com niet kan bereiken, vraag ik jullie hulp.
ik heb de volgende source uit het boek overgenomen,
ik krijg de volgende foutmeldingen.
rec.cpp:43 int function 'int main ()'
rec.cpp:43 Rectangle undeclared
ik begrijp er niks van, ik heb deze wel gedeclared???
ik gebruik de mingw compiler, wie kan mij helpen ???
"Teach yourself c++ in 21 days 3rd ed". Aangezien bij dit boek geen source code is toegevoegd, en ik de site www.samspublishing.com niet kan bereiken, vraag ik jullie hulp.
ik heb de volgende source uit het boek overgenomen,
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
| #include <iostream.h> intintboolfalsetrue enum CHOICE { DrawRect = 1, GetArea, GetPerim, ChangeDimensions, Quit}; class Rectangle { public: Rectangle(int width, int height); ~Rectangle(); int GetHeight() const { return itsHeight; } int GetWidth() const { return itsWidth; } int GetArea () const { return itsHeight * itsWidth; } int GetPerim () const { return 2*itsHeight + 2*itsWidth; } void SetSize (int newWidth, int newHeight); private: int itsWidth; int itsHeight; }; void Rectangle::SetSize(int newWidth, int newHeight) { itsWidth = newWidth; itsHeight = newHeight; } Rectangle::Rectangle(int width, int height) { itsWidth = width; itsHeight = height; } Rectangle::~Rectangle() {} int DoMenu(Rectangle); void DoDrawRect(Rectangle); void DoGetArea(Rectangle); void DoGetPerim(Rectangle); int Main () { Rectangle theRect(30,5); int choice; int fQuit = false; while (!fQuit) { choice = DoMenu(); if (choice < DrawRect || choice > Quit) { cout << "\nInvalvid Choice, please try again\n\n"; continue; } switch (choice) { case DrawRect: DoDrawRect(theRect); break; case GetArea: DoGetArea(theRect); break; case GetPerim: DoGetPerim(theRect); break; case ChangeDimensions: int newLenght, newWidth; cout << "\nNew Width: "; cin >> newWidth; cout << "New Height: "; cin >> newLenght; theRect.SetSize(newWidth, newLenght); DoDrawRect(theRect); break; case Quit: cout << "\nExiting...\n"; fQuit = true; break; default: cout << "Error in choice!\n"; fQuit = true; break; } } return 0; } int DoMenu() { int choice; cout << "\n\n *** Menu *** \n"; cout << "(1) Draw Rectangle\n"; cout << "(2) Area\n"; cout << "(3) Perimeter\n"; cout << "(4) Resize\n"; cout << "(5) Quit\n"; cin >> choice; return choice; } void DoDrawRect(Rectangle theReact) { int height = theReact.GetHeight(); int width = theReact.GetWidth(); for (int i=0; i<height; i++) { for (int j=0; j<width; j++) cout << "*"; cout << "\n"; } } void DoGetArea (Rectangle theReact) { cout << "Area: " << theReact.GetArea() << endl; } |
ik krijg de volgende foutmeldingen.
rec.cpp:43 int function 'int main ()'
rec.cpp:43 Rectangle undeclared
ik begrijp er niks van, ik heb deze wel gedeclared???
ik gebruik de mingw compiler, wie kan mij helpen ???
[ Voor 24% gewijzigd door .oisyn op 27-12-2002 21:41 . Reden: syntax highlighting toegepast :) ]