Advertisement
Guest User

Simple_Library_System

a guest
Mar 17th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5.  
  6. string addRecord()
  7. {
  8. string info1, info2;
  9. cin>>info1; info2=info1; getline(cin,info1);
  10. info1 =info2+info1;
  11. return info1;
  12. }
  13.  
  14.  
  15.  
  16. void displayRecord(string input[20][5],int j){
  17. int l;
  18. cout<<input [j][0]<<"\t\t"<<input[j][1]<<"\t";
  19. l = input[j][1].size();
  20. if(l<=15&&l>=8)
  21. cout<<"\t";
  22. else if(l<8)
  23. cout<<"\t\t";
  24.  
  25. cout<<input [j][2]<<"\t";
  26. l = input[j][2].size();
  27. if(l<=15&&l>=8)
  28. cout<<"\t";
  29. else if(l<8)
  30. cout<<"\t\t";
  31. cout<<input [j][3];
  32. cout<<"\n";
  33. }
  34.  
  35. void edit(string input[20][5], int record)
  36. {
  37. string pk;
  38. int z=-1,x;
  39. cout<<"Enter Book code: ";
  40. cin>>pk;
  41.  
  42. do{
  43. z++;
  44. if(z > record)
  45. {
  46. cout<<"\nBook code not found\n";
  47. break;
  48. }
  49. } while(input[z][0] != pk);
  50.  
  51. if(input[z][0] == pk)
  52. for(x=1;x<3;x++)
  53. {
  54. if(x==1)cout<<"\nNew Book Title: ";
  55. if(x==2)cout<<"New Book Author: ";
  56. input[z][x] = addRecord();
  57. }
  58. }
  59.  
  60. int main(){
  61.  
  62. int numRecord=0,i,z;
  63. string input[20][5], borrow;
  64. char ch,again;
  65. do{
  66. system("cls");
  67. cout<<"\t\t\t ****Simple Library System**** "<<endl;
  68. cout<<"\n--------------------------------------------------------------------------------";
  69. cout<<"\n[1] - Add Book"<<endl;
  70. cout<<"[2] - Display"<<endl;
  71. cout<<"[3] - Edit"<<endl;
  72. cout<<"[4] - Borrow"<<endl;
  73. cout<<"[5] - Delete"<<endl;
  74. cout<<"[6] - Quit"<<"\n\nChoice: ";
  75.  
  76. cin>>ch;
  77.  
  78. switch(ch){
  79.  
  80. case '1':{
  81. do{
  82. numRecord++;
  83. system("cls");
  84. cout<<"--------------------------------------------------------------------------------\n\t\t\t\t Add Book\n--------------------------------------------------------------------------------";
  85.  
  86.  
  87. do{
  88. cout<<"\nBook Code: ";
  89. input[numRecord-1][0]=addRecord();
  90. z=-1;
  91. if(numRecord==1)
  92. break;
  93. do{
  94. z++;
  95. if(z > numRecord-3)
  96. break;
  97. }while(input[z][0] != input[numRecord-1][0]);
  98.  
  99. if(input[z][0] == input[numRecord-1][0])
  100. cout<<"Book Code already exist";
  101.  
  102.  
  103. }while(input[z][0] == input[numRecord-1][0]);
  104.  
  105.  
  106. cout<<"Book Title: ";
  107. input[numRecord-1][1]=addRecord();
  108. cout<<"Author: ";
  109. input[numRecord-1][2]=addRecord();
  110. input[numRecord-1][3]="Available";
  111. do{
  112. cout<<"Enter Again? [Y][N]: ";
  113. cin>>again;
  114. }
  115. while (again!='y' &&
  116. again!='n');
  117. }
  118. while (again=='y');
  119. break;
  120. }
  121.  
  122. case '2': {
  123. system("cls");
  124. cout<<"-----------------------------------------------";
  125. cout<<"\n\t\t +-+Display Book+-+";
  126. cout<<"\n-----------------------------------------------";
  127. cout<<"\nBook Code\tBook Title\t\tAuthor\t\t\tStatus"<<endl;
  128. for(int y=0;y<numRecord;y++)
  129. displayRecord(input,y);
  130. break;
  131. }
  132.  
  133. case '3': {
  134. do{
  135. system("cls");
  136. cout<<"\t\t - - - - - - - Edit Book - - - - - - - -"<<endl<<endl;
  137. cout<<"Book Code\tBook Title\t\tAuthor\t\t\tStatus"<<endl;
  138. for(int y=0;y<numRecord;y++)
  139. {
  140. displayRecord(input,y);
  141. }
  142. cout<<endl;
  143. edit(input,numRecord);
  144.  
  145. do{
  146. cout<<"\nEdit another.?(y/n): ";
  147. cin>>again;
  148. if(again!='y'&&again!='n') cout<<"\nInvalid Input\n\n";
  149. }while(again!='y'&&again!='n');
  150.  
  151. }while(again=='y');
  152. break;
  153. }
  154.  
  155. case '4': {
  156. do{
  157. system("cls");
  158. cout<<"\t\t - - - - - - - Borrow Book - - - - - - - -"<<endl;
  159. cout<<"Book Code\tBook Title\t\tAuthor\t\t\tStatus\t\t"<<endl;
  160. for(int y=0;y<numRecord;y++)
  161. displayRecord(input,y);
  162.  
  163. z=-1;
  164. cout<<"\nBook Code: ";
  165. cin>>borrow;
  166.  
  167. do{
  168. z++;
  169. if (z>numRecord){
  170. cout<<"\nBook Not Found"<<endl;
  171. break;
  172. }
  173.  
  174. }while (input[z][0] != borrow);
  175. if (input[z][0] == borrow){
  176. if(input[z][3]!="Borrowed")
  177. {
  178. input[z][3] = "Borrowed";
  179. cout<<"\nBorrowing Successful! ^^"<<endl;
  180. }
  181. else
  182. cout<<"\nBook Already Borrowed! :("<<endl;
  183.  
  184. }
  185. do{
  186. cout<<"Enter Again? [Y][N]: ";
  187. cin>>again;
  188. }
  189. while (again!='y' &&
  190. again!='n');
  191. }
  192. while (again=='y');
  193. break;
  194. }
  195.  
  196. case '5': {
  197. system("pause");
  198. return 0;
  199. }
  200. default:cout<<"\nWhy are you trying to input what is not in the choice? ;)\nPlease enter again...\n"<<endl;
  201. }
  202. system("pause");
  203. }
  204. while (ch !=3);
  205.  
  206. return 0;
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement