Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A C++ program that meets all of the following and compiles with no errors. This

ID: 3764013 • Letter: A

Question

A C++ program that meets all of the following and compiles with no errors.

This program will have names and addresses saved in a linked list. In addition, a birthday and anniversary date will be saved with each record.

When the program is run, it will search for a birthday or an anniversary using the current date to compare with the saved date. It will then generate the appropriate card message. Because this will be an interactive system, your program should begin by displaying a menu.

Items on the menu should include:

• Enter a new name into the address book

• Delete a name from the address book

• Change a name or date in the address book

• Display the whole address book

• Generate birthday cards

• Generate anniversary cards

• Exit the card program

Each of these sections will call individual functions to perform their appropriate task.

This address book is to be sorted in alphabetical order. Be aware of this when you are entering, deleting, or changing the name, and plan your code accordingly. Use classes and objects where appropriate. Be sure to comment your code and use appropriate variable, function, and class names so that it is clear how the program flows. The user gets the menu and creates information to be stored in your address book. (To save sanity in testing, you may fill in 5 or 6 records within the code or written to a file to start your address book.) The user can add a new record to your existing ones, delete a record, modify a record or print the whole address book on the screen. For each of the options, make sure you give suitable prompts on the screen so that the user knows what is expected by the program.

Expect that the user will enter both a birthday and anniversary date. (If you’d like, you can handle the situation where the user chooses not to enter an anniversary date.) A year may be entered or omitted in birthday and anniversary dates. Also be sure to redisplay the menu any time a function has concluded, until the user presses the Exit option.

Create and display the card created on the screen (you do not need to print it). You may design the layout of the card as you wish. For example, it could be:

Dear <fname>,

Hope your birthday is really wonderful and this coming year is the best yet!

Love,

Joanne

“Generate Birthday Cards” and “Generate Anniversary Cards” will use the system date (today) as the date to match. Using this date, display the card below it on the screen. Be ready to print multiple cards if more than one birthday or anniversary falls on the same day.

“Display the Whole Address Book” will be done on the screen. Output should look something like:

Wilson, Fred

123 Main Street

Anytown, NJ 00000

Birthday: May 7

Anniversary: June 25

Or include the structure variable names you’ve used:

lname: Wilson fname: Fred

addr: 123 Main Street

city: Anytown state: NJ zip: 00000

bday: May 7

aday: June 25

Explanation / Answer

Here is the program for you.
#include <iostream.h>
#include <fstream.h>
#include <sstream.h>
#include <string.h>
#include <time.h>

class Node
{
public:
Node(string newName)
{
name = newName;
nextNode = NULL;
}
string name;
string address;
time_t birthday;
time_t anniversary;
Node *nextNode;
};

Node* pHeadNode;

