Write a program that will allow the user to sum two integers

Assignment Help Programming Languages
Reference no: EM131274366

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)

Reference no: EM131274366

Questions Cloud

Why does the court reject smyths comparison : Smyth wants the court to look at what happened to him regarding privacy and view any violations as comparable to violations of privacy related to urinalysis and/or personal property searches. Why does the court reject Smyth's comparison?
Improve the interactions of members and increase : Working with organizations to improve the interactions of members and increase productivity through collaborative behavior is an essential role of the organization development human resources specialist.
Identify a community problem in your area : Developing relationships within the community is essential to implementing change. Unfortunately, many times this does not occur. Why is this important part of the process often overlooked. Identify a community problem in your area. What are the ..
Developing a requirements specification for the mhc-pms : What viewpoints should be considered when developing a requirements specification for the MHC-PMS? What are likely to be the most important cross-cutting concerns?
Write a program that will allow the user to sum two integers : 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.
Business analysts make in modeling process or data : What do you think are three most common mistakes that novice business analysts make in modeling process or data?
Explain two specific challenges states : Explain two specific challenges states are facing as they try to regulate the Internet.- Explain how the concepts of domain names, trademarks, and cybersquatting are related.
Protect the employee from retaliation : Explain how the whistleblower act has improved for employees and what can be done to protect the employee from retaliation?
Explain two specific kinds of crime : Explain how the Internet is giving employers the opportunity to show that they understand the employment-at-will doctrine.

Reviews

Write a Review

Programming Languages Questions & Answers

  Basics of hypertext markup language

The basics of Hypertext Markup Language and World Wide Web.

  Function to recognize employee-s number and address

You are given with 45 telephone numbers of Employee who are misusing call center resources.Write down Fcomputer program function to recognize Employee no.

  Create the object-oriented design for dvd collection

Create the object-oriented design for system which keeps tracks of your CD and DVD collection. Recognize each of the classes, associated data, and operations for classes.

  Design a program allow the user to select air

Design a program that displays a menu allowing the user to select air, water, or steel. After the user has made a selection, he or she should be asked to enter the number of seconds the sound will travel in the selected medium

  Describe benefits of code citations to avoid plagiarism.

Describe some benefits of code citations in addition to avoiding plagiarism.

  Create the calculate and exit buttons on the form

Make sure the application accepts and calculates decimal values

  Run multiple clients and one server

Run multiple clients and one server - create your client side and server

  Write down program to arbitarily choose numbers

Write down a program to arbitarily select the numbers of 3 finalist to recieve a prize. Ensure not to choose same number twice. For instance picking finalist 3, 15, 29 woul valid but picking 3,3,31 would be invalid.

  Write a program that prompts the user for a positive integer

Write a program that prompts the user for a positive integer greater than 1. The program should then output either "prime" if the given number is a prime or "composite" otherwise. Recall that an integer is prime if and only if its only divisors are 1..

  Application development and programming languages

Compare and contrast object-oriented languages (Java, C++, C#, etc.) to imperative languages (C, Pascal, etc.) in terms of:

  Interactive program that plays the game hangman

Write an interactive program that plays the game Hangman. Use the random integer function to randomly select the word to guess out of the file provided. The player must guess the letters belonging to the word.

  Construct a finite state machine m that accepts

Construct a finite state machine M that accepts these variables, constants, assignment operators and others, as well as all the reserved words for this primitive programming language that you are defined in Problem 1.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd