Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that creates a linked list of Customer data. Each entry in the list is to have the customers last name, firstname,

Write a C program that creates a linked list of Customer data. Each entry in the list is to have the customers last name, firstname, id (int), balance (float), and a pointer to the next customer data. Create a struct for the Customer first. Then create a pointer (head)that points to the first element in the linked list (initially NULL), as a global variable. Also, you need to create the following functions:

int insertAtIndex(char * lastname, char * firstname, int id, float balance, int index) - This function attempts to insert a new customer data into the linked list using the parameter valueslastname, firstname, id, and balance at the location indicated by the parameter index. If index is 0, then that means that it should be inserted as the first data in the linked list. If it is successfully inserted, then it should return the index of where it is inserted. If the parameter index value is not within the linked list size(for instance, less than 0, or greater than the index of the end data in the list.), then it should return -1.

int size() -This function returns the number of entries in the linked list. If the linked list isempty, it should return 0.

void displayLinkedList( ) -It prints all entries in the linked list in the following format: Last Name: Clinton First Name: Hillary Customer ID: 555555 Customer Balance: $ 3456.00 Last Name: Obama First Name: Barack Customer ID: 5 Customer Balance: $ 300.00 Last Name: Bush First Name: George Customer ID: 8 Customer Balance: $ 500.00 Last Name: Clinton First Name: Bill Customer ID: 222 Customer Balance: $ 6000.00

int removeCustomer(int id) -This function searches a customer with the parameter id, removes the customer entry, and returns the index of where that entry was located. It should return -1 if such customer entry with the given id was not found. The first customer in the linked list with the id should be removed if there are two such customer entries.

struct Customer * searchCustomer(int id) -This function searches a customer entry with the parameter id, and returns that customer entry once it is found. It should return NULL if not found.

int main() -The main function should start by displaying this menu in this format: Choice\t\tAction ------\t\t------ A\t\tAdd Customer D\t\tDisplay List Size P\t\tPrint List Elements R\t\tRemove Customer S\t\tSearch Customer Q\t\tQuit ?\t\tDisplay Help Next, the following prompt should be displayed: What action would you like to perform? Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase. The following describes what needs to be done for each command. A Add Customer Your program should display the following prompt: Please enter a customer to add: Please enter the last name: Read in the customers last name. Then prompt the following: Please enter the first name: Read in the customers first name. Then prompt the following: Please enter the id(number): Read in the customers id. Then prompt the following: Please enter the balance: Read in the customers balance. Then prompt the following: Please enter the index to insert: Read in the index. Then attempt to insert the customer entry with those information at the given index. If the insertion is not successful, then display the message: The customer could not be added If the insertion is successful, then display the message: The customer is added at 2 where 2 is the index where it was added.

D Display List Size Your program should display the following message: The size of the linked list is 5 where 5 is the number of entries in the linked list.

P Print List Elements Each customer information in the customer list should be displayed in the following format: Last Name: Obama First Name: Barack Customer ID: 5 Customer Balance: $ 300.00 If there is no customer entry in the linked list, display: The list is empty A real example is looked like this: What action would you like to perform? Last Name: Obama First Name: Barack Customer ID: 5 Customer Balance: $ 300.00 Last Name: Bush First Name: George Customer ID: 8 Customer Balance: $ 500.00 Last Name: Clinton First Name: Bill Customer ID: 222 Customer Balance: $ 6000.00 R Remove Customer Your program should display the following prompt: Please enter an id(number) to remove: Read in the id. If a customer entry with the id is found in the linked list, then remove it from the list, and display the following: Customer was removed If there is no such customer entry in the linked list, display: Customer with the id was not found

S Search Customer Your program should display the following prompt: Please enter an id(number) to search: Read in the id and look up the linked list, if there does not exist a customer with the id, then it should display the following: Customer with the id was not found If a customer with the id was found, display their last name, first name, and balance in the following format: The customer's last name is Clinton The customer's first name is Bill The customer's balance is $ 6000.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions