| |
//======================================================================
// By Xuan Sun
// Dec. 22, 99
// File: administration.cpp
//=======================================================================
#include "item_record.h"
void create(void);
void store(void);
void retrieve(void);
void edit(void);
void display(void);
itemRecord items[11];
FILE* recordfile;
void main() {
create();
char command[10];
int i;
printf("There are 10 records in the list.\n");
printf("Every time the program is started, the list of records is flushed.\n");
printf("You can retrieve the list from the file, use 4 key.\n");
printf("It's very important that no blank in names, directories, and comments.\n");
printf("And you must not set any names, directories, or comments to be empty.\n");
printf("If you have no entry put in, set it to be ----- temporarily.\n");
printf("The maximum length of name is 50, directory 50, comments 100\n");
do{
printf("\nMAIN MENU:\n");
printf("1 - edit 2 - display 3 - store \n");
printf("4 - retrieve 5 - flush 6 - quit\n");
printf("Please enter(1-6): ");
gets(command);
i=atoi(command);
switch (i) {
case 1:
edit();
break;
case 2:
display();
break;
case 3:
store();
break;
case 4:
retrieve();
break;
case 5:
create();
break;
case 6:
store();
break;
default:
printf("Wrong commands used. Please enter again.\n");
break;
}
} while(i!=6);
}
void create (void)
{
char itemId[10];
for (int i=1; i<=10; i++) {
_itoa(i, itemId, 10);
items[i].iniRecord(itemId);
}
printf("\nAll records are re-initialized.\n");
}
void store (void)
{
recordfile=fopen("g:\\classwork\\w_ftp\\p_ftpadn\\record.txt", "w");
char itemId[10], itemName[50], itemDir[50], itemComm[100];
for (int i=1; i<=10; i++) {
items[i].getRecord(itemId, itemName, itemDir, itemComm);
fprintf(recordfile, "%s\n%s\n%s\n%s\n", itemId, itemName, itemDir, itemComm);
}
fclose(recordfile);
printf("\nFile Stored.\n");
}
void retrieve (void)
{
char itemId[10], itemName[50], itemDir[50], itemComm[100];
recordfile=fopen("g:\\classwork\\w_ftp\\p_ftpadn\\record.txt", "r");
for (int i=1; i<=10; i++) {
fscanf(recordfile, "%s\n%s\n%s\n%s\n", itemId, itemName, itemDir, itemComm);
items[i].setRecord(itemId, itemName, itemDir, itemComm);
}
fclose(recordfile);
printf("\nFile Retrieved.\n");
}
void display (void)
{
char command[10];
int i;
printf("\nRecord Index(1-10, 0 for all records): ");
gets(command);
i=atoi(command);
switch (i) {
case 1: case 2: case 3: case 4: case 5:
case 6: case 7: case 8: case 9: case 10:
items[i].displayRecord();
break;
case 0:
for(i=0; i<=10; i++)
items[i].displayRecord();
break;
default:
printf("Wrong commands used.\n");
break;
}
}
void edit (void)
{
char itemId[10];
int i;
do {
printf("\nEdit the Next Record (1-10, 0 to exit): ");
gets(itemId);
i=atoi(itemId);
if(i)
items[i].editRecord();
}while (i!=0);
}
|
|