Could some one point out what's wrong with the classes of this program?

#include <iostream>
using namespace std;
class box
{
    private:
    int height;
    int length;
    int width;
    public:
    box();//constructor
    int  surface_area();
    int volume();
    void set_dim(int ,int, int);
};
//implementation
box::box(){
int height;
int width;
int length;}

box::int surface_area(){
int sa=2*(length*width+length*height+height*width);
return sa;
}
box::int volume(){
return length*width*height;
}
box::void set_dim(int l,int w,int h){
int height=h;
int length=l;
int width = w;
}
int main(){
box a;
a.set_dim(2,3,4);
cout<<"The volume is: "<<a.volume()<<endl;
cout<<"The surface area is: "<<a.surface_area()<<endl;
return 0;
}

Recommended Answers

All 3 Replies

Never mind I found the solution
For those interested here it is. Now how do you delete posts?

#include <iostream>
using namespace std;
class box
{
    private:
    int height;
    int length;
    int width;
    public:
    box();//constructor
    float  surface_area();
    float volume();
    void set_dim(int ,int, int);
};
//implementation
box::box(){
int height;
int width;
int length;}

float box::surface_area(){
return 2.0*(length*width+length*height+height*width);}

float box::volume(){return length*width*height;}

void box::set_dim(int l,int w,int h){
height=h;
length=l;
width = w;}

int main(){
box a;
a.set_dim(1,1,4);
cout<<"The volume is: "<<a.volume()<<endl;
cout<<"The surface area is: "<<a.surface_area()<<endl;
return 0;}

Glad to help! :-)

For those interested here it is. Now how do you delete posts?

If the post was deleted, why would we be interested? ;o)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.