Question

i need help making this C++ code. Lab #2 Assignments: Numbers Class that translate whole dollar...

i need help making this C++ code.

Lab #2 Assignments: Numbers Class that translate whole dollar amounts in the range 0 through 9999 into an English description of the number.

Numbers Class

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 state array of string objects that specify how to translate key dollar amounts into the designed 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 the main program that asks the user to enter a number in the proper range then prints out its English description.    

REQUIREMENT:

1. Decomposition requirement report. Include your name in the decomposition report file.
2. UML Diagram to show classes, member variables and member functions (methods)
3. Source code for all the programs solutions
4. Screenshots for all the test cases to demonstrate a successful completion of the project requirements
5. Test Data Listing for test cases

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given below is the code for the question. Please do rate the answer if it helped. Thank you.


#include <iostream>
using namespace std;

class Numbers{
   private:
       int num;
   public:
       Numbers(int n){
           num = n;
       }
      
       void print(){
           string lessthan20[20] = {"zero", "one", "two", "three", "four", "five" ,"six" ,"seven", "eight", "nine", "ten",
               "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
           string twentyPlus[] = {"", "", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
          
           string hundred = "hundred";
           string thousand = "thousand";
          
           int thousands = num / 1000;
           int hundreds = (num % 1000) / 100;
           int remaining = num % 100;
          
           if(thousands != 0)
               cout << lessthan20[thousands] << " " << thousand << " ";
          
           if(hundreds != 0)
               cout << lessthan20[hundreds] << " " << hundred << " ";
          
          
           if(remaining < 20)
               cout << lessthan20[remaining];
           else{
               int tens = remaining / 10;
               int ones = remaining % 10;
               cout << twentyPlus[tens] << " ";
               if(ones != 0)
                   cout << lessthan20[ones];
           }
           cout << endl;
          
       }
};

int main(){
   int num;
  
   cout << "Enter a number in the range 0-9999: ";
   cin >> num;
  
   Numbers n(num);
   n.print();
   return 0;
}

==================
output
============

Enter a number in the range 0-9999: 713
seven hundred thirteen

Enter a number in the range 0-9999: 8203
eight thousand two hundred three

Add a comment
Know the answer?
Add Answer to:
i need help making this C++ code. Lab #2 Assignments: Numbers Class that translate whole dollar...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++ Design a class called Numbers that can be used to translate integers in the range 0 to ...

    Using C++ Design a class called Numbers that can be used to translate integers in the range 0 to 9999 into an English description of the number. The class should have a single integer member variable: int number; and a static array of string objects that specify how to translate the number into the desired format. For example, you might use static string arrays such as: string lessThan20[20] = {"zero", "one", ..., "eighteen", "nineteen"}; string hundred = "hundred"; string thousand...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Need help writing beginner C# program, I will make sure to provide feedback to whoever can...

    Need help writing beginner C# program, I will make sure to provide feedback to whoever can help me figure it out! No public or global variables should be used. You need to consider passing arguments between the methods according to the ways described in the lecture. i.e. all variables should be declared inside the methods and passed to other methods by value/ref/out as needed Description: We want to design a Date class to represent a date using three integer numbers...

  • I need java code... Background Suppose you're working on the next great cligital assistant to compete...

    I need java code... Background Suppose you're working on the next great cligital assistant to compete with the likes of Siri, Cortana Alexa, and the lameless Google Assistant. An important part of your assistant is a text-10-speerlingine, You've managed to get your assistant to pronounce Englisli words, but you've hit a sag! The resistant is unable to pronounce numbers. When it sees 6243, it just says "six two four three insteud of the proper "six thousand two hundred forty three."...

  • I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good...

    I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr. Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • I need this in C++. This is all one question Program 2: Linked List Class For...

    I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT