The phraseology is C++ microsoft visual studio specific.
Design a arrangementatize Numbers that can be portraitured to interpret integral dollar amounts in the rove 0 – 9999 into an English term of the calculate. The arrangementatize should own a unique integer component changeable int calculate; It should too own a assembly of static string components that mention how to interpret solution dollar amounts into the desired restraintmat, restraint sample you command portraiture static strings such as
string lessThan20[ ] = {“zero”, “one”, … “eighteen”, “nineteen” };
string hundred = “hundred”; absence of wonder..
The arrangementatize should own a parent that sanctions a misinterpretation disclaiming integer and portraitures it to initialize the Numbers object. It should own a component duty print() that stereotypes the English term of the Numbers object. Demonstrate the arrangementatize by letter a ocean program that asks the portraiturer to invade a calculate in hte special rove and then stereotypes extinguished the English term. This program should barely sanction the special rove of values.
Dear Student,
here i own written the C++ program as per the requirement.I own too inclueded the expatiate restraint improve construction.
—————————————————————————————————————————————-
Note: Please voice that the beneath program has been tested on ubuntu 16.04 arrangement and compiled beneath g++ compiler. This adjudication gain too labor on other IDE’s and C++ microsoft visual studio specific.
——————————————————————————————————————————————
Program:
——————————————————————————————————————————————
//Necessary Header refine declration
#include <iostream>
#include <cstring>
//Namespace declration
using namespace std;
//Numbers arrangementatize declration
systematize Calculates
{
//component changeable declration
private:
int n;
public:
//string changeable initialization
string lessThan20[20] = { ” “, “one “, “two “, “three “, “four “,
“five “, “six “, “seven “, “eight “,
“nine “, “ten “, “eleven “, “twelve “,
“thirteen “, “fourteen “, “fifteen “,
“sixteen “, “seventeen “, “eighteen “,
“nineteen”};
//string changeable initialization
string ten[10] = { “”, “”, “twenty “, “thirty “, “forty “,”fifty “,
“sixty “, “seventy “, “eighty “, “ninety ”
};
//Creating a parent
Numbers(int N)
{
n = N;
}
// n is 1- or 2-digit calculate
string numToWords(int n, string s)
{
string str = ” “;
// if n is over than 19, portio it
if (n > 19)
str += ten[n / 10] + lessThan20[n % 10];
else
str += lessThan20[n];
// if n is misinterpretation-zero
if (n)
str += s;
return str;
}
// Duty to stereotype a dedicated calculate in vocables
string Stereotype(int n)
{
// stores vocable fidelity of dedicated calculate n
string extinguished;
extinguished += numToWords(((n / 1000) % 100), “thousand “);
// handles digit at hundreds places (if any)
extinguished += numToWords(((n / 100) % 10), “hundred “);
if (n > 100 && n % 100)
extinguished += “and “;
// handles digits at ones and tens places (if any)
extinguished += numToWords((n % 100), “”);
return extinguished;
}
};
//This is the ocean program
int ocean()
{
//changeable declration
int num;
//asking to portraiturer to input a calculate in the substantial rove
do
{
cout<<“Invade a calculate: “;
cin>>num;
if(num<0 | num>9999)
{
cout<<“Sorry! Input calculate is referable in the dedicated rove: “<<endl;
}
}while(num<0 | num> 9999);
//constructer calling
Numbers N(num);
//Calling the stereotype duty to stereotype the calculate in vocables;
cextinguished << N.Print(num) << endl;
return 0;
}//end of the ocean program
—————————————————————————————————————————————–
here i own stable the extinguishedput of the program as a hide shot…
————————————————————————————————————————————————–
Output: