Calculating rectangular area This program is working correctly, but I need to check if the structure is good or can be improved. Plus, if I called ra.area() immediately after declaring ra, I get 687194768. Why is that?

#include "stdafx.h"
#include "iostream"
using namespace std;
class rectangleclass
{
 int w,h;
public:
void setnum(int x, int y)
{
w=x;
h=y;
}
int area() 
{
    return w*h;
}
};
int main()
{
rectangleclass ra;
int l;
int L;
cout&lt;&lt;"please write the height and width in m\n" ;
cin&gt;&gt;L;
cin&gt;&gt;l;
ra.setnum(L,l);
cout&lt;&lt;ra.area()&lt;&lt;"m^2";
 system("pause");
 }
Readability

First things first. Formatting. Indent after each brace, consistently. It is more or less impossible to read your code.

Secondly, variable naming. 1 (el) is a terrible name for a variable, since it looks exactly like a l (one), so much so that I just flipped them and you probably didn't notice. Not to mention that one of your Ls is really width. So you should name them length and width. 

Rectangle

Rather than having setnum(), which is not a meaningful name, instead require your Rectangle to be constructed directly with the values:

class Rectangle {
public:
    Rectangle(int w, int h)
    : width_(w), height_(h)
    { }

private:
    int width_, height_;
};


Note the improved naming of the member variables and the class. Adding class to the type name is unnecessary and redundant. This constructor will additionally solve your other problem: accidentally misusing Rectangle by accessing its member functions before you set any of the values (uninitialized ints have indeterminate value). This way, you're guaranteeing that width_ and height_ are set.

Usage here would be like:

cin &gt;&gt; width;
cin &gt;&gt; height;
Rectangle ra(width, height);
cout &lt;&lt; ra.area();


const-ness

The area() member function doesn't (and shouldn't) modify any of its members. So it'd be better to mark it const:

int area() const { ... }


This lets you get the area of a const Rectangle.