Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

add this three lines to your main to double check if your function works first cout < < add(2345566777844567, 9999988777765768009998) < < endl; // 9999991123332545854565

add this three lines to your main to double check if your function works first

cout << add("2345566777844567", "9999988777765768009998") << endl; // 9999991123332545854565

cout << add("9999988777765768009998", "9999988777765768009998") << endl; // 19999977555531536019996

cout << add("2345566777844567", "745566777844567") << endl; // 3091133555689134student submitted image, transcription available below

#include using namespace std; string add(string small, string big) { string result = ""; int carry = 0; // compare the length of the passed in variables "small" and "big" // if "small" has Zonger length than big, swap "small" and "big" // write a loop to concat 'o's to the beginning of "small" to make two strings equal length. // loop backward from the last index to index of either "big" or "small" /* Since string is char array, use big[i] and small[i] to represent each char (each digit). If you do arithmetic calculation of char, e.g. if you do 'O' + 'l', you are actually doing 48 + 49 (their ASCII values). You have to convert first. See notes. */ // int value = sum of converted big[i] and converted small[i] and carry; // if value < 10, // concat** the value to result. // set carry to o // else, // concat** the right digit of value only to the result. // set carry to 1 // Finally (outside the loop), if carry == 1 for the left-most index, add 'l' to the beginning of result. // **Note: You cannot concat int to string, so don't forget to convert int back to char when you concat. return result; int main() { // add this three lines to your main to double check if your function works first cout << add(2345566777844567","9999988777765768009998") << endl; // 9999991123332545854565 cout << add("9999988777765768009998", "9999988777765768009998") << endl; // 19999977555531536019996 cout << add("2345566777844567", "745566777844567") << endl; // 3091133555689134 // write the required loop descripted in the problem statement. cout << "End of Program." << endl; return 0

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 ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

Students also viewed these Databases questions

Question

a is: (a) 1.75772 (b) 1.5455 (c) 4.19978 (d) 0.01659

Answered: 1 week ago

Question

Why should a consultants progress be regularly monitored?

Answered: 1 week ago