Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So I tried the following code to solve the problem below, but I am still having

ID: 3559892 • Letter: S

Question

So I tried the following code to solve the problem below, but I am still having problems. The program compiles, but the numbers in English don't show up. What am I doing wrong?

//Header File Numbers.h//

#ifndef NUMBERS_H
#define NUMBERS_H
#include<string>
#include<math.h>

using namespace std;

class Numbers
{
   //Declare variables
private:
   int num;
public:
   Numbers(int x)
   {
       num=x;
   }
   void print();
};

void Numbers::print()
{
   int n;

   //Declare static strings
   string lessThan20[20]={"zero", "one", "two", "three", "four", "five", "six",
                           "seven", "eight", "nine", "ten", "eleven", "twelve",
                           "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
                           "eighteen", "nineteen"};

   string hundred= "hundred";
   string thousand= "thousand";
   string tens[]={"zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty",
       "seventy", "eighty", "ninety"};
if (num<0)
cout<<"It is a negative number ";
num=abs(num);
n=num/1000;

if(n>0)
cout<<" "<<lessThan20[n]<<thousand;
num%=1000;
n=num/100;

if(n>0)
cout<<lessThan20[n]<<hundred;
num%=100;

if(num>=20)
{
   n=num/10;
   if(n>0)
       cout<<tens[n]<<" ";
}
else if(num>=10)
{
   cout<<lessThan20[num]<<" ";

   return;

   num%=10;
   if(num>0)
       cout<<lessThan20[num];
   cout<<" ";
}
};
#endif

//Source File .cpp//

#include<iostream>
#include "Numbers.h"

using namespace std;

int main()
{
   int n;

   cout<<"Enter a number between 0-9999 or 0 to Exit: ";
   cin>>n;

   while(n!=0)
   {
       cout<<"The number "<<n<<" translated into string is: ";
           Numbers number(n);
           number.print();
           cout<<" Enter a Number between 0-9999 or 0 to Exit: ";
           cin>>n;
   }//End of while loop

   system("pause");
   return 0;
}

I need this soon with as detailed and thorough an explanation as possible. Please help. Thanks!

1. 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 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 aReview Programming
Questions and
Challenges
Exercises
main program that asks the user to enter a number in the proper range and then prints
out its English description.

Please follow the instructions in the question to write codes. Credits will not be given if codes do not use class or do not follow the instructions in the question.

Explanation / Answer

#ifndef NUMBERS_H
#define NUMBERS_H
#include<string>
#include<math.h>

using namespace std;

void print(int num)
{
int n;

//Declare static strings
string lessThan20[20]={"zero", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
"eighteen", "nineteen"};

string hundred= "hundred ";
string thousand= "thousand ";
string tens[]={"zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty",
"seventy", "eighty", "ninety"};
if (num<0)
cout<<"It is a negative number ";
num=abs(num);
n=num/1000;

if(n>0)
cout<<" "<<lessThan20[n]<<thousand;
num%=1000;
n=num/100;

if(n>0)
cout<<lessThan20[n]<<hundred;
num%=100;

if(num>=20)
{
n=num/10;
if(n>0)
cout<<tens[n]<<" ";
}
else if(num>=10)
{
cout<<lessThan20[num]<<" ";

return;

num%=10;
if(num>0)
cout<<lessThan20[num];
cout<<" ";
}
}
#endif

int main()
{
int n;

//cout<<"Enter a number between 0-9999 or 0 to Exit: ";
//cin>>n;
n=8702;

while(n!=0)
{
cout<<"The number "<<n<<" translated into string is: ";
print(n);
//cout<<" Enter a Number between 0-9999 or 0 to Exit: ";
//cin>>n;
}//End of while loop

system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote