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 the actual bits sent by the sender

Determine the actual bits sent by the sender? Include some idleness bits before and after the frame. Let bit-stuffing (also known as bit-insertion).

  Create a console-based application

create a console-based application whose Main() method accepts ten integer values from the user and stores them in an array. Next, create a method that determines and displays the smallest and largest of the ten values

  Generate dropdown to create example c++ code

Submit your C++ source code that you generated from RAPTOR with comments added to each line or where necessary to explain program flow. Also submit the RAPTOR file (flowchart) of your working program.

  What are the differences between a struct and a class

What are the differences between a struct and a class?

  A priority encoder has 2^n inputs

A priority encoder has 2^n inputs. It produces an N-bit binary output indiciating the most significant bit of the input that is TRUE, or 0 if none of the inputs are TRUE

  Explaining gui differences and security differences

With that being said, its great that each of you pointed out the GUI differences. What about the Security differences?

  How would you deallocate memory in a destructor

We can use the destructor to deallocate memory for an object. How would you deallocate memory in a destructor?

  Write the code for invoking a method

Write the code for invoking a method named sendSignal . There are no arguments for this method. Assume that sendSignal is defined in the same class that calls it.

  Analysis of competitive organization and possible threats

Analysis of competitive organization and possible threats and how organization is using E-Business Management facilities for daily activities? Limitations if any, adding more features for E-Business if required.

  Use regression analysis definition

Problem 3.  For the following set of points, calculate the value of 'r' and infer how are the points correlated. Use regression analysis definition or 'r' using covariance (x, y), var(x) and var(y).

  The strike predicate need not work

Define a predicate strike(X,Y,Z) that succeeds if and only if the list Z would be obtained if one were to remove all occurrences of element X from list Y. The strike predicate need not work well when Y is an unbound variable.

  Describe why suggestion of connecting by twisted pair cable

Describe why you would suggest connecting all current and new client computers using twisted pair cable instead of staying with the current coax wiring structure.

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