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

Create a Checkbook program using C (3 points): At the top of the file include th

ID: 3751329 • Letter: C

Question

Create a Checkbook program using C (3 points): At the top of the file include the following comments Your name The purpose (core concept found below) of the program The date created o Create a Check structure. Include: Check number (should be an integer) Date (use type char[I -To Amount Description o Add functions to: Add a Check. Collect all information for a single check and return the check. Should not take any parameters. Gather all data in the function from the user. Call the function to display the values for the check before returning the Check. Display the values for a single check. Format the amount for two decimal places. Display the values for the entire checkbook, one check at a time. o In the main function: Create a checkbook. It should be an array of at least size ten Repeat until the checkbook is full or the user quits. Give the user these options Add a check Display a single check. Ask the user for the check number to be displayed. Display the checkbook. Quit Compile and run your code. Submit your source code as a plain text file with a .c extension. Make sure it compiles without error before submitting it

Explanation / Answer




Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you


#include <stdio.h>
struct Check{
int checkNumber;
char date[12];
char to[30];
double amount;
char description[100];
};
struct Check inputCheck();
void displayCheck(struct Check c);
void displayAll(struct Check c[], int n);
int indexOf(struct Check c[], int n, int checkNum);
int main(){
int choice = 0;
const int max = 10;
struct Check checks[max];
int n = 0;
struct Check c;
int checkNum, index;
while(n < max && choice != 4){
printf("1. Add a check ");
printf("2. Display a check ");
printf("3. Display checkbook ");
printf("4. Quit ");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice){
case 1:
checks[n] = inputCheck();
n++;
break;
case 2:
printf("Enter check number to be displayed: ");
scanf("%d", &checkNum);
index = indexOf(checks, n, checkNum);
if(index == -1)
printf("No such check! ");
else
displayCheck(checks[index]);
break;
case 3:
displayAll(checks, n);
break;
case 4:
break;
default:
printf("Invalid choice! ");
}
}
}
struct Check inputCheck(){
struct Check c;
printf("Enter the check details: ");
printf("Check number: ");
scanf("%d", &c.checkNumber);
printf("Date: ");
scanf("%s", c.date);
printf("Pay To: ");
getchar(); //get rid of newline
gets(c.to);
printf("Amount: ");
scanf("%lf", &c.amount);
printf("Description: ");
getchar(); //get rid of newline
gets(c.description);
return c;
}
void displayCheck(struct Check c){
printf("Check number: %d ", c.checkNumber);
printf("Date: %s ", c.date);
printf("Pay To: %s ", c.to);
printf("Amount: $%.2f ", c.amount);
printf("Description: %s ", c.description);
printf(" ");
}
void displayAll(struct Check c[], int n){
int i;
for(i = 0; i < n; i++){
displayCheck(c[i]);
}
}
int indexOf(struct Check c[], int n, int checkNum){
int i;
for(i = 0; i < n; i++){
if(c[i].checkNumber == checkNum)
return i;
}
return -1;
}

output
-----
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 1
Enter the check details:
Check number: 123
Date: 21/09/2018
Pay To: John Smith
Amount: 1000
Description: Repayment
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 1
Enter the check details:
Check number: 2233
Date: 18/10/2018
Pay To: Alice
Amount: 2000
Description: Savings
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 3
Check number: 123
Date: 21/09/2018
Pay To: John Smith
Amount: $1000.00
Description: Repayment
Check number: 2233
Date: 18/10/2018
Pay To: Alice
Amount: $2000.00
Description: Savings
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 2
Enter check number to be displayed: 1111
No such check!
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 1
Enter the check details:
Check number: 4455
Date: 10/03/2018
Pay To: Bob
Amount: 500
Description: Gift check
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 3
Check number: 123
Date: 21/09/2018
Pay To: John Smith
Amount: $1000.00
Description: Repayment
Check number: 2233
Date: 18/10/2018
Pay To: Alice
Amount: $2000.00
Description: Savings
Check number: 4455
Date: 10/03/2018
Pay To: Bob
Amount: $500.00
Description: Gift check
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 2
Enter check number to be displayed: 4455
Check number: 4455
Date: 10/03/2018
Pay To: Bob
Amount: $500.00
Description: Gift check
1. Add a check
2. Display a check
3. Display checkbook
4. Quit
Enter your choice: 4