unknown error. Please help

Following is the code. Error occurs in reading the file somewhere I guess but I am not sure Please help me out of this.



#include<iostream>
#include<fstream>
#include<string>

using namespace std;

class personType
{
public:
void print() const;
void setName(string first, string second);
void getName(string& first, string& last);
personType(string first, string last);
personType();

private:
string firstName;
string lastName;
};

void personType::print() const
{
cout<<firstName<<" "<<lastName;
}
void personType::setName(string first, string last)
{
firstName = first;
lastName = last;
}
void personType::getName(string& first, string& last)
{
first = firstName;
last = lastName;
}
personType::personType(string first, string last)
{
firstName = first;
lastName = last;
}
personType::personType()
{
firstName = "";
lastName = "";
}


class dateType
{
public:
void setDate(int month, int day, int year);
void getDate(int& month, int& day, int& year);
void printDate() const;
dateType(int month, int day, int year);
dateType();

private:
int dMonth;
int dDay;
int dYear;
};

void dateType::setDate(int month, int day, int year)
{
dMonth = month;
dDay = day;
dYear = year;
}

void dateType::getDate(int& month, int& day, int& year)
{
month = dMonth;
day = dDay;
year = dYear;
}

void dateType::printDate() const
{
cout<<dMonth<<"-"<<dDay<<"-"<<dYear<<endl;
}

dateType::dateType(int month, int day, int year)
{
dMonth = month;
dDay = day;
dYear = year;
}

dateType::dateType()
{
dMonth = 1;
dDay = 1;
dYear = 1900;
}

class addressType
{
public:
void setAddr(string, string, string, long);
void getAddr(string&, string&, string&, long&);
void printAdd() const;
addressType(string="", string="", string="", long=0);

private:
string strAddr;
string city;
string state;
long zip;
};

class extPersonType: public addressType, public personType, public dateType
{
public:
void setPhNo(long);
void getPhNo(long&);
void printPhNo() const;
void setMemT(string);
void getMemT(string&);
void printMemT() const;
extPersonType(string a="", string b="", int c=0, int d=0, int e=0, string f="", string g=""
, string h="", long i=0, long j=0, string k="");

private:
long phoneNo;
string memT;
};

class addressBookType: public extPersonType
{}addressBook[3], addressBookTemp;

void addressType::setAddr(string a, string b, string c, long d)
{
strAddr = a;
city = b;
state = c;
zip = d;
}

void addressType::getAddr(string& addr, string& cit, string& stat, long& z)
{
addr = strAddr;
cit = city;
stat = state;
z = zip;
}

void addressType::printAdd() const
{
cout<<"Street Address: "<<strAddr<<endl
<<"City: "<<city<<endl
<<"State: "<<state<<endl
<<"Zip: "<<zip<<endl;
}

addressType::addressType(string a, string b, string c, long d)
{
strAddr = a;
city = b;
state = c;
zip = d;
}

void extPersonType::setPhNo(long a)
{
phoneNo = a;
}

void extPersonType::getPhNo(long& a)
{
a = phoneNo;
}

void extPersonType::printPhNo() const
{
cout<<"Phone No: "<<phoneNo<<endl;
}

void extPersonType::setMemT(string a)
{
memT = a;
}

void extPersonType::getMemT(string& b)
{
b = memT;
}

void extPersonType::printMemT() const
{
cout<<"Member relation: "
<<memT<<endl;
}

extPersonType::extPersonType(string a, string b, int c, int d, int e, string f,
string g, string h, long i, long j, string k)
: personType(a,b), dateType(c,d,e), addressType(f,g,h,i)
{
phoneNo = j;
memT = k;
}

void loadData();
void sortAddressBook();
short searchPerson(string);
bool searchFunction(string, string);
void printAPB();
void nameBPeople();
bool dBirthFunction(short, short, short, short, short, short, short);
void printBName();
void printRName();
void userRequestName();
int main()
{
loadData(); //Here is some error I think but I m not sure
cout<<"***Sample of loadData function***"<<endl;
addressBook[0].print();
sortAddressBook();
cout<<"***Sample sortAddressBook function***"<<endl;
for(short i=0; i<2; i++)
addressBook[i].print();
cout<<"**************************************"<<endl;
string a;
cout<<"Please enter the last name of the person"<<endl
<<"you are looking for: ";
cin>>a;
if(searchPerson(a))
cout<<"Search person not found."<<endl;
else
{
cout<<"Person found"<<endl;
addressBook[searchPerson(a)].print();
}
printAPB();
cout<<"***Search people by birthday***"<<endl;
nameBPeople();
cout<<"***Print names between two last names***"<<endl;
printBName();
cout<<"***User request names***"<<endl;
userRequestName();

system("pause");

return 0;
}

void loadData()
{
string a,b,f,g,h,k;
int c,d,e;
long i,j;
ifstream inPut("addressBook.txt");
if(inPut.is_open())
{
cout<<"File opened"<<endl;
short l=0;
while(!inPut.eof())
{
inPut>>a>>b>>c>>d
>>e>>f>>g>>h
>>i>>j>>k;
addressBook[l].setName(a,b);
addressBook[l].setDate(c,d,e);
addressBook[l].setAddr(f,g,h,i);
addressBook[l].setPhNo(j);
addressBook[l].setMemT(k);
l++;
}
inPut.close();
}
else
{
cout<<"File addressBook.txt not found."<<endl
<<"Program will terminate now"<<endl;
}
}

void sortAddressBook()
{
string a, last1, last2;
for(int i=0; i<3-1; i++)
{
addressBook[i].getName(a, last1);
for(int j=i+1; j<3; j++)
{
addressBook[j].getName(a, last2);
if(static_cast<int>(last1[0])>static_cast<int>(last2[0]))
{
addressBookTemp = addressBook[i];
addressBook[i]= addressBook[j];
addressBook[j]=addressBookTemp;
}
}
}
}

short searchPerson(string a)
{
string b, last;
for(int i=0; i<3; i++)
{
addressBook[i].getName(b, last);
if(searchFunction(last, a))
{
cout<<"Name exists";
return i;
}
}
cout<<"Name not found."<<endl;
return 0;
}

bool searchFunction(string a, string b)
{
if(a.size() != b.size())
return 0;
for(short j=0; j<=b.size(); j++)
if(a[j] != b[j])
return 0;
return 1;
}

void printAPB()
{
string a;
cout<<"Enter the last name of the person"<<endl
<<"whose address, phone and date of "<<endl
<<"birth is required: ";
cin>>a;
if(!searchPerson(a)==0)
cout<<"Information about required person"<<endl
<<"not found"<<endl;
else
{
addressBook[searchPerson(a)].printAdd();
addressBook[searchPerson(a)].printPhNo();
addressBook[searchPerson(a)].printDate();
}

}

void nameBPeople()
{
short m1,d1,y1,m2,d2,y2;
cout<<"Enter first month, day and year: ";
cin>>m1>>d1>>y1;
cout<<"Enter second month, day and year: ";
cin>>m2>>d2>>y2;
for(short i=0; i<3; i++)
if(dBirthFunction(m1,d1,y1,m2,d2,y2,i))
addressBook[i].print();
}

bool dBirthFunction(short m1, short d1, short y1, short m2,
short d2, short y2, short i)
{
int m,d,y;
addressBook[i].getDate(m,d,y);
if(m>m1 && m<m2 && d>d1 && d<d2 && y>y1 && y<y2)
return 1;
else
return 0;
}

void printBName()
{
string ist, second, temp, a;
cout<<"Enter the first last name: ";
cin>>ist;
cout<<"Enter the second last name: ";
cin>>second;
if(static_cast<int>(ist[0]) > static_cast<int>(second[0]))
{
temp = ist;
ist = second;
second = temp;
}
bool start = 0;
for(short i=0; i<3; i++)
{
addressBook[i].getName(a, temp);
if(searchFunction(temp, ist) || start)
{
if(!start)
start =1;
addressBook[i].print();
if(searchFunction(temp, second))
start = 0;
}
}
}

void printRName(string a)
{
string b;
for(short i=0; i<3; i++)
{
addressBook[i].getMemT(b);
if(searchFunction(b,a))
addressBook[i].print();
}
}

void userRequestName()
{
short r;
string temp;
cout<<"Please choose one option and press enter:"<<endl
<<"0) Print family names"<<endl
<<"1) Print friends names"<<endl
<<"2) Print business names"<<endl;
cin>>r;
if(!r)
{
temp = "family";
printRName(temp);
}
else if(r==1)
{
temp = "friend";
printRName(temp);
}
else if(r==2)
{
temp = "business";
printRName(temp);
}
}


//Following is the text file

waqas
imtiaz
9
1
1985
asfklajsj
lahore
punjab
54000
5244856624
family
yasir
imtiaz
10
29
1983
asdfasde
lahore
punjab
54000
454835663
family
meow
imtiaz
11
30
1945
asfasdae
lahore
punjab
54000
4521554886
family
Last edited on
Topic archived. No new replies allowed.