hi, i have problems with static member function
the compiler's problems = "undefined reference"
**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
**
first time i make this program, i make w/o static std::string, i use normal string and it works, but then i tried to use static std::string for class varables teh compiler keep telling errors
here's the main.cpp:
#include "Account.h"
#include <iostream>
#include <cctype>
#include <fstream>
int main()
{
int num;
Account write;
char choice;
std::string input;
std::fstream file("below20.txt", std::ios::in);
for(int count = 0; count < 20; count++)
{
getline(file, input);
Account::setlessThan20(count, input);
}
file.close();
file.open("thousand.txt", std::ios::in);
for(int count = 0; count < 10; count++)
{
getline(file, input);
Account::setThousand(count, input);
}
file.close();
file.open("hundred.txt", std::ios::in);
for(int count = 0; count < 10; count++)
{
getline(file, input);
Account::setHundred(count, input);
}
file.close();
file.open("tens.txt", std::ios::in);
for(int count = 0; count < 9; count++)
{
getline(file, input);
Account::setTens(count, input);
}
file.close();
file.open("ones.txt", std::ios::in);
for(int count = 0; count < 10; count++)
{
getline(file, input);
Account::setOnes(count, input);
}
file.close();
do
{
std::cout<<"enter number = ";
std::cin>>num;
write.setNum(num);
write.print();
std::cout<<"do you want to print again? ";
std::cin>>choice;
}while(toupper(choice) != 'N');
}
here's the Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <string>
class Account
{
private:
static std::string lessThan20[20];
static std::string thousand[9];
static std::string hundred[9];
static std::string tens[8] ;
static std::string ones[9] ;
char data[10];
public:
void setNum(int);
void print();
void set();
static void setlessThan20(int, std::string);
static void setThousand(int, std::string);
static void setHundred(int, std::string);
static void setTens(int, std::string);
static void setOnes(int, std::string);
};
#endif
here's the Account.cpp
#include "Account.h"
#include <string>
#include <cstdlib>
#include <iostream>
void Account::setlessThan20(int a, std::string x)
{
lessThan20[a] = x;
}
void Account::setThousand(int a, std::string x)
{
thousand[a] = x;
}
void Account::setHundred(int a, std::string x)
{
hundred[a] = x;
}
void Account::setTens(int a,std::string x)
{
tens[a] = x;
}
void Account::setOnes(int a, std::string x)
{
ones[a] = x;
}
void Account::setNum(int a)
{
itoa(a, data, 10);
data[5] = '\0';
}
void Account::print()
{
int num;
char temp[3];
temp[0] = data[0];
temp[1] = '\0';
num = atoi(temp);
std::cout<<data<<std::endl;
if(num > 0)
{
num--;
std::cout<<thousand[num]<<" ";
}
temp[0] = data[1];
temp[1] = '\0';
num = atoi(temp);
if(num > 0)
{
num -=1;
std::cout<<std::endl<<hundred[num]<<" ";
}
temp[0] = data[2];
temp[1] = '\0';
num = atoi(temp);
if(num >= 2)
{
num -=2;
std::cout<<tens[num]<<" ";
temp[0] = data[3];
temp[1] = '\0';
num = atoi(temp);
num--;
std::cout<<ones[num]<<std::endl;
}
else
{
temp[0] = data[2];
temp[1] = data[3];
temp[2] = '\0';
num = atoi(temp);
std::cout<<lessThan20[num]<<std::endl;
}
}
erm, whats wrong with my code? anyone can tell?