Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this C++ project. A singly-linked list can be used to store large integers one digit at a time. For example, the integer

Need help with this C++ project.

A singly-linked list can be used to store large integers one digit at a time. For example, the integer 1234 could be stored in a list by storing 1 in the first node, 2 in the second node, 3 in the third node, and 4 in the last node. However, for this assignment you may find it more useful to store the digits backwards; that is, store 4 in the first node, 3 in the second node, 2 in the third node, and 1 in the last node. You will see why this is the case shortly. Write a program in C++ that reads two positive integers that are of arbitrary length and then outputs the sum of the two numbers. Your program will read the digits as values of type char so that the number 1234 is read as the four characters '1', '2', '3', and '4'. As the characters are read they are changed to values of type int and stored in a list. (Now you can see the first reason why storing the digits backwards has an advantage.) After the first number has been read your program reads the second number, storing it in a second list. Your program will perform the addition by implementing the usual paper-and-pencil addition algorithm. (Now you should discover the second reason why storing the digits backwards is advantageous.) The result of the addition is stored in a list and the result is then written to the screen. Include a loop that allows the user to continue to do more additions until the user says the program should end. Of course, your multiple precision addition code should be formulated as a function that accepts a pair of lists, returning a list as its result (the sum of the two inputs). You might want to base your List class on a simplification of the Node class described in our textbook.

It did not provide any linked list class for this assignment. We suppose to write program for what it stated above in bold.

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions