Hello everyone, this is my very first post in this webpage so here we go.
I've got this problem with my hw assignment, it's almost finished except for one part.
The hw is as follows:
- Create an address book, creating 4 text files in the computer memory. Each text file belong to each of the categories: Classmates Contacts, Colleagues, Friends and Family.
-The address book must be able to:
*add new contact [done]
*delete contact [done]
*edit contact [where the problem is...]
*show contacts [done]
*search contacts [done]
*sort contact[done]
The problem is in editing a contact. When i run my program and input a name to check if the contact exists to be edited, no matter if i input a name that matched with those of my contacts, it shows as if it doesn't match.
if someone can help me...:S
here is my code, kinda long...
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <Windows.h>
using namespace std;
class Date
{ int YY, MM, DD, DOW, sday, smonth, syear;
static int sdaynum, daynum;
char *dow;
public:
Date(int yy=0, int mm=0, int dd=0 ); //Constructor function, gets the year, month and day from a certain date
void getSysDate (); //Gets the system date (Date from the computer)
void printSysDate(); //Prints out the system date
char *getDayOfWeek(); //From a date, returns a char variable that gives if the date is Sunday, Monday, etc
int getSysDayNum(); //From the system date, returns a int variable that gives which day of the year it is
int getDayNum(); //From a date, returns a int variable that gives which day of the year it is
int getSysMonth(); //Returns the month of the system
};
Date::Date(int year, int month, int day)
{ YY = year; MM = month; DD = day;
}
int Date::sdaynum = 0; //Static integer 'sdaynum', set to 0
int Date::daynum = 0; //Static integer 'daynum', set to 0
void Date::getSysDate()
{ SYSTEMTIME st; //Systemtime struct, automatically define by system
GetSystemTime(&st);
syear = st.wYear;
smonth = st.wMonth;
sday = st.wDay;
}
void Date::printSysDate()
{
cout << "Today is: "<< sday << "/" << smonth << "/" << syear << endl;
}
char *Date::getDayOfWeek()
{
if (MM < 3)
{ MM = MM + 12;
YY = YY - 1;
}
DOW = ( DD + (2 * MM) + int(6 * (MM + 1) / 10) + YY + int(YY / 4) - int(YY / 100) + int(YY / 400) + 1) % 7;
switch (DOW)
{ case 0: dow = "Sun"; break;
case 1: dow = "Mon"; break;
case 2: dow = "Tue"; break;
case 3: dow = "Wed"; break;
case 4: dow = "Thu"; break;
case 5: dow = "Fri"; break;
case 6: dow = "Sat"; break;
}
return dow;
}
int Date::getSysDayNum()
{
switch (smonth)
{ case 1: sdaynum = sday; break;
case 2: sdaynum = sday + 31; break;
case 3: sdaynum = sday + 59; break;
case 4: sdaynum = sday + 90; break;
case 5: sdaynum = sday + 120; break;
case 6: sdaynum = sday + 151; break;
case 7: sdaynum = sday + 181; break;
case 8: sdaynum = sday + 212; break;
case 9: sdaynum = sday + 243; break;
case 10: sdaynum = sday + 273; break;
case 11: sdaynum = sday + 304; break;
case 12: sdaynum = sday + 334; break;
default: return 0;
}
if ((syear % 4 == 0 && syear % 100 != 0) || syear % 400 == 0)
{ if ((smonth != 1) && (smonth!=2))
{sdaynum = sdaynum+1;}
}
return sdaynum;
}
int Date::getDayNum()
{
switch (MM)
{ case 1: daynum = DD; break;
case 2: daynum = DD + 31; break;
case 3: daynum = DD + 59; break;
case 4: daynum = DD + 90; break;
case 5: daynum = DD + 120; break;
case 6: daynum = DD + 151; break;
case 7: daynum = DD + 181; break;
case 8: daynum = DD + 212; break;
case 9: daynum = DD + 243; break;
case 10: daynum = DD + 273; break;
case 11: daynum = DD + 304; break;
case 12: daynum = DD + 334; break;
default: return 0;
}
if (smonth == 12 && MM == 1 )
{ daynum = daynum + 365;
}
if ((YY%4 == 0 && YY%100 != 0) || YY%400 == 0)
{ if ((MM != 1) && (MM!=2))
{ daynum = daynum+1;}
}
return daynum;
}
int Date::getSysMonth()
{ return smonth;
}
//Contact class
class Contact
{ public:
Contact(); //Constructor Function
void CreateAddressBooks(); //Creates address books
virtual char Menu();//Displays main menu
virtual void Title();
void Help();
protected:
char *name, *tel, *email, *special;
int yy, mm, dd;
Contact *next;
char mopt;
};
Contact::Contact()
{
name = "";
tel = "";
email = "";
special = "";
yy = 0;
mm = 0;
dd = 0;
}
void Contact::CreateAddressBooks()
{
char file1[20]="d:\\AddressBook1.txt", file2[20]="d:\\AddressBook2.txt", file3[20]="d:\\AddressBook3.txt", file4[20]="d:\\AddressBook4.txt";
ofstream outstuf;
ifstream instuf1(file1, ios::in);
if (!instuf1)
{
cout << "Creating AddressBook1" << endl;
outstuf.open(file1, ios::out);
outstuf.close();
}
ifstream instuf2(file2, ios::in);
if (!instuf2)
{
cout << "Creating AddressBook2" << endl;
outstuf.open(file2, ios::out);
outstuf.close();
}
ifstream instuf3(file3, ios::in);
if (!instuf3)
{
cout << "Creating AddressBook3" << endl;
outstuf.open(file3, ios::out);
outstuf.close();
}
ifstream instuf4(file4, ios::in);
if (!instuf4)
{
cout << "Creating AddressBook4" << endl;
outstuf.open(file4, ios::out);
outstuf.close();
}
}
char Contact::Menu()
{ system ("cls");
Date d;
d.getSysDate();
d.printSysDate();
cout << "*******************************************" << endl
<< "* Please select action to perform *" << endl
<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" << endl
<< "* [1] Add Contact || [5] Search *" << endl
<< "* [2] Delete Contact || [6] Sort *" << endl
<< "* [3] Edit Contact || [7] Help&Info *" << endl
<< "* [4] Show Contacts || [Other] Exit *" << endl
<< "*******************************************" << endl;
cout << "Enter option: ";
cin >> mopt;
return mopt;
}
void Contact::Title()
{ system("cls");
cout << left << setw(15) << "Name" << "Birthday" << " " << setw(12) << "Telephone" << setw(25) << "E-mail" << setw(17) << "Other";
}
void Contact::Help()
{ system("cls");
cout << " Thanks for using our Address Book App! \n"
<< endl
<< "----------------------------------ABOUT--------------------------------------\n"
<< "This app is created by Antonio Wu Lin.\n"
<< "This app is for personal use only, not for commercial use.\n"
<< "Current version: AB 1.0 Beta\n"
<< "Updates will be available in the future\n"
<< endl
<< "-------------------------------INFORMATION-----------------------------------\n"
<< " *****Main Menu*****\n"
<< "The main menu appears automatically when the app is executed.\n"
<< "It offers 8 options to choose: \n"
<< "1. Add a new contact.\n"
<< "2. Delete an exist contact\n"
<< "3. Edit an existing contact\n"
<< "4. Show existing contacts\n"
<< "5. Search for an existing contact\n"
<< "6. Sort existing contacts\n"
<< "7. Open the Help & Info Guide\n"
<< "8. Exit the app\n"
<< endl
<< " *****Adding a new contact*****\n"
<< "This is the first option available in our app.\n"
<< "Allows the user to add a new contact to the address books.\n"
<< "When this option is chosen, the submenu will open.\n"
<< "After the menu is open, we can choose to add a contact in any of the four \n"
<< "categories: Classmates, Colleagues, Friends or Family. Also there is a option\n"
<< "to go back to main menu or exit the app.\n"
<< "To add a contact, the user must input the name, birthday, telephone number,\n"
<< "email and a different field for each of the categories:\n"
<< "Classmates: School that attended together\n"
<< "Colleagues: Company that worked together in\n"
<< "Friends: Place of first meeting\n"
<< "Family: Relationship with the contact\n"
<< endl
<< " *****Deleting a contact*****\n"
<< "To delete a contact, the app will ask the user to input the name of the contact\n"
<< "to be deleted. If the name matches with any of the contact names, it will\n"
<< "delete the contact automatically. After deleting, the app will ask the user if\n"
<< "he/she wants to continue deleting. If yes, the user inputs a new name. If no,\n"
<< "app returns to the Main Menu.\n"
<< endl
<< " *****Editing a contact*****\n"
<< "To edit a contact, the app will ask the user to input the name of the contact\n"
<< "to be edited. If the name matches with any of the existing contacts' name, it\n"
<< "will open a new interface. The new interface will allow the user to edit only\n"
<< "the telephone number, email and the special field of the existing contacts.\n"
<< endl
<< " *****Show contacts*****\n"
<< "Shows the existing contact of the address books to the user. Afte chooseing \n"
<< "this option, the submenu will appear. There are five choices available to \n"
<< "the user: show all or show classmates, colleagues, friends or family contacts.\n"
<< endl
<< " *****Search a contact*****\n"
<< "Option to search for a existing contacts from the address books. There are four\n"
<< "ways to search for a contact: \n"
<< "By name: Asks users to input a name, after that the app will search for the \n"
<< " ways and automatically shows the contact to the user. \n"
<< "By birthday: Asks users to input a date, after that the app will search for the\n"
<< " contacts and automatically shows the contact to the user. \n"
<< "Birthday in 5 days: Automatically searches for the contacts that are having \n"
<< " their birthdays within 5 days of the current date and shows\n"
<< " them to the user. \n"
<< " Automatically sends email to these contacts\n"
<< "Birthday in current month: Automatically searches for contacts having birthday \n"
<< " within current month and shows them to the user. \n"
<< endl
<< " *****Sort contacts*****\n"
<< "Sorts and displays contact alphabetically by their name. Upper case letters \n"
<< "first and then lower case ones. Can sort all the contacts or by any of their\n"
<< "categories. \n"<< endl;
}
//NewContact class, inherit from Contact
//Function: Create contacts and saves them to the address books
class NewContact:public Contact
{ public:
char Menu(); //Displays menu of new contact
void AddContact(); //Enters information of the contact
void SaveClassmate(); //Saves the contact to d:\\AddressBook1, Classmates category
void SaveColleague(); //Saves the contact to d:\\AddressBook2, Colleagues category
void SaveFriend(); //Saves the contact to d:\\AddressBook3, Friends category
void SaveFamily(); //Saves the contact to d:\\AddressBook4, Family category
protected:
string name, tel, email, special;
int yy, mm, dd;
char mopt;
};
char NewContact::Menu()
{
//Date & Menu
system ("cls");
cout << "*******************************************" << endl
<< "* Select category to add new contact: *" << endl
<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" << endl
<< "* [1] Classmates || [4] Family *" << endl
<< "* [2] Colleagues || [5] Back *" << endl
<< "* [3] Friends || [Other] Exit *" << endl
<< "*******************************************" << endl;
cout << "Enter option: ";
cin >> mopt;
return mopt;
}
void NewContact::AddContact()
{ system ("cls");
cout <<endl <<"Enter the following information:" <<endl <<endl
<<"Name: " ;
cin >> name;
cout <<"Birthday: "
<<"Year: ";
cin >> yy;
cout << "Month: ";
cin >> mm;
cout << "Day: ";
cin >> dd;
cout << "Telephone: ";
cin >> tel;
cout << "Email: ";
cin >> email;
if (mopt == '1')
{ cout << "School: ";
cin >> special;
SaveClassmate();
}
if (mopt == '2')
{ cout << "Company: ";
cin >> special;
SaveColleague();
}
if (mopt == '3')
{ cout << "First meeting: ";
cin >> special;
SaveFriend();
}
if (mopt == '4')
{ cout << "Relantionship: ";
cin >> special;
SaveFamily();
}
}
void NewContact::SaveClassmate()
{ ofstream outstuf;
outstuf.open("d:\\AddressBook1.txt",ios::app);
outstuf << left << setw(15) << name
<< yy << " " << setw(2) << mm << " " <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
outstuf.close();
}
void NewContact::SaveColleague()
{ ofstream outstuf;
outstuf.open("d:\\AddressBook2.txt",ios::app);
outstuf << left << setw(15) << name
<< yy << " " << setw(2) << mm << " " <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
outstuf.close();
}
void NewContact::SaveFriend()
{ ofstream outstuf;
outstuf.open("d:\\AddressBook3.txt",ios::app);
outstuf << left << setw(15) << name
<< yy << " " << setw(2) << mm << " " <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
outstuf.close();
}
void NewContact::SaveFamily()
{ ofstream outstuf;
outstuf.open("d:\\AddressBook4.txt",ios::app);
outstuf << left << setw(15) << name
<< yy << " " << setw(2) << mm << " " <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
outstuf.close();
}
//DeleteContact class, inherit from Contact
//Function: Delete contacts from the address books
class DeleteContact:public Contact
{ public:
void EnterInfo(); //Enter name of the person to be deleted
void getDelName(string n); //Gets a name to be compared and deleted
void DeleteClassmate(); //Search in AddressBook1.txt and deletes contact if matched the name
void DeleteColleague(); //Search in AddressBook2.txt and deletes contact if matched the name
void DeleteFriend(); //Search in AddressBook3.txt and deletes contact if matched the name
void DeleteFamily(); //Search in AddressBook4.txt and deletes contact if matched the name
void printNo(); //Prints no matches if no contacts can be found
private:
string name, tel, email, special, delname;
int yy, mm, dd;
static int counter;
};
int DeleteContact::counter=0;
void DeleteContact::EnterInfo()
{ system("cls");
cout << "Enter name of contact to be deleted: ";
cin >> delname;
}
void DeleteContact::getDelName(string n)
{ delname = n;
}
void DeleteContact::DeleteClassmate()
{ string str;
ofstream outstuf("d:\\Delete.txt", ios::out);
ifstream instuf("d:\\AddressBook3.txt", ios::in); //
while (instuf >> name )
{ getline(instuf, str);
if (delname==name)
{ cout << "Deleting in Classmates Address Book:" << endl;
cout << name << str <<endl;
counter++;
}
outstuf << name << str <<endl;
}
while (getline(instuf, str))
{ outstuf <<str <<endl;
}
outstuf.close();
instuf.close();
ofstream outstuf1("d:\\AddressBook3.txt", ios::out);
ifstream instuf1("d:\\Delete.txt", ios::in);
while (getline(instuf1, str))
{ outstuf1 <<str <<endl;
}
outstuf1.close();
instuf1.close();
}
void DeleteContact::DeleteColleague()
{ string str;
ofstream outstuf("d:\\Delete.txt", ios::out);
ifstream instuf("d:\\AddressBook2.txt", ios::in); //
while (instuf >> name )
{ getline(instuf, str);
if (delname==name)
{ cout << "Deleting in Classmates Address Book:" << endl;
cout << name << str <<endl;
counter++;
}
outstuf << name << str <<endl;
}
while (getline(instuf, str))
{ outstuf <<str <<endl;
}
outstuf.close();
instuf.close();
ofstream outstuf1("d:\\AddressBook2.txt", ios::out);
ifstream instuf1("d:\\Delete.txt", ios::in);
while (getline(instuf1, str))
{ outstuf1 <<str <<endl;
}
outstuf1.close();
instuf1.close();
}
void DeleteContact::DeleteFriend()
{ string str;
ofstream outstuf("d:\\Delete.txt", ios::out);
ifstream instuf("d:\\AddressBook1.txt", ios::in); //
while (instuf >> name )
{ getline(instuf, str);
if (delname==name)
{ cout << "Deleting in Classmates Address Book:" << endl;
cout << name << str <<endl;
counter++;
}
outstuf << name << str <<endl;
}
while (getline(instuf, str))
{ outstuf <<str <<endl;
}
outstuf.close();
instuf.close();
ofstream outstuf1("d:\\AddressBook1.txt", ios::out);
ifstream instuf1("d:\\Delete.txt", ios::in);
while (getline(instuf1, str))
{ outstuf1 <<str <<endl;
}
outstuf1.close();
instuf1.close();
}
void DeleteContact::DeleteFamily()
{ string str;
ofstream outstuf("d:\\Delete.txt", ios::out);
ifstream instuf("d:\\AddressBook14.txt", ios::in); //
while (instuf >> name )
{ getline(instuf, str);
if (delname==name)
{ cout << "Deleting in Classmates Address Book:" << endl;
cout << name << str <<endl;
counter++;
}
outstuf << name << str <<endl;
}
while (getline(instuf, str))
{ outstuf <<str <<endl;
}
outstuf.close();
instuf.close();
ofstream outstuf1("d:\\AddressBook4.txt", ios::out);
ifstream instuf1("d:\\Delete.txt", ios::in);
while (getline(instuf1, str))
{ outstuf1 <<str <<endl;
}
outstuf1.close();
instuf1.close();
}
void DeleteContact::printNo()
{ if (counter==0) {cout<< "No matches" << endl;}
}
//EditContact class, inherited from Contact class
//Function: Edit an existing contact from the Address Books
// Can only edit telephone, email and depending on the category: school, company, first meeting or relationship
class EditContact:public Contact
{ public:
string EnterName();
string getName();
string getTel();
string getEmail();
string getSP();
friend void EditInfo(EditContact *head);
protected:
string name, tel, email, special, fname;
int yy, mm, dd, nd, nm, ny;
char mopt;
EditContact *next;
};
string EditContact::getName()
{ return name;
}
string EditContact::getTel()
{ return tel;
}
string EditContact::getEmail()
{ return email;
}
string EditContact::getSP()
{ return special;
}
string EditContact::EnterName()
{ system("cls");
cout << "Enter name of contact to be edited: ";
cin >> fname;
return fname;
}
void EditInfo(EditContact *head)
{ string N;
EditContact EC;
N=EC.EnterName();
EditContact *p=head,*s;
ifstream instuf;
instuf.open("d:\\AddressBook1.txt",ios::in);
s=new EditContact;
while(instuf>>s->getName())
{ cout << s->getName();
if(s->getName()== N)
{ instuf >>s->yy >>s->mm>> s->dd >>s->getTel() >>s->getEmail() >> s->getSP();
cout << "Enter the following information:";
cout << "New telephone: ";
cin >> s->getTel ();
cout << "New Email: ";
cin >> s->getEmail ();
cout << "New school: ";
cin >> s->getSP() ;
}
if(head==NULL) head=s,p=head;
else p->next=s;
p=s;
s=new EditContact;
}
p->next =NULL;
delete s;
ofstream outstuf;
outstuf.open("AddressBook1.txt",ios::out);
while (head)
{ outstuf << left << setw(15) << head->getName()
<< head->yy<<" "<<head->mm<<" "<<head->dd
<< setw(12) << head->getTel()
<< setw(25) << head->getEmail()
<< setw(17) << head->getSP()<<endl ;
head=head->next ;
}
outstuf.close ();
instuf.close();
}
//ShowContact class, inherit from Contact
//Function: Show contacts from the address books
class ShowContact:public Contact
{ public:
char Menu(); //Displays menu to the user
void ShowClassmate(); //Show all the contacts in AddressBook1.txt
void ShowColleague(); //Show all the contacts in AddressBook2.txt
void ShowFriend(); //Show all the contacts in AddressBook3.txt
void ShowFamily(); //Show all the contacts in AddressBook4.txt
private:
char name, tel, email, special;
int yy, mm, dd;
char mopt;
static int counter;
};
int ShowContact::counter=0;
char ShowContact::Menu()
{
system ("cls");
cout << "*******************************************" << endl
<< "* Select to show: *" << endl
<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" << endl
<< "* [1] All || [5] Family *" << endl
<< "* [2] Classmates || [6] Back *" << endl
<< "* [3] Colleagues || [Other] Exit *" << endl
<< "* [4] Friends || *" << endl
<< "*******************************************" << endl;
cout << "Enter option: ";
cin >> mopt;
return mopt;
}
void ShowContact::ShowClassmate()
{ ifstream instuf("d:\\AddressBook1.txt",ios::in);
string s;
while (getline(instuf, s))
{ cout << s << endl;
counter++;
}
instuf.close();
}
void ShowContact::ShowColleague()
{ ifstream instuf("d:\\AddressBook2.txt",ios::in);
string s;
while (getline(instuf,s))
{ cout << s << endl;
counter++;
}
instuf.close();
}
void ShowContact::ShowFriend()
{ ifstream instuf("d:\\AddressBook3.txt",ios::in);
string s;
while (getline(instuf,s))
{ cout << s << endl;
counter++;
}
instuf.close();
}
void ShowContact::ShowFamily()
{ ifstream instuf("d:\\AddressBook4.txt",ios::in);
string s;
while (getline(instuf,s))
{ cout << s << endl;
counter++;
}
instuf.close();
}
//SearchContact class, inherited from Contact
//Function: Search contacts from the address books
class SearchContact:public Contact
{ public:
char Menu();
void EnterName(); //Enter name of person to search
void EnterBday(); //Enter a specific date to search
void ByName(); //Search contacts matching the search name
void ByBday(); //Search contacts matching the search date
void BdayFiveDays(); //Search contacts that have birthdays within 5 days of system date
void BdayMonth(); //Search contacts that have birthdays within the current month
void printNo(); //Print no matches if names and dates don't match
private:
string name, tel, email, special, seaname;
int yy, mm, dd, month, day;
static int counter;
char mopt;
};
int SearchContact::counter=0;
char SearchContact::Menu()
{ system("cls");
cout << "*******************************************" << endl
<< "* Select to search by: *" << endl
<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" << endl
<< "* [1] Name *" << endl
<< "* [2] Birthday *" << endl
<< "* [3] Birthday within 5 days *" << endl
<< "* [4] Birthday within current month *" << endl
<< "* [5] Back *" << endl
<< "* [Other] Exit *" << endl
<< "*******************************************" << endl;
cout << "Enter option: ";
cin >> mopt;
return mopt;
}
void SearchContact::EnterName()
{ system("cls");
cout << "Enter name: ";
cin >> seaname;
}
void SearchContact::EnterBday()
{ system("cls");
cout << "Enter month: ";
cin >> month;
cout << "Enter day: ";
cin >> day;
}
void SearchContact::ByName()
{ system("cls");
string s1, s2, s3, s4;
ifstream instuf;
instuf.open("d:\\AddressBook1.txt",ios::in);
while (instuf >> name)
{ getline(instuf, s1);
if (name == seaname)
{ cout << name << s1 << endl;
counter++;
}
}
instuf.close();
instuf.open("d:\\AddressBook2.txt",ios::in);
while (instuf >> name)
{ getline(instuf, s2);
if (name == seaname)
{ cout << name << s2 << endl;
counter++;
}
}
instuf.close();
instuf.open("d:\\AddressBook3.txt",ios::in);
while (instuf >> name)
{ getline(instuf, s3);
if (name == seaname)
{ cout << name << s3 << endl;
counter++;
}
}
instuf.close();
instuf.open("d:\\AddressBook4.txt",ios::in);
while (instuf >> name)
{ getline(instuf, s4);
if (name == seaname)
{ cout << name << s4 << endl;
counter++;
}
}
instuf.close();
}
void SearchContact::ByBday()
{ system("cls");
//Search in AddressBook1.txt
ifstream instuf;
instuf.open("d:\\AddressBook1.txt",ios::in);
while (instuf >> name)
{ instuf >> yy >> mm >> dd >> tel >> email >> special;
if (month == mm && day == dd)
{cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
}
}
instuf.close();
//Search in AddressBook2.txt
ifstream instuf2;
instuf2.open("d:\\AddressBook2.txt",ios::in);
while (instuf2 >> name)
{ instuf2 >> yy >> mm >> dd >> tel >> email >> special;
if (month == mm && day == dd)
{ cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
}
}
instuf2.close();
//Search in AddressBook3.txt
ifstream instuf3;
instuf3.open("d:\\AddressBook3.txt",ios::in);
while (instuf3 >> name)
{ instuf3 >> yy >> mm >> dd >> tel >> email >> special;
if (month == mm && day == dd)
{ cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
}
}
instuf3.close();
//Search in AddressBook4.txt
ifstream instuf4;
instuf4.open("d:\\AddressBook4.txt",ios::in);
while (instuf4 >> name)
{ instuf4 >> yy >> mm >> dd >> tel >> email >> special;
if (month == mm && day == dd)
{ cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
}
}
instuf4.close();
}
void SearchContact::BdayFiveDays()
{ Date sys;
char ch;
char *weekday;
sys.getSysDate();
//Search in AddressBook1.txt
ifstream instuf;
instuf.open("d:\\AddressBook1.txt",ios::in);
while (instuf >> name)
{ instuf >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if ((d.getDayNum()-sys.getSysDayNum()<=5)&&(d.getDayNum()-sys.getSysDayNum()>=0) )
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ system("cls");
cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf.close();
//Search in AddressBook2.txt
ifstream instuf2;
instuf2.open("d:\\AddressBook2.txt",ios::in);
while (instuf2 >> name)
{ instuf2 >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if ((d.getDayNum()-sys.getSysDayNum()<=5)&&(d.getDayNum()-sys.getSysDayNum()>=0) )
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf2.close();
//Search in AddressBook3.txt
ifstream instuf3;
instuf3.open("d:\\AddressBook3.txt",ios::in);
while (instuf3 >> name)
{ instuf3 >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if ((d.getDayNum()-sys.getSysDayNum()<=5)&&(d.getDayNum()-sys.getSysDayNum()>=0) )
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf3.close();
//Search in AddressBook4.txt
ifstream instuf4;
instuf4.open("d:\\AddressBook4.txt",ios::in);
while (instuf4 >> name)
{ instuf4 >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if ((d.getDayNum()-sys.getSysDayNum()<=5)&&(d.getDayNum()-sys.getSysDayNum()>=0) )
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf4.close();
}
void SearchContact::BdayMonth()
{ Date sys;
char ch;
char *weekday;
sys.getSysDate();
//Search in AddressBook1.txt
ifstream instuf;
instuf.open("d:\\AddressBook1.txt",ios::in);
while (instuf >> name)
{ instuf >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if (mm==sys.getSysMonth())
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ system("cls");
cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf.close();
//Search in AddressBook2.txt
ifstream instuf2;
instuf2.open("d:\\AddressBook2.txt",ios::in);
while (instuf2 >> name)
{ instuf2 >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if (mm==sys.getSysMonth())
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ system("cls");
cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf2.close();
//Search in AddressBook3.txt
ifstream instuf3;
instuf3.open("d:\\AddressBook3.txt",ios::in);
while (instuf3 >> name)
{ instuf3 >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if (mm==sys.getSysMonth())
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ system("cls");
cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf3.close();
//Search in AddressBook4.txt
ifstream instuf4;
instuf4.open("d:\\AddressBook4.txt",ios::in);
while (instuf4 >> name)
{ instuf4 >> yy >> mm >> dd >> tel >> email >> special;
Date d(yy, mm, dd);
if (mm==sys.getSysMonth())
{ system("cls");
weekday = d.getDayOfWeek();
cout << weekday << ":" << endl;
cout << left << setw(15) << name
<< yy << "/" << setw(2) << mm << "/" <<setw(3) << dd
<< setw(12) << tel
<< setw(25) << email
<< setw(17) << special << endl;
counter++;
cout << "Send email?(y/n): ";
cin >> ch;
if (ch=='y' || ch == 'Y')
{ system("cls");
cout << "Sending the following email: " << endl;
cout << "***********************************" << endl
<< "* " << left << setw(30)<< name << " *" << endl
<< "* *" << endl
<< "* Happy Birthday! *" << endl
<< "* *" << endl
<< "* Antonio *" << endl
<< "***********************************" << endl;
}
system("pause");
}
}
instuf4.close();
}
void SearchContact::printNo()
{ if (counter==0) {cout<< "No matches" << endl;}
}
//
//
//SortContact clas, inherited from Contact class
//Function: Ability to sort the existing contacts in all or either of the Address Books
class SortContact:public Contact
{ public:
char Menu();
char SubMenu();
void SortAll();
void SortClassmate();
void SortColleague();
void SortFriend();
void SortFamily();
private:
string name, tel, email, special;
int yy, mm, dd, month, day;
static int counter;
char mopt, mopt2;
};
int SortContact::counter=0;
char SortContact::Menu()
{ system("cls");
cout << "*******************************************" << endl
<< "* Select to sort: *" << endl
<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" << endl
<< "* [1] All || [5] Family *" << endl
<< "* [2] Classmates || [6] Back *" << endl
<< "* [3] Colleagues || [Other] Exit *" << endl
<< "* [4] Friends || *" << endl
<< "*******************************************" << endl;
cout << "Enter option: ";
cin >> mopt;
return mopt;
}
char SortContact::SubMenu()
{ system("cls");
cout << "*******************************************" << endl
<< "* Select to sort by: *" << endl
<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" << endl
<< "* [1] Name || [3] Back *" << endl
<< "* [2] Birthday || [Other] Exit *" << endl
<< "*******************************************" << endl;
cout << "Enter option: ";
cin >> mopt2;
return mopt2;
}
void SortContact::SortAll()
{ vector <string> array;
string s;
ifstream instuf ( "d:\\AddressBook1.txt",ios::in );
while ( getline ( instuf, s) )
{ array.push_back ( s );
}
instuf.close();
ifstream instuf2 ( "d:\\AddressBook2.txt",ios::in );
while ( getline ( instuf2, s) )
{ array.push_back ( s );
}
instuf2.close();
ifstream instuf3 ( "d:\\AddressBook3.txt",ios::in );
while ( getline ( instuf3, s) )
{ array.push_back ( s );
}
instuf3.close();
ifstream instuf4 ( "d:\\AddressBook4.txt",ios::in );
while ( getline ( instuf4, s) )
{ array.push_back ( s );
}
instuf4.close();
sort ( array.begin(), array.end() ); //Sorts the contacts from the AddressBooks
cout << "Classmates sorted:" << endl; //Output sorted contacts
for ( int i = 0; i < array.size(); i++ )
{ cout << array[i] << endl;
}
}
void SortContact::SortClassmate()
{ vector <string> array;
ifstream instuf ( "d:\\AddressBook1.txt",ios::in );
string s;
while ( getline ( instuf, s) )
{ array.push_back ( s );
}
instuf.close();
sort ( array.begin(), array.end() ); //Sorts the contacts from the AddressBooks
cout << "Classmates sorted:" << endl; //Output sorted contacts
for ( int i = 0; i < array.size(); i++ )
{ cout << array[i] << endl;
}
}
void SortContact::SortColleague()
{ vector <string> array;
ifstream instuf ( "d:\\AddressBook2.txt", ios::in );
string s;
while ( getline ( instuf, s) )
{ array.push_back ( s );
}
instuf.close();
sort ( array.begin(), array.end() ); //Sorts the contacts from the AddressBooks
cout << "Colleagues sorted:" << endl; //Output sorted contacts
for ( int i = 0; i < array.size(); i++ )
{ cout << array[i] << endl;
}
}
void SortContact::SortFriend()
{ vector <string> array;
ifstream instuf ( "d:\\AddressBook3.txt", ios::in );
string s;
while ( getline ( instuf, s) )
{ array.push_back ( s );
}
instuf.close();
sort ( array.begin(), array.end() ); //Sorts the contacts from the AddressBooks
cout << "Friends sorted:" << endl; //Output sorted contacts
for ( int i = 0; i < array.size(); i++ )
{ cout << array[i] << endl;
}
}
void SortContact::SortFamily()
{ vector <string> array;
ifstream instuf ( "d:\\AddressBook4.txt", ios::in );
string s;
while ( getline ( instuf, s) )
{ array.push_back ( s );
}
instuf.close();
sort ( array.begin(), array.end() ); //Sorts the contacts from the AddressBooks
cout << "Family sorted:" << endl; //Output sorted contacts
for ( int i = 0; i < array.size(); i++ )
{ cout << array[i] << endl;
}
}
int main()
{ char op, op2, op3, yn='y';
Contact con;
NewContact newcon;
DeleteContact delcon;
EditContact editcon;
EditContact *EChead=NULL;
ShowContact showcon;
SearchContact seacon;
SortContact sortcon;
A:
con.CreateAddressBooks(); //Create address books in Disk D
op = con.Menu(); //Displays main menu
//Option 1: Add contacts
if (op == '1')
{ op2 = newcon.Menu();
switch (op2)
{ case '1':
case '2':
case '3':
case '4': { while (yn == 'y'|| yn == 'Y')
{ newcon.AddContact();
cout << "Continue? (y/n): ";
cin >> yn;
if (yn=='n' || yn=='N') { goto A;}
}
break;
}
case '5': goto A; break;
default: return 0;
}
}
//Option 2: Delete contacts
if (op == '2')
{ while (yn == 'y'|| yn == 'Y')
{ delcon.EnterInfo();
delcon.DeleteClassmate();
delcon.DeleteColleague();
delcon.DeleteFriend();
delcon.DeleteFamily();
delcon.printNo();
cout << "Continue? (y/n): ";
cin >> yn;
if (yn=='n' || yn=='N') { goto A;}
}
}
//Option 3: Edit contacts
if (op == '3')
{ while(yn == 'y' || yn == 'Y')
{ EditInfo(EChead);
cout << "Continue? (y/n): ";
cin >> yn;
if (yn=='n' || yn=='N') { goto A;}
}
}
//Option 4: Show contacts
if (op == '4')
{
op2 = showcon.Menu();
con.Title();
switch (op2)
{ case '1': showcon.ShowClassmate();
showcon.ShowColleague();
showcon.ShowFamily();
showcon.ShowFriend();
system("pause");
goto A;
break;
case '2': showcon.ShowClassmate();
system("pause");
goto A;
break;
case '3': showcon.ShowColleague();
system("pause");
goto A;
break;
case '4': showcon.ShowFriend();
system("pause");
goto A;
break;
case '5': showcon.ShowFamily();
system("pause");
goto A;
break;
case '6': goto A;
default: return 0;
}
}
//Option 5: Search contacts
if (op == '5')
{
op2 = seacon.Menu();
switch (op2)
{ case '1': seacon.EnterName();
con.Title();
seacon.ByName();
seacon.printNo();
system("pause");
goto A;
break;
case '2': seacon.EnterBday();
con.Title();
seacon.ByBday();
seacon.printNo();
system("pause");
goto A;
break;
case '3': seacon.BdayFiveDays();
seacon.printNo();
goto A;
break;
case '4': seacon.BdayMonth();
seacon.printNo();
goto A;
break;
case '5': goto A;
default: return 0;
}
}
//Option 6: Sort Contact
if (op == '6')
{ op2 = sortcon.Menu();
switch (op2)
{ case '1': op3 = sortcon.SubMenu();
sortcon.SortAll();
system("pause");
goto A;
break;
case '2': op3 = sortcon.SubMenu();
sortcon.SortClassmate();
system("pause");
goto A;
break;
case '3': op3 = sortcon.SubMenu();
sortcon.SortColleague();
system("pause");
goto A;
break;
case '4': op3 = sortcon.SubMenu();
sortcon.SortFriend();
system("pause");
goto A;
break;
case '5': op3 = sortcon.SubMenu();
sortcon.SortFamily();
system("pause");
goto A;
break;
case '6': goto A; break;
default: return 0;
}
}
//Option 7: Open the guide of the program
if (op == '7')
{ con.Help();
system ("pause");
goto A;
}
//Option 8: Exit the program
if (op == '8')
{ return 0;
}
}
the problem is in this part, in case u can't find it in the code above
//EditContact class, inherited from Contact class
//Function: Edit an existing contact from the Address Books
// Can only edit telephone, email and depending on the category: school, company, first meeting or relationship
class EditContact:public Contact
{ public:
string EnterName();
string getName();
string getTel();
string getEmail();
string getSP();
friend void EditInfo(EditContact *head);
protected:
string name, tel, email, special, fname;
int yy, mm, dd, nd, nm, ny;
char mopt;
EditContact *next;
};
string EditContact::getName()
{ return name;
}
string EditContact::getTel()
{ return tel;
}
string EditContact::getEmail()
{ return email;
}
string EditContact::getSP()
{ return special;
}
string EditContact::EnterName()
{ system("cls");
cout << "Enter name of contact to be edited: ";
cin >> fname;
return fname;
}
void EditInfo(EditContact *head)
{ string N;
EditContact EC;
N=EC.EnterName();
EditContact *p=head,*s;
ifstream instuf;
instuf.open("d:\\AddressBook1.txt",ios::in);
s=new EditContact;
while(instuf>>s->getName())
{ cout << s->getName();
if(s->getName()== N)
{ instuf >>s->yy >>s->mm>> s->dd >>s->getTel() >>s->getEmail() >> s->getSP();
cout << "Enter the following information:";
cout << "New telephone: ";
cin >> s->getTel ();
cout << "New Email: ";
cin >> s->getEmail ();
cout << "New school: ";
cin >> s->getSP() ;
}
if(head==NULL) head=s,p=head;
else p->next=s;
p=s;
s=new EditContact;
}
p->next =NULL;
delete s;
ofstream outstuf;
outstuf.open("AddressBook1.txt",ios::out);
while (head)
{ outstuf << left << setw(15) << head->getName()
<< head->yy<<" "<<head->mm<<" "<<head->dd
<< setw(12) << head->getTel()
<< setw(25) << head->getEmail()
<< setw(17) << head->getSP()<<endl ;
head=head->next ;
}
outstuf.close ();
instuf.close();
}