private: extPersonType list[500];becuase the main reason for doing this is to over come that limit imposed there. Im not sure what all code would be helpful so Ill post the main that the type first.
Here is the code as it stands
//Address Book Main
#include <iostream>
#include <fstream>
#include <string>
#include "addressBookType.h"
using namespace std;
void loadAddressBook(addressBookType& adBook);
void saveData(addressBookType& adBook);
void addEntry(addressBookType& adBook);
void deleteEntry(addressBookType& adBook);
void showMenu();
int main()
{
addressBookType addressBook;
string str;
string str1;
string str2;
int choice;
int loc;
int month;
loadAddressBook(addressBook);
addressBook.sort();
showMenu();
cin >> choice;
cin.ignore(100, '\n');
while (choice != 0)
{
switch (choice)
{
case 1:
cout << "Enter the last name of the person: ";
getline(cin , str);
cout << endl;
loc = addressBook.search(str);
if (loc != -1)
cout << str << " is in the address book" << endl;
else
cout << str << " is not in the address book" << endl;
break;
case 2:
cout << "Enter the last name of the person: ";
getline(cin , str);
cout << endl;
loc = addressBook.search(str);
if (loc != -1)
addressBook.printAt(loc);
else
cout << str << " is not in the address book" << endl;
break;
case 3:
cout << "Enter the month number: ";
cin >> month;
cin.ignore(100, '\n');
cout << endl;
addressBook.printNameInTheMonth(month);
break;
case 4:
cout << "Enter starting last name: ";
getline(cin , str1);
cout << endl;
cout << "Enter ending last name: ";
getline(cin , str2);
cout << endl;
addressBook.printNamesBetweenLastNames(str1, str2);
break;
case 5:
cout << "Enter person type Family, Friend, Business: ";
getline(cin , str);
cout << endl;
addressBook.printNamesWithStatus(str);
break;
case 6:
addressBook.print();
break;
case 7:
saveData(addressBook);
break;
default:
cout << "Invalid choice" << endl;
//problem 1a setting up the menu
case 8:
addEntry(addressBook);
break;
default:
cout << "Invalid choice" << endl;
case 9:
deleteEntry(addressBook);
break;
default:
cout << "Invalid choice" << endl;
//end addition for problem 1a
}
showMenu();
cin >> choice;
cin.ignore(100, '\n');
}
char response;
cout << "Save data Yes (Y/y) No(N/n)?: ";
cin >> response;
cout << endl;
if (response == 'y' || response == 'Y')
saveData(addressBook);
//problem 1b save on exit
outfile.open(filename);
if (!outfile)
{
cout << "Output file does not exists. "
<< "Program terminates!!!" << endl;
return;
}
adBook.saveData(outfile)
//end problem 1b
return 0;
}
void loadAddressBook(addressBookType& adBook)
{
ifstream infile;
char filename[50];
string first;
string last;
int month;
int day;
int year;
string street;
string city;
string state;
string zip;
string phone;
string pStatus;
extPersonType temp;
cout << "Enter file name: ";
cin >> filename;
cout << endl;
infile.open(filename);
if (!infile)
{
cout << "Input file does not exists. "
<< "Program terminates!!!" << endl;
exit(0);
}
int i = 0;
infile >> first >> last >> month >> day >> year;
infile.ignore(100,'\n');
getline(infile,street);
getline(infile,city);
getline(infile, state);
infile >> zip >> phone >> pStatus;
while (infile)
{
temp.setInfo(first, last, month, day, year, street, city,
state, zip, phone, pStatus);
adBook.insertAt(temp, i);
i++;
infile >> first >> last >> month >> day >> year;
infile.ignore(100, '\n');
getline(infile, street);
getline(infile, city);
getline(infile, state);
infile >> zip >> phone >> pStatus;
}
}
void saveData(addressBookType& adBook)
{
ofstream outfile;
char filename[50];
cout << "Enter file name: ";
cin >> filename;
cout << endl;
outfile.open(filename);
if (!outfile)
{
cout << "Output file does not exists. "
<< "Program terminates!!!" << endl;
return;
}
adBook.saveData(outfile);
}
//problem 1a
void addEntry(addressBookType& adBook)
{
}
void deleteEntry(addressBookType& adBook)
{
}
//end problem 1a
void showMenu()
{
cout << "Welcome to the address book program." << endl;
cout << "Choose among the following options:" << endl;
cout << "1: To see if a person is in the address book"
<< endl;
cout << "2: Print the information of a person" << endl;
cout << "3: Print the names of person having birthday in "
<< "a particular month" << endl;
cout << "4: Print the names of persons between two "
<< "last names" << endl;
cout << "5: Print the names of persons having a "
<< "particular status" << endl;
cout << "6: Print the address book" << endl;
cout << "7: Save data" << endl;
cout << "8: Add Entry" << endl;
cout << "9: Delete Entry" << endl;
cout << "0: Terminate the program" << endl;
and the type
//addressBookType.h
#ifndef H_addressBookType
#define H_addressBookType
#include <string>
#include <fstream>
#include "extPersonType.h"
using namespace std;
class addressBookType
{
public:
void print() const;
void printNameInTheMonth(int month);
void printInfoOf(string lName);
void printNamesWithStatus(string status);
void printAt(int i);
void printNamesBetweenLastNames(string last1, string last2);
void insertAt(const extPersonType& eP, int i);
void insertLast(const extPersonType& eP);
int search(string lName);
void sort();
void saveData(ofstream&);
addressBookType();
private:
extPersonType list[500];
int length;
};
#endif
any help or suggestions would be apprciated

New Topic/Question
This topic is locked




MultiQuote


|