DATA CONVERSION BETWEEN CLASSES


Hello,
Iam new to classes.I had written the following program to test data conversion between different data types in Dev-Cpp.But I am unable to debug it .PLz help

# include<iostream>

using namespace std;

class invent2//destination class declared

class invent1//source class
{
int code;
int items;
float price;
invent1(int a,int b,float c)
{
code=a;
items=b;
price=c;
}
void putdata()
{
cout<<"Code:"<<code<<endl;
cout<<"Items:"<<items<<endl;
cout<<"value:"<<price<<endl;
}
int getcode(){return code;}
int getitems(){return items;}
float getprice(){return price;}
operator float(){return(items*price);}

/*operator invent2() //invent 1 to invent 2
{
invent2 temp;
temp.code=code;
temp.value=price*items;
return temp;
}*/
};//end of source class
class invent2//destination class
{
int code;
float value;
public:
invent2()
{
code=0;value=0;
}
invent2(int x,float y)//constructor for initialiazation
{
code=x;
value=y;
}
void putdata()
{
cout<<"Code:"<<code<<endl;
cout<<"value:"<<value<<endl;
}

/*invent2(invent1 p)//constructor for conversion
{
code=p.getcode();
value=p.getitems()*p.getprice();
}
}*/;//end of detination class

int main()
{
invent1 s1(100,5,140.0);
invent2 d1;
float totsl_value;

/*invent1 to float*/
total_value=s1;

/*invent1 to invent2*/
d1=s1;

cout<<"product details-invent1 type"<<endl;
s1.putdata();

cout<<"\n Stock value"<<"\n";
cout<<"value"<<total_value<<endl;

cout<<"product details-invent2 type"<<endl;
d1.putdata();

system("pause");
return 0;
}
Topic archived. No new replies allowed.