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

Instructions To complete this assignment Complete the Weeks 4 and 5 lesson found

ID: 3743781 • Letter: I

Question

Instructions To complete this assignment Complete the Weeks 4 and 5 lesson found by clicking on the Weeks 4 and 5 Lesson link in the sidebar. Create a Checkbook program using C (3 points): o At the top of the le include the following comments: . Your name . The purpose (core concept found below) of the program . The dete created o Creale a Check structure. Include: . Check number (should be an integer). . Date (use type charl I Amount o Add functions to: Add Check. Collect all informat on for Single he and return the check. Should not take any parameters Gather all dat, n the function from he user Call e funcion to d splay 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 loeast 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 e Compile and run your e Submit your source code as a plain text file with a.c extension. Make sure it compiles without error before submitting it. code. The core concept for this assignment is to use structures in a C program.

Explanation / Answer

Assumptions :

CODE :

#include <stdio.h>
#include <stdlib.h>

// NAME
// This program saves and reviews previous given checks
// DATE

struct check
{
int CN;               // check number
char date[12];        // date created : correct format to input is DD-MM-YYYY
char to[10];          // to whom the check is addressed
float Amount;           // amount, in the limits of a float number
char des[50];         // description of the check... under 50 char
struct check *next;
};

void print(struct check * newc)     // prints the contents of a check
{
    printf(" Check Number : ");
    printf("%d", newc->CN);
    printf(" Date : ");
    printf("%s", newc->date);
    printf(" TO : ");
    printf("%s", newc->to);
    printf(" Amount : ");
    printf("%.2f", newc->Amount);
    printf(" Description : ");
    int z = 0;
    while((newc->des[z]!='.')&&(z<50))
    {
        printf("%c", newc->des[z]);
        z++;
    }
    printf(".");
}

void display_all(struct check *head)    // prints the complete check book
{
    printf("CHECK-BOOK :");
    struct check *temp = head;
    while(temp->next!=NULL)
    {
        printf(" ");
        print(temp);
        printf(" ");
        temp = temp->next;
    }
    printf(" ");
    print(temp);
    printf(" ");
}

void display(struct check *head)    // searches for a specific check and prints its details
{
    int cn;
    printf(" Enter the check number to search for ");
    scanf("%d", &cn);
    struct check *temp = head;
    while((temp->CN != cn)&&(temp!=NULL))
        temp = temp->next;
    if(temp == NULL)
    {
        printf("ERROR : No such Check found. ");
    }
    else
    {
        print(temp);
    }
}

struct check * add_check (struct check * head)
{
    struct check* newc = (struct check *)malloc(sizeof(struct check));
    printf(" Enter the check number ");
    scanf("%d", &newc->CN);
    printf("Enter the date in format DD-MM-YYYY ");
    scanf("%s", newc->date);
    printf("Enter the name of the person to send the check to (First Name only) ");
    scanf("%s", newc->to);
    printf("Enter the amount ");
    scanf("%f", &newc->Amount);
    printf("Enter the description of this check (terminate the description with a '.') ");
    int z = 0;
    char t ;
    scanf("%c", &t);
    while((t!='.')&&(z<50))
    {
        newc->des[z] = t;
        z++;
        scanf("%c", &t);
    }
    if(t == '.')
    {
        newc->des[z] = t;
    }
    print(newc);
    if(head == NULL)        // if the checkbook is currently empty, put the check in the first position
    {
        head = newc;
    }
    else                    // put the check in the first unoccupied position
    {
        struct check * temp = head;
        while(temp->next!=NULL)
            temp = temp->next;
        temp->next = newc;
        newc->next = NULL;
    }
    printf("Check successfully saved. ");
    return head;
}

int main()
{
    int n = 0;
    struct check* head = NULL;
    printf("Your checkbook is empty... Add a check. ");
    head = add_check(head);              // forgot to update head* on this line
    n++;
    int i;
    while(n!=10)
    {
        printf(" Enter the correct number for the choice. ");
        printf("1: Add a check. ");
        printf("2: Enter a check number and display the check. ");
        printf("3: List all the checks ");
        printf("4: quit ");
        scanf("%d", &i);
        if(i==1)
        {
            head = add_check(head);
            n++;
        }
        else if(i==2)
            display(head);
        else if(i==3)
            display_all(head);
        else
        {
            printf(" EXIT ");
            return 0;
        }
    }
    printf("CheckBook is Full.");
    display_all(head);
    printf("Exit.");
    return 0;
}

*************NOTE*************
If there is any problem, please reply in the comments.
If everything is clear, please rate accordingly :)