SHOPPING LIST BY C++ PROGRAMMING LANGUAGE

 // ******Refereced by a book that is E- balagurusamy . i got it from library******



#include <iostream>

using namespace std;

const int m = 100;

class items

{

private:


  int itemcode[m];

  float itemprice[m];

  int count;

public:

  void cnt (void)

  {

    count = 0;

  }

  void getitem (void);

  void displaysum (void);

  void remove (void);

  void displayitems (void);


};


void items::getitem (void)

{

  cout << "Enter item code: ";

  cin >> itemcode[count];

  cout << "Enter item cost:";

  cin >> itemprice[count];

  count++;


}


void

items::displaysum (void)

{

  float sum = 0;

  for (int i = 0; i < count; i++)

    sum = sum + itemprice[i];

  cout << "total value: " << sum << endl;

}


void

items::remove (void)

{

  int a;

  cout << "Enter item code: ";

  cin >> a;

  for (int i = 0; i < count; i++)

    if (itemcode[i] == a)

      itemprice[i] = 0;


}



void

items::displayitems (void)

{

  cout << "code price " << endl;

  for (int i = 0; i < count; i++)

    {

      cout << itemcode[i]<<endl;

      cout << itemprice[i]<<endl;

    }

  

}


int

main ()

{

  items order;

  order.cnt ();

  int x;

  do

    {

      cout << "\n \n \n ****you can  do the follwing***** :" << endl;

      cout << "    enter appropriate number " << endl;

      cout << "1 :add an item " << endl;

      cout << "2 :display total value " << endl;

      cout << "3 :delete an item" << endl;

      cout << "what is your option ? jaldi batao ?????" << endl;

      cin >> x;

      if (x >= 4)

{

  cout << "Hey enter correct number  you can enter only 1-3" << endl;


}

      else

{

  cout << "" << endl;

}

      switch (x)

{

case 1:

  order.getitem ();

  break;

case 2:

  order.displaysum ();

  break;

case 3:

  order.displayitems ();

  break;

case 4:

  order.displayitems ();

  break;

case 5:

  break;

default:

  cout << "Error in input " << endl;

  cout << "Try again" << endl;


}

    }

  while (x != 5);

  return 0;


}


Comments

Post a Comment

Popular posts from this blog

250+ C Programs for Practice

FUNCTION OVERRIDING IN CPP