...

View Full Version : using class in C++



Adeel.Rekhi
01-10-2012, 08:49 PM
i m having problem in this prog.
please help me out.....


#include<iostream.h>

class Square{
private:
int length, weigth;

public:
void set_value(int a,int b)
{
lenght=a; weigth=b;
}
int Area()
{
return length*weigth;
}
};

main()
{ int A,B;
Square sqar1;
cout<<"enter the value of length"<<endl;
A=getche();
cout<<"enter the value of weigth"<<endl;
B=getche();
sqar1.set_value(A,B);
cout<<"The are is"<<sqar1.Area()<<endl;
getch();

}

abduraooft
01-11-2012, 10:59 AM
...and your question?

Adeel.Rekhi
01-11-2012, 12:29 PM
its not being compiled.....
Whats the problem in it....?

oracleguy
01-11-2012, 06:39 PM
You didn't post what the compiler errors are. However just looking at the code I can see you misspelled a variable in your set function which is certainly causing some or all of the errors you are getting.

Adeel.Rekhi
01-11-2012, 08:00 PM
1. 32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

2. G:\My practice\First_Class_Pro.cpp In function `int main()':
3. 22 G:\My practice\First_Class_Pro.cpp `getche' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

4. 27 G:\My practice\First_Class_Pro.cpp `getch' undeclared (first use this function)

These were the errors.
i got in mind one thing to ask. which header file is required for getche() Function?

Adeel.Rekhi
01-11-2012, 08:26 PM
after adding
#include<stdio.h>
#include<conio.h>
only this error is being appeared. and i have changed the spell of Variable.
32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

oracleguy
01-12-2012, 07:53 PM
As the message says you are using a deprecated header. Change iostream.h to iostream like it says to do and that message will go away.

Adeel.Rekhi
01-14-2012, 12:10 PM
Thanks Dear.
I got it.....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum