Write a program that allows the user to enter data into a form. The program shou
ID: 3571532 • Letter: W
Question
Write a program that allows the user to enter data into a form. The program should use character graphics and capabilities provided by the ncurses library. The program should display the prompts of the form continuously in the same positions (the specific prompts and positions are at the discretion of the programmer). After each keypress by the user, the data entered into the form should be updated and displayed. The fields of the form should include the first name, last name, and street address for a person. The two name fields should be limited to 20 characters, the street address field should be limited to 30 characters. Pressing the [ENTER] key should cause the cursor (current point of data entry) to jump to the first character in the next field. If the current field is the street address, then pressing [ENTER] should cause the program to report the entered data and then exit. Optional: Pressing the backspace key should allow the user to delete the last character entered in the current field.Explanation / Answer
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
// Structure declaration
struct acc_type
{
char first_name[20];
char last_name[20];
int acc_number;
char address[100];
float available_balance;
};
struct acc_type account[20];
int num_acc;
void Create_new_account();
void Cash_Deposit();
void Cash_withdrawl();
void Account_information();
void Log_out();
void display_options();
/* main program */
int main()
{
char option;
char f2f[50] = "http://fresh2refresh.com/";
num_acc=0;
while(1)
{
printf(" ***** Welcome to Bank Application ***** ");
printf(" This demo program is brought you by %s",f2f);
display_options();
printf("Please enter any options (1/2/3/4/5/6) ");
printf("to continue : ");
option = getch();
printf("%c ", option);
switch(option)
{
case '1': Create_new_account();
break;
case '2': Cash_Deposit();
break;
case '3': Cash_withdrawl();
break;
case '4': Account_information();
break;
case '5': return 0;
case '6': system("cls");
break;
default : system("cls");
printf("Please enter one of the options");
printf("(1/2/3/4/5/6) to continue ");
break;
}
}
return 0;
}
/*Function to display available options in this application*/
void display_options()
{
printf(" 1. Create new account ");
printf("2. Cash Deposit ");
printf("3. Cash withdrawl ");
printf("4. Account information ");
printf("5. Log out ");
printf("6. Clear the screen and display available ");
printf("options ");
}
/* Function to create new account */
void Create_new_account()
{
char first_name[20];
char last_name[20];
int acc_number;
char address[100];
float available_balance = 0;
fflush(stdin);
printf(" Enter the first name : ");
scanf("%s", &first_name);
printf(" Enter the last name : ");
scanf("%s", &last_name);
printf(" Enter the account number(1 to 10): ");
scanf("%d", &acc_number);
printf(" Enter the account holder address : ");
scanf("%s", &address);
strcpy(account[acc_number-1].first_name,first_name);
strcpy(account[acc_number-1].last_name,last_name);
account[acc_number-1].acc_number=acc_number;
strcpy(account[acc_number-1].address,
address);
account[acc_number-1].available_balance=available_balance;
printf(" Account has been created successfully ");
printf("First name : %s " ,
account[acc_number-1].first_name);
printf("Last name : %s " ,
account[acc_number-1].last_name);
printf("Account holder name : %s " ,
account[acc_number-1].acc_number);
printf("Account holder address : %s " ,
account[acc_number-1].address);
printf("Available balance : %f " ,
account[acc_number-1].available_balance);
}
void Account_information()
{
register int num_acc = 0;
//if (!strcmp(customer,account[count].name))
while(strlen(account[num_acc].first_name)>0)
{
printf(" First name : %s " ,
account[num_acc].first_name);
printf("Last name : %s " ,
account[num_acc].last_name);
printf("Account number : %d " ,
account[num_acc].acc_number);
printf("Account holder address : %s " ,
account[num_acc].address);
printf("Available balance : %f " ,
account[num_acc].available_balance);
num_acc++;
}
}
// Function to deposit amount in an account
void Cash_Deposit()
{
auto int acc_no;
float add_money;
printf("Enter account number you want to deposit money:");
scanf("%d",&acc_no);
printf(" The current balance for account %d is %f ",
acc_no, account[acc_no-1].available_balance);
printf(" Enter money you want to deposit : ");
scanf("%f",&add_money);
while (acc_no=account[acc_no-1].acc_number)
{
account[acc_no-1].available_balance=
account[acc_no-1].available_balance+add_money;
printf(" The New balance for account %d is %f ",
acc_no, account[acc_no-1].available_balance);
break;
}acc_no++;
}
// Function to withdraw amount from an account
void Cash_withdrawl()
{
auto int acc_no;
float withdraw_money;
printf("Enter account number you want to withdraw money:");
scanf("%d",&acc_no);
printf(" The current balance for account %d is %f ",
acc_no, account[acc_no-1].available_balance);
printf(" Enter money you want to withdraw from account ");
scanf("%f",&withdraw_money);
while (acc_no=account[acc_no-1].acc_number)
{
account[acc_no-1].available_balance=
account[acc_no-1].available_balance-withdraw_money;
printf(" The New balance for account %d is %f ",
acc_no, account[acc_no-1].available_balance);
break;
}acc_no++;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.