Check Writing
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 a single integer member variable
int number;
and a collection of static string members that specify how to translate key dollar amounts into the desired format. For example, you might use static strings such as
string 1essThan20[ ] =
{"zero", "one", …, "eighteen", "nineteen" };
string hundred = "hundred";
string thousand = "thousand";
The class should have a constructor that accepts a non-negative 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
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Starting Out With C++: Early Objects, Student Value Edition & Myprogramminglab With Pearson Etext -- Standalone Access Card Package, 9/e
Additional Engineering Textbook Solutions
C How to Program (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Starting Out with Java: Early Objects (6th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- In C++ Language: Suppose I have a class named Person. Here is how I would like to use the class: //Create a person named Dave Smith Person dave("Smith", "Dave", 'R'); //Create a person named Gal Gadot Person gal("Gadot", "Gal", 'G'); //Dave and Gal gets married gal = dave + gal; dave = dave + gal; //print Gal and Dave's new married name cout << gal << endl; cout << dave << endl; This will output the following: Gal Smith-Gadot Dave Smith-Gadot Write the class declaration for Personarrow_forwardOverload the assignment operators (=) for Distance class. Your operator must be able to do multi-level assignments, e.g., statements like “d3 = d2 = d1;” must work as expected. A sample output is given below: Distance d1: 3'-9" Distance d2: 3'-6" After assigning d1 to d2 to d3 Distance d1: 3'-9" Distance d2: 3'-9" Distance d3: 3'-9" by using c++arrow_forwardin c++ A complex number has the form a+bi , can be expressed as theordered pair of real numbers (a,b). The class represents the real andimaginary parts as double precision values.Provide a constructor that enables an object of this class to beinitialized when it is instantiated. The constructor should containdefault values.Provide Public member functions for each of the followingarithmetic’s functions (addition – subtraction – multiplication –division), a complex absolute value operation, printing the number inthe form (a,b), printing the real part , printing the imaginary part andfinal overload the == operator to allow comparisons of two complexnumbers.Include any additional operations that you think would be useful fora complex number class.Design, implement, and test your class.arrow_forward
- Problem: Create a Fraction class with two private positive integer member variables numerator and denominator, one constructor with two integer parameters num and den with default values 0 and 1, one display function that print out a fraction in the format numerator/denominator in the proper form such as 2/3 or ½ . Note: 2/4 should be displayed as ½.arrow_forwardIN C++, create a class called Employee that includes three pieces of information as data members—a first name (type string), a last name (type string) and a monthly salary (type int). Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display each Employee’s yearly salary again.arrow_forwardCombine the modified Time class of the modified Date class of into one class called DateAndTime . Modifythe tick function to call the nextDay function if the time increments into the next day. Modify functions toStandardString and toUniversalString so that each returns a string containing the date and time. Write a program to test the new class DateAndTime . Specifically, test incrementing the time into the next day.arrow_forward
- USING C++ Write a simple class named Circle, with three private variables: doubles named x, y and radius. The center of the circle is denoted by coordinates (x,y), and the radius of the circle is denoted by radius. It should have public member functions with the following signatures: void setRadius(double r)void setX(double value)void setY(double value)double getRadius()double getX()double getY()double getArea()bool containsPoint(double xValue, double yValue) The first six member functions are straightforward functions to set and get the private member variables. double getArea() This member function should return the area of the circle. When you are calculating the area you can use 3.14 for pi. The formula is radius * radius * pi. bool containsPoint(double xValue, double yValue) This member function should return true if the point at (xValue, yValue) is contained in the circle, and false if not. You can determine whether or not a point is in a circle by calculating the…arrow_forwardFrom the below given code, Add default and parameterized constructor for the given data fields and write down the instantiation statement that invokes both constructor. Illustrate the use of this. class person { int reg; string name; int age; …….. public static void main(string [] args) { …..arrow_forwardWrite a program in C++ object oriented programming Create a class Class1 with a string data member ‘paragraph’. Provide a constructor and getParagraph() method in the class. The constructor just assigns NULL to the data member. getParagraph() method must read a paragraph from user. The paragraph should contain at least 30 words. If there are less than 20 words, the program must ask user to enter paragraph again. Create another class Class2, and make it a friend of the class Class1. Provide a function getSubString(Class1 &obj1, int startIndex, int lastIndex) with return type string in the class Class2 which accepts an object of class Class1 (by reference) and two integers. The getSubString() function should return the substring starting from location startIndex and ending at location lastIndex. Class2 must also contain a store() function that stores the substring in a file. Print screenshot of substring stored in file as well. (Topics covered: File Handling, Friend Classes.arrow_forward
- Create a class: Doctor, with private data members: id, name, specialization and salary with public member function: get_data () to take input for all data members, show_data () to display the values of all data members and get specialization () to return specialization. Write a program to write for detail of n doctors by allocating the memory at run time only. Write the program in c++ language.arrow_forwardMake a class Distance having a member meter. Now create a friend function named convert() that increments meter by 5 and then convert that meter in kilo meters and return the answer. Call the function in main. Note: Solve as soon as possible Use C++ Language Soloution must be well explained with double lines commentsarrow_forwardImplement a class named Animal has two private member variables: name of type string and numLegs of type int, and has the following member functions: • setName—Function to set the name • setNumLegs—Function to set the number of animal legs • getName—Value-returning function to return the name • getNumLegs—Value-returning function to return the number of animal legs • speak()—Value-returning function to return the empty string • move()—Value-returning function to return the empty string • print()—Outputs the data stored in the instance variables with the appropriate titles • Constructor with parameter—Sets the values of the instance variables to the values specified by the user, in default: sets name to the empty string and number of legs to 0 2. Using an Animal class as a base class, implement two derived classes simulating a Cat and Dog, each redefining three functions constructor, speak(), move() to represent each animal the most suitable. 3. Write a function to handle the…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning