Really need help with the interactive Calculator program, or will be dead

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 2
Reputation: tendyhk is an unknown quantity at this point 
Solved Threads: 0
tendyhk tendyhk is offline Offline
Newbie Poster

Really need help with the interactive Calculator program, or will be dead

 
0
  #1
Sep 1st, 2007
got my first HW on the first day of class, have no idea of what to do, please help me!!!!
The HW question is this

write a program that will act as an interactive calculator capable of handling very large (larger than the largest long integer) nonnegative integers. this calculator need perform only the operations of addidtion and multiplication

in this program, each input line is of the form

num1 op num2

and should produce output such as

num1
op num2
-------------
num3

where num1 and num2 are(possibly very large) nonnegative integers, op is the single character + or *, and num3 is the integer that result fromt he desired calculation.

Program 1

Write the interactive calculator described in Programming Problem 5 on page 64 of the text.



· Do not use classes. Do use an appropriate typedef for your long numbers.

· Do use fixed-length arrays to store the digits of the long numbers the program manipulates.

· Ignore the optional part of the problem.

· Assume there is at least one space between each number and the operator symbol. Of course there will not be spaces between the digits in a number (i.e. 123, not 1 2 3).

· Do not implement multiplication. If the operator symbol is *, have the output indicate that multiplication is not yet implemented.

· Be sure to follow the guidelines given in the programming standards document on this course website.


Just to be clear, input to the program should look like this:

000655123897667676422 + 21346615433431

or like this:

564557655123897667676422 * 77621346615433431

Of course, in the second case, the program just says that it can't yet handle multiplication.


what I had though is to use 4 array, 3 that hold the numbers, and one that hold the sign, but I dont know how to write an array plus another array and save it to another array. plese help, here's the code that I had try
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. const int arraysize=30; //an array of could hold up to 30 characters
  8. typedef char string; //defind string as char data type
  9. string num1[arraysize]; //array to store first set of numbers
  10. string sign[arraysize]; //array to store the operation sign
  11. string num2[arraysize]; //array to store second set of numbers
  12. string num3[arraysize]; //array to store the answer
  13.  
  14. cin>>num1>>sign>>num2;
  15. num3=int(num1-'2')+int(num2-'1');
  16.  
  17. cout<<num1<<endl<<sign<<num2<<endl<<--------<<num3<<endl;
  18.  
  19.  
  20.  
  21. return 0;
  22.  
  23. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #2
Sep 1st, 2007
I think you need to plan how to do this on paper to get ideas.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #3
Sep 2nd, 2007
don't expect any problem-solving from us if you dont try it first... and actualli iamthwee is right... you should plan how you're gonna work it before you code anything... if not it's just blindfolded bat swinging...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #4
Sep 2nd, 2007
> got my first HW on the first day of class
> Write the interactive calculator described in Programming Problem 5 on page 64 of the text.
I find these statements to be inconsistent.

How does this work then?
It's the first day of the advanced class, but you haven't bothered with the beginners class. As such, you're already way out of your depth.

It's the 5th day of the class (hence problem 5), but it's the first one you could be bothered to turn up for.

If "or will be dead" means you'll be kicked off the course, then that is perhaps a good thing. It will allow you to find your true path, and everyone else on the course will benefit from the extra attention the tutor can give, which would otherwise be wasted on you.

The problem is simple enough, but I wouldn't say that it's in the "first day of the beginners class" range of problems.

> 000655123897667676422 + 21346615433431
Before you write the code, do you know how to do this on paper?

> Be sure to follow the guidelines given in the programming standards document on this course website.
How are we supposed to make it look like your own work, when we don' t even know what these are
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #5
Sep 2nd, 2007
there's this very interesting language called NOLAE... if you can write a program in that code, you certainly can do it in any programming language...

also you should be able to draw flow charts...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 120
Reputation: ft3ssgeek is an unknown quantity at this point 
Solved Threads: 7
ft3ssgeek's Avatar
ft3ssgeek ft3ssgeek is offline Offline
Junior Poster

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #6
Sep 3rd, 2007
Dare I ask about NOLAE???
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #7
Sep 3rd, 2007
i don't know if that's what its called in english... (should've made sure first... ), but its the language base for every other languages, where commands are written in plain english... i.e:
integer num;
read num;
num=>num*num;
write num;

hope i explained myself clearly...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 120
Reputation: ft3ssgeek is an unknown quantity at this point 
Solved Threads: 7
ft3ssgeek's Avatar
ft3ssgeek ft3ssgeek is offline Offline
Junior Poster

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #8
Sep 3rd, 2007
pseudocode?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 2
Reputation: tendyhk is an unknown quantity at this point 
Solved Threads: 0
tendyhk tendyhk is offline Offline
Newbie Poster

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #9
Sep 3rd, 2007
here is my updated code, I dont know how to convert int back to char and store in the string, can any one help me? and how to do the carry in the array? please help me

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9. const int arraysize=30; //an array of could hold up to 30 characters
  10. typedef char string; //defind string as char data type
  11. string num1[arraysize]; //array to store first set of numbers
  12. string sign[arraysize]; //array to store the operation sign
  13. string num2[arraysize]; //array to store second set of numbers
  14. string num3[arraysize]; //array to store the answer
  15.  
  16. char null='\0';
  17. int num1size=0;
  18. int num2size=0;
  19.  
  20.  
  21.  
  22. char mul='*'; //This use to compare the sign store in the sign array
  23.  
  24. cin>>num1>>sign>>num2;
  25.  
  26. if(sign[0]==mul) //compare sign arry, if sign is multiplication then program terminate
  27. {
  28. cout<<"The Program can not yet handle multiplication"<<endl;
  29. return 0;
  30. }
  31. else //addition begin to run if sign equal to +
  32. {
  33.  
  34. while(null!=num1[num1size]) //calculate the size of arry num1
  35. {
  36. num1size++;
  37. }
  38. num1size--;
  39. while(null!=num2[num2size]) //calculate the size of array num2
  40. {
  41. num2size++;
  42. }
  43. num2size--;
  44.  
  45.  
  46. int answer=int(num1[num1size]-'0')+int(num2[num2size]-'0');
  47. itoa(answer,num3,num1size);
  48.  
  49.  
  50. cout<<num1[num1size]
  51. <<endl
  52. <<strlen(num1)
  53. <<answer
  54. <<endl
  55. <<"--------"
  56. <<endl;
  57.  
  58. }
  59.  
  60. return 0;
  61.  
  62. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Really need help with the interactive Calculator program, or will be dead

 
0
  #10
Sep 3rd, 2007
> I dont know how to convert int back to char
http://faq.cprogramming.com/cgi-bin/...&id=1043284385

[edit] Don't use itoa ... it is wrong [/edit]
Last edited by iamthwee; Sep 3rd, 2007 at 4:20 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC