separe coding into 3 file

i have done this coding and its can be run.. but if i seperated into, header,implementation and main file its have error. someone plz help how do i seperate this file into (header)shape.h, (implemtation)shape.cpp and (main)testshape.cpp

here is my full coding

#include <iostream>
#include<math.h>
using namespace std;

class Shape
{
public:
double height;
double width;
double lenght;
double radius;
};

class Rectangle: public Shape {
public:
Rectangle(double w, double l) {

width = w;
lenght = l;
}
double getarea() {
return lenght * width;
}
double perimeter() {
return (2 * width) + (2 * lenght);
}
};

class Circle: public Shape {
public:
double mark;
Circle(double r) {
radius = r;
}
double getdiameter()
{
return (2 * radius) ;
}
double getarea(){

return 3.142*((pow(radius,2)));
}
};

class cylinder : public Shape {
public:

cylinder(double h, double r) {
height = h;

radius = r;
}
double getvolume() {
return ((pow(radius,2)) * 3.142) * height;

}
double getSurface(){
return ((2 * 3.142)* radius) * height;
}

};


int main()
{
int choice;
Rectangle recObj(5.0, 2);
Circle cirObj(5);
cylinder cylObj(4.0, 3);

cout<<"\t****************************************************************"<<endl;
cout<<"\t SHAPE "<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<"\t 1--> RECTANGLE "<<endl;
cout<<"\t 2--> CIRCLE "<<endl;
cout<<"\t 3--> CYLINDER "<<endl;
cout<<"\t****************************************************************"<<endl;

cout << "Enter your selection";
cin>>choice;
cout << " "<<endl;
if(choice==1)
{

cout << "Fomula of calculating Area For rectangle is (lenght *Width)"<<endl;
cout << "Fomula of calculating Perimeter For rectangle is (2Width * 2lenght)"<<endl;
cout << " "<<endl;
cout << " Example Rectangle with : "<<endl;
cout << " width = 5"<<endl;
cout << " length = 2"<<endl;
cout << " "<<endl;
cout << " Area of Rectangle: " << recObj.getarea()<< endl;
cout << " Perimeter of Rectangle: " << recObj.perimeter() << endl;}

else if(choice==2){

cout << "Fomula of calculating Diameter For Circle is (2 * radius)"<<endl;
cout << "Fomula of calculating Area For Circle is (3.142 * radius^2)"<<endl;
cout << " "<<endl;
cout << " Example Circle with : "<<endl;
cout << " Radius = 5"<<endl;
cout << " "<<endl;
cout << "Circle Diameter: " <<cirObj.getdiameter()<< endl;
cout << "Circle Area: " <<cirObj.getarea()<< endl;}

else if(choice==3){
cout << "Fomula of calculating volume Cylinder is (radius^2 * 3.142 * height)"<<endl;
cout << "Fomula of calculating surface For Cylinder is (2(3.142) * radius * height)"<<endl;
cout << " "<<endl;
cout << " Example Cylinder with : "<<endl;
cout << " height = 4.0"<<endl;
cout << " radius = 3"<<endl;
cout << " "<<endl;
cout << "Cylinder volume: " <<cylObj.getvolume() << endl;
cout << "Cylinder Surface: " <<cylObj.getSurface() << endl;
}

else
{
cout << "Wrogly enter"<<endl;
}


return 0;
}

Try to indent your code, if you don't is almost impossible to read.

main.cpp
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 <iostream>
#include<math.h>

#include "shapes.h"

int main()
{
    int choice;
    Rectangle recObj(5.0, 2);
    Circle cirObj(5);
    Cylinder cylObj(4.0, 3);

    cout<<"\t****************************************************************"<<endl;
    cout<<"\t SHAPE "<<endl;
    cout<<"\t****************************************************************"<<endl;
    cout<<"\t 1--> RECTANGLE "<<endl;
    cout<<"\t 2--> CIRCLE "<<endl;
    cout<<"\t 3--> CYLINDER "<<endl;
    cout<<"\t****************************************************************"<<endl;

    cout << "Enter your selection";
    cin>>choice;
    cout << " "<<endl;
    if(choice==1)
    {

        cout << "Fomula of calculating Area For rectangle is (lenght *Width)"<<endl;
        cout << "Fomula of calculating Perimeter For rectangle is (2Width * 2lenght)"<<endl;
        cout << " "<<endl;
        cout << " Example Rectangle with : "<<endl;
        cout << " width = 5"<<endl;
        cout << " length = 2"<<endl;
        cout << " "<<endl;
        cout << " Area of Rectangle: " << recObj.getarea()<< endl;
        cout << " Perimeter of Rectangle: " << recObj.perimeter() << endl;
    }

    else if(choice==2)
    {

        cout << "Fomula of calculating Diameter For Circle is (2 * radius)"<<endl;
        cout << "Fomula of calculating Area For Circle is (3.142 * radius^2)"<<endl;
        cout << " "<<endl;
        cout << " Example Circle with : "<<endl;
        cout << " Radius = 5"<<endl;
        cout << " "<<endl;
        cout << "Circle Diameter: " <<cirObj.getdiameter()<< endl;
        cout << "Circle Area: " <<cirObj.getarea()<< endl;
    }

    else if(choice==3)
    {
        cout << "Fomula of calculating volume Cylinder is (radius^2 * 3.142 * height)"<<endl;
        cout << "Fomula of calculating surface For Cylinder is (2(3.142) * radius * height)"<<endl;
        cout << " "<<endl;
        cout << " Example Cylinder with : "<<endl;
        cout << " height = 4.0"<<endl;
        cout << " radius = 3"<<endl;
        cout << " "<<endl;
        cout << "Cylinder volume: " <<cylObj.getvolume() << endl;
        cout << "Cylinder Surface: " <<cylObj.getSurface() << endl;
    }

    else
    {
        cout << "Wrogly enter"<<endl;
    }


    return 0;
}


shapes.h
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
#ifndef SHAPES_H_INCLUDED
#define SHAPES_H_INCLUDED

class Shape
{
public:
    double height;
    double width;
    double lenght;
    double radius;
};

class Rectangle: public Shape
{
public:
    Rectangle(double w, double l);
    double getarea();
    double perimeter();
};

class Circle: public Shape
{
public:
    double mark;
    Circle(double r);
    double getdiameter();
    double getarea();
};

class Cylinder : public Shape
{
public:
    Cylinder(double h, double r);
    double getvolume();
    double getSurface();
};

#endif // SHAPES_H_INCLUDED


shapes.cpp
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
#include <iostream>
#include<math.h>

#include "shapes.h"

using namespace std;

Rectangle::Rectangle(double w, double l)
{
    width = w;
    lenght = l;
}
double Rectangle::getarea()
{
    return lenght * width;
}
double Rectangle::perimeter()
{
    return (2 * width) + (2 * lenght);
}

Circle::Circle(double r)
{
    radius = r;
}
double Circle::getdiameter()
{
    return (2 * radius) ;
}
double Circle::getarea()
{
    return 3.142*((pow(radius,2)));
}

Cylinder::Cylinder(double h, double r)
{
    height = h;
    radius = r;
}
double Cylinder::getvolume()
{
    return ((pow(radius,2)) * 3.142) * height;
}
double Cylinder::getSurface()
{
    return ((2 * 3.142)* radius) * height;
}
thank u... its work nw :)
let us know what grade you get on that assignment!
Topic archived. No new replies allowed.