943,936 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1752
  • C++ RSS
Feb 24th, 2006
0

check for errors in my code

Expand Post »
#include<iostream.h>
class rectangle
{
protected:

int lenght,widht,height;


public:
rectangle(){lenght=0;widht=0;height=0;};
void seta(int lenghti);
void setb(int widthi);
void setc(int heighti);
int getlenght();
int getwidth();
int getheight();
};
class box:protected rectangle
{
private:
int length,width,height;
public:
rectangle(){length=0;width=0;height=0;};
void setlenght(int lenght);
void setwidth(int width);
void setheight(int height);
int getlenght();
int getwidht();
int getArea();
int getPerimeter();
int getVolume();
};

#include<iostream.h>
#include"rectangle.h"

void main()

{
box mybox;
int lenght,widht,height;
cout<<"enter lenght";
cin>>lenght;
cout<<"enter width";
cin>>width;
cout<<"enter height";
cin>>height;
int a,b,c,;
cout<<"enter lenght";cin>>lenght;
cout<<"enter width";cin>>widht;
cout<<"enter height";cin>>height;
mybox.setlenght(lenght);
mybox.setwidth(width);
mybox.setheight(height);
cout<<"Area is"<<mybox.getArea()endl;
cout<<"Parameter is"<<mybox.getparameter()endl;
cout<<"volume is"<<mybox.getvolume()endl;

#include<iostream.h>
#include"rectangle.h"
#include"mybox.cpp"
void box::seta,b,c,(int a,int b,int c,);
{
lenght=a;
widht=b;
height=c;
}
{
int box::geta();
return a;
}
{
int box::getb();
return b;
}
}
int box::getc();
return c;
}
{
int box::getarea()
return a*b;
}
{
int box::getparameter()
return a+b;
}
{
int box::getVolume()
return a*b*c;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
brianotieno is offline Offline
5 posts
since Feb 2006
Feb 24th, 2006
0

Re: check for errors in my code

what errors does your compiler produce? post the first few error messages.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Feb 24th, 2006
0

Re: check for errors in my code

hi,

first at all <iostream.h> is out of date from 1999 years is only <iostream>.

and please post your code in CODE section (bbcode).
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ludesign is offline Offline
9 posts
since Feb 2006
Feb 28th, 2006
0

Re: check for errors in my code

Put your code in [code] [/code] tags.
C++ Syntax (Toggle Plain Text)
  1. class box:Protected rectangle
->
C++ Syntax (Toggle Plain Text)
  1. class box : protected rectangle
All C++ keywords are in lowercase.

C++ Syntax (Toggle Plain Text)
  1. void main()
It's int main().

C++ Syntax (Toggle Plain Text)
  1. #include"mybox.cpp"
You shouldn't include .cpp files. Use a project instead.

void box::seta,b,c,(int a,int b,int c,);
{
lenght=a;
widht=b;
height=c;
}
You have an extra comma and an extra semicolon as well. Remove both of them.
C++ Syntax (Toggle Plain Text)
  1. {
  2. int box::getVolume()
  3. return a*b*c;
  4. }
->
C++ Syntax (Toggle Plain Text)
  1. int box::getVolume()
  2. {
  3. return a*b*c;
  4. }
etc . . . .
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005
Feb 28th, 2006
0

Re: check for errors in my code

C++ Syntax (Toggle Plain Text)
  1. class box:Protected rectangle
  2. {
  3. private:
  4. int length,width,height;
  5. public:
  6. rectangle(){length=0;width=0;height=0;};
  1. As mentioned, Protected is lowercase.
  2. This isn't in the rectangle class, so you don't use the rectangle constructor.
  3. You have an extra semicolon at the end of your constructor (it's not an error, but it isn't required, either).

And work on your indentation . . . or just code tags.
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Creating dynamic arrays
Next Thread in C++ Forum Timeline: Great what did I miss?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC