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
|
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
enum select_t
{
eAdd = 1, eDisplay, eUpdate, eSearch, eDelete, eSort, eQuit, eAgain
};
select_t ShowAndSelect();
void AddRec();
select_t AddSelect();
void DisplayRec();
void UpdateRec();
void SearchRec();
void DeleteRec();
void SortRec();
int main()
{
do
{
select_t choice = ShowAndSelect();
switch (choice)
{
case eAdd:
{
select_t choice = eQuit;
do
{
AddRec();
choice = ShowAndSelect();
}
while (choice == eAgain);
}
break;
case eDisplay:
DisplayRec();
break;
case eUpdate:
UpdateRec();
break;
}
}
while (choice != eQuit);
getch();
}
select_t ShowAndSelect()
{
clrscr();
printf("=====MENU=====");
printf("\n\n[1] = Add");
printf("\n[2] = Display");
printf("\n[3] = Update");
printf("\n[4] = Search");
printf("\n[5] = Delete");
printf("\n[6] = Sort");
printf("\n[7] = Exit Program");
printf("\n\nChoice : ");
int choice;
scanf("%d",&choice);
// return static_cast<select_t>(choice); // Don't know if Turbo C++ supports new casts
return (select_t)choice;
}
void AddRec()
{
FILE * f = fopen("test.txt","r+");
if (f==NULL)
{
printf("No Database");
}
else
{
char c[50];
char id[50];
char age[50];
char last[100];
char first[100];
char dep[50];
char add[50];
printf(" ");
gets(c);
printf("\nEnter ID No. : ");
gets(id);
printf("Enter Age :");
gets(age);
printf("Enter Lastname : ");
gets(last);
printf("Enter Firstname : ");
gets(first);
printf("Enter Department : ");
gets(dep);
printf("Enter Address : ");
gets(add);
fprintf(f,"%s\t",id);
fprintf(f,"%s\t",age);
fprintf(f,"%s\t",last);
fprintf(f,"%s\t",first);
fprintf(f,"%s\t",dep);
fprintf(f,"%s\t",add);
}
fclose(f);
}
select_t AddSelect()
{
printf("\n\n\n\n\n\n\t\t");
printf("Add Another Record? ( Y=[yes] or N=[no] ) : ");
fflush(stdin);
int choice;
scanf("%d",&choice);
return (choice == 'Y') ? eAgain : eQuit;
}
void DisplayRec()
{
clrscr();
printf("ID No. Age Lastname Firstname Department Address\n");
printf("===============================================================\n");
FILE * fp = fopen("test.txt","r");
char c = getc(f) ;
while (c!= EOF)
{
putchar(c);
c = getc(fp);
}
fclose(fp);
}
void UpdateRec()
{
clrscr();
printf("All Records Successfully Deleted!");
FILE * f1 = fopen("test.txt","w");
char d = getc(f) ;
while (d!= EOF)
{
putchar(d);
d = getc(f1);
}
fclose(f1);
}
void SearchRec()
{
}
void DeleteRec()
{
}
void SortRec()
{
}
|