StudyLover
  • Home
  • Study Zone
  • Profiles
  • Contact us
  • Sign in
StudyLover 14. Program to process a shopping list for a departmental store using a class. The list includes details such as code number and price of each item, and operations like adding, deleting items, and printing the total value of an order.
Download
  1. C++ Programs list
13. Program to create a class called `Cube` with data members `length`, `breadth`, and `height` and member functions to accept details, calculate the volume, and display the details. : 15. Program to display names, roll numbers, and grades of 3 students who have appeared in an examination using a class. Create an array of class objects and read and display the contents of the array.
C++ Programs list

1.      Program to process a shopping list for a departmental store using a class. The list includes details such as code number and price of each item, and operations like adding, deleting items, and printing the total value of an order.

  1. #include <iostream.h>

  2. #include<conio.h>

  3. class Item {

  4. public:

  5.     int code;

  6.     float price;

  7.  

  8.     void inputDetails() {

  9.         cout << "Enter item code: ";

  10.         cin >> code;

  11.         cout << "Enter item price: ";

  12.         cin >> price;

  13.     }

  14.  

  15.     void displayDetails() {

  16.         cout << "Item Code: " << code << endl;

  17.         cout << "Item Price: " << price << endl;

  18.     }

  19. };

  20.  

  21. class ShoppingList {

  22. public:

  23.     Item items[100];

  24.     int count;

  25.  

  26.     ShoppingList() {

  27.         count = 0;

  28.     }

  29.  

  30.     void addItem() {

  31.         if (count < 100) {

  32.             items[count].inputDetails();

  33.             count++;

  34.             cout << "Item added successfully." << endl;

  35.         } else {

  36.             cout << "Shopping list is full." << endl;

  37.         }

  38.     }

  39.  

  40.     void deleteItem(int code) {

  41.         int i, found = 0;

  42.         for (i = 0; i < count; i++) {

  43.             if (items[i].code == code) {

  44.                 found = 1;

  45.                 break;

  46.             }

  47.         }

  48.  

  49.         if (found) {

  50.             for (int j = i; j < count - 1; j++) {

  51.                 items[j] = items[j + 1];

  52.             }

  53.             count--;

  54.             cout << "Item deleted successfully." << endl;

  55.         } else {

  56.             cout << "Item not found." << endl;

  57.         }

  58.     }

  59.  

  60.     void printTotal() {

  61.         float total = 0;

  62.         for (int i = 0; i < count; i++) {

  63.             total += items[i].price;

  64.         }

  65.         cout << "Total value of the order: " << total << endl;

  66.     }

  67. };

  68.  

  69. int main() {

  70.     ShoppingList list;

  71.     int choice;

  72.  

  73.     do {

  74.         cout << "\n1. Add Item\n2. Delete Item\n3. Print Total\n4. Exit\n";

  75.         cout << "Enter your choice: ";

  76.         cin >> choice;

  77.  

  78.         switch (choice) {

  79.             case 1:

  80.                 list.addItem();

  81.                 break;

  82.             case 2: {

  83.                 int code;

  84.                 cout << "Enter item code to delete: ";

  85.                 cin >> code;

  86.                 list.deleteItem(code);

  87.                 break;

  88.             }

  89.             case 3:

  90.                 list.printTotal();

  91.                 break;

  92.             case 4:

  93.                 cout << "Exiting..." << endl;

  94.                 break;

  95.             default:

  96.                 cout << "Invalid choice." << endl;

  97.         }

  98.     } while (choice != 4);

  99.     getch();

  100.     return 0;

  101. }

13. Program to create a class called `Cube` with data members `length`, `breadth`, and `height` and member functions to accept details, calculate the volume, and display the details. 15. Program to display names, roll numbers, and grades of 3 students who have appeared in an examination using a class. Create an array of class objects and read and display the contents of the array.
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website