Using C write a user-interface which allows the user a menu of choices for a ban
ID: 3752027 • Letter: U
Question
Using C write a user-interface which allows the user a menu of choices for a bank database application. The database contains the accountnumber (int), name (char [ ]), and address(char [ ]) fields for each person. For more details, see the following requirements below.
Assume that the information is stored in a database which is a black box and can only be accessed by the functions, addRecord, printRecord, printAllRecords and deleteRecord, which have the following prototypes:
Do not implement or complete the above functions. They are stubs at the moment, and will be implemented in later assignments. (if you don't know what "stub" means, go research!)
The following menu choices must be available:
Add a new record in the database
Print information about a record using the accountno as the key
Print all information in the database
Delete an existing record from the database using the accountno as a key
Quit the program
You must use a while or do-while loop for the menu.
For each menu option, collect the appropriate information from the user (including an account number).
Write your own getaddress function to obtain the address information
the address field may have multiple lines of address
It must be stored as one character array
You CANNOT ask the user how many lines of address they are going to type
Prototype for the function is
The name entered by the user may have spaces.
Source Files
the stubs, representing database functions, must be defined in a separate file.
All stubs must be in one source file and the user-interface functions in one or more files.
DO NOT DEFINE a structure or array to hold the entire database, but use the following structure as a separate, record.h file
Define the following items:
and pass it or its address to the database functions.
Explanation / Answer
filename : record.h
struct record
{
int accountno;
char name[25];
char address[80];
struct record* next;
};
filename: stub.h
#include "record.h"
int addRecord (struct record **, int, char [ ],char [ ]);
int printRecord (struct record *, int);
void printAllRecords(struct record *);
int deleteRecord(struct record **, int);
filename: stub.c
#include<stdio.h>
#include "record.h"
int addRecord (struct record **, int, char [ ],char [ ])
{
/*To be implemented*/
}
int printRecord (struct record *, int)
{
/*To be implemented*/
}
void printAllRecords(struct record *)
{
/*To be implemented*/
}
int deleteRecord(struct record **, int)
{
/*To be implemented*/
}
filename: main.c {interfaces)
#include<stdio.h>
#include "record.h"
#include "stub.h"
void getaddress (char addr[ ], int len);
{
int size = 0;
char c;
while((c = getchar()) != '!' && (size+1) <len )
{
addr[size++] = c;
}
addr[size]='';
}
int main()
{
int ac_num;
char name[25];
char addr[80]
struct record * start;
start = NULL;
int option;
while(1)
{
printf("please select one of the option ");
printf("1.Add new record ");
printf("2.print a record ");
printf("3.print all records ");
printf("4.Delete a record ");
printf("5.Quit ");
scanf("%d",&option);
getchar();
switch(option)
{
case 1: printf("Enter a/c number");
scanf("%d",&ac_num);
printf("Enter name");
scanf("%s",name);
getchar();
printf("Enter address [press '!' to end input]");
getaddress(addr,80);
if(addRecord(&start,ac_num,name,addr) !=0 )
printf("Adding record failed ");
break;
case 2:printf("Enter a/c number");
scanf("%d",&ac_num);
printRecord(start,ac_num);
break;
case 3: printAllRecords(start);
break;
case 4: printf("Enter a/c number");
scanf("%d",&ac_num);
deleteRecord(start,ac_num);
break;
case 5: return 0;
default:printf("invalid option try again ");
}
}
filename : record.h
/*Contains record structure for database*/
struct record
{
int accountno;
char name[25];
char address[80];
struct record* next;
};
filename: stub.h
/*Contains prototypes of database handler functions*/
#include "record.h"
int addRecord (struct record **, int, char [ ],char [ ]);
int printRecord (struct record *, int);
void printAllRecords(struct record *);
int deleteRecord(struct record **, int);
filename: stub.c
/*Contains definations of handler function*/
#include<stdio.h>
#include "record.h"
int addRecord (struct record **, int, char [ ],char [ ])
{
/*To be implemented*/
}
int printRecord (struct record *, int)
{
/*To be implemented*/
}
void printAllRecords(struct record *)
{
/*To be implemented*/
}
int deleteRecord(struct record **, int)
{
/*To be implemented*/
}
filename: main.c {interfaces)
/*Entry point of application*/
#include<stdio.h>
#include "record.h"
#include "stub.h"
/*function to get address field upto a maximum length*/
void getaddress (char addr[ ], int len);
{
int size = 0;
char c;
while((c = getchar()) != '!' && (size+1) <len )
{
addr[size++] = c;
}
addr[size]='';
}
int main()
{
int ac_num;
char name[25];
char addr[80]
struct record * start;
start = NULL;
int option;
while(1)
{
printf("please select one of the option ");
printf("1.Add new record ");
printf("2.print a record ");
printf("3.print all records ");
printf("4.Delete a record ");
printf("5.Quit ");
scanf("%d",&option);
getchar();
switch(option)
{
case 1: printf("Enter a/c number");
scanf("%d",&ac_num);
printf("Enter name");
scanf("%s",name);
getchar();
printf("Enter address [press '!' to end input]");
getaddress(addr,80);
if(addRecord(&start,ac_num,name,addr) !=0 )
printf("Adding record failed ");
break;
case 2:printf("Enter a/c number");
scanf("%d",&ac_num);
printRecord(start,ac_num);
break;
case 3: printAllRecords(start);
break;
case 4: printf("Enter a/c number");
scanf("%d",&ac_num);
deleteRecord(start,ac_num);
break;
case 5: return 0;
default:printf("invalid option try again ");
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.