I am having problems with the validatessn function, it will always return false, or at least it seems like that is what it is doing. it also takes way too long (or at least it seems like it to me) to validate (around 10 seconds or so... running a p4 2.8 ghz) any suggestions, I know that I am going about it wrong, but my book is of no help to me on this...
Code:
// person.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
#include "person.h"
using std::cout;
using std::cin;
using std::endl;
void Get_Input (Person &tmp){
char name[100];
char lname[100];
char soc[100];
int byr,
bmo,
bdy;
bool ValidSSN;
cout <<"Input a name ";
cin >> name;
tmp.SetfName(name);
cout <<"Input a last name ";
cin >> lname;
tmp.SetlName(lname);
cout <<tmp.GetlName() << endl;
cout <<"Input a SSN (9 digits) ";
cin >> soc;
ValidSSN = tmp.validateSSN(soc);
if (ValidSSN == true)
tmp.SetSSN(soc);
else
{
cout <<"Input a SSN (9 digits) ";
cin >> soc;
ValidSSN = tmp.validateSSN(soc);
}
cout <<"Input birth year: ";
cin >> byr;
tmp.SetBirth_Year(byr);
cout <<"Input birth month (1-12): ";
cin >> bmo;
tmp.SetBirth_Month(bmo);
cout <<"Input birth day (1-31): ";
cin >> bdy;
tmp.SetBirth_Day(bdy);
}
int main() {
Person firstPerson, secondPerson;
Person workers[2];
for (int i=0; i<2; i++)
Get_Input(workers[i]);
cout << workers[i].GetfName() << endl;
return 0;
}
Code:
#ifndef Person_H
#define Person_H
class Person{
private:
char *fName;
char *lName;
char ........N;
int Birth_Year;
int Birth_Month;
int Birth_Day;
int Length;
char* value;
int findLength ();
public:
Person ();
bool validateSSN (char *soc);
void SetfName (char* first);
void SetlName (char* last);
void SetSSN (char* soc);
void SetBirth_Year (int byr);
void SetBirth_Month (int bmo);
void SetBirth_Day (int bdy);
char* GetfName ();
char* GetlName ();
char* GetSSN ();
int GetBirth_Year ();
int GetBirth_Month ();
int GetBirth_Day ();
};
#endif;
Code:
#include "stdafx.h"
#include "person.h"
using std::cout;
using std::cin;
using std::endl;
Person::Person (){
fName = "";
lName = "";
SSN = "";
Birth_Year = 0000;
Birth_Month = 00;
Birth_Day = 00;
}
int Person::findLength (){
int len = 0;
char *s=value;
for (;s!='\0'; s++, len++);
return len;
}
bool Person::validateSSN (char* soc){
value = soc;
Length = findLength();
if (Length == 9)
return true;
else
return false;
}
void Person::SetfName (char* first){
fName = first;
}
void Person::SetlName (char* last){
lName = last;
}
void Person::SetSSN (char* soc){
SSN = soc;
}
void Person::SetBirth_Year (int byr){
Birth_Year = byr;
}
void Person::SetBirth_Month (int bmo){
Birth_Month = bmo;
}
void Person::SetBirth_Day (int bdy){
Birth_Day = bdy;
}
char* Person::GetfName (){
return fName;
}
char* Person::GetlName (){
return lName;
}
char* Person::GetSSN (){
return SSN;
}
int Person::GetBirth_Year (){
return Birth_Year;
}
int Person::GetBirth_Month (){
return Birth_Month;
}
int Person::GetBirth_Day (){
return Birth_Day;
}