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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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