Exactly how would I type my input file name in this program in order who it to r
ID: 3583884 • Letter: E
Question
Exactly how would I type my input file name in this program in order who it to read correctly? the file name is Ch11_ExData. Apparently i dont have it typed in my program correctly because i'm getting an error
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////file-1: addressType.h///////
#ifndef H_addressType
#define H_addressType
#include <iostream>
#include <string>
using namespace std;
class addressType
{
public:
void setStreet (string myStreet);
void setCity (string myCity);
void setState (string myState);
void setZIP (int myZIP);
string getStreet () const;
string getCity() const;
string getState() const;
int getZIP() const;
void printAddress() const;
addressType (string = " ", string = " ", string = " ", int = 0);
private:
string street;
string city;
string state;
int ZIP;
};
#endif
///////fle-2 : addressType.cpp/////
#include "addressType.h"
#include<iostream>
void addressType::setStreet(string myStreet)
{
street=myStreet;
}
void addressType::setCity(string myCity)
{
city=myCity;
}
void addressType::setState(string myState)
{
state=myState;
}
void addressType::setZIP(int myZIP)
{
ZIP=myZIP;
}
string addressType::getStreet() const
{
return street;
}
string addressType::getCity() const
{
return city;
}
string addressType::getState() const
{
return state;
}
int addressType::getZIP() const
{
return ZIP;
}
void addressType::printAddress() const
{
cout<<" "<<getStreet()<<", "<<getCity()<<" "<<getState()<<"-"<<getZIP();
}
addressType::addressType(string myStreet, string myCity, string myState, int myZIP)
{
setStreet (myStreet);
setCity (myCity);
setState(myState);
setZIP (myZIP);
}
/////file-3: dateType.h///////
#ifndef dateType_H
#define dateType_H
#include <iostream>
#include <ctime>
using namespace std;
class dateType
{
public:
void setDate (int month, int day, int year);
void getDate (int& month, int& day, int& year);
int getDay () const;
int getMonth() const;
int getYear() const;
void isLeapYear ();
void printDate () const;
dateType (int nonth=1, int day=1, int year=1900);
private:
int dMonth;
int dDay;
int dYear;
};
#endif
/////////file4: : dateType.cpp//////////////////
#include <iostream>
#include "dateType.h"
void dateType::setDate(int month, int day, int year)
{
char dateStr[9];
_strdate (dateStr);
int thisYear=2000 + (dateStr [6] - 48)*10 + dateStr[7]-48;
if ((year>=1900) && (year<=thisYear))
dYear=year;
else
dYear=1900;
if (month >=1 && month <=12)
dMonth=month;
else
dMonth=1;
int days [12]= { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (dYear % 400 == 0 || ( dYear % 100 != 0 && dYear % 4 == 0))
days [1]++;
if (day >= 1 && day <= days [dMonth - 1])
dDay= day;
else
dDay=1;
}
void dateType::getDate (int& month, int& day, int& year)
{
dMonth=month;
dDay=day;
dYear=year;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getYear() const
{
return dYear;
}
void dateType::printDate() const
{
cout<<" "<<dMonth<<"-"<<dDay<<"-"<<dYear;
}
dateType::dateType(int month, int day, int year)
{
setDate(month, day, year);
}
void dateType::isLeapYear()
{
if (dYear % 400 == 0 || (dYear % 100 != 0 && dYear % 4 == 0))
cout<<" Year"<<dYear<<"is a leap year.";
else
cout<<" Year"<<dYear<<"is not a leap year.";
}
//////file-5: personType.h/////////
#ifndef personType_H
#define personType_H
#include<iostream>
#include<string>
#include "dateType.h"
using namespace std;
class personType
{
public:
void setFirstName (string myFirstName);
void setLastName (string myLastName);
string getFirstName () const;
string getLastName () const;
void print () const;
personType (string=" ", string = " ");
private:
string firstName;
string lastName;
};
#endif
////////file-6: personType.cpp/////////
#include<iostream>
#include "personType.h"
void personType::setFirstName (string myFirstName)
{
firstName=myFirstName;
}
void personType::setLastName (string myLastName)
{
lastName=myLastName;
}
string personType::getFirstName() const
{
return firstName;
}
string personType::getLastName() const
{
return lastName;
}
void personType::print() const
{
cout<<" "<<firstName<<" "<<lastName;
}
personType::personType(string myFirstName,string myLastName)
{
setFirstName(myFirstName);
setLastName(myLastName);
}
//////file-7:extPersonType.h/////
#ifndef extPersonType_H
#define extPersonType_H
#include <iostream>
#include <string>
#include "addressType.h"
#include "personType.h"
#include "dateType.h"
using namespace std;
class extPersonType
{
public:
void print () const;
void setBirthDate (const dateType);
void getBirthDate (dateType&) const;
void setAddress (const addressType address);
void getAddress (const addressType& address) ;
void setPerson (const string, const string);
void getPerson (string&, string&) const;
void setAssociation(const string);
string getAssociation () const;
void setPhone (const string);
string getPhone () const;
void setExtPerson ( string, string, int, int, int, string, string, string, int, string, string);
extPersonType (string = " ", string = " ", int =1, int =1, int=1900, string = " ", string = " ", string = " ", int = 0, string = " ", string = " ");
private:
personType person;
dateType birthDate;
addressType myAddress;
string association;
string phone;
};
#endif
////////file-8: extPersonType.cpp////////
#include "extPersonType.h"
#include "personType.h"
#include "dateType.h"
#include "dateType.cpp"
#include "personType.cpp"
#include "addressType.h"
#include "addressType.cpp"
void extPersonType::setBirthDate(const dateType myDate)
{
birthDate.setDate (myDate.getMonth(), myDate.getDay(), myDate.getYear());
}
void extPersonType::getBirthDate (dateType& myDate) const
{
myDate.setDate(birthDate.getMonth(), birthDate.getDay(), birthDate.getYear());
}
void extPersonType::setAddress(const addressType address)
{
myAddress.setStreet(address.getStreet());
myAddress.setCity(address.getCity());
myAddress.setState(address.getState());
myAddress.setZIP(address.getZIP());
}
void extPersonType::getAddress(const addressType &address)
{
myAddress.setStreet(address.getStreet());
myAddress.setCity(address.getCity());
myAddress.setState(address.getState());
myAddress.setZIP(address.getZIP());
}
void extPersonType::print() const
{
birthDate.printDate();
person.print ();
myAddress.printAddress();
cout<<" "<<association<<", "<<phone;
}
void extPersonType::setPerson (const string first, const string last)
{
person.setFirstName(first);
person.setLastName(last);
}
void extPersonType::getPerson (string& first, string& last) const
{
first = person.getFirstName();
last=person.getLastName();
}
void extPersonType::setAssociation(const string myAssociation)
{
association=myAssociation;
}
void extPersonType::setPhone (const string myPhone)
{
phone=myPhone;
}
string extPersonType::getAssociation() const
{
return association;
}
string extPersonType::getPhone() const
{
return phone;
}
void extPersonType::setExtPerson (string first, string last, int month, int day, int year, string myStreet, string myCity, string myState, int myZIP, string asso, string ph)
{
person.setFirstName(first);
person.setLastName(last);
birthDate.setDate (month, day, year);
myAddress.setStreet (myStreet);
myAddress.setCity (myCity);
myAddress.setState (myState);
myAddress.setZIP (myZIP);
setAssociation(asso);
setPhone(ph);
}
extPersonType::extPersonType(string first, string last, int month, int day, int year, string myStreet, string myCity, string myState, int myZIP, string asso, string ph):person (first, last), birthDate (month, day, year), myAddress (myStreet, myCity, myState, myZIP)
{
setAssociation(asso);
setPhone(ph);
}
////////file-9:addressBookType.h/////////
#ifndef addressBookType_H
#define addressBookType_H
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include "extPersonType.h"
using namespace std;
const int MAX_ENTRIES = 500;
class addressBookType
{
public:
addressBookType();
void sortByLastName();
int searchByName() const;
void printAPerson () const;
void printAddressBook () const;
void printByBirthday() const;
void printNamesBetween() const;
void printAssociation() const;
private:
extPersonType persons [MAX_ENTRIES];
int ind;
void swap (int, int);
};
#endif
/////////file-10:addressBookType.cpp////////0
#include<iostream>
#include "extPersonType.h"
#include "extPersonType.cpp"
#include "addressBookType.h"
void addressBookType::swap(int m, int n)
{
string str1, str2, str3, str4;
persons [m].getPerson (str1, str2);
persons [n].getPerson (str3, str4);
persons [m].setPerson (str3, str4);
persons [n].setPerson (str1, str2);
dateType bd1, bd2;
persons [m].getBirthDate (bd1);
persons [n].getBirthDate (bd2);
persons [m].setBirthDate (bd2);
persons [n].setBirthDate (bd1);
addressType add1, add2;
persons [m].getAddress(add1);
persons [n].getAddress(add2);
persons [m].setAddress(add2);
persons [n].setAddress(add1);
str1=persons [m].getAssociation();
str2=persons [n].getAssociation();
persons[m].setAssociation(str2);
persons[n].setAssociation(str1);
str1=persons [m].getPhone();
str2=persons [n].getPhone();
persons[m].setPhone(str2);
persons[n].setPhone(str1);
}
addressBookType::addressBookType()
{
ifstream inFile;
string fileName = " ";
cout<<" Enter input file name:";
cin>>fileName;
inFile.open(Ch11_Ex5Data.c_str());
if (!inFile.is_open())
{
cout<<" Error reading in input file";
system("pause");
exit(0);
}
string strs [7];
int nums [4];
ind = 0;
while ((inFile>>strs[0]>>strs[1]>>nums[0]>>nums[1]>>nums[2]>>strs[2]>>strs[3]>>strs[4]>>nums[3]>>strs[5]>>strs[6]) != NULL)
{
persons [ind].setExtPerson(strs[0], strs[1], nums[0], nums[1], nums[2], strs[2], strs[3], strs[4], nums[3], strs [5], strs[6]);
ind++;
}
}
void addressBookType::sortByLastName()
{
int i, j, smallestInd;
string str1, str2, temp;
for (i=0; i<(ind-1); i++)
{
smallestInd=i;
for(j = i+1; j<ind; j++)
{
persons[j].getPerson(temp, str1);
persons[smallestInd].getPerson(temp, str2);
if (str1.compare(str2)<0)
smallestInd=j;
}
if (smallestInd != i)
swap(i, smallestInd);
}
}
void addressBookType::printAddressBook() const
{
for(int i=0; i<ind; i++)
{
cout<<" ";
persons[i].print();
}
}
int addressBookType::searchByName() const
{
string keyName, name, temp;
int count=0;
cout<<" Enter the last name to search:";
cin>>keyName;
for(int i=0; i<ind; i++)
{
persons[i].getPerson(temp,name);
if (keyName.compare(name)==0)
return i;
}
return -1;
}
void addressBookType::printAPerson() const
{
int result=searchByName();
if (result == -1)
cout<<" No person found as specified by you.";
else
{
cout<<" ";
persons[result].print();
}
}
void addressBookType::printByBirthday() const
{
dateType bd;
int month, count=0;
cout<<" Search address book for a given month of birthdays."<<" Please remember name is case sensitive.";
cout<<" Enter the month number (1...12):";
cin>>month;
for(int i=0; i<ind;i++)
{
persons[i].getBirthDate(bd);
if(bd.getMonth()==month)
{
cout<<" ";
persons[i].print();
count++;
}
}
if(count==0)
cout<<" No person found as specified by you.";
}
void addressBookType::printNamesBetween() const
{
string keyName1, keyName2, name, temp;
int count=0;
cout<<" Search address book between two given names."<<" Please remember name is case sensitive.";
cout<<" Enter the last name1:";
cin>>keyName1;
cout<<" Enter the last name2:";
cin>>keyName1;
if(keyName1.compare(keyName2)>0)
keyName1.swap(keyName2);
for(int i=0; i<ind; i++)
{
persons[i].getPerson(temp, name);
if((keyName1.compare(name)<=0) && (keyName2.compare(name)>=0))
{
cout<<" ";
persons[i].print();
count++;
}
}
if (count==0)
cout<<" No person found as specified by you.";
}
void addressBookType::printAssociation() const
{
string asso;
string types[3]={"Family member", "Family friend", "Business Associate"};
int choice, count=0;
cout<<" Search address book by association."<<" Please remember name is case sensitive.";
cout<<" Associatin Types";
cout<<" Family member : 1";
cout<<" Family friend : 2";
cout<<" Business Associate : 3";
cout<<" Enter the association type: ";
cin>>choice;
for (int i=0; i<ind; i++)
{
asso=persons[i].getAssociation();
if(asso.compare(types[choice-1])==0)
{
cout<<" ";
persons[i].print();
count++;
}
}
if (count==0)
cout<<" No person found as specified by you.";
}
//////////file-11: driver program(main) driver.cpp//////
#include<iostream>
#include "addressBookType.h"
#include "addressBookType.cpp"
using namespace std;
int main()
{
cout<<" A program that works with addressBookType.";
addressBookType add1;
cout<<" Before sorting, the addresses are:";
add1.printAddressBook();
add1.sortByLastName();
cout<<" After sorting, the addresses are:";
add1.printAddressBook();
if(add1.searchByName()==-1)
cout<<" No person found as specified by you.";
else
cout<<" Person found as specified by you.";
add1.printNamesBetween();
add1.printByBirthday();
add1.printAssociation();
return 0;
}
Explanation / Answer
Change the code in file AddressBookType.cpp and in methd AddressBookType constructor to read File name.
cout<<" Enter input file name:";
//cin>>fileName;
//inFile.open(Ch11_Ex5Data.c_str());
getline(cin,fileName);
inFile.open(fileName.c_str());
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.