I need help!

I'm trying to create classes and put them in a menu. Why isn't this working?

#include <iostream>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(){
int choice;
cout << "Choose numbers from 1-5 to select your option: " << endl;
cout << "[1]: Square" << endl;
cout << "[2]: Rectangle" << endl;
cout << "[3]: Circle" << endl;
cout << "[4]: Traingle" << endl;
cout << "[5]: EXIT" << endl;

cin >> choice;
}

switch(choice)
{
case 1:
class CSquare {
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
int per () {return (x*y);}
};

void CSquare::set_values (int a, int b) {
x = a;
y = b;
}

int main4() {
CSquare sq;
int a;
cout << "Enter the lenght of the square: ";
cin >> a;
cout << endl;
sq.set_values (a,2);
cout << "Area Square: " << sq.area() << endl;
sq.set_values (a,4);
cout << "Perimeter Square: " << sq.per() << endl;
return 0;
}
break;

case 2:
class CRectangle{
int f, g;
public:
void set_values (int,int);
int area () {return (f*g);}
int per () {return 2*(f*g);}
};

void CRectangle::set_values (int q, int p) {
f = q;
g = p;
}

int main1() {
CRectangle rect;
int a,b;
cout << "Enter the Lenght of the Rectangle: ";
cin >> a;
cout << "Enter the Width of the Rectangle: ";
cin >> b;
cout << endl;
rect.set_values (a,b);
cout << "Area Rectangle: " << rect.area() << endl;
rect.set_values (a,b);
cout << "Perimeter Rectangle: " << rect.per() << endl;
return 0;
}
break;

case 3:
class CCircle {
float r, d;
public:
void set_values (int,int);
int cir () {return (3.14159*d);}
int diameter () {return (2*r);}
};

void CCircle::set_values (int i, int j) {
r = i;
d = j;
}

int main2() {
CCircle cir;
float a,b;
cout << "Enter the Diameter of the Circle: ";
cin >> a;
cout << "Enter the Radius of the Circle: ";
cin >> b;
cout << endl;
cir.set_values (3.14159,a);
cout << "Circumference Circle: " << cir.cir() << endl;
cir.set_values (2,b);
cout << "Diameter: " << cir.diameter() << endl;
return 0;
}
break;
default:
cout << "END";
break;

}
The indentation is gone so it's a bit hard to see what is going on but you can't have switches outside functions.
The indentation is gone so it's hard to see what is going on but you can't have switches outside of functions.
Both functions and classes are declared/implemented outside of any functions.

Inside a function you create variables and call functions and do the math.
How can i do this please?
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
#include <iostream>
#include <stdlib.h>
#include <math.h>

using namespace std;

class CSquare
{
    int x, y;
public:
    void set_values (int,int);
    int area ()
    {
        return (x*y);
    }
    int per ()
    {
        return (x*y);
    }
};

void CSquare::set_values (int a, int b)
{
    x = a;
    y = b;
}

int main4()
{
    CSquare sq;
    int a;
    cout << "Enter the lenght of the square: ";
    cin >> a;
    cout << endl;
    sq.set_values (a,2);
    cout << "Area Square: " << sq.area() << endl;
    sq.set_values (a,4);
    cout << "Perimeter Square: " << sq.per() << endl;
    return 0;
}

class CRectangle
{
    int f, g;
public:
    void set_values (int,int);
    int area ()
    {
        return (f*g);
    }
    int per ()
    {
        return 2*(f*g);
    }
};

void CRectangle::set_values (int q, int p)
{
    f = q;
    g = p;
}

int main1()
{
    CRectangle rect;
    int a,b;
    cout << "Enter the Lenght of the Rectangle: ";
    cin >> a;
    cout << "Enter the Width of the Rectangle: ";
    cin >> b;
    cout << endl;
    rect.set_values (a,b);
    cout << "Area Rectangle: " << rect.area() << endl;
    rect.set_values (a,b);
    cout << "Perimeter Rectangle: " << rect.per() << endl;
    return 0;
}

class CCircle
{
    float r, d;
public:
    void set_values (int,int);
    int cir ()
    {
        return (3.14159*d);
    }
    int diameter ()
    {
        return (2*r);
    }
};

void CCircle::set_values (int i, int j)
{
    r = i;
    d = j;
}

int main2()
{
    CCircle cir;
    float a,b;
    cout << "Enter the Diameter of the Circle: ";
    cin >> a;
    cout << "Enter the Radius of the Circle: ";
    cin >> b;
    cout << endl;
    cir.set_values (3.14159,a);
    cout << "Circumference Circle: " << cir.cir() << endl;
    cir.set_values (2,b);
    cout << "Diameter: " << cir.diameter() << endl;
    return 0;
}
int main()
{
    int choice;
    cout << "Choose numbers from 1-5 to select your option: " << endl;
    cout << "[1]: Square" << endl;
    cout << "[2]: Rectangle" << endl;
    cout << "[3]: Circle" << endl;
    cout << "[4]: Traingle" << endl;
    cout << "[5]: EXIT" << endl;

    cin >> choice;

    switch(choice)
    {
    case 1:
        main4();
        break;
    case 2:
        main1();
        break;

    case 3:
        main2();
        break;
    default:
        cout << "END";
        break;

    }
}
Thanks VERY VERY MUCH!! :)
Topic archived. No new replies allowed.