The goal is to cover an interview-related practice problem based on a basic data structure (container) from a CS140 lab, but with a more explicit C++/OOP-centric view, namely using the STL and/or templating. Using friendship and/or operator overloading is optional. Input / Output You will be given a series of integers from standard input in the follow format: integer1 integer2 integer1 integer2 ... integer1 integer2 Each integer is of arbitrary length. Moreover, integer1 is not guaranteed to be the same length as integer2. Example You are to add each pair of integers. Given the following input: 1 1 123 123 1 12 Your program should output the following: 2 246 13 Requirements On top of being interview prep, this specific assignment is intended to both review and assess your understanding of templated sequence containers. Please choose one of the following solution frameworks: You can create a custom, templated linked list implementation in C++ (i.e., you cannot use std::list); however, you are allowed to use Dr. Emrich's code and/or your notes from a prior class as a starter/template. You can use the appropriate STL container adapter for this problem (HINT: this is either a queue or a stack). You must instantiate this container adapter with the with the fundamental type int. Either implementation must manage dynamic memory properly for full credit (i.e., no memory leaks or segmentation faults). This is obviously harder with Option #1. Hints (same as before) You may wish to read the integers in as std::strings. Be sure to account for the carry when you perform addition.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Problem overview

As you may already know from earlier courses, integer values in C++ (as well as other programming languages) are limited by the number of bits used to represent these data. For instance, a 64-bit unsigned integer has the maximum value of 2^64 - 1 or 18446744073709551615.

One method of representing integers of arbitrary length, which was covered last spring, is a a linked list data structure such that that a node in the linked list corresponds to a single digit in the integer.

For instance, the number 123 can be stored as linked-list that could look like this:

[ 3 ] -> [ 2 ] -> [ 1 ] -> NULL
Note that the first (or head) node in this list contains the least significant digit (in this case 3), while the last node contains the most significant digit (1).

For this problem, you are to read in pairs of arbitrary length integers and produce correct output as outlined below.

Inspiration
Note, this problem is inspired by Problem 8.19 from Elements of Programming Interviews and Problem 2.5 from Cracking the Code Interview.

The goal is to cover an interview-related practice problem based on a basic data structure (container) from a CS140 lab, but with a more explicit C++/OOP-centric view, namely using the STL and/or templating. Using friendship and/or operator overloading is optional.

Input / Output
You will be given a series of integers from standard input in the follow format:

integer1 integer2
integer1 integer2
...
integer1 integer2
Each integer is of arbitrary length. Moreover, integer1 is not guaranteed to be the same length as integer2.

Example
You are to add each pair of integers. Given the following input:

1 1
123 123
1 12
Your program should output the following:

2
246
13
Requirements
On top of being interview prep, this specific assignment is intended to both review and assess your understanding of templated sequence containers. Please choose one of the following solution frameworks:

You can create a custom, templated linked list implementation in C++ (i.e., you cannot use std::list); however, you are allowed to use Dr. Emrich's code and/or your notes from a prior class as a starter/template.

You can use the appropriate STL container adapter for this problem (HINT: this is either a queue or a stack). You must instantiate this container adapter with the with the fundamental type int.
Either implementation must manage dynamic memory properly for full credit (i.e., no memory leaks or segmentation faults). This is obviously harder with Option #1.

Hints (same as before)
You may wish to read the integers in as std::strings.

Be sure to account for the carry when you perform addition.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education