- 1
Find area of rectangle??? Where m i wrong?? I can't get any output!!!!
#include<iostream> using namespace std; class area rect { public: int len, width, res ; area(int a, int b); }; int area rect :: area(int a, int b) { res=a*b; return res; } void main() { int res; area rect a; a.len = 2; a.width= 7; res= a.area(2,7); cout <<"area of rect"<< res ; }
4 Réponses
+ 1
Mistakes:
× Define return type for function 'area'
× main() must return an int
× There is no type 'area', do not use it as type
#include <iostream>
using namespace std;
class rect{
public:
int len, bre, res ;
int area(int a, int b);
};
int rect :: area(int a, int b){
res=a*b;
return res;
}
int main()
{
int res;
rect a;
a.len = 2;
a.bre = 7;
res= a.area(2,7);
cout <<"area of rect: "<< res ;
}
0
No, you can't, somehow switched the keyword.. it's #include.
(Reply to: "thanks.....now I got it......but 1 question.......can I replace import to include")
0
why did you use len,width there?
0
#include<iostream>
using namespace std;
class area{
public:
int rect(int a,int b);
}
area::rect(int a,int b)
{
return a*b;
}
int main()
{
int l,b;
area a;
cout<<"Enter length";
cin>>l;
cout<<"Enter breadth";
cin>>b;
cout<<"Area is"<<a.rect(l,b);
return 0;
}