Search This Blog

Tuesday 23 February 2016

Create a class called ITEM that has separate member data for item number(int) and item cost(float).Include the following member functions: setdata( )to set these values to predefined values in the program getdata( )to get these values from the user putdata( ) to display these values.

Practical 10

#include<iostream>
using namesapce std;

class ITEM
{
      int number;
     float cost;

     void setdata(int,float);
     void getdata();
     void putdata();
};

void ITEM :: setdata(int i,float j)
{
      number=i;
     cost=j;
}

void ITEM :: getdata()
{
      int i;  float j;
      cout<<"Enter number";
     cin>>i;
     cout<<"\nEnter cost";
     cin>>j;
}

void ITEM :: putdata()
{
     cout<<"Number is :"<<number;
     cout<<"Cost is :"<<cost;
}

int main()
{
     ITEM i;
     i.getdata();
     i.putdata();
     i.setdata(12,15.16);
     i.putdata();
}



output:


enter number  : 2
enter cost : 1.5

number is 2
cost is 1.5

number is 12
cost is 15.16

No comments:

Post a Comment