Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by effect ( 7 years ago )
#include<iostream>
#include<vector>
 
using namespace std;
 
int main()
{
	vector<string> shop;
 
	int action;
 
	while(action!=5)
	{
		cout<<"\n\t ** Shoping List Manager **\n\n";
		cout<<"\nEnter Your Choice";
		cout<<"\n1. To delete an item from the list.";
		cout<<"\n2. To add an item at specific location.";
		cout<<"\n3. To add an item at the end of list.";
		cout<<"\n4. To print the contents of the list.";
		cout<<"\nPress 5 to exit the program.\n";
		cin>>action;
		
		if(action==1)
		{
			if(shop.empty()==false)
			{
					int a;
					cout<<"\nEnter the item position to delete : ";
					cin>>a;
					if(a<shop.size()+1)
					{
						shop.erase(shop.begin()+a-1);
						cout<<"\nItem Deleted Successfully\n";
					}
					else cout<<"\nEnter Proper Position.";
			}
			else
				cout<<"\nSorry!! The Vector Is Empty\n";
		}
		
		else if(action==2)
		{
			string s;
			int a;
			cout<<"\nEnter the Position : ";
			cin>>a;
			if(a>shop.size()+1)
			{
				cout<<"\nWrong Postition Exceeds Last Place\n";
			}
			else
			{
			cout<<"\nItem Name : ";
			cin>>s;
			shop.insert(shop.begin()+a-1,s);
			cout<<"Item Inserted Successfully\n";
			}
		}
		
		else if(action==3)
		{
			string s;
			cout<<"\nPlease enter the Item Name to be Inserted at the End";
			cout<<"\nItem Name : ";
			cin>>s;
			shop.insert(shop.end(),s);
			cout<<"Item Inserted Successfully\n";
		}
		
		else if(action==4)
		{
			cout<<"\nShopping List\n";
			if(shop.empty() == true )
			{
				cout<<"List is Empty\nTry adding some items first.\n";
			}
			else
			{
			for(int i=0; i<= shop.size()-1; i++)
				{
					cout<<i+1<<" :- "<<shop[i]<<"\n";
				}
			}
		}
		
		else if(action==5)
		{
			cout<<"\n Please Enter Choice From Above (1 to 5) \n";
		}
	}
	return 0;
}

 

Revise this Paste

Your Name: Code Language: