1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
// ***** THIS IS A MEDIA MUSIC LIBRARY *****//
// Libraries
#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
using namespace std;
// Function Protoypes
void printMenu(char &);
void getInput(string[], string[], string[], int[] );
void viewAll(string[], string[], string[], int[]);
void deleteItem(string[], string[], string[], int[]);
void printGuide(string);
int searchIndex(string[], string[], string[], int[]);
void searchItem(string[], string[], string[], int[]);
void editUpdate(string[], string[], string[], int[]);
int main()
{
// variable declaration
bool endProgram = true;
string guide = " ";
char option = ' ';
string itemName[99] = {" Ladders ", " Tried To Be Nice ", " Sweet Lies ", " Pretty Boy ", " Brown Skin " };
string artistName[99] = {" Witt Lowry ", " Witt Lowry ", " Beres Hammond ", " Prophet Benjamin ", " Richie Spice" };
string genre[99] = { " Rap " , " Rap ", " Reggae ", " Reggae ", " Reggae " };
int year[99] = { 2015 , 2015 , 2009 , 2006 , 2009 };
do{ //loop
printMenu(option); //calling function
switch(option) //switch statement used to print menu
{
case '1':
cout << "\n You have Selected to Add A New Item ";
getInput(itemName, artistName, genre, year); // function call
break;
case '2':
cout << "\n You Have Selected To Search for an item";
searchItem(itemName, artistName, genre, year); // function call
break;
case '3':
cout << "\n You have Selected to Edit and Update an item"; // function call
editUpdate(itemName, artistName, genre, year);
break;
case '4':
cout << "\n You Have Selected to Delete an Item";
deleteItem(itemName, artistName, genre, year); // function call
break;
case '5':
cout << "\n You Have Selected To View all Items";
viewAll(itemName, artistName, genre, year); // function call
break;
case '6':
cout << "\n You have Selected to use the help guide";
printGuide(guide); // function call
break;
case '7':
endProgram = false; // option to close program using bool (true or false to determine )
break;
default:
cout << "\n This is an invalid option";
}
}while(endProgram); // end while
} // end
// FUNCTION DEFINITIONS
void printMenu(char &option)
{
cout << "\n ------------------------------ ";
cout << "\n Welcome To Your Media Library ";
cout << "\n ------------------------------ ";
cout << "\n Please Select Your Option ";
cout << "\n 1. Add a New Item";
cout << "\n 2. Search for an Item";
cout << "\n 3. Edit/Update an Item";
cout << "\n 4. Delete an Item";
cout << "\n 5. View All Items";
cout << "\n 6. Help Guide";
cout << "\n 7. Exit";
cout << "\n ******* PLEASE VIEW OPTION 6 FIRST *********";
cout << "\n Choose Your option using Numbers 1-7 : ";
cin >> option;
// THIS FUNCTION DISPLAYS AND TAKES IN INPUT FOR THE MENU.
} //end
void getInput(string itemName[], string artistName[], string genre[], int year[])
{
int index = searchIndex(itemName, artistName, genre, year);
cout << "\n You have selected To Add an Item !";
cout << "\n Please Enter Your : \n Item Name , Artist, Genre, Year! (Separated by a space ) \n";
cin >> itemName[index] >> artistName[index] >> genre[index] >> year[index];
cout << " Your data was entered successfully, Please see option 5 to view your added item. ";
// THIS FUNCTION ASKS FOR THE INPUT FOR ADDING A NEW ITEM TO THE LIBRARY.
} //end
void viewAll(string itemName[], string artistName[], string genre[], int year[] )
{
for(int i = 0; i < 99; i++) //loop
{
if(year[i] != 0){
cout << "\n Item : " << i+1 << "\n Name:" << itemName[i] << "\n Artist:" << artistName[i] << "\n Genre :" << genre[i] << "\n Year :" << year[i] << "."<<endl;
}
}
// THIS FUNCTION DISPLAYS ALL ITEMS IN THE LIBRARY
} //end
void deleteItem(string itemName[], string artistName[], string genre[], int year[])
{
int number = 0; // variable declaration
char option = 0;
viewAll(itemName, artistName, genre, year); //function
cout << "\n Please select the item number you wish to delete starting from 1 : ";
cin >> number;
cout << " Are you Sure ? Select Y : ";
cin >> option;
if(option == 'Y') //loop
{
itemName[number -1] = " ";
}
// THIS FUNCTION DELETES ITEMS FROM THE LIBRARY
}// end
void printGuide(string guide) // Option 6 Function
{
cout << "\n Welcome To My Program \n There are Interesting things you would like to View So Follow on! ";
cout << "\n Option 1 Allows you to add an item ! ";
cout << "\n Option 2 Allows you to search for a desired item! ";
cout << "\n Option 3 allows you to Update Items";
cout << "\n Option 4 Allows you to Delete an item ";
cout << "\n Option 5 Allows you to View All items !";
cout << "\n Option 7 lets you view this guide!";
cout << "\n Option 7 lets you exit ";
}//end
int searchIndex(string itemName[], string artistName[], string genre[], int year[])
{
for(int i = 0; i < 99; i++){ //loop used to search for an empty index.
if(year[i]== 0)
return i;
}
}//end
void searchItem(string itemName[], string artistName[], string genre[], int year[])
{
viewAll(itemName, artistName, genre, year); //calling function to view all items
int yearInput = 0; // variable declaration
cout << " Please enter the year you want to search for ";
cin >> yearInput; // asking for input example : 2009
for(int i = 0; i < 99; i++) // loop to search year enntered
{
if(year[i]== yearInput)
cout << "\n Name:" << itemName[i] << "\n Artist:" << artistName[i] << "\n Genre :" << genre[i] << "\n Year :" << year[i] << "."<<endl;
}
}//end
void editUpdate(string itemName[], string artistName[], string genre[], int year[])
{
int itemYear;
int index = searchIndex(itemName, artistName, genre, year);
viewAll(itemName, artistName, genre, year);
cout << " Please Enter The Item Year you Wish To Edit/Update ";
cin >> itemYear;
for(int i = 0; i < 99; i++)
{
if(year[i]== itemYear)
cin >> itemName[index] >> artistName[index] >> genre[index] >> year[index];
cout << itemName[i] << artistName[i] << genre[i] << year[i];
}
}
|