Created
February 4, 2017 00:44
-
-
Save nihitx/1f56c129b35c992d35ba9c11647d2721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include<array> | |
using namespace std; | |
int main() | |
{ | |
cout << "** welcome to the database **" << endl; | |
char choice; | |
string bookname; | |
string removebook; | |
int countnum; | |
string authorname; | |
string fullbook; | |
vector<string> bookarray; | |
do{ | |
cout << " a. Add a book" << endl; | |
cout << " b. Remove a book" << endl; | |
cout << " c. Empty database" << endl; | |
cout << " d. show number of books" << endl; | |
cout << " e. show all of books" << endl; | |
cout << "f . quit" << endl; | |
cin >> choice; | |
if(choice == 'f' ) { | |
printf("Terminating the program..."); | |
} | |
else{ | |
if(choice == 'a'){ | |
cout << "please enter name of book: " ; | |
cin >> bookname; | |
cout << "please enter author name :"; | |
cin >> authorname; | |
fullbook = bookname + " " + authorname; | |
bookarray.push_back(fullbook); | |
cout << "Book has been added" << endl; | |
}else if(choice =='b'){ | |
cout << "Please enter book number to delete: " ; | |
cin >> removebook; | |
for(int i = 0; i < bookarray.size() ; i++){ | |
if (bookarray[i].find(removebook) != std::string::npos) { | |
bookarray.erase (bookarray.begin()+i); | |
break; | |
} | |
} | |
cout << " " << endl; | |
cout << "book has been removed" << endl; | |
cout << " " << endl; | |
}else if(choice == 'c'){ | |
bookarray.clear(); | |
cout << "Database cleared" << endl; | |
cout << " " << endl; | |
}else if(choice == 'd'){ | |
countnum = bookarray.size(); | |
cout << "number of books in array:" << countnum << endl; | |
}else if(choice == 'e'){ | |
cout << "name of books in array " << endl; | |
for(int i = 0; i < bookarray.size() ; i++){ | |
cout << i << " " << bookarray[i] << " " << endl; ; | |
} | |
cout << " " << endl; | |
} | |
} | |
}while(choice != 'f'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A CRUD for C++