954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

class

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 ;
}
bis student
Newbie Poster
16 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

To start with change

findArea(double&;double &)

to

findArea(double&,double &)

replace the ';' with ','

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

Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
 

but it is still have errors,

bis student
Newbie Poster
16 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

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.

Laiq Ahmed
Junior Poster
148 posts since Jun 2006
Reputation Points: 113
Solved Threads: 20
 
#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.

BlackJavaBean
Light Poster
39 posts since Feb 2008
Reputation Points: 13
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You