| | |
Really need help with the interactive Calculator program, or will be dead
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
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
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
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstring> using namespace std; int main() { const int arraysize=30; //an array of could hold up to 30 characters typedef char string; //defind string as char data type string num1[arraysize]; //array to store first set of numbers string sign[arraysize]; //array to store the operation sign string num2[arraysize]; //array to store second set of numbers string num3[arraysize]; //array to store the answer cin>>num1>>sign>>num2; num3=int(num1-'2')+int(num2-'1'); cout<<num1<<endl<<sign<<num2<<endl<<--------<<num3<<endl; return 0; }
> 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
> 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
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:
hope i explained myself clearly...
), 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<-- •
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
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
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> #include <cstring> using namespace std; int main() { const int arraysize=30; //an array of could hold up to 30 characters typedef char string; //defind string as char data type string num1[arraysize]; //array to store first set of numbers string sign[arraysize]; //array to store the operation sign string num2[arraysize]; //array to store second set of numbers string num3[arraysize]; //array to store the answer char null='\0'; int num1size=0; int num2size=0; char mul='*'; //This use to compare the sign store in the sign array cin>>num1>>sign>>num2; if(sign[0]==mul) //compare sign arry, if sign is multiplication then program terminate { cout<<"The Program can not yet handle multiplication"<<endl; return 0; } else //addition begin to run if sign equal to + { while(null!=num1[num1size]) //calculate the size of arry num1 { num1size++; } num1size--; while(null!=num2[num2size]) //calculate the size of array num2 { num2size++; } num2size--; int answer=int(num1[num1size]-'0')+int(num2[num2size]-'0'); itoa(answer,num3,num1size); cout<<num1[num1size] <<endl <<strlen(num1) <<answer <<endl <<"--------" <<endl; } return 0; }
> 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]
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.
![]() |
Similar Threads
- C++ Calculator Program (C++)
- starting a calculator program in C (C)
- Java Swing Calculator program not running. It has 0 errors (Java)
- Wierd error messages with calculator program (C++)
- I just need help starting this program please (C++)
- need help with calculator program in C (C)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: compiler errors
- Next Thread: Why do I get the following printf() result?
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






