Find us On Facebook

Wednesday, April 6, 2011

W.A.P to store detail as product code, prod name, unitprice & quantity for a product in a class. Compute amount & display detail for the product. Use constructor to initialize class data members.


#include<iostream.h>
#include<conio.h>
class product {
            int pc,qty;
            char nm[20];
            float up,amt;
public:
            product() {
                        cout<<"\n Enter Product Code  :  =  ";
                        cin>>pc;
                        cout<<"Enter the Name         :  =  ";
                        cin.get();  // to clear the buffer
                        cin.getline(nm,20);
                        cout<<"\n Enter unit price & qty : = ";
                        cin>>up>>qty;
            }
             void compute() {
                        amt = qty *up;
             }
              void putdata() {
                        cout<<"\n Product Code = "<<pc;
                        cout<<"\n Product Name = "<<nm;
                        cout<<"\n Total Amount = "<<amt;
              }
              ~product() {
                        cout<<"\n Destroting object";
              }
            };
            void main() {
                        clrscr();
                        product prod;
                        prod.compute();
                        prod.putdata();
                        getch();
            }






OUTPUT:-




 Enter Product Code  :   =  101
 Enter the Name          :  =  Pen

 Enter unit price & qty : = 25 10

 Product Code = 101
 Product Name = Pen
 Total Amount = 250

0 comments:

Post a Comment

Programms

C,C++,VB, PL/SQL EBOOK SEARCH ENGINE