Code debugging assistance

I could use some help with debugging my code. I am not very good at debugging code so I could use some assistance with what I might need to change in order to get my code to work.

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include <iomanip>

using namespace std;

//This is a class circleType definition which defines the operations on circle.

class circleType

{

public :

/*this function is to set the radius of the circle with the parameter value */

void setRadius(double r)

{

cir_radius=r;

}

//This setCenter function is to set the center of the circle with the parameter values x,y.

void setCenter(double x, double y)

{

xCoordinate=x;

yCoordinate=y;

}

double getRadius()

//this function is to return the radius.

{

return cir_radius;

}

double cirlceArea()

//*this function is to calculate the area of circle using its formula pi*r*r.*/

{

return 3.14*cir_radius*cir_radius;

}

//The circleCircumference function is to calculate the circumference of circle using the formula 2*pi*r.

double circleCircumference()

{

return 2*3.14159*cir_radius;

}

void print()

{

cout<<"the radius of the circle is :"<<

cout<<"the area of the circle is:"<<

cout<<"the circumference of the circle is :" <<

circleCircumference()<

}

circleType()

//*this is default constructor of class circleType*/

{

xCoordinate=0.0;

yCoordinate=0.0;

cir_radius=0.0;

}

circleType(double x, double y, double r)

/*This is a constructor with parameters of the class circleType*/

{

xCoordinate=x;

yCoordinate=y;

cir_radius=r;

}

private:

//these are the data members of the class circleType.

double xCoordinate;

double yCoordinate;

double cir_radius;

};

//The cylinderType class is to define the various operation on cylinder and is derived from the class circleType.

class cylinderType: public circleType

