Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Program of class to class conversion

Posted By: Vitoria Silva     Category: C++ Programming     Views: 8058

Write a program of class to class conversion.

Code for Program of class to class conversion in C++ Programming

# include <iostream.h>
# include <conio.h>
class in1
{
    int code,items;
    float price;
    public:
        in1(int a,int b,int 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;
        }
        int getprice()
        {
            return price;
        }
        operatorfloat ()
        {
             return items*price;
        }
};

class in2
{
    int code;
    floatvalue;
    public:
    in2()
    {
        code=0;
        value=0;
    }
    in2(int x,float y)
    {
        code=x;
        value=y;
    }
    void putdata()
    {
        cout<<"CODE= "<<code<<endl;
        cout<<"VALUE= "<<value<<endl;
    }
    in2(in1 p)
    {
        code=p.getcode();
        value=p.getitems()*p.getprice();
    }
};

main()
{
clrscr();
    in1 s1(100,51,140.0);
    float tot_value;
    in2 d1;
    tot_value=s1;
    d1=in1(s1);
    cout<<"PRODUCT DETAILS INVENT-1 TYPES:->"<<endl;
    s1.putdata();
    cout<<"STOCK VALUE"<<endl;
    cout<<"VALUE= "<<tot_value<<endl;
    cout<<"PRODUCT DETAILS INVENT-2 TYPES:->"<<endl;
    d1.putdata();
}
  
Share: 


Didn't find what you were looking for? Find more on Program of class to class conversion Or get search suggestion and latest updates.

Vitoria Silva
Vitoria Silva author of Program of class to class conversion is from Salvador, Brazil.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Shallinkumar Purohit from United States Comment on: Dec 13
class in1
{
int code,items;
float price;
public:
in1(int a,int b,int c)
{
code=a;
items=b;
price=c;
}
void putdata()
{
cout<<"\nCODE: "<<code<<"\nITEMS: "<<items<<"\nVALUE: "<<price;
}
int getcode()
{
return code;
}
int getitems()
{
return items;
}
int getprice()
{
return price;
}
operator float ()
{
return items*price;
}
};

class in2
{
int code, item;
float value, tol_val;
public:
in2()
{
code=0, value=0;
}
in2(int x,float y)
{
code=x, value=y;
}
void putdata()
{
cout<<"\nCODE: "<<code<<"\nITEMS: "<<items<<"\nVALUE: "<<price;
cout<<endl<<endl<<"\nTotal Price is "<<tol_val;
}
in2(in1 p)
{
code=p.getcode();
item=p.getitems()
value=p.getprice();
tol_val=p.getitems()*p.getprice();
}
};

void main()
{
clrscr();
in1 s1(100,51,140.0);
in2 d1;

d1=s1; //class type to class type ...

cout<<"\nPRODUCT DETAILS INVENT-1 TYPES:->";
s1.putdata();
cout<<"\nPRODUCT DETAILS INVENT-2 TYPES:->";
d1.putdata();

getch();
}

View All Comments