Code:
#include<stdio.h>
#include<conio.h>
#define MAX_PERSONS 50
/* Assignment 3A (55 Marks Needed)
Write a Program To Create A Banking Database */
/* Declaration Of Structures */
struct acc_type
{
char name[50];
float balance;
};
struct acc_type account[20];
int number;
int current;
typedef struct acc_type ACC_TYPE;
struct date
{
int day;
int month;
int year;
};
typedef struct date DATE;
struct personnel
{
int number;
int phone_number;
int age;
char occupation[25];
char surname[25];
char first_name[10];
char Address[30];
char gender;
DATE dob;
};
typedef struct personnel CUSTOMER;
/* Function Prototypes */
void add_a_customer(CUSTOMER []);
void delete_a_customer(CUSTOMER []);
void edit_a_customer(CUSTOMER []);
void add_money_to_account(CUSTOMER []);
void withdraw_money_from_account(CUSTOMER []);
void display_a_customer(CUSTOMER []);
void display_customer_details(CUSTOMER *);
void apply_for_overdraft(CUSTOMER []);
void init_database(CUSTOMER []);
int search_database(CUSTOMER [], int);
int menu(void);
/* Main Program Scope */
void main()
{
CUSTOMER persons[MAX_PERSONS];
int menu_choice;
init_database(persons);
do
{
menu_choice = menu();
switch ( menu_choice )
{
case 1 : add_a_customer(persons);
break;
case 2 : delete_a_customer(persons);
break;
case 3 : edit_a_customer(persons);
break;
case 4 : add_money_to_account(persons);
break;
case 5 : withdraw_money_from_account(persons);
break;
case 6 : apply_for_overdraft(persons);
break;
case 7 : search_database(persons);
break;
case 8 : display_customer_details(persons);
break;
}
}
while ( menu_choice != 0);
}
/* Menu Display */
/*------------------------------------------------------------------------------------/
| Function: Display A Menu |
| |
| Purpose: Display A Menu For The Customer To Make A Choice |
| |
| Arguements: Calls A Function When Choice Is Made |
|--------------------------------------------------------------------------------------*/
int menu(void)
{
int choice;
/*Display the menu to the user*/
printf("1. Add an account.\n\n");
printf("2. Delete an account.\n\n");
printf("3. Edit an account.\n\n");
printf("4. Add money into an account\n\n");
printf("5. Withdraw money from an account\n\n");
printf("6. Apply for an overdraft\n\n");
printf("7. Search the database\n\n");
printf("8. Display customer details\n\n");
printf("0. End program.\n\n");
do
{
scanf("%d",&choice);
fflush(stdin);
} while( choice < 0 || choice > 9 );
return choice;
}
/* Case 1 */
/*------------------------------------------------------------------------------------/
| Function: Add A Customer |
| |
| Purpose: Add A Customer To The Banking System |
| |
| Arguements: A Pointer To The Customer Array |
|--------------------------------------------------------------------------------------*/
void add_a_customer(CUSTOMER person_array[])
{
int i=0;
/*Search The Array For Empty Slot.
An Empty Slot = 0 */
while ( person_array[i]. number !=0 && i < MAX_PERSONS )
if ( i == MAX_PERSONS)
printf(" Unfortunatly The Database Is Full!!\n");
else /* Add To Database */
{
printf("\n\n Customer Number (1 To 4 Digits, Except 0) : ");
do
scanf( "%3d",&person_array[i].number);
while (person_array[i].number<=0);
/*Customer Details Gender */
printf("\n Customer Gender : " );
scanf ("%7s",person_array[i].gender);
/*Customer Details Name */
printf("\n Customer Surname (Maximum 25 Characters) : " );
scanf ("%25s",person_array[i].surname);
printf("\n First Name (Maximum 10 Characters) : " );
scanf ("%25s",person_array[i].first_name);
/*Customer Details Date Of Birth */
printf("\nDate Of Birth\n" );
printf(" Day (1 Or 2 Digits) ; ");
scanf ("%2d",&person_array[i].dob.day);
printf(" Month (1 Or 2 Digits ; ");
scanf ("%2d",&person_array[i].dob.month);
printf(" Year (1 Or 2 Digits ; ");
scanf ("%2d",&person_array[i].dob.year);
/*Customer Details Occupation */
printf("\nJob:");
scanf("%20s",person_array[i].occupation);
/*Customer Details Address */
printf("House Number : ");
printf(" House (1 - 3 Digits) ; ");
scanf ("%2d",&person_array[i].Address.house_number);
printf("Street Name : ");
scanf ("%25s",&person_array[i].Address.street);
printf("City : ");
scanf ("%15s",&person_array[i].Address.city);
/*Customer Details Phone Number */
printf("Phone Number : ");
printf("Phone (7 Or 10 Digits) ; ");
scanf ("%10s",&person_array[i].phone_number);
}
}
/* Case 2 */
/*------------------------------------------------------------------------------------/
| Function: Delete A Customer |
| |
| Purpose:Delete A Customer From The Banking System |
| |
| Arguements: A Pointer To The Customer Array |
|--------------------------------------------------------------------------------------*/
void delete_a_customer(CUSTOMER person_array[])
{
int CUSTOMER_number;
int pos;
/* A Customer Is Deemed Deleted By Placing A 0 In The Customer Number */
/* First The Customer Number Has To Be Obtained */
printf(" Please Enter Your Personal Number : ");
do
scanf("%10d",&CUSTOMER_number);
while(CUSTOMER_number <= 0 );
pos = search_database(person_array,CUSTOMER_number);
if(pos == MAX_PERSONS) /* Yes */
printf("This Customer is not in the database\n");
else /* No */
{
printf("Customer Account number %10d is deleted.\n",CUSTOMER_number);
person_array[pos].number == 0;
}
}
/* Case 3 */
/*------------------------------------------------------------------------------------/
| Function: Edit A Customer |
| |
| Purpose: Edit A Customer From The Banking System |
| |
| Arguements: A Pointer To The Customer Array |
|--------------------------------------------------------------------------------------*/
{
int account_number;
int pos;
printf("Customer Account Number to edit: ");
do
scanf("%d",&account_number);
while(account_number <=0 || account_number > SIZE);
pos = deletion_search(customer, account_number);
if(pos==SIZE)
printf("This customer is not in the database\n");
else
{
/* Customer Name */
printf("\n\nCustomer Surname (Up to 25 letters): ");
scanf("%25s",customer[pos].surname);
printf("\nFirst Name (Up to 10 letters): ");
scanf("%10s",customer[pos].first_name);
/* Customer Date Of Birth */
printf("\nDate of Birth\n");
printf("\nDay (1-31): ");
scanf("%d",&customer[pos].dob.day);
printf("\nMonth (1-12): ");
scanf("%2d",&customer[pos].dob.month);
printf("\nYear (2 digits i.e. 1990 is 90): ");
scanf("%2d",&customer[pos].dob.year);
printf("\nOverdraft Taken (Yes or No): ");
scanf("%3s",customer[pos].overdraft);
printf("\nBalance: ");
scanf("%d",&customer[pos].balance);
printf("\n\n");
}
}
/* Case 4 */
/*------------------------------------------------------------------------------------/
| Function: Add Money To An Account |
| |
| Purpose: Add Money To A Customers Account |
| |
| |
|--------------------------------------------------------------------------------------*/
void add_money_to_account()
{
float add_sum;
char dummy;
printf("\nThe current balance for %s is %c%4.2f",account[current].name,156,
account[current].balance);
printf("\nHow much do you want to add to the account? %c",156);
dummy=getch(); /* Clear Out Input Buffer */
scanf("%f",&add_sum);
if(add_sum < 0)
{
printf("\nNo negative sums allowed here");
return;
}
account[current].balance += add_sum;
printf("\nThe new balance is %c%4.2f",156,account[current].balance);
return;
}
/* Case 5 */
/*------------------------------------------------------------------------------------/
| Function: Withdraw Money From An Account |
| |
| Purpose: Withdraw Money From A Customers Account |
| |
| |
|--------------------------------------------------------------------------------------*/
void withdraw_money_from_account()
{
float take_sum;
char dummy;
printf("\nThe current balance for %s is %c%4.2f",account[current].name,156,
account[current].balance);
if(account[current].balance == 0)
{
printf("\nThis account has zero balance - no overdraft facility!");
return;
}
printf("\nHow much do you want to take from the account? %c",156);
dummy=getch();//clear out input buffer
scanf("%f",&take_sum);
if(take_sum < 0)
{
printf("\nNo negative sums allowed here");
return;
}
if(take_sum > account[current].balance)
{
printf("\nInsufficient funds!");
return;
}
account[current].balance -= take_sum;
printf("\nThe new balance is %c%4.2f",156,account[current].balance);
}
/* Case 7 */
/*------------------------------------------------------------------------------------/
| Function: Search Database |
| |
| Purpose: Search Database For Customer |
| |
| |
|--------------------------------------------------------------------------------------*/
{
int i =0;
while (i<SIZE && customer[i].account_number != account_number)
i++;
return (i);
}
/* Case 8 */
/*------------------------------------------------------------------------------------/
| Function: Display A Customer |
| |
| Purpose: Display A Customer From The Banking System |
| |
| Arguements: A Pointer To The Customer Array |
|--------------------------------------------------------------------------------------*/
void display_a_customer( CUSTOMER person_array )
{
int CUSTOMER_number;
int pos;
/* Get The Customer Number */
printf(" Customer Number To Display ( 1-4 Digits, Except 0) :");
do
scanf("%3d",&CUSTOMER_number);
while( CUSTOMER_number <= 0);
/* Find The Customer In The Database */
pos = seacrh_database( person_array,CUSTOMER_number);
/* Does The Customer Exist In The Databse */
if ( pos == MAX_PERSONS) /* No */
printf(" The Selected Customer Is Not In The Databse\n" );
else /* Yes - Display The Details */
display_customer_details(&person_array[pos]);
}
/*------------------------------------------------------------------------------------/
| Function: Display A Customers Details |
| |
| Purpose: Display A Customers Details From The Banking System |
| |
| Arguements: A Pointer To The Customers Details |
|--------------------------------------------------------------------------------------*/
void display_customer_details(CUSTOMER *ptr)
{
printf("\n\n");
printf("Account number : %d\n",ptr->number);
printf("Surname : %s\n",ptr->surname);
printf("Firstname : %s\n",ptr->first_name);
printf("Job : %s\n",ptr->occupation);
printf("Surname : %s\n",ptr->surname);
printf("Telephone : %d\n",ptr->phone_number);
printf("Date of Birth : %2d/%2d/%2d\n",ptr->dob.day, ptr->dob.month, ptr->dob.year);
}
errors:
Error E2193 Assignment_original.c 97: Too few parameters in call to 'search_database(personnel *,int)' in function main()
Error E2294 Assignment_original.c 203: Structure required on left side of . or .* in function add_a_customer(personnel *)
Error E2294 Assignment_original.c 205: Structure required on left side of . or .* in function add_a_customer(personnel *)
Error E2294 Assignment_original.c 207: Structure required on left side of . or .* in function add_a_customer(personnel *)
Error E2040 Assignment_original.c 265: Declaration terminated incorrectly