hi ,
my program calculate the area of rectangle , and I have some errors , and dont know how to correct them .
this is the program ,

``````#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 ;
}``````
4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by BlackJavaBean

findArea(double&;double &)

to

findArea(double&,double &)

replace the ';' with ','

arguments in a function defn n decl are separated by comma not semi-colon

but it is still have errors,

set the prototype of functions
like this

``````void setW();
void setL();``````

replace above two with

``````void setW(double num1)
void setL(double num2)``````

remember to add semicolon where required.

``````#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.