/* THIS CODE HAS BEEN TESTED AND IS FULLY OPERATIONAL. Problem Statement: Write C++ program using STL for sorting and searching with user defined records such as item record (Item code, name, cost,quantity) using vector container Code from Object Oriented Programming (SPPU - Second Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-se-comp-content/ObjectOrientedProgramming */ // BEGINNING OF CODE #include #include #include using namespace std; class Item { public: char name[10]; int quantity; int cost; int code; bool operator==(const Item& i1) { if(code==i1.code) return 1; return 0; } bool operator<(const Item& i1) { if(code o1; void print(Item &i1); void display(); void insert(); void search(); void dlt(); bool compare(const Item &i1, const Item &i2) { return i1.cost < i2.cost; } int main() { int ch; do { cout<<"\n*** Menu ***"; cout<<"\n1.Insert"; cout<<"\n2.Display"; cout<<"\n3.Search"; cout<<"\n4.Sort"; cout<<"\n5.Delete"; cout<<"\n6.Exit"; cout<<"\nEnter your choice: "; cin>>ch; switch(ch) { case 1: insert(); break; case 2: display(); break; case 3: search(); break; case 4: sort(o1.begin(),o1.end(),compare); cout<<"\n\n Sorted on Cost"; display(); break; case 5: dlt(); break; case 6: exit(0); default: cout<>i1.name; cout<<"\nEnter Item Quantity: "; cin>>i1.quantity; cout<<"\nEnter Item Cost: "; cin>>i1.cost; cout<<"\nEnter Item Code: "; cin>>i1.code; o1.push_back(i1); } void display() { for_each(o1.begin(),o1.end(),print); } void print(Item &i1) { cout<<"\n"; cout<<"\nItem Name: "<::iterator p; Item i1; cout<<"\nEnter Item Code to search: "; cin>>i1.code; p=find(o1.begin(),o1.end(),i1); if(p==o1.end()) { cout<<"\nNot found."; } else { cout<<"\nFound."<name<quantity<cost<code<::iterator p; Item i1; cout<<"\nEnter Item Code to delete: "; cin>>i1.code; p=find(o1.begin(),o1.end(),i1); if(p==o1.end()) { cout<<"\nNot found."; } else { o1.erase(p); cout<<"\nDeleted."; } } // END OF CODE