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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
#include<iostream>
#include <windows.h>
#include<conio.h>
#include<cstring>
#include<string>
#define SIZE 20
using namespace std;
struct Books
{
int book_number;
char title[50];
char author[50];
char subject[100];
int book_id;
}Book[SIZE],Book_2[SIZE],temporary;
void Display_Title()
{
cout<<"\n\t\t\tBook Record's\n";
system("Color F6");
}
void Input_Record(struct Books Book[],int Number_of_Records,int x)
{
int y,z=0,checker;
for(x=1;x<=Number_of_Records;x++)
{
z++;
Book[x].book_number=z;
cout<<"\n\tBook "<<Book[x].book_number<<"\n";
cout<<"\n\t\tTitle: ";
cin.getline(Book[x].title,50);
cout<<"\n\t\tAuthor: ";
cin.getline(Book[x].author,50);
cout<<"\n\t\tSubject: ";
cin.getline(Book[x].subject,100);
do
{
checker=0;
cout<<"\n\t\tID: ";
Book_ID:
cin>>Book[x].book_id;cin.ignore();
if(Book[x].book_id<0)
{
cout<<"\n\t\tInvalid Input\n";
checker=1;
}
for(y=1;y<=5;y++)
if(Book[x].book_id==Book[y].book_id)
if(y!=x)
{
cout<<"\n\t\tDuplicate Detected,Enter another!\n";
checker=1;
}
}while(checker==1);
}
}
void delRec(struct Books Book[], int x){
int a;
int deleID;
cout<<"Deleting a Record.....\n\n";
cout<<"Enter Book ID -> ";
cin>>deleID;
for(a=0;a<x;a++){
if(deleID==Book[a].book_id){
cout<<"Record Found...\n";
cout<<"\t Title Author Subject Book ID \n ";
cout<<"\t"<<Book[a].title <<" ";
cout<<Book[a].author<<" ";
cout<<Book[a].subject<<" ";
cout<<Book[a].book_id<<" ";
cout<<endl;
for(int b=0;b<x-1;b++)
Book[a]=Book[a+1];
cout<<"One Record Deleted ......" ;
system("pause");
break;
}
}
}
void Backup_Copy(struct Books Book[],int x)
{
for(x=0;x<SIZE;x++)
Book_2[x]=Book[x];
}
bool Search_Record(int x,int Search_Book_ID)
{
for(x=1;x<=SIZE;x++)
if(Search_Book_ID==Book[x].book_id)
return 1;
return 0;
}
void Display_Search_Record(int x,int Search_Book_ID)
{
for(x=1;x<=SIZE;x++)
{
if(Search_Book_ID==Book[x].book_id)
{
cout<<"\n\n\tTitle \t\tAuthor \t\tSubject \t\tID";
cout<<"\n\nBOOK "<<x;
cout<<"\t"<<Book[x].title;
cout<<"\t"<<Book[x].author;
cout<<"\t"<<Book[x].subject;
cout<<"\t"<<Book[x].book_id;
}
}
}
void Search_Validation(int Search_Book_ID)
{
int x, Result;
if(Search_Record(x,Search_Book_ID)==1)
{
Display_Search_Record(x,Search_Book_ID);
cout<<"\n\nTHE BOOK ID "<<Search_Book_ID<<" Is in the record!";
}
else
cout<<"\nTHE BOOK ID "<<Search_Book_ID<<" Is not in the record!";
}
void Sort_Record(struct Books Book[],int x,int Number_of_Records)
{
int y;
for (x=Number_of_Records-1;x>0;x--)
for(y=0;y<=x;y++)
if (Book_2[y].book_id>Book_2[y+1].book_id)
{
temporary=Book_2[y];
Book_2[y]=Book_2[y+1];
Book_2[y+1]=temporary;
}
}
void Display_Sorted_Record(struct Books Book[],int x,int Number_of_Records,int z)
{
for(x=1;x<=Number_of_Records;x++)
{
cout<<"\n\nBOOK "<<Book_2[x].book_number;
cout<<"\t"<<Book_2[x].title;
cout<<"\t"<<Book_2[x].author;
cout<<"\t"<<Book_2[x].subject;
cout<<"\t"<<Book_2[x].book_id;
}
}
void Display_Original_Record(struct Books Book[],int x,int Number_of_Records,int z)
{
for(x=1;x<=Number_of_Records-1;x++)
{
cout<<"\n\nBOOK "<<Book[x].book_number;
cout<<"\t"<<Book[x].title;
cout<<"\t"<<Book[x].author;
cout<<"\t"<<Book[x].subject;
cout<<"\t"<<Book[x].book_id;
}
}
int main(void)
{
int x,y,z,Number_of_Records,Search_Book_ID,Result,test=0;
char choice,choice_2;
Display_Title();
cout<<"\n\tInput Book Records's: ";
cin>>Number_of_Records;cin.ignore();
cout<<"\n\tPlease Input "<<Number_of_Records<<" Book Record's: \n";
Input_Record(Book,Number_of_Records,x);
do{
MENU:
system("cls");
Display_Title();
cout<<"\nPlease choose the operation to be use in the Record:";
cout<<"\n[1]-Make a Backup Copy";
cout<<"\n[2]-Search a Record";
cout<<"\n[3]-Delete a Record";
cout<<"\n[4]-Sort Record";
cout<<"\n[5]-Display Sorted Record";
cout<<"\n[6]-Display Original File Record";
cout<<"\n[7]-Exit\n";
cout<<"Please input your choice here: ";
cin>>choice;
choice=toupper(choice);
system("Color F6");
system("cls");
switch(choice)
{
case '1':
{
Display_Title();
test=1;
cout<<"\nMake a Backup Copy:\n";
Backup_Copy(Book,x);
cout << "Back Up copy initializing,Please Wait" << endl;
Sleep( 2000 );
cout<<"\nBack Up Is Successfull.";
Sleep(4000);
cout<<"\n\nPress [ENTER] to choose another operation.";
break;
}
case '2':
{
Display_Title();
cout<<"\nSearch a Record:\n";
cout<<"\nPlease input the Book ID to be searched: ";
cin>>Search_Book_ID;
Result=Search_Record(x,Search_Book_ID);
Search_Validation(Search_Book_ID);
cout<<"\n\nPress <ENTER> to choose another operation.";
break;
}
case '3':
{
Display_Title();
delRec(Book,x);
break;
}
case '4':
{
Display_Title();
if(test==1)
{
cout<<"\nSort Record:\n";
Sort_Record(Book,x,Number_of_Records);
cout<<"Initializing Sorting,Please Wait";
Sleep( 2000 );
cout<<"\nSorting Successfull!";
Sleep(4000);
cout<<"\n\nPress [ENTER] to choose another operation.";
}
else
{
cout<<"\nBack Up First!";
cout<<"\nPRESS <ENTER> TO RETURN IN THE MENU!!!";
}
break;
}
case '5':
{
Display_Title();
if(test!=1)
cout<<"\nInvalid!";
else
{
cout<<"\nDisplay Sorted Record:";
Display_Sorted_Record(Book,x,Number_of_Records,z);
cout<<"\n\nPress <ENTER> to choose another operation.";
}
break;
}
case '6':
{
Display_Title();
cout<<"\nDisplay Original File Record:";
Display_Original_Record(Book,x,Number_of_Records,z);
cout<<"\n\nPress <ENTER> to choose another operation.";
break;
}
case '7':
{
cout<<"This Program will close!";
exit(0);
break;
}
default:
{
cout<<"Invalid,Try Another!";
break;
}
}
getch();
}while(choice_2!='E');
}
|