1. Engineering
  2. Computer Science
  3. numbersh ifndef numbersh define numbersh include ltstringgt using stdstring class...

Question: numbersh ifndef numbersh define numbersh include ltstringgt using stdstring class...

Question details

//Numbers.h

#ifndef NUMBERS_H
#define NUMBERS_H

#include <string>
using std::string;

class Numbers
{
private:
   int num;
   static string zeroToTwenty[20];
   static string tens[10];
   static string hundred;
   static string thousand;
public:
   Numbers(int);
   string describeTens(int);
   void print();
   int getNumber() const
   {return num;}  
};
#endif

//Numbers2.cpp

#include <iostream>
#include <string>
#include "Numbers.h"
using namespace std;

string Numbers::zeroToTwenty[] = { "zero", "one", "two", "three", "four", "five",
                                   "six", "seven", "eight", "nine", "ten", "eleven",
                                   "twelve", "thriteen", "fourteen", "fifteen", "sixteen",
                                   "seventeen", "eighteen", "nineteen" };
string Numbers::hundred = "hundred";
string Numbers::thousand = "thousand";
string tens[] = { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty",
                   "seventy", "eighty", "ninety" };

Numbers::Numbers(int n)
{
   num = n;
}

string Numbers::describeTens(int n)
{
   string tmpTens = "";
   if (n < 20)
   {
       return tmpTens = zeroToTwenty[n];
   }
   else if (n >= 20 && n % 10 == 0)
   {
       return tmpTens = tens[n / 10];
   }
   else
   {
       return tmpTens = tens[n / 10] + " " + zeroToTwenty[n % 10];
   }
}

void Numbers::print()
{
   string description = "";

   if (getNumber() < 100)
   {
       description.append(describeTens(getNumber()));
   }
   else if (getNumber() < 1000)
   {
       description.append(zeroToTwenty[(getNumber() / 100)] + " " + hundred + " " +
           describeTens(getNumber() % 100));
   }
   if (getNumber() > 999)
   {
       description.append(zeroToTwenty[getNumber() / 1000] + " " + thousand + ", ");

       if (getNumber() % 1000 < 100)
       {
           description.append(describeTens(getNumber() % 1000));
       }
       else
       {
           description.append(zeroToTwenty[(getNumber() % 1000) / 100] + " " + hundred + " and " +
               describeTens(getNumber() % 100));
       }
   }

   cout << " This is your dollar amount converted to English words: ";
   cout << "---------------------------------------------------- ";
   cout << description << " dollar(s) ";
}

//Number.cpp

#include <iostream>
#include <string>
#include "Numbers.h"
#include "Numbers2.cpp"
using namespace std;

int main()
{
   char again = ' ';            // Temporary variable holding a user's choice
   int tempNum = 0;            // Temporary variable to hold a number in an approriate range

   cout << " DOLLAR AMOUNT TO ENGLISH WORD CONVERTER ";

   do
   {
       cout << " Please enter a dollar amount in the range of 0 through 9999: ";
       cin >> tempNum;

       while (tempNum < 0 || tempNum > 9999)
       {
           cout << " Input Error! ";
           cout << "Please enter a dollar amount in the range of 0 through 9999: ";
           cin >> tempNum;
       }

       // Create a Numbers class object
       Numbers number(tempNum);
       number.print();

       cout << " Do you wish to convert another dollar amount (y/N)? ";
       cin >> again;

       while (toupper(again) != 'Y' && toupper(again) != 'N')
       {
           cout << " Do you wish to convert another dollar amount (y/N)? ";
           cin >> again;
       }

       if (toupper(again) == 'N')
       {
           cout << " Thank you for trying this demo program. Have a nice day! ";
       }

   } while (toupper(again) == 'Y');


   cin.get();
   cin.ignore();
   return 0;
};

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 inte- ger 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, string hundredhundred string thousandthousand; one , eighteen, nineteen); , 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 a main program that asks the user to enter a number in the proper range and then prints out its English description.

Above is the programming problem I'm struggling with.

LNK2001 unresolved external symbol private: static class std:basic_string<char,struct std:.char traits<char>,class std::allocator <char> > Numberstens(? tens@Numbers@@OPAV?$basic_string@DU?$char_traits@D@std@@V? Şallocator@D@2@@std@@A) LNK2001 unresolved external symbol private: static class std:basic_string<char,struct std:.char traits<char>,class std::allocator <char> > Numberstens(? tens@Numbers@@OPAV?$basic_string@DU?$char_traits@D@std@@V? Şallocator@D@2@@std@@A) LNK1120 1 unresolved externals LNK2005 public:_thiscall Numbers:Numbers(int) (??0Numbers@@OAE@H@Z) already 1 defined in Numbers.obi 3 LNK2005 public: void_thiscall Numbers:print(void) (?print@Numbers@@QAEXXZ) 1 already defined in Numbers.obj LNK2005 public: class std:basic_string<char,struct std::char_traits<char>,class std:allocator<char> > _thiscall Numbers:describeTens(int)(? describeTens@Numbers@@OAE?AV?$basic_string@DU? Şchar_traits@D@std@@V?$allocator@D@2@@std@@H@Z) already defined in Numbers.obj LNK2005 private: static class std:basic_string<char,struct std:char_traits<char>,class std:allocator<char> > Numbers:thousand (?thousand@Numbers@@OV? Şbasic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Numbers.obj LNK2005 private: static class std:basic_string<char,struct std:char_traits<char>,class std:allocator<char> > Numbers:hundred (?hundred@Numbers@@0V? Şbasic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Numbers.obj LNK2005 private: static class std:basic_string<char,struct std:char_traits<char>,class std allocator<char> >Numbers: zeroToTwenty (? zeroToTwenty@Numbers@@OPAV?Şbasic_string@DU?Schar_traits@D@std@@V? Şallocator@D@2@@std@@A) already defined in Numbers.obj LNK2005 class std:basic_string<char,struct std::chartraits<char>,class std:allocator<char> 1

Above are most of the errors that appear when I try running my code. What's wrong with my code? Also, there are 3 files that are part of my final program.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution