fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Shoppinglist{
  7. private:
  8. string Items[100];
  9. int Itemcount;
  10.  
  11. public:
  12. Shoppinglist():Itemcount(0){}
  13.  
  14. void additem(string item){
  15. if (Itemcount<100){
  16. Items[Itemcount]= item;
  17. Itemcount++;
  18. cout<<item <<"added to the shopping List. \n";
  19. }
  20. else{
  21. cout<< "Shopping List is full.Can not Add more items. \n";
  22. }
  23. }
  24. void removeItem(int index){
  25. if(index-1<Itemcount){
  26. Itemcount--;
  27. cout<<Items[index-1]<<"remove from Shopping List.\n";
  28. }
  29. else{
  30. cout<<index<<"index not found in the Shopping List.\n";
  31. }
  32. for (int j=index-1;j<=Itemcount;j++){
  33. Items[j]=Items[j+1];
  34. }
  35. }
  36. void viewlist(){
  37. if (Itemcount==0){
  38. cout<<"Shopping List is empty.\n";
  39. }
  40. else{
  41. cout<<"Items in the Shopping List:\n";
  42. for(int i=0;i<Itemcount;i++){
  43. cout<<i+1<<"."<< Items[i]<< "\n";
  44. }
  45. cout<<"\n";
  46. }
  47. void clearlist()
  48. {
  49. Itemcount =0;
  50. cout<< "Shopping List cleared.\n";
  51. }
  52. }
  53. };
  54.  
  55. main(){
  56. Shoppinglist shoppinglist;
  57. int choice, index;
  58. string item;
  59. cout<<" Welcome To The Shopping List Manager\n";
  60. do{
  61. cout << "1. Add Item\n";
  62. cout << "2. Remove Item\n";
  63. cout << "3. View List\n";
  64. cout << "4. clear List\n";
  65. cout << "5. Exit\n";
  66. cout << "Enter Your Choice";
  67. cin>> choice;
  68. Switch(choice)
  69. {
  70. case 1:
  71. cout << "Enter itemd to add:";
  72. cin>>item;
  73. shoppinglist.additem(item);
  74. break;
  75. case 2:
  76. cout << "Enter item index to remove:";
  77. cin>> index;
  78. shoppinglist.removeItem(index);
  79. break;
  80. case 3:
  81. shoppinglist.viewlist();
  82. break;
  83. case 4:
  84. shoppinglist.cleatlist();
  85. break;
  86. case 5:
  87. cout << "Exiting program. Goodye!\n";
  88. break;
  89. default:
  90. cout <<"Invalid choice.Please Try Again.\n";
  91. }
  92. }while(choice !=5);
  93. }
Success #stdin #stdout 0.02s 25860KB
stdin
Standard input is empty
stdout
#include <iostream>
#include <string>

using namespace std;

class Shoppinglist{
	private:
		string Items[100];
		int Itemcount;
		
	public:
	Shoppinglist():Itemcount(0){}
	
	void additem(string item){
		if (Itemcount<100){
			Items[Itemcount]= item;
			Itemcount++;
			cout<<item <<"added to the shopping List. \n";
		}
		else{
			cout<< "Shopping List is full.Can not Add more items. \n";
		}
	}	
	void removeItem(int index){
		if(index-1<Itemcount){
			Itemcount--;
			cout<<Items[index-1]<<"remove from Shopping List.\n";
		}
		else{
			cout<<index<<"index not found in the Shopping List.\n";	
		}
		for (int j=index-1;j<=Itemcount;j++){
			Items[j]=Items[j+1];
		}
	}	
	void viewlist(){
		if (Itemcount==0){
			cout<<"Shopping List is empty.\n";
		}
		else{
			cout<<"Items in the Shopping List:\n";
			for(int i=0;i<Itemcount;i++){
				cout<<i+1<<"."<< Items[i]<< "\n";
			}			
			cout<<"\n";
		}
		void clearlist()
		{
			Itemcount =0;
			cout<< "Shopping List cleared.\n";
		}
	}
};

main(){
	Shoppinglist shoppinglist;
	int choice, index;
	string item;
	cout<<" Welcome To The Shopping List Manager\n";
	do{
		cout << "1. Add Item\n";
		cout << "2. Remove Item\n";
		cout << "3. View List\n";
		cout << "4. clear List\n";
		cout << "5. Exit\n";
		cout << "Enter Your Choice";
		cin>> choice;
		Switch(choice)
		{
			case 1:
				cout << "Enter itemd to add:";
				cin>>item;
				shoppinglist.additem(item);
				break;
			case 2:
				cout << "Enter item index to remove:";
				cin>> index;
				shoppinglist.removeItem(index);
				break;
			case 3:
				shoppinglist.viewlist();
				break;
			case 4:
				shoppinglist.cleatlist();
				break;
			case 5:
				cout << "Exiting program. Goodye!\n";
				break;
			default:
				cout <<"Invalid choice.Please Try Again.\n";
		}
	}while(choice !=5);
}