{

public :

/*following are the member function of the class cylinderType.*/

void setHeight(double);

void print();

double getHeight();

double volume_value();

double surface_area();

cylinderType();

cylinderType(double, double, double, double);

private:

/*this is member variable of the class cylinderType.

double cyl_height;

};

void cylinderType::setHeight(double height)

/*This function is to set the height of cylinder value with the parameter height. */

{

cyl_height=height;

}

double cylinderType::getHeight()

//this function is to return the height of cylinder .

{

return cyl_height;

}

//The cylinderType function prints radius, area, circumference of the cylinder base and height, volume, circumference of the cylinder.

void cylinderType::print()

{

  // Output

cout<<"The radius of the base is :" << getRadius()

<

cout<<"The area of the cylinder baseis:"<

<

cout<<"The circumference of the cylinder base is :" <<

circleCircumference()<

cout<<"The height of the cylinder is:" << getHeight()

<

cout<<"The volume of the the cylinder is:" <<

volume_value()<

cout<<"The surface area of the cylinder is:" <<

surface_area()<

}

double cylinderType::volume_value()

/*this function calculates the volume of the cylinder and returns the value.*/

{

return (3.14*getRadius()*getRadius()*cyl_height);

}

//The cylinderType function calculates the surface area of the cylinder and returns the value.

double cylinderType::surface_area()

{

return(2*3.14)*(getRadius()*getHeight())+(2*3.14)*(get

Radius()*getRadius());

}

cylinderType::cylinderType():circleType()

/*this is default constructor definiton of class cylinderType*/

{

cyl_height=0.0;

}

cylinderType::cylinderType(double x, double y, double

height, double radius): circleType(x,y,radius)

/*this is constructor definition of class cylinderType with parameters*/

{

cyl_height=height;

}

//This is the main function which calls the class objects to perform class operations.

int main()

{

//circleType object c1 declared.

circleType c1(15,10,6);

c1.print();//prints the values of circle

circleType c2;
//circleType object c2 is declared

double r;

cout<<"enter the value of radius";

cin>>r;//reading the radius value

c2.setRadius(r);// setting the radius value

cylinderType cyl1(15,10,20,8); //cylinderType object

declared.

cyl1.print();//dispays the values of cylinder.

//exit from the system.

system("pause");

} //end main




Here are my errors that I am getting.

main.cpp:153:1: warning: "/*" within comment [-Wcomment]
/*This function is to set the height of cylinder value with the parameter height. */

main.cpp: In member function ‘void circleType::print()’:
main.cpp:69:1: error: ‘cout’ was not declared in this scope
cout<<"the radius of the circle is :"<<
^~~~
main.cpp:77:1: error: expected primary-expression before ‘}’ token
}
^
main.cpp: At global scope:
main.cpp:155:1: error: expected unqualified-id before ‘{’ token
{
^
main.cpp:161:8: error: extra qualification ‘cylinderType::’ on member ‘getHeight’ [-fpermissive]
double cylinderType::getHeight()
^~~~~~~~~~~~
main.cpp:161:8: error: ‘double cylinderType::getHeight()’ cannot be overloaded
main.cpp:133:8: error: with ‘double cylinderType::getHeight()’
double getHeight();
^~~~~~~~~
main.cpp:173:6: error: extra qualification ‘cylinderType::’ on member ‘print’ [-fpermissive]
void cylinderType::print()
^~~~~~~~~~~~
main.cpp:173:6: error: ‘void cylinderType::print()’ cannot be overloaded
main.cpp:131:6: error: with ‘void cylinderType::print()’
void print();
^~~~~
main.cpp:205:8: error: extra qualification ‘cylinderType::’ on member ‘volume_value’ [-fpermissive]
double cylinderType::volume_value()
^~~~~~~~~~~~
main.cpp:205:8: error: ‘double cylinderType::volume_value()’ cannot be overloaded
main.cpp:135:8: error: with ‘double cylinderType::volume_value(’
double volume_value();
^~~~~~~~~~~~
main.cpp:217:8: error: extra qualification ‘cylinderType::’ on member ‘surface_area’ [-fpermissive]
double cylinderType::surface_area()
^~~~~~~~~~~~
main.cpp:217:8: error: ‘double cylinderType::surface_area()’ cannot be overloaded
main.cpp:137:8: error: with ‘double cylinderType::surface_area(’
double surface_area();
^~~~~~~~~~~~
main.cpp:227:1: error: extra qualification ‘cylinderType::’ on member ‘cylinderType’ [-fpermissive]
cylinderType::cylinderType():circleType()
^~~~~~~~~~~~
main.cpp:227:1: error: ‘cylinderType::cylinderType()’ cannot be overloaded
main.cpp:139:1: error: with ‘cylinderType::cylinderType()’
cylinderType();
^~~~~~~~~~~~
main.cpp:237:1: error: extra qualification ‘cylinderType::’ on member ‘cylinderType’ [-fpermissive]
cylinderType::cylinderType(double x, double y, double
^~~~~~~~~~~~
main.cpp:237:1: error: ‘cylinderType::cylinderType(double, double, double, double)’ cannot be overloaded
main.cpp:141:1: error: with ‘cylinderType::cylinderType(double, double, double, double)’
cylinderType(double, double, double, double);
^~~~~~~~~~~~
main.cpp:282:1: error: expected ‘}’ at end of input
} //end main
^
main.cpp: In member function ‘double cylinderType::getHeight()’:
main.cpp:167:8: error: ‘cyl_height’ was not declared in this scope
return cyl_height;
^~~~~~~~~~
main.cpp:167:8: note: suggested alternative: ‘setHeight’
return cyl_height;
^~~~~~~~~~
setHeight
main.cpp: In member function ‘void cylinderType::print()’:
main.cpp:179:1: error: ‘cout’ was not declared in this scope
cout<<"The radius of the base is :" << getRadius()
^~~~
main.cpp:185:1: error: expected primary-expression before ‘<’ token
<
^
main.cpp:203:1: error: expected primary-expression before ‘}’ token
}
^
main.cpp: In member function ‘double cylinderType::volume_value()’:
main.cpp:211:38: error: ‘cyl_height’ was not declared in this scope
adius()*getRadius()*cyl_height);
^~~~~~~~~~
main.cpp:211:38: note: suggested alternative: ‘setHeight’
adius()*getRadius()*cyl_height);
^~~~~~~~~~
setHeight
main.cpp: In member function ‘double cylinderType::surface_area()’:
main.cpp:223:1: error: expected ‘)’ before ‘Radius’
Radius()*getRadius());
^~~~~~





You have a multi-line comment that starts on line 145 but you don't have a closing */
Just change it to a C++ // (one-line) comment.

Aside from that,
you should
#include <iostream>

And wtf is happening in lines 75?
Get rid of the training <<'s, put semi-colons.
Last edited on
Don't

double

space

your

code.

It

makes

it

hard

to

read.

In general when fixing compiler errors, start with the first one. Read the message carefully and try to understand what it's saying. Look at the line if code it refers you to. Fix the first error and then compile again. Sometimes one error leads to a whole bunch of other errors.

Here are some things to look at:
Line 45: circleArea is misspelled.
Line 51 etc: Make a const for PI with a ton of digits. 3 figures went out with the slide rule.
Lines 211 and 221: calculate the volume and surface area using the base area and height
Here's a bit of a tidy up that runs. You had most of it done but need to check it for accuracy, I haven't.

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <iostream>
#include <iomanip>

using namespace std;

// This is a class Circle definition which defines the operations
// on circle

static const double PI = 3.1415;

class Circle
{
private:
    double xCoordinate;
    double yCoordinate;
    double cir_radius;
    
    public :
    Circle()
    //*this is default constructor of class Circle*/
    {
        xCoordinate=0.0;
        yCoordinate=0.0;
        cir_radius=0.0;
    }
    
    Circle(double x, double y, double r)
    // This is a constructor with parameters of the class Circle
    {
        xCoordinate=x;
        yCoordinate=y;
        cir_radius=r;
    }
    
    ~Circle(){};
    
    void setRadius(double r)
    {
        cir_radius=r;
    }
    
    // This setCenter function is to set the center of the circle with
    // the parameter values x,y.
    void setCenter(double x, double y)
    {
        xCoordinate=x;
        yCoordinate=y;
    }
    
    double getRadius()
    //this function is to return the radius.
    {
        return cir_radius;
    }
    
    double circleArea()
    // *this function is to calculate the area of circle using its
    // formula pi*r*r
    {
        return PI*cir_radius*cir_radius;
    }
    
    // The circleCircumference function is to calculate the circumference
    // of circle using the formula 2*pi*r.
    double circleCircumference()
    {
        return 2*PI*cir_radius;
    }
    
    void print()
    {
        cout
        <<"the radius of the circle is :"<< cir_radius << '\n'
        <<"the area of the circle is: "<< circleArea() << '\n'
        <<"the circumference of the circle is: " << circleCircumference()
        << '\n';
    }
    
    
};
// The Cylinder class is to define the various operation on cylinder
// and is derived from the class Circle.
class Cylinder: public Circle
{
    public :
    /*following are the member function of the class Cylinder.*/
    void setHeight(double);
    void print();
    double getHeight();
    double volume_value();
    double surface_area();
    Cylinder();
    Cylinder(double, double, double, double);
private:
    /*this is member variable of the class Cylinder.*/
    double cyl_height;
};
void Cylinder::setHeight(double height)
// This function is to set the height of cylinder value with the
// parameter height.
{
    cyl_height=height;
}
double Cylinder::getHeight()
//this function is to return the height of cylinder .
{
    return cyl_height;
}
//The Cylinder function prints radius, area, circumference of the
// volume, circumference of the cylinder.
void Cylinder::print()
{
    // Output
    cout
    <<"The radius of the base is: " << getRadius() << '\n'
    <<"The area of the cylinder base is: " << " ??????" << '\n'
    <<"The circumference of the cylinder base is: "
    << circleCircumference() << '\n'
    <<"The height of the cylinder is: " << getHeight() << '\n'
    <<"The volume of the the cylinder is: " << volume_value()<< '\n'
    <<"The surface area of the cylinder is: " << surface_area() << '\n';
}

double Cylinder::volume_value()
//this function calculates the volume of the cylinder and returns
// the value.
{
    return (PI*getRadius()*getRadius()*cyl_height);
}
//The Cylinder function calculates the surface area of the cylinder
// and returns the value.
double Cylinder::surface_area()
{
    return(2*PI)*(getRadius()*getHeight())+(2*PI)*(getRadius()*getRadius());
}

Cylinder::Cylinder():Circle()
/*this is default constructor definiton of class Cylinder*/
{
    cyl_height=0.0;
}
Cylinder::Cylinder(double x, double y, double height, double radius): Circle(x,y,radius)
/*this is constructor definition of class Cylinder with parameters*/
{
    cyl_height=height;
}
//This is the main function which calls the class objects to perform
// class operations.
int main()
{
    //Circle object c1 declared.
    Circle c1(15,10,6);
    c1.print();//prints the values of circle
    Circle c2;
    //Circle object c2 is declared
    double r;
    cout<<"Enter the value of radius: ";
    cin>>r;//reading the radius value
    c2.setRadius(r);// setting the radius value
    Cylinder cyl1(15,10,20,8); //Cylinder object declared.
    cyl1.print();//dispays the values of cylinder.
    //exit from the system.
    system("pause");
} //end main 

BTW static const PI can best be put inside the class (it's not a data member though) and,
TIP: if you #include <cmath> then PI = 4*atan(1)
Topic archived. No new replies allowed.