Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Language used C) The purpose of this assignment is to practice the use of structures and pointers to build and manipulate linked lists. Your program

(Language used C)

The purpose of this assignment is to practice the use of structures and pointers to build and manipulate linked lists. Your program should present the user with a menu to choose between addition, subtraction or quit. Something simple like: Please enter: 1 - Addition 2 - Subtraction 3 - Quit If the user chooses Quit, the program should print a good bye message and terminate. Otherwise, it should ask the user to enter two operands, one per line, the operands will be strings of characters representing arbitrarily long integers (bigger than can be stored in a long variable). The data should be read character by character and stored in a linked list in reverse order, one digit per node. For instance, if user enters 1234567, it should be stored in the LL as top -> 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 1. Once both operands have been read and stored in their corresponding Linked Lists, the program should call an add or a subtract function, depending on the user chosen option ( 1 or 2 ) of the initial menu. Note that each character read should be converted from a character to an integer before it is stored in the corresponding node and inserted in the linked list. You probably need a function that reads a line of text (the number) character by character and builds the linked list, returning the pointer to the list. You can call the function twice, once for each operand. The add/subtract functions should receive two pointers to the linked lists that represent the two integers and perform a digit-by-digit addition/subtraction and return a pointer to a linked list representing the result also stored in reverse order. Make sure your functions work when one of the operands is an empty list. You will also need a function that receives a linked list and prints the number represented by the linked list out to the screen. E.g. if it receives top, where is top -> 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 1, it should print the number: 1234567. Note, you cannot convert the list to an int or a long, since it might be bigger than the biggest integer that an int or long can hold, so the number must be printed character by character.

Make sure your function works the list provided is an empty list. After printing the result of the operation, the program should loop back to print the top menu.

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_2

Step: 3

blur-text-image_3

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions