Design a class numbers

Assignment Help Basic Computer Science
Reference no: EM13215236

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 <iostream>
#include <string>
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;
}

 

Reference no: EM13215236

Questions Cloud

What is this maximum revenue next month : What price maximizes JJ's revenue, and what is this maximum revenue and what price maximizes revenue, and what is this maximum revenue next month?
Explain outcome requires the lowest monthly contribution : As their financial planner, provide some assistance with these calculations. The two primary options are listed below. Considering all previous information, which outcome requires the lowest monthly (end-of-month) contribution if they also require..
Add an overloaded assignment operator : Add an overloaded assignment operator, a copy constructor to the Cube class, and a printCube member function in the attached lab6_ex2_copy_operator_starter.cpp. This starter is incomplete, you have to fill the right stuff in the blank in order to ..
Develope a good business plan : You have a product in mind you want to manufacture. You have also developed a good business plan and are sure you will have no problem with financing.
Design a class numbers : 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.
Apply the dynamic programming algorithm : Apply the dynamic programming algorithm to find all the solutions to the change-making problem for the denominations 1, 3, 5 and the amount n = 9
Create a four-function fraction calculator : Create a four-function fraction calculator. Here are the formulas for the four arithmetic operations applied to fractions.
Tolerate or even encourage the abuse tof the children : Should american companies refuse to do business in countries that tolerate or even encourage the abuse tof the children? explain
Why bill is obligated to furnish over one-half of the cost : Jane and Bill have lived in a home Bill inherited from his parents. Their son Jim lives with them. Bill and Jane obtain a divorce during the current year. Under the terms of the divorce, Jane receives possession of the home for a period of five ye..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Determine physical address that code byte fetched

Suppose the same code segment base what physical address will code byte be fetched from if instruction pointer contains 539CH?

  Determine value of maximum element for mle is maximum

Assume that n = 5 points are drawn from distribution and maximum value of which occurs to be 0.6. Plot likelihood p(D|) in range 0  1. Describe in words why you do not need to know values.

  Create and conducting an online questionnaire

Create a free SurveyMonkey or QuestionPro online questionnaire account. If you did not create one, revisit the Week 5 e-Activity to create an account before attempting this assignment.

  The program must use a loop

The program MUST use a loop to read in the series of integers from the user. The output is then displayed after the loop. Algorithm   or Pseudo Code  (as an outline): At the beginning or end or your program write the algorithm or pseudo code as a mul..

  System development methodologies in information systems

There are literally thousands of system development methodologies in the Information Systems field. Suggest some reasons why there might be so many.

  Distinct integers that has the following property

You have an array A[0], A[1], ..., A[n - 1] of distinct integers that has the following property:The values in the array increase up to index p for some p between 0 and n - 1, and then decrease for all indices beyond p through positio

  Sequence of events and signals activated

Describe the sequence of events and signals activated when a 6800 device wants to exchange data with the 68000 processor.

  What ''are the differences between a policy, a standard

What 'are the differences between a policy, a standard, and a practice? What are the three types of security policies? Where would each be used? What type of policy would be needed to guide use of the Web? E-mail? Office equipment for personal use?

  Write a version of sum pairs i that sums each component

Using SML write a version of sumPairs that sums each component of the pairs separately, returning a pair consisting of the sumof the first components and the sum of the second components

  Classify memory in hierarchy

Classify a memory in hierarchy according to the two most common attributes like accessing method and speed.

  Determine size of one minute mono audio file

Digital audio transducer samples real sound at the rate of 40 kHz and assigns 8 bits to each sample. Determine the size of one minute mono audio file?

  How system access big date to maximum in usage?

How system access big date to maximium in usage?

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