WAP using a class to store price list of 5 items and to print the largest prices as well as the sum of all prices.

/*WAP using a class to store price list of 5 items and to print the largest prices as well as the sum of all prices.*/
#include<iostream.h>
#include<stdlib.h>
class ITEM{ int itemcode[5];
                  float it_price[5];
            public:
                  void initialize (void);
                  float largest (void);
                  float sum (void);
                  void display_items (void);
            };
//.....Member Function Definitions Follow.....
void ITEM::initialize (void)
{ for(int i=0;i<5;i++)
      {     cout<<"\n"<<"Item No.: "<<(i+1);
            cout<<"\n"<<"Enter item code: ";
            cin>>itemcode[i];
            cout<<"\n"<<"Enter item price: ";
            cin>>it_price[i];
            cout<<"\n";
      }
}
float ITEM::largest(void)
{     float large = it_price[0];
      for(int i=1;i<5;i++)
      {
            if(large<it_price[i])
                  large = it_price[i];
      }
      return large;
}
float ITEM::sum (void)
{     float sum = 0;
      for(int i = 0; i<5;i++)
      sum+=it_price[i];
      return sum;
}
void ITEM::display_items(void)
{     cout<<"\nCode Price\n";
      for(int i = 0; i<5;i++)
      {     cout<<"\n"<<itemcode[i];
            cout<<" "<<it_price[i];
      }
      cout<<"\n";
}
int main()
{
      ITEM order;
      order.initialize();     //initialize arrays
      float total, biggest;
      int ch = 0;
      system ("cls");
      do
      {
            cout<<"\nMain Menu.\n";
            cout<<"\n1.Display largest price.";
            cout<<"\n2.Display sum of prices.";
            cout<<"\n3.Display item list.";
            cout<<"\nEnter your choice(1-3): ";
            cin>>ch;
            switch(ch)
            {     case 1: biggest = order.largest();
                              cout<<"The Largest price is "<<biggest<<"\n";
                              break;
                  case 2: total = order.sum();
                              cout<<"The sum of prices is "<<total<<"\n";
                              break;
                  case 3: order.display_items();
                              break;
                  default: cout<<"\nWrong choicee!\n";
                               break;
            } //end of switch
      }
      while(ch>=1&&ch<=3);
      return 0;
      }
OUTPUT


Comments

Post a Comment

Popular posts from this blog

WAP to get roll numbers and marks of the student of a class (get from the user) and store these details into a file called Marks.dat

WAP to create a single file and then display its contents.