void DrawMenu()
{
cout << "1. Enter a new name into the address book" << endl;
cout << "2. Delete a name from the address book" << endl;
cout << "3. Change a name or date in the address book" << endl;
cout << "4. Generate birthday cards" << endl;
cout << "5. Generate anniversary cards" << endl;
cout << "6. Exit the card program" << endl;
cout << "" << endl;
cout << "You choice: ";
}
Node* FindName(string name)
{
if (pHeadNode)
{
Node *pCurrentNode = pHeadNode;
while(pCurrentNode && pCurrentNode->name!=name)
{
if (pCurrentNode->name==name)
return pCurrentNode;
pCurrentNode = pCurrentNode->nextNode;
}
}
return NULL;
}
enter code heretime_t MakeTime(int year, int month, int day)
{
tm tm1;
tm1.tm_year = year-1900;
tm1.tm_mon = month;
tm1.tm_mday = day;
tm1.tm_hour = 0;
tm1.tm_isdst = 0;
tm1.tm_min = 0;
tm1.tm_sec = 0;
tm1.tm_wday = 0;
tm1.tm_yday = 0;
return mktime(&tm1);
}
void InsertNewNode(Node* pNewNode)
{
if (!pHeadNode || (pNewNode->name < pHeadNode->name))
{
pNewNode->nextNode = pHeadNode;
pHeadNode = pNewNode;
} else {
Node *pCurrentNode = pHeadNode;
Node *pPrevNode = pCurrentNode;
while(pCurrentNode && pCurrentNode->name < pNewNode->name)
{
pPrevNode = pCurrentNode;
pCurrentNode = pCurrentNode->nextNode;
}
pNewNode->nextNode = pPrevNode->nextNode;
pPrevNode->nextNode = pNewNode;
}
}
void AddNewEntry()
{
string name;
string address;
time_t birthday;
time_t anniversary;
cout << "Enter name of new Entry: ";
getline(cin, name);
cin.clear();
cin.sync();
getline(cin, name);
if (pHeadNode)
{
if (FindName(name))
{
cout << "" << endl;
cout << "Name already exists";
cout << "" << endl;
return;
}
}
cout << "Enter address for new Entry: ";
getline(cin, address);
int bday, bmonth, byear;
cout << "Enter (day month year) of birthday: ";
cin >> bday >> bmonth >> byear;
birthday = MakeTime(byear, bmonth, bday);
int aday, amonth, ayear;
cout << "Enter (day month year) of anniversary: ";
cin >> aday >> amonth >> ayear;
anniversary = MakeTime(ayear, amonth, aday);
if (pHeadNode)
{
Node* pNewNode = new Node(name);
pNewNode->address = address;
pNewNode->birthday = birthday;
pNewNode->anniversary = anniversary;
InsertNewNode(pNewNode);
} else {
pHeadNode = new Node(name);
pHeadNode->address = address;
pHeadNode->birthday = birthday;
pHeadNode->anniversary = anniversary;
}
cout << "" << endl;
cout << "New Entry is added" << endl;
cout << "" << endl;
}
void DeleteEntry()
{
string name;
if (pHeadNode)
{
cin.clear();
cin.sync();
cout << "Enter name of Entry you want to delete: ";
getline(cin, name);
Node *pCurrentNode = pHeadNode;
Node *pPrevNode = pCurrentNode;
while(pCurrentNode && pCurrentNode->name!=name)
{
if (pCurrentNode->name==name)
break;
pCurrentNode = pCurrentNode->nextNode;
}
if (pCurrentNode)
{
if (pCurrentNode==pHeadNode)
{
pHeadNode = pCurrentNode->nextNode;
} else {
pPrevNode->nextNode = pCurrentNode->nextNode;
}
delete pCurrentNode;
} else {
cout << "" << endl;
cout << "Entry is not found" << endl;
cout << "" << endl;
}
} else {
cout << "" << endl;
cout << "Address book is empty already" << endl;
cout << "" << endl;
return;
}
}
void ChangeEntry()
{
string name;
string address;
time_t birthday;
time_t anniversary;
if (pHeadNode)
{
cin.clear();
cin.sync();
cout << "Enter name of Entry you want to edit: ";
getline(cin, name);
Node *pCurrentNode = pHeadNode;
Node *pPrevNode = pCurrentNode;
while(pCurrentNode && pCurrentNode->name!=name)
{
if (pCurrentNode->name==name)
break;
pCurrentNode = pCurrentNode->nextNode;
}
if (pCurrentNode)
{
cin.clear();
cin.sync();
cout << "Enter name of new Entry: ";
getline(cin, name);
if (pHeadNode)
{
if (FindName(name))
{
cout << "" << endl;
cout << "Name already exists";
cout << "" << endl;
return;
}
}
if (pCurrentNode==pHeadNode)
{
pHeadNode = pCurrentNode->nextNode;
} else {
pPrevNode->nextNode = pCurrentNode->nextNode;
}
delete pCurrentNode;
cout << "Enter address for new Entry: ";
getline(cin, address);
int bday, bmonth, byear;
cout << "Enter (day month year) of birthday: ";
cin >> bday >> bmonth >> byear;
birthday = MakeTime(byear, bmonth, bday);
int aday, amonth, ayear;
cout << "Enter (day month year) of anniversary: ";
cin >> aday >> amonth >> ayear;
anniversary = MakeTime(ayear, amonth, aday);
Node* pNewNode = new Node(name);
pNewNode->address = address;
pNewNode->birthday = birthday;
pNewNode->anniversary = anniversary;
InsertNewNode(pNewNode);
cout << "" << endl;
cout << "Entry is changed" << endl;
cout << "" << endl;
} else {
cout << "" << endl;
cout << "Entry is not found" << endl;
cout << "" << endl;
}
} else {
cout << "" << endl;
cout << "Address book is empty " << endl;
cout << "" << endl;
return;
}
}
void GenerateBirthdayCards()
{
Node *pCurrentNode = pHeadNode;

time_t t = time(NULL);
tm *tm1 = localtime(&t);
while(pCurrentNode)
{
tm *ct = localtime(&pCurrentNode->birthday);
if (ct->tm_mon==tm1->tm_mon && ct->tm_mday==tm1->tm_mday)
{
cout << "" << endl;
cout << "Dear " << pCurrentNode->name << "," << endl;
cout << "" << endl;
cout << "Hope your birthday is really wonderful and this coming year is the best yet!" << endl;
cout << "" << endl;
cout << "Love," << endl;
cout << "Joanne" << endl;
cout << "" << endl;
}
pCurrentNode = pCurrentNode->nextNode;
}
}
void GenerateAnniversaryCards()
{
Node *pCurrentNode = pHeadNode;
time_t t = time(NULL);
tm *tm1 = localtime(&t);
while(pCurrentNode)
{
tm *ct = localtime(&pCurrentNode->anniversary);
if (ct->tm_mon==tm1->tm_mon && ct->tm_mday==tm1->tm_mday)
{
cout << "" << endl;
cout << "Dear " << pCurrentNode->name << "," << endl;
cout << "" << endl;
cout << "Hope your anniversary is really wonderful and this coming year is the best yet!" << endl;
cout << "" << endl;
cout << "Love," << endl;
cout << "Joanne" << endl;
cout << "" << endl;
}
pCurrentNode = pCurrentNode->nextNode;
}
}
void SaveListToFile()
{
ofstream outfile;
outfile.open("list.txt");
Node* pCurrentNode = pHeadNode;
while(pCurrentNode)
{
Node* pNode = pCurrentNode;
pCurrentNode = pCurrentNode->nextNode;
outfile << pNode->name << endl;
outfile << pNode->address << endl;
outfile << pNode->birthday << endl;
outfile << pNode->anniversary << endl;
}
outfile.close();
}
void LoadListFromFile()
{
ifstream infile;
infile.open("list.txt");
string name;
while (getline(infile, name))
{
string address;
getline(infile, address);
time_t birthday;
time_t anniversary;
string strBirthday;
getline(infile, strBirthday);
istringstream iss1(strBirthday);
iss1 >> birthday;
string strAnniversary;
getline(infile, strAnniversary);
istringstream iss2(strAnniversary);
iss2 >> anniversary;
if (!pHeadNode)
{
pHeadNode = new Node(name);
pHeadNode->address = address;
pHeadNode->birthday = birthday;
pHeadNode->anniversary = anniversary;
} else {
Node *pCurrentNode = pHeadNode;
Node *pPrevNode = pCurrentNode;
while(pCurrentNode)
{
pPrevNode = pCurrentNode;
pCurrentNode = pCurrentNode->nextNode;
}
pPrevNode->nextNode = new Node(name);
pPrevNode->nextNode->address = address;
pPrevNode->nextNode->birthday = birthday;
pPrevNode->nextNode->anniversary = anniversary;
}
//std::istringstream iss(line);
//int a, b;
//if (!(iss >> a >> b)) { break; } // error
// process pair (a,b)
}

infile.close();
}
int main()
{
int choice;
bool stop = false;
LoadListFromFile();
do
{
do
{
DrawMenu();
cin >> choice;
if (choice<1 || choice>6)
cout << "Incorrect choice. Try again" << endl << endl;
}while(choice<1 || choice>6);
switch(choice)
{
case 1:
AddNewEntry();
break;
case 2:
DeleteEntry();
break;
case 3:
ChangeEntry();
break;
case 4:
GenerateBirthdayCards();
break;
case 5:
GenerateAnniversaryCards();
break;
case 6:
stop = true;
break;
default:
//it's impossible,
break;
}
}while(!stop);
SaveListToFile();
Node* pCurrentNode = pHeadNode;
while(pCurrentNode)
{
Node* pNode = pCurrentNode;   
pCurrentNode = pCurrentNode->nextNode;
delete pNode;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote