Answer & Explanation:homework 4.pdf
homework_4.pdf
Unformatted Attachment Preview
Computer Science 120
Homework 4 (3 points)
Due: 2015-10-18
Given:
int main(int argc, char **argv)
{
string words;
short number, hundreds, tens, ones;
hundreds = tens = ones = -1;
number = atoi(argv[1]);
if(number > 999 || number < 0) {
cerr << "Not a positive three-digit number!" << endl;
return 1;
}
if(number == 0) {
cout << "zero" << endl;
return 0;
}
Deliverables:
main.cpp
Requirements:
Write a program that converts a two-digit integer into words.
• First, change the supplied code to apply to two-digit numbers, since this homework was
originally going to be done with three digits.
• Write switch-cases to convert a number into words (45 → fourty-five).
• You may use no more than two if statements. (Or none. There are a few different ways to
do this.)
• NOTICE that you do not have to use cin to get the number from the user. It's taken as an
argument when you call the program, like numconvert.exe 45 . (atoi(argv[1]) is
taking the number (taken as a c-string from the argument array) into an integer.)
Notes:
• Notice that the digit places are -1, which makes comparing easy, since you will only be
using positive numbers anyway.
• What easy math function can separate a number into its separate digits? (Same one that
can be used to distinguish between odds and evens.)
• Remind me to show you how to pass arguments to the executable in CodeLite so that you
don't have to switch to a terminal to do it. You can simply cheat, and make number equal
some number for now.
...
Purchase answer to see full
attachment
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more