| | |
class
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
hi ,
my program calculate the area of rectangle , and I have some errors , and dont know how to correct them .
this is the program ,
my program calculate the area of rectangle , and I have some errors , and dont know how to correct them .
this is the program ,
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; class Rectangle { private: double length ,width ; public: double getW(); double getL(); void setW(); void setL(); double findArea(double&;double&); void display(); }; double Rectangle::getW(){ return width ; } double Rectangle::getL(){ return length ; } void Rectangle::setW(double num1){ width=num1; } void Rectangle::setL(double num2){ length=num2; } double Rectangle::findArea(double &w;double &l){ int area; w=width; l=length; area=length*width; return area ; void Rectangle::display(){ cout<<length<<endl; cout<<width<<endl; } int main (){ double x=8.3,y=5.8; Rectangle rec ; rec.setW(x); rec.setL(y); rec.getW(); rec.getL(); rec.findArea(x,y); rec.display(); } return 0 ; }
Last edited by bis student; Mar 31st, 2008 at 10:19 am.
there are always hope
•
•
Join Date: Jun 2006
Posts: 147
Reputation:
Solved Threads: 20
set the prototype of functions
like this
replace above two with
remember to add semicolon where required.
like this
C++ Syntax (Toggle Plain Text)
void setW(); void setL();
C++ Syntax (Toggle Plain Text)
void setW(double num1) void setL(double num2)
remember to add semicolon where required.
Last edited by Laiq Ahmed; Mar 31st, 2008 at 10:44 am. Reason: Hinting
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; class Rectangle { private: double length ,width ; public: double getW(); double getL(); void setW(); //<-Needs to pass a double void setL(); //<- Needs to pass a double double findArea(double&;double&); //<-See chandra.rajat's post void display(); }; double Rectangle::getW(){ return width ; } double Rectangle::getL(){ return length ; } void Rectangle::setW(double num1){//<-Doesn't match prototype width=num1; } void Rectangle::setL(double num2){//<-Doesn't match prototype length=num2; } double Rectangle::findArea(double &w;double &l){//<-See chandra.rajat's post int area; w=width; l=length; area=length*width; return area ; /*} <-Missing a closing curly brace here*/ void Rectangle::display(){ cout<<length<<endl; cout<<width<<endl; } int main (){ double x=8.3,y=5.8; Rectangle rec ; rec.setW(x); rec.setL(y); rec.getW(); rec.getL(); rec.findArea(x,y); rec.display(); }//<-Extra curly brace return 0 ; }
Aside from chandra.rajat's observations, there are just a couple of prototype mismatches and a missing/hanging curly brace.
![]() |
Similar Threads
- java and using observable class (Java)
- Accessing functions from base class (C)
- Circle class (C++)
- "missing storage-class or type specifiers" error (C++)
- first math class in uni (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: deleting a random node from a singly linked list
- Next Thread: Converting Integer to double
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





