//DEBUG3-1
//This program contains a class to hold social security numbers
//including a member function to display them with dashes
#include<iostream>
//declaration section
class SocSecNum
{
private:
int first3;
int middle2;
int last4;
static char dash='-';
public:
void getNum(const int f,const int m, const int l);
void showNum(void);
};
static char SocSecNum::dash;
// implementation section
void SocSecNum::getNum(const int f, const int m, const int l)
{
SocSecNum::first3=f;
SocSecNum::middle2 = m;
SocSecNum::last4=l;
}
void SocSecNum::showNum(void)
{
cout<<"\nSocSecNum is "<<SocSecNum::first3<<SocSecNum::dash;
cout<<SocSecNum::middle2<<SocSecNum::dash<<SocSecNum::last4<<endl;
}
ok I got it down to this for the code..but cant figure out how to declare and use the dash..I am not good with class, and inheritance stuff, please help
//DEBUG3-1
//This program contains a class to hold social security numbers
//including a member function to display them with dashes
#include<iostream>
using namespace std;
//declaration section
class SocSecNum
{
private:
int first3;
int middle2;
int last4;
static char dash;
public:
void getNum(const int f,const int m, const int l);
void showNum(void);
};
void SocSecNum::dash(char dash)
{
static char dash='-';
}
// implementation section
void SocSecNum::getNum(const int f, const int m, const int l)
{
SocSecNum::first3=f;
SocSecNum::middle2 = m;
SocSecNum::last4=l;
}
void SocSecNum::showNum(void)
{
static char dash='-';
cout<<"\nSocSecNum is "<<SocSecNum::first3<<SocSecNum::dash;
cout<<SocSecNum::middle2<<SocSecNum::dash<<SocSecNum::last4<<endl;
}
int main()
{
SocSecNum oneSocSecNum;
oneSocSecNum.getNum(333,44,5555);
oneSocSecNum.showNum();
system("pause");
Try replacing every instance of SocSecNum::dash with "-". Should work the same way. From what I can tell, you were trying to make a constant called "dash" that would display a dash when referred to... Again, "-" should work fine.