Dsa - 01
Dsa - 01
class ItemType
private:
string name;
float price;
int quantity;
public:
};
class GroceryList
private:
ItemType *items;
int capacity;
int size;
public:
if (size == capacity)
newArray[i] = items[i];
delete[] items;
items = newArray;
capacity = newCapacity;
items[size++] = item;
if (size == 0)
return;
string n = items[i].getName();
if (n == name)
{
1
--size;
return;
void sortItemsByPrice()
int n = size;
int minIndex = i;
minIndex = j;
if (minIndex != i)
swap(items[i], items[minIndex]);
}
1
void sortItemsByPriceInsertion()
int j = i - 1;
items[j + 1] = items[j];
j--;
items[j + 1] = key;
if (size == 0)
cout << "Name: " << items[i].getName() << ", Price: " <<
items[i].getPrice() << ", Quantity: " << items[i].getQuantity() << std::endl;
}
1
~GroceryList()
delete[] items;
};
class Menu
private:
GroceryList groceryList;
int userChoice;
public:
void displayMenu()
userChoice = 0;
cout << "3) Sort the List By Selection Sort: " << endl;
cout << "4) Sort the List By Insertion Sort: " << endl;
switch (userChoice)
1
case 0:
case 1:
string name;
float price;
int quantity;
groceryList.addItem(newItem);
groceryList.displayItems();
break;
case 2:
string choice;
groceryList.removeItem(choice);
1
break;
case 3:
groceryList.sortItemsByPrice();
groceryList.displayItems();
break;
case 4:
groceryList.sortItemsByPriceInsertion();
groceryList.displayItems();
break;
case 5:
groceryList.displayItems();
break;
default:
break;
Menu()
1
displayMenu();
};
int main()
Menu menu;}
Remove an item