Write code for a program in c preferably in visual studio 20

Write code for a program in c++ preferably in visual studio 2008 or 2015 that takes an input of any number up to 2 billion and converts the number into its equivalent string word. For instance the number 1 equals ONE when typed inby user all the way to 2,000,000,000 = TWO BILLION take account of numbers like 11 = eleven, twelve = 12, 112 = ONE HUNDRED AND TWELVE. Also take account for the decimals place and commas. It works - for all numbers between 0 and 2 billion , for all positive, signed integers. Each function should be small, single-purposed, and readable. You should have decomposed the problem using the repeating three-digit pattern. You really really should havea function string threeDigitsToWrittenStr ( int onesTensHundreds ) Your names don\'t need to be my suggestions... but should be readable, convey meaning, and make your design more understandable. Your main function should have explicit tests for boundaries of interest: 0-31, all decades, 99-119, all hundreds, 999-1019, 9999-10019, 99999-100019, 999999-1000019, up to the maximum. You should have a basic input loop using cin >> double, and have begun working on the input/floating point.

Solution

#include <iostream>

using namespace std;

string threeDigitsToWrittenStr( int onesTensHundreds){
const char * const ones[20] = {\"zero\", \"one\", \"two\", \"three\",\"four\",\"five\",\"six\",\"seven\",
\"eight\",\"nine\",\"ten\",\"eleven\",\"twelve\",\"thirteen\",\"fourteen\",\"fifteen\",\"sixteen\",\"seventeen\",
\"eighteen\",\"nineteen\"};
const char * const tens[10] = {\"\", \"ten\", \"twenty\", \"thirty\",\"forty\",\"fifty\",\"sixty\",\"seventy\",
\"eighty\",\"ninety\"};
if(onesTensHundreds >= 100)
{
threeDigitsToWrittenStr(onesTensHundreds / 100);
cout<<\" hundred\";
if(onesTensHundreds % 100)
{
cout << \" and \";
threeDigitsToWrittenStr(onesTensHundreds % 100);
}
}
else if(onesTensHundreds >= 20)
{
cout << tens[onesTensHundreds / 10];
if(onesTensHundreds % 10)
{
cout << \" \";
threeDigitsToWrittenStr(onesTensHundreds % 10);
}
}
else
{
cout<<ones[onesTensHundreds];
}
return \"\";
}
int* splitNumber( int number ){
int* arrNum;
for(int i=0;i<4;i++){
if(number > 1000){
arrNum[i] = number%1000;
number = number/1000;
}
else{
arrNum[i] = number;
number = 0;
}
}
return arrNum;
}
int main()
{
double iNumber;
cout << \"Enter a number (between 0 and 2 billion)\" << endl;
cin>> iNumber;
if(iNumber > 0 && iNumber <= 2000000000){
int* arrNum;
arrNum = splitNumber(iNumber);
for(int i=3;i>=0;i--){
if(arrNum[i]!= 0){
threeDigitsToWrittenStr(arrNum[i]);
switch(i){
case 1: cout<<\" thousand \"; break;
case 2: cout<<\" million \"; break;
case 3: cout<<\" billion \"; break;
}
}
}
}else if(iNumber == 0){
cout<<\"Zero\";
}
else{
cout<< \"Number should be between 0 and 2 billion. Quiting!!\";
}
cout<<endl;
return 0;
}

Write code for a program in c++ preferably in visual studio 2008 or 2015 that takes an input of any number up to 2 billion and converts the number into its equi
Write code for a program in c++ preferably in visual studio 2008 or 2015 that takes an input of any number up to 2 billion and converts the number into its equi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site