Weird out of country dictator....
Author |
Message |
PJ_69
|
Posted: Thu Mar 09, 2006 12:49 pm Post subject: Weird out of country dictator.... |
|
|
I have this really weird teacher, who speaks werid and I do not understand her...She assigned our FIRST ever test in computer science.....Anyway, that is not important, what is important is that she gave us a asignment, and I do not understand what she is saying...Here is the assignment.... If anyone can translate it...I would appreciate it...
Quote:
Assignment #6
Evaluate mathematical expressions
Write a program that evaluates mathematical expressions given as input.
The mathematical expressions should have only:
+ and - operators or
* and / operators or
^
as shown below:
34+5-75= 0.25*4=
-45-6-90= 2^3=
2.5+8.83= 5^100=
4*6/2= 0.5^2=
45/9*34*2=
The program asks the user for a mathematical expression that ends with an equal (=) sign.
The program reads the expression as a string, evaluates the expression and prints out the correct answer to the right side of the equal sign.
After one expression is evaluated the program should give the user the option to introduce another expression for evaluation or to quit the program.
Hint: Create your own set of instructions that convert a string as "56" into an integer as 56 or "23.5" into a real number as 23.5. Do not use Turing predefined functions to convert a string into a number.
You may add any other items to this assignment for bonus marks. (max 5)
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Dan

|
Posted: Thu Mar 09, 2006 1:36 pm Post subject: (No subject) |
|
|
I don't konw it seems prity start forword for what it whonts to me. But if u are just asking about clearfiction of what she whonts maybe you should ask her seening that we can not read her mind. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
 |
PJ_69
|
Posted: Thu Mar 09, 2006 1:51 pm Post subject: (No subject) |
|
|
When I did ask her, she made it more complicated... |
|
|
|
|
 |
codemage

|
Posted: Thu Mar 09, 2006 1:54 pm Post subject: (No subject) |
|
|
The user can type in a calculator sequence, like
5+7=
Your program takes that input as a string
You then break up the string into numbers and symbols
The string above is:
number 5
symbol "+"
number 7
symbol "="
Then you do the operation based on what symbols you've found.
(Tell the user that the answer is 12).
shake, rinse, repeat, exit when the user asks to quit. |
|
|
|
|
 |
Dan

|
Posted: Thu Mar 09, 2006 5:46 pm Post subject: (No subject) |
|
|
This is a great application for a stack, esptaly if you whont to add in ()s.
As for the coverting the string to a int or real number there was a recnt help post on just that with out the use of the bulit in functions.
I whould recomend giving it a try and posting what you get to so we can help more. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
 |
MysticVegeta

|
Posted: Mon Mar 13, 2006 7:42 pm Post subject: (No subject) |
|
|
I agree with dan, the ()s really reduce the skill level, also no BEDMAS makes the problem fall apart. Think about this, so start off your calculation:
Step 1: if first character is "-" then the next character is a negative #.
Step 2: Read the string until you encounter 1 more sign, if one more sign is encountered, then convert the string from the previous sign to the current sign into an int/real (depending on input type)
Step 3: Repeat this until you find 2nd #
Step 4: Make a var answer, set its value to the 1st num +/-/*/div 2nd num.
Step 5: Repeat from 2 - 4 until the end, output answer  |
|
|
|
|
 |
|
|