Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Design a class Numbers that can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number. For example, the number 713 would be translated into the string seven hundred thirteen, and 8203 would be translated into eight thousand two hundred three. The class should have asingle integer member variable:

int number;

and a static array of string objects that specify how to translate key dollar amounts into the desired format. For example, you might use static strings such as

string lessThan20[20] = {"zero", "one", ..., "eighteen", "nineteen"};
string hundred = "hundred";
string thousand = "thousand";

The class should have a constructor that accepts a nonnegative integer and uses it to initialize the Numbers object. It should have a member function print() that prints the English description of the Numbers object. Demonstrate the class by writing a main program that asks the user to enter a number in the proper range and then prints out its English description.

Fill the blank starting at line 64 of the lab6_ex1_starter.cpp and complete the following functions:

// Take care of hundreds, if any.

// Take care numbers less than a 100.

// Take care of anything less than 20

This starter can work out of the box, however, the denomination other than "thousand" are not working.

the Lab6_ex1_starter.cpp is


// Chapter 14, Programming Challenge 1: Number Class
#include
#include
using namespace std;

// Declaration of Numbers class
class Numbers
{
private:
int number; // To hold a number

// Static arrays to hold words
static string lessThan20[20];
static string tens[10];
static string hundred;
static string thousand;

public:
// Constructor
Numbers(int x){ number = x;}

// Function to print the words for the number
void print();
};

// Static member variables must be defined
// outside of the class
string Numbers::lessThan20[20] =
{ "zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen",
"nineteen",
};

string Numbers::tens[10] =
{ "zero", "ten", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety",
};


string Numbers::hundred = "hundred";
string Numbers::thousand = "thousand";

// *********************************************
// The print fucntion prints the English words *
// for the number *
// *********************************************

void Numbers::print()
{
// Residue holds what remains to be printed.
int residue = number;

// Take care of thousands, if any.
int n_thousands = residue/1000;
residue = residue % 1000;
if (n_thousands > 0)
{
cout << " " << lessThan20[n_thousands];
cout << " thousand ";
}

// Fill the blank
// Take care of hundreds, if any.

// Take care numbers less than a 100.

// Take care of anything less than 20

}

// Demo program
int main()
{
int number;

// Tell user what the program does.
cout << "Translates whole dollar amounts into words for"
<< "the purpose of writing checks.n"
<< "Entering a negative number terminates the program.n"
<< "Enter an amount (less than 20000)for be translated into words: ";
cin >> number;

while (number >= 0)
{
// Create a Numbers object.
Numbers n(number);

// Print the English description.
n.print();

// Get another number.
cout << "nEnter another number: ";
cin >> number;
}
return 0;
}

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9681640

Have any Question?


Related Questions in Computer Engineering

Suppose that you are given a sorted list of n elements

Suppose that you are given a sorted list of n elements followed by f(n) randomly ordered elements. How would you sort the entire list if a. f(n) = 2? b. f(n) = vn? c. How large can f(n) be for the entire list to be sorte ...

Question cyber attacks on critical infrastructures-a risk

Question: Cyber Attacks On Critical Infrastructures-A Risk To The Nation There has been a great deal of research related to cyber attacks and vulnerabilities and critical infrastructure, but there is an incomplete unders ...

Supposed datagrams are limited to 1600 bytes including

Supposed datagrams are limited to 1600 bytes (including header, with header size = 40) between host A and destination host B. Assuming a 20-byte IP header; further assume that the data is carried in TCP segments, with ea ...

What is federalism and why is it unique to the united

What is Federalism and why is it unique to the United States compared to other countries? Please respond to the following: Based on the scenario and the knowledge gained from this section, address the following: Discuss ...

We can represent numbers in different bases think of how

We can represent numbers in different bases. Think of how you could represent the number 5 in base 2. Essentially, how can you break the number 5 into powers of 2. It contains one 4 and one 1. In base 2, your digit overf ...

Wanda is placing dog biscuits in her bed to save them for

Wanda is placing dog biscuits in her bed (to save them for later). How many patterns can she create if she has 6 beef biscuits, 8 chicken biscuits, and 3 bacon biscuits, assuming she must place all 10 biscuits?

Simulate a dispatcher using a priority queue system in

Simulate a dispatcher using a priority queue system in Java. New processes are to be entered using a GUI with priority included (numbering should be automatic). Processes are also to be terminated by GUI command. Context ...

On crait 40 of the surviving resistance fightersnbspare

On Crait, 40% of the surviving resistance fighters are pilots. Preparing for KyloRen's assault on their position, a random sample of 25 resistance fighters is taken. Using this information, answer the following questions ...

Explain why some organizations may not place enough

Explain why some organizations may not place enough importance on disaster recovery. What might happen to these organizations in the event of an actual disaster?

Scenario upon logging into the centos7 server you notice

Scenario: Upon logging into the CentOS7 server you notice that the system seems sluggish. You suspect that a runaway process is causing the problem, so you open the top utility and notice that there are numerous "cat bom ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As