#include <iostream>
#include <string.h>
#include <iomanip>
using namespace std;
class LIST {
unsigned short int code;
char name[30];
int qty;
float price;
float amount;
static int count;
static float total;
public:
LIST() {
code = 0;
strcpy(name, "");
qty = 0;
price = 0.0;
amount = 0.0;
void getdata() {
cout << "Enter item code, name, quantity and price: " << endl;
cin >> code >> name >> qty >> price;
amount = qty * price;
count++;
total += amount;
void showlist() {
cout << setw(10) << code
<< setw(15) << name
<< setw(10) << qty
<< setw(10) << price
<< setw(10) << amount << endl;
unsigned short int getcode() {
return code;
void del_item() {
total -= amount;
qty = 0;
price = 0;
amount = 0;
static void showtotal() {
cout << "Final Amount to be paid is Rs. " << total << endl;
};
int LIST::count = 0;
float LIST::total = 0.0;
int main() {
LIST obj[50];
int choice;
int n = 0;
do {
cout << "\nYou can do the following:\n";
cout << "1. Add an item\n";
cout << "2. Delete an item\n";
cout << "3. Display list\n";
cout << "4. Display total\n";
cout << "5. Exit\n";
cout << "Enter your choice: \n";
cin >> choice;
switch(choice) {
case 1:
obj[n].getdata();
n++;
break;
case 2: {
unsigned short int c;
cout << "Enter item code of the item to be deleted: ";
cin >> c;
for (int i = 0; i < n; i++) {
if (obj[i].getcode() == c) {
obj[i].del_item();
break;
break;
case 3:
cout << "\n" << setw(10) << "Item Code"
<< setw(15) << "Item Name"
<< setw(10) << "Quantity"
<< setw(10) << "Price"
<< setw(10) << "Amount" << endl;
for (int i = 0; i < n; i++) {
obj[i].showlist();
break;
case 4:
LIST::showtotal();
break;
case 5:
cout << "Thank you and visit again." << endl;
break;
default:
cout << "Invalid choice! Please try again." << endl;
} while(choice != 5);
return 0;