This program should be written in C/C++ or JAVA. DATABASE SQL should not be used. Only traditional file processing management system.
Someone please give me a traditional file processing database program source code?
# include %26lt;stdio.h%26gt;
# include %26lt;windows.h%26gt;
# include %26lt;stdlib.h%26gt;
# include %26lt;string.h%26gt;
struct MOVIE
{
char title [20];
char type [20];
int serial;
char actor [20];
char actress [20];
int price;
int stockQuantity;
int onRentQuantity;
};
struct ADDRESS
{
char houseNo [10];
char roadNo [10];
char area [20];
char post [20];
char city [20];
};
struct MYDATE
{
int day;
int month;
int year;
};
struct CUSTOMER
{
char name [20];
int age;
ADDRESS adr;
int rentMovieSerial;
MYDATE dateOfRent;
};
int main (void)
{
MOVIE m;
CUSTOMER c;
int choice, srl;
char actr [20], typ [20], mname [20];
FILE *mfp, *tfp, *rfp;
mfp = fopen ("record.txt", "rb+");
if (mfp == NULL)
{
mfp = fopen ("record.txt", "wb+");
if (mfp == NULL)
{
system ("cls");
printf ("RECORD FILE COULD NOT BE OPEN!\n");
}
}
rfp = fopen ("customer.txt", "rb+");
if (rfp == NULL)
{
rfp = fopen ("customer.txt", "wb+");
if (rfp == NULL)
{
system ("cls");
printf ("CUSTOMER FILE COULD NOT BE OPEN!\n");
}
}
do
{
system ("cls");
printf ("MENU : \n\n");
printf ("1. ADD NEW MOVIE\n");
printf ("2. DELETE MOVIE ONE BY ONE\n");
printf ("3. LET MOVIE BE ON RENT\n");
printf ("4. SHOW ALL MOVIE\n");
printf ("5. SEARCH MOVIE\n");
printf ("6. DELETE ALL MOVIE\n");
printf ("7. MODIFY MOVIE RECORDS\n");
printf ("8. UNRENT MOVIE\n");
printf ("9. SHOW ALL RENT ITEMS\n\n");
printf ("77. SYSTEM RESET\n");
printf ("70. EXIT\n\n");
printf ("ENTER YOUR CHOICE : ");
scanf ("%d", %26amp;choice);
switch (choice)
{
case 1:
do
{
system ("cls");
fflush (stdin);
printf ("ENTER THE TITLE OF THE MOVIE : ");
gets (m.title);
fflush (stdin);
printf ("ENTER THE TYPE OF THE MOVIE : ");
gets (m.type);
fflush (stdin);
printf ("ENTER THE SERIAL NUMBER OF THIS MOVIE : ");
scanf ("%d", %26amp;m.serial);
fflush (stdin);
printf ("ENTER THE NAME OF THE ACTOR : ");
gets (m.actor);
fflush (stdin);
printf ("ENTER THE NAME OF THE ACTRESS : ");
gets (m.actress);
fflush (stdin);
printf ("ENTER THE PRICE OF THIS MOVIE : $");
scanf ("%d", %26amp;m.price);
printf ("ENTER THE NUMBER OF COPIES AVAILABLE IN STOCK : ");
scanf ("%d", %26amp;m.stockQuantity);
m.onRentQuantity = 0;// set to zero by default koz
// initially it cannot be more than 1
fwrite (%26amp;m, sizeof (m), 1, mfp);
printf ("DO U WANNA ADD ANOTHER MOVIE? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 2:
do
{
system ("cls");
printf ("ENTER THE SERIAL NUMBER OF THE MOVIE : ");
scanf ("%d", %26amp;srl);
rewind (mfp);
tfp = fopen ("temp.txt", "wb+");
if (tfp == NULL)
{
system ("cls");
printf ("DELETION ACCESS IS DENIED!\n");
}
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
if (m.serial != srl)
fwrite (%26amp;m, sizeof (m), 1, tfp);
}
fclose (mfp);
fclose (tfp);
remove ("record.txt");
rename ("temp.txt", "record.txt");
mfp = fopen ("record.txt", "rb+");
system ("cls");
printf ("DO U WANNA DELETE ANOTHER MOVIE? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 3:
do
{
system ("cls");
printf ("ENTER THE SERIAL NUMBER OF THE MOVIE TO RENT : ");
scanf ("%d", %26amp;srl);
rewind (mfp);
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
if (m.serial == srl)
{
if (m.stockQuantity %26lt; 1)
{
system ("cls");
printf ("SORRY! ALL %d COPIES ARE ON RENT!\nPRESS ANY KEY...", m.onRentQuantity);
getchar ();
system ("cls");
break;
}
else
{
system ("cls");
tfp = fopen ("temp.txt", "wb+");
rewind (mfp);
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
if (m.serial != srl)
fwrite (%26amp;m, sizeof (m), 1, tfp);
else
{
m.onRentQuantity = m.onRentQuantity + 1;
m.stockQuantity = m.stockQuantity - 1;
fwrite (%26amp;m, sizeof (m), 1, tfp);
}
fclose (tfp);
fclose (mfp);
remove ("record.txt");
rename ("temp.txt", "record.txt");
mfp = fopen ("record.txt", "rb+");
fflush (stdin);
printf ("ENTER THE NAME OF THE CUSTOMER : ");
gets (c.name);
fflush (stdin);
printf ("ENTER THE AGE OF THE CUSTOMER : ");
scanf ("%d", %26amp;c.age);
fflush (stdin);
printf ("ENTER THE ADDRESS : \n");
printf ("1. HOUSE NUMBER : ");
gets (c.adr.houseNo);
fflush (stdin);
printf ("2. ROAD NUMBER : ");
gets (c.adr.roadNo);
fflush (stdin);
printf ("3. AREA : ");
gets (c.adr.area);
fflush (stdin);
printf ("4. POST : ");
gets (c.adr.post);
fflush (stdin);
printf ("5. CITY : ");
gets (c.adr.city);
fflush (stdin);
c.rentMovieSerial = srl;
printf ("ENTER THE DATE OF RENT : \n");
printf ("DAY : ");
scanf ("%d", %26amp;c.dateOfRent.day);
printf ("MONTH : ");
scanf ("%d", %26amp;c.dateOfRent.month);
printf ("YEAR : ");
scanf ("%d", %26amp;c.dateOfRent.year);
fwrite (%26amp;c, sizeof (c), 1, rfp);
break;
}
}
}
printf ("DO U WANT TO TRY RENT AGAIN? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 4:
do
{
system ("cls");
rewind (mfp);
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
printf ("MOVIES ON RECORD ARE AS FOLLOWS : \n\n");
printf ("TITLE : %s\n", m.title);
printf ("TYPE : %s\n", m.type);
printf ("SERIAL # %d\n", m.serial);
printf ("ACTOR NAME : %s\n", m.actor);
printf ("ACTRESS NAME : %s\n", m.actress);
printf ("PRICE : %d\n", m.price);
printf ("ON RENT QUANTITY : %d\n", m.onRentQuantity);
printf ("STOCK QUANTITY : %d\n\n", m.stockQuantity);
fflush (stdin);
printf ("PRESS ANY KEY...");
getchar ();
system ("cls");
}
printf ("DO U WANNA SEE FROM THE TOP AGAIN? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 5:
do
{
system ("cls");
printf ("SEARCH MENU : \n");
printf ("1. ACTOR/ACTRESS NAME\n");
printf ("2. MOVIE TYPE\n");
printf ("3. MOVIE NAME\n\n");
printf ("ENTER YOUR CHOICE : ");
scanf ("%d", %26amp;choice);
switch (choice)
{
case 1:
system ("cls");
fflush (stdin);
printf ("ENTER THE NAME OF THE ACTOR OR ACTRESS : ");
gets (actr);
fflush (stdin);
rewind (mfp);
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
if ((strcmp (actr, m.actor) == 0) || strcmp (actr, m.actress) == 0)
{
system ("cls");
printf ("SEARCH RESULT : \n\n");
printf ("TITLE : %s\n", m.title);
printf ("TYPE : %s\n", m.type);
printf ("SERIAL # %d\n", m.serial);
printf ("ACTOR NAME : %s\n", m.actor);
printf ("ACTRESS NAME : %s\n", m.actress);
printf ("PRICE : %d\n", m.price);
printf ("ON RENT QUANTITY : %d\n", m.onRentQuantity);
printf ("STOCK QUANTITY : %d\n\n", m.stockQuantity);
fflush (stdin);
printf ("PRESS ANY KEY...");
getchar ();
}
}
break;
case 2:
system ("cls");
fflush (stdin);
printf ("ENTER THE TYPE OF THE MOVIE : ");
gets (typ);
fflush (stdin);
rewind (mfp);
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
if (strcmp (typ, m.type) == 0)
{
system ("cls");
printf ("SEARCH RESULT : \n\n");
printf ("TITLE : %s\n", m.title);
printf ("TYPE : %s\n", m.type);
printf ("SERIAL # %d\n", m.serial);
printf ("ACTOR NAME : %s\n", m.actor);
printf ("ACTRESS NAME : %s\n", m.actress);
printf ("PRICE : %d\n", m.price);
printf ("ON RENT QUANTITY : %d\n", m.onRentQuantity);
printf ("STOCK QUANTITY : %d\n\n", m.stockQuantity);
fflush (stdin);
printf ("PRESS ANY KEY...");
getchar ();
}
}
break;
case 3:
system ("cls");
fflush (stdin);
printf ("ENTER THE NAME OF THE MOVIE : ");
gets (mname);
fflush (stdin);
rewind (mfp);
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
if (strcmp (mname, m.title) == 0)
{
system ("cls");
printf ("SEARCH RESULT : \n\n");
printf ("TITLE : %s\n", m.title);
printf ("TYPE : %s\n", m.type);
printf ("SERIAL # %d\n", m.serial);
printf ("ACTOR NAME : %s\n", m.actor);
printf ("ACTRESS NAME : %s\n", m.actress);
printf ("PRICE : %d\n", m.price);
printf ("ON RENT QUANTITY : %d\n", m.onRentQuantity);
printf ("STOCK QUANTITY : %d\n\n", m.stockQuantity);
fflush (stdin);
printf ("PRESS ANY KEY...");
getchar ();
break;
}
}
break;
default:
system ("cls");
printf ("INVALID SELECTION! PRESS ANY KEY...\n\n");
getchar ();
continue;
}
printf ("DO U WANNA USE THE SEARCH MENU AGAIN? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 6:
system ("cls");
printf ("ARE U SURE THAT U WANNA DELETE ALL MOVIES? [1/0] : ");
scanf ("%d", %26amp;choice);
if (choice != 0)
{
fclose (mfp);
remove ("record.txt");
mfp = fopen ("record.txt", "wb+");
}
break;
case 7:
do
{
system ("cls");
printf ("ENTER THE SERIAL NUMBER OF THE MOVIE U WANNA MODIFY : ");
scanf ("%d", %26amp;srl);
rewind (mfp);
tfp = fopen ("temp.txt", "wb+");
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
if (m.serial == srl)
{
system ("cls");
fflush (stdin);
printf ("ENTER THE TITLE OF THE MOVIE : ");
gets (m.title);
fflush (stdin);
printf ("ENTER THE TYPE OF THE MOVIE : ");
gets (m.type);
fflush (stdin);
printf ("ENTER THE SERIAL NUMBER OF THIS MOVIE : ");
scanf ("%d", %26amp;m.serial);
fflush (stdin);
printf ("ENTER THE NAME OF THE ACTOR : ");
gets (m.actor);
fflush (stdin);
printf ("ENTER THE NAME OF THE ACTRESS : ");
gets (m.actress);
fflush (stdin);
printf ("ENTER THE PRICE OF THIS MOVIE : $");
scanf ("%d", %26amp;m.price);
printf ("ENTER THE NUMBER OF COPIES AVAILABLE IN STOCK : ");
scanf ("%d", %26amp;m.stockQuantity);
printf ("ENTER THE NUMBER OF QUANTITY ON RENT : ");
scanf ("%d", %26amp;m.onRentQuantity);
fwrite (%26amp;m, sizeof (m), 1, tfp);
}
else
fwrite (%26amp;m, sizeof (m), 1, tfp);
}
fclose (tfp);
fclose (mfp);
remove ("record.txt");
rename ("temp.txt", "record.txt");
mfp = fopen ("record.txt", "rb+");
system ("cls");
printf ("DO U WANNA MODIFY ANOTHER RECORD? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 8:
do
{
system ("cls");
printf ("ENTER THE SERIAL NUMBER THE MOVIE TO UNRENT : ");
scanf ("%d", %26amp;srl);
rewind (mfp);
rewind (rfp);
tfp = fopen ("temp.txt", "wb+");
while (fread (%26amp;m, sizeof (m), 1, mfp) == 1)
{
if (m.serial != srl)
fwrite (%26amp;m, sizeof (m), 1, tfp);
else
{
m.onRentQuantity -= 1;
m.stockQuantity += 1;
fwrite (%26amp;m, sizeof (m), 1, tfp);
}
}
fclose (tfp);
fclose (mfp);
remove ("record.txt");
rename ("temp.txt", "record.txt");
mfp = fopen ("record.txt", "rb+");
while (fread (%26amp;c, sizeof (c), 1, rfp) == 1)
{
if (c.rentMovieSerial == srl)
{
tfp = fopen ("temp.txt", "wb+");
if (tfp == NULL)
{
system ("cls");
printf ("UNRENT ACCESS IS DENIED!\n");
}
while (fread (%26amp;c, sizeof (c), 1, rfp) == 1)
{
if (c.rentMovieSerial != srl)
fwrite (%26amp;c, sizeof (c), 1, tfp);
}
fclose (rfp);
fclose (tfp);
remove ("customer.txt");
rename ("temp.txt", "customer.txt");
rfp = fopen ("customer.txt", "rb+");
break;
}
}
system ("cls");
printf ("DO YOU WANT TO UNRENT AGAIN? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 9:
do
{
system ("cls");
rewind (rfp);
while (fread (%26amp;c, sizeof (c), 1, rfp) == 1)
{
printf ("CUSTOMER NAME : %s\n", c.name);
printf ("AGE : %d\n", c.age);
printf ("ADDRESS : \n");
printf ("HOUSE # %s\n", c.adr.houseNo);
printf ("ROAD # %s\n", c.adr.roadNo);
printf ("AREA : %s\n", c.adr.area);
printf ("POST : %s\n", c.adr.post);
printf ("CITY : %s\n", c.adr.city);
printf ("DATE OF RENT : %d / %d / %d\n", c.dateOfRent.day, c.dateOfRent.month, c.dateOfRent.year);
printf ("SERIAL NUMBER OF THE RENT MOVIE : %d\n\n", c.rentMovieSerial);
fflush (stdin);
printf ("PRESS ANY KEY...");
getchar ();
system ("cls");
}
printf ("DO U WANNA SEE THE RENT ITEMS FROM THE TOP? [1/0] : ");
scanf ("%d", %26amp;choice);
}
while (choice);
break;
case 77:
system ("cls");
printf ("ARE U SURE THAT U WANNA RESET THE SYSTEM? [1/0] : ");
scanf ("%d", %26amp;choice);
if (choice == 1)
{
fclose (mfp);
fclose (rfp);
remove ("record.txt");
remove ("customer.txt");
mfp = fopen ("record.txt", "wb+");
rfp = fopen ("customer.txt", "wb+");
}
break;
case 70:
system ("cls");
printf ("ARE YOU SURE THAT YOU WANNA EXIT ? [1/0] : ");
scanf ("%d", %26amp;choice);
if (choice == 1)
{
fclose (mfp);
fclose (rfp);
exit (1);
}
continue;
default:
system ("cls");
fflush (stdin);
printf ("YOU HAVE ENTERED INVALID CHOICE!!! PRESS ANY KEY...\n\n");
getchar ();
continue;
}
system ("cls");
}
while (1);
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment