Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Write a program that will allow the user to sum two integers up to 20 digits big. The integers should be stored in a string with no more than size 20. The integers will be read in as a string, not an integer. Hints...

1) since each integer is stored as a string, it is already in a character array.

2) reverse each integer and store it in a temp string to do the addition. You are not required to do this, but this will make the processing a lot easier.

3) it would be best to declare an int for the carry. If you add two elements of an array and there is a carry, add the carry to the next summation.

4) If the sum of the 2 integers is more than 20 digits, print 'Overflow'

5) Prompt the user to do another.

6) Clear the screen between runs (using our new cls() and pause() presented in class, not system calls)

7) Use functions for most of the processing. Below are the prototypes for the functions you should use. string inputnums(); //Used to input the numbers (the string returned is the input number)

Declare a string (to store the input) and an int to store the size
Get the string
Calculate size
Loop while size is greater than maxsize (20)
Input error overflow
Input new number
Get the new size
End of loop
Initialize a LCV to 0
Loop while LCV is less than the size
if the character at index LCV is a digit
increment LCV
else (if it never enters here, then one the characters in the number was a digit)
print error message that a character was detected in the number please re enter input new number
set LCV back to zero and start the loop over again to check the new number
end of loop
return the string to main() as a number that has passed input error checking;
End of input()
string reverse(string, int); String is the number, int is the size of the number declare a string that will contain the reversed number;
loop from size-1 to 0 (decrementing by 1)
concatenate the number string index to the reversed string
end loop
return reversed string to a string declared in main(). This is the string you will use to add
end of reverse()
void pad( string &, string &, int &, int &); //concatenates ‘0' to the shortest reversed string, so that both numbers are the same length the strings is the reversed numbers, the ints are the lengths of the padded strings because we need to pad the shortest string with ‘0's (so that both string have the same length
before we add them), we pass both strings in by reference, so that the original string gets
changed (only the shortest will get changed, but we don't know which one, so we have to pass
both by reference, same thing with the lengths)
if (s1 is larger)
loop from 1 to larger size - smaller size concatenating shorter string with ‘0' (by passing by reference will change original number so we don't have to return it)
end =loop;
get new size for shorter string (by passing by reference the size of the shorter number has
been changed, so we don't have to return it)
else
do the same thing as above, except you are padding the other number
string add(string, string, int); //Adds the two numbers. Don't forget to reverse the answer
void print(string, string, string, int); //Prints the answer in the following form (see below)
char prompt(); //prompts the user to do another
Answer printed in the following format (make adjustments for the size of the numbers)

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92029088
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Programming Language

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As