Program for simple 4-function calculator, C/C++ Programming

Assignment Help:

Most first graders know that nine hundred and ninety nine plus one is one thousand, but C++ doesn't! Sure, a computer can easily compute 999 + 1 and get 1000. But reading and writing the numbers in words is not so easy.

Task

Consider the following code, which implements a very simple 4-function calculator:
float n1, n2;
char op;
while (cin >> n1 >> op >> n2) {
switch (op) {
case '+': cout << n1 + n2 << endl; break;
case '-': cout << n1 - n2 << endl; break;
case '*': cout << n1 * n2 << endl; break;
case '/': cout << n1 / n2 << endl; break;
}
}
The code will read input consisting of expressions like these
2.1 + 3.7
1.732906E-9 / 4.5870021E-25
and for each expression it will display the result:
5.8
3.77786e+15
By simply changing the type of the numbers n1 and n2 (here it's float), the calculator can compute the answers for various kinds of number. For example, changing the code to read
int n1, n2;
will mean that numbers are computed and displayed according to the rules of integer arithmetic (so that you could compute that 7 / 2 is 3), and changing it to read
complex n1, n2; // also need #include
will let you verify that i is the square root of -1. [Compute (0,1) * (0,1) and get the answer (-1,0)]

Your task for this assignment is to define a class, named Wordnum, that will read and write numbers expressed in word form. To use the class in the calculator, simply include the class header file and change the type of the numbers n1 and n2 to Wordnum. Then the program can read input consisting of expressions such as
five + six
ninety_nine - ninety_nine
one_thousand_two_hundred_thirty_four * five_hundred_forty_three
one million / negative_one hundred
and for each line it will write the result in words:
eleven
zero
six_hundred_seventy_thousand_sixty_two
negative_ten_thousand

Numbers are written as English words separated by underscore characters, with the default wording following the US conventions (because they are simpler to program). Thus 1001 is written "one_ thousand_ one" and 123000009 is "one_ hundred_ twenty_ three_ million_ nine".

If British format is in effect (from level 6), tens and units are separated by a hyphen and preceded by the word "and". For example 123 would be written one_ hundred_ and_ twenty-three.


Related Discussions:- Program for simple 4-function calculator

Compiler design, Compiler Design - Limit In The Method Instructions

Compiler Design - Limit In The Method Instructions

Objects., what are objects or simply define objects

what are objects or simply define objects

Explain the function of five elements that are on a, explain the function o...

explain the function of five elements that are found on a motherboard#

Assignmet, I have a assignment deadline is 11.11.2015 can I get help

I have a assignment deadline is 11.11.2015 can I get help

Can i overload operator == so it allow me compare two char[], Q: Can I over...

Q: Can I overload operator == so it allow me compare two char[] by a string comparison? A: No: at least one operand of particular overloaded operator should be of some user-defi

We are seeking someone to search mp3 link, Project Description: We are s...

Project Description: We are seeking someone to search mp3 link form audio or m3u8 for videos. Skills required are .NET, C Programming, Engineering, C# Programming

multithreaded server, Implement a multithreaded server that can be used as...

Implement a multithreaded server that can be used as a proxy server to access some designated file (say it reflects the proxy copy of two file1.txt, file2.txt). Now use a client to

Compiler design limiting instruction, Ravi is a newbie to the programming a...

Ravi is a newbie to the programming and while learning the programming language he came to know the following rules: · Each program must start with ''''{'''' and end with ''''}

Write Your Message!

Captcha
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