- 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 ; }

24th Nov 2016, 9:34 AM
zerin jawah
zerin jawah - avatar
4 odpowiedzi
+ 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 ; }
24th Nov 2016, 9:43 AM
Magyar Dávid
Magyar Dávid - avatar
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")
24th Nov 2016, 10:21 PM
Magyar Dávid
Magyar Dávid - avatar
0
why did you use len,width there?
27th Nov 2016, 8:40 AM
Selva Kumar
Selva Kumar - avatar
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; }
27th Nov 2016, 9:02 AM
Selva Kumar
Selva Kumar - avatar