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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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