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

My program keeps failing when I try to enter the birthdate or when I try to gene

ID: 3856238 • Letter: M

Question

My program keeps failing when I try to enter the birthdate or when I try to generate an birthday or anniversary card. I'm assuming I'm missing some piece of the code. Please help me figure out why this program keeps failing.

----------C++ Code Below----------

#include
#include
#include
#include
using namespace std;

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

Node* pHeadNode;

void DrawMenu()
{
std::cout << "1. Enter a new name into the address book "
<< "2. Delete a name from the address book "
<< "3. Change a name or date in the address book "
<< "4. Generate birthday cards "
<< "5. Generate anniversary cards "
<< "6. Exit the card program "
<< " "
<< "Enter your 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;
}

int TimeEntry(int year, int month, int day)
{
tm tm1;
tm1.tm_year = year - 1900;
tm1.tm_mon = month;
tm1.tm_mday = day;
return TimeEntry(year, month, day);
}

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;
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;
  }
}
int bday, bmonth, byear;
cout << "Enter (day month year) of birthday: ";
cin >> bday >> bmonth >> byear;
birthday = TimeEntry(byear, bmonth, bday);
int aday, amonth, ayear;
cout << "Enter (day month year) of anniversary: ";
cin >> aday >> amonth >> ayear;
anniversary = TimeEntry(ayear, amonth, aday);
if (pHeadNode)
{
  Node* pNewNode = new Node(name);
  pNewNode->birthday = birthday;
  pNewNode->anniversary = anniversary;
  InsertNewNode(pNewNode);
}
else {
  pHeadNode = new Node(name);
  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;
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;
   int bday, bmonth, byear;
   cout << "Enter (day month year) of birthday: ";
   cin >> bday >> bmonth >> byear;
   birthday = TimeEntry(byear, bmonth, bday);
   int aday, amonth, ayear;
   cout << "Enter (day month year) of anniversary: ";
   cin >> aday >> amonth >> ayear;
   anniversary = TimeEntry(ayear, amonth, aday);
   Node* pNewNode = new Node(name);
   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;
{
  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;
}
};
void GenerateAnniversaryCards()
{
  Node *pCurrentNode = pHeadNode;

  {
   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;

  }
};

int main()
{
int choice;
bool stop = false;
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);
Node* pCurrentNode = pHeadNode;
while (pCurrentNode)
{
  Node* pNode = pCurrentNode;
  pCurrentNode = pCurrentNode->nextNode;
  delete pNode;
}
return 0;
}

Capstone Data Structures (Global Scope) TimeEntry(int year, int month, int day) 45 46 47 48 49 50 51 52 53 54 if (pCurrentNode-namename) return pCurrentNode; pCurrentNode->nextNode; nextNode Exception Unh pCurrentNode Exception Unhandled Unhandled exception at OxOOEC6A19 in Capstone Data Structures.exe OxC0000005: Access violation writing location Cx00400FBO. return NULL; int TimeEntry (int year, int month, int day) Copy Details Exception Settings 56 57 58 59 60 61 62 63 void InsertNewNode (Node* pNewNode) 64 tmi.tm year year - 1900; tm1.tm_monmonth; tm1.tm_mdayday; return TimeEntry(year, month, day); Break when this exception type is thrown Except when thrown from: Capstone Data Structures.exe Open Exception Settings Edit Conditions if (oHeadNode I1 (oNewNode->name name)) 100 %

Explanation / Answer

After a lot of research on you project what I found was:

Report me the results

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote