Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a user-interface which allows the user a menu of choices for a bank databa

ID: 3850164 • Letter: W

Question

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.

Requirements

Menu Options

Assume that the information is stored in a database which is a black box and can only be accessed by the functions, addRecord, modifyRecord, printRecord and deleteRecord, which have the following prototypes:

int addRecord (struct record **, int, char [ ],char [ ]);
int printRecord (struct record *, int);
int modifyRecord (struct record *, int, char [ ]); // This should modify the address field
void printAllRecords(struct record *);
int deleteRecord(struct record **, int);

Do not implement or complete the above functions

The following menu choices must be available:

Add a new record in the database

Modify a record in the database using the accountno as the key

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).

User Inputs

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 typing

Prototype for the function is void getaddress (char [ ], int);

The name entered by the user may have spaces.

Debug Mode

Your program must use command-line arguments for debugging.

This program may be invoked by typing the executable name(for example, hw3) or with the option "debug". (e.g. hw3 debug). Anything else such as "hw3 debug test" or "hw3 test" should give an error. The format of the error must be similar to the one you get when you type "cp" in UNIX.

When the program is called using the debug option, additional output will be printed on the screen such as name of function called and parameters passed. This is in addition to everything the program does when called without the debug argument. (You may ignore the printing of pointer arguments)

Every function definition, including the stubs must have output identifying the function called and the parameters passed, when the "debug" option is invoked.

A global variable, debugmode must be used to keep track of how the program was invoked.

Source Files

struct record
{
    int                accountno;
    char               name[25];
    char               address[80];
    struct record*     next;
};

Stubs for the above five 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 using the following structure as a separate, record.h file

Define:

struct record * start;
start = NULL;

and pass it/its address to the database functions.

Im not really sure what to do for the debug mode

The language is C and im compiling with -ansi -pedantic-errors

Explanation / Answer

Here is the code for the question. Since the question asks NOT to implement the functions, they have been left as stubs and only debug messages are printed. Also in the output shown, all the functions returned false, so none of the functions are functional as said before. Please post a comment if any doubts, I shall respond to it. To print debug messages, you need to invoke the program with command line parameter debug.

record.h

#ifndef record_h

#define record_h

#include <stdio.h>

int DEBUG_MODE = 0; // 0 means no debug messages and 1 means print debug messages

struct record

{

int accountno;

char name[25];

char address[80];

struct record* next;

};

int addRecord (struct record **start, int accno, char name[ ],char address[ ])

{

if(DEBUG_MODE)

{

printf(" DEBUG: addRecord function called with name=%s , address=%s", name, address);

}

//implement code to add a record

return 0;

}

int printRecord (struct record *rec, int accno)

{

if(DEBUG_MODE)

{

printf(" DEBUG: printRecord function called with accno=%d ", accno);

}

  

//implement code to print a record

return 0;

}

int modifyRecord (struct record *rec, int accno, char address[ ]) // This should modify the address field

{

if(DEBUG_MODE)

{

printf(" DEBUG: modifyRecord function called with accno=%d , address=%s", accno, address);

}

  

//implement code to modify a record

return 0;

}

void printAllRecords(struct record *start)

{

if(DEBUG_MODE)

{

printf(" DEBUG: printAllRecords function called");

}

  

//implement code to print all records

}

int deleteRecord(struct record **start, int accno)

{

if(DEBUG_MODE)

{

printf(" DEBUG: deleteRecord function called with accno=%d", accno );

}

  

//implement code to delete a record

return 0;

}

#endif /* record_h */

main.c

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include "record.h"

void addMenu(struct record **start);

void modifyMenu(struct record *start);

void deleteMenu(struct record **start);

void printRecordMenu(struct record *start);

void getAddress(char address[], int max);

int main(int argc, char *argv[]) {

  

struct record *start = NULL;

int choice = 0;

int error = 0;

  

if(argc > 1)

{

if(argc == 2)

{

if(strcasecmp("debug", argv[1]) == 0)

{

DEBUG_MODE = 1;

}

else

error = 1;

}

else

error = 1;

}

  

if(error)

{

printf(" usage: %s [debug] ", argv[0]);

exit(1);

}

  

  

while(choice != 6)

{

printf(" 1. Add a record");

printf(" 2. Modify a record");

printf(" 3. Delete a record");

printf(" 4. Print a record");

printf(" 5. Print all records");

printf(" 6. Quit");

printf(" Enter your choice: ");

scanf("%d", &choice);

  

switch(choice)

{

case 1: addMenu(&start);

break;

case 2: modifyMenu(start);

break;

case 3: deleteMenu(&start);

break;

case 4: printRecordMenu(start);

break;

case 5:

printAllRecords(start);

break;

case 6:

break;

default:

printf(" Invalid menu choice!");

break;

  

}

  

}

  

}

void addMenu(struct record **start)

{

int accno;

char name[25], addr[80];

  

printf(" Adding a record...");

printf(" Enter account number: ");

scanf("%d", &accno);

getchar();//flush newline

printf(" Enter name: ");

fgets(name, 25, stdin);

printf(" Enter address lines (empty line to finish): ");

getAddress(addr, 80);

  

if(addRecord(start, accno, name, addr) == 1)

{

printf(" Record added succefully.");

}

else

{

printf(" Record was not added!");

}

  

}

void modifyMenu(struct record *start)

{

int accno;

char addr[80];

  

printf(" Modify a record...");

printf(" Enter account number: ");

scanf("%d", &accno);

getchar();//flush newline

printf(" Enter new address lines (empty line to finish): ");

getAddress(addr, 80);

if(modifyRecord(start, accno, addr) == 1)

{

printf(" Record modified succefully.");

}

else

{

printf(" Record was not modified!");

}

}

void deleteMenu(struct record **start)

{

int accno;

  

  

printf(" Delete a record...");

printf(" Enter account number: ");

scanf("%d", &accno);

  

if(deleteRecord(start, accno) == 1)

{

printf(" Record deleted succefully.");

}

else

{

printf(" Record was not deleted!");

}

  

}

void printRecordMenu(struct record *start)

{

int accno;

  

  

printf(" Print a record...");

printf(" Enter account number: ");

scanf("%d", &accno);

  

if(printRecord(start, accno) == 0)

printf(" Record was not found!");

  

}

//receive multiple lines of input for address, upto max characters. Stops when empty line is entered

void getAddress(char address[], int max)

{

int len = 0;

while(fgets(address+len, max, stdin)) //get chars and store in address+len

{

if(strlen(address+len) == 1) //only newline i.e empty line was entered, then stop

break;

  

len = strlen(address);

max = max - len;

  

if(max <= 0) //no more characters can be taken, then stop

break;

}

if(DEBUG_MODE)

{

printf(" DEBUG: scanned address lines : %s ", address);

}

}

output

compile: gcc main.c -o hw3

run: ./hw3 debug

============

./a.out DEBUG

1. Add a record
2. Modify a record
3. Delete a record
4. Print a record
5. Print all records
6. Quit
Enter your choice: 1

Adding a record...
Enter account number: 111

Enter name: John

Enter address lines (empty line to finish): #123, Stree 1
California


DEBUG: scanned address lines :
#123, Stree 1
California


DEBUG: addRecord function called with name=John
, address=#123, Stree 1
California


Record was not added!
1. Add a record
2. Modify a record
3. Delete a record
4. Print a record
5. Print all records
6. Quit
Enter your choice: 2

Modify a record...
Enter account number: 222

Enter new address lines (empty line to finish): 888, new street
new area


DEBUG: scanned address lines :
888, new street
new area


DEBUG: modifyRecord function called with accno=222 , address=888, new street
new area


Record was not modified!
1. Add a record
2. Modify a record
3. Delete a record
4. Print a record
5. Print all records
6. Quit
Enter your choice: 3

Delete a record...
Enter account number: 444

DEBUG: deleteRecord function called with accno=444
Record was not deleted!
1. Add a record
2. Modify a record
3. Delete a record
4. Print a record
5. Print all records
6. Quit
Enter your choice: 4

Print a record...
Enter account number: 111

DEBUG: printRecord function called with accno=111
Record was not found!
1. Add a record
2. Modify a record
3. Delete a record
4. Print a record
5. Print all records
6. Quit
Enter your choice: 5

DEBUG: printAllRecords function called
1. Add a record
2. Modify a record
3. Delete a record
4. Print a record
5. Print all records
6. Quit
Enter your choice: 6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote