Hello,
The C++ Compiler built into my brain says that it might be a case of uninitialized variables.
#include <iostream>
using namespace std;
class CRectangle
{
int x, y;
public:
void values(int, int);
int area() {return (x*y);}
void CRectangle::shapeformat() {
x = 3;
y = 4;
}
};
int main()
{
CRectangle rect_shape;
cout<<endl<<rect_shape.area();
cout<<endl;
return 0;
}
In Line No. 10, qualifier `CRectangle::` for the function `shapeformat` isn't necessary. Delete it.
Make a call to `shapeformat` from main().
Make it look something like:
#include <iostream>
using namespace std;
class CRectangle
{
int x, y;
public:
void values(int, int);
int area()
{
return (x*y);
}
void shapeformat()
{
x = 3;
y = 4;
}
};
int main()
{
CRectangle rect_shape;
rect_shape.shapeformat();
cout<<endl<<rect_shape.area();
cout<<endl;
return 0;
}
NOTE: I have modified the code and did some cleanup to avoid confusions. Try to use proper and uniform indentation, alignment and linespacing so that the code is more `readable`.
Secondly, you've called `endl` before and after call to the class member `area()`. The former causes an empty line which may not be desired. It could be something like:
cout <<rect_shape.area() << endl;