THIS IS A C++ ASSIGNMENT Okay so, this is a seemingly huge program to write. I r
ID: 3578560 • Letter: T
Question
THIS IS A C++ ASSIGNMENT
Okay so, this is a seemingly huge program to write. I really need help here to even begin wrapping my mind around it. Please help me out here! It looks like I need allot of while/for loops that run through a .txt file to print everything out correctly. I need a lesson on this too if you can figure it out! Thanks so much for any help!
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 , 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
Note: With the provided time i could implemented all the functions except reading from file and option 3-change name or date.
Answer:
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<ctime>
using namespace std;
struct myDate
{
int month;
int date;
int year;
};
struct Node
{
string name1;
string name2;
string address;
string city;
string state;
int zip;
myDate bday;
myDate aday;
Node *next;
};
class AddressBook
{
// Public Functions/Variables
public:
AddressBook();
~AddressBook();
void printAddress_Bk();
void sort();
void insrt_Front();
void insrt_Frontt(string nme1, string nme2,string add, string city, string st, int zp,int bdate,int byear, int bmon, int adate, int ayear, int amon);
bool remove_Nme(string name);
void displayBirthCard(int date, int mon);
void displayAnniversaryCard(int date, int mon);
private:
Node *first;
};
AddressBook::AddressBook()
{
first = NULL;
}
AddressBook::~AddressBook()
{
while(first != NULL)
{
Node *temp;
temp = first;
first = first->next;
free(temp);
}
}
void AddressBook::printAddress_Bk()
{
sort();
string monAry[]={"January","Febraury","March","April","May","June","July","August","September","October","November","December"};
Node *temp = first;
cout<<"Address Book:"<<endl;
cout<<"----------------------------------------------------------"<<endl;
while(temp != NULL)
{
cout<<temp->name1<<","<<temp->name2<<" "<<temp->address<<" "<<temp->city<<","<<temp->state<<" "<<temp->zip<<" Birthday:"<<monAry[temp->bday.month-1]<<" "<<temp->bday.date<<" Anniversary:"<<monAry[temp->aday.month-1]<<" "<<temp->aday.date<<endl;
temp = temp->next;
}
cout<<"---------------------------------------------------------"<<endl;
}
void AddressBook::insrt_Front()
{
string tp;
Node *temp = (Node *)malloc(sizeof(Node));
cout<<" Enter the lastname:";
cin>>tp;
temp->name1=tp;
cout<<" Enter the firstname:";
cin>>tp;
temp->name2=tp;
cout<<" Enter the address:";
getline(cin, tp);
temp->address=tp;
cout<<" Enter the city:";
cin>>temp->city;
cout<<" Enter the state:";
cin>>temp->state;
cout<<" Enter the zipcode";
cin>>temp->zip;
cout<<" Enter the birthday date";
cin>>temp->bday.date;
cout<<" Enter the birthday month";
cin>>temp->bday.month;
cout<<" Enter the birthday year";
cin>>temp->bday.year;
cout<<" Enter the anniversary date";
cin>>temp->aday.date;
cout<<" Enter the anniversary month";
cin>>temp->aday.month;
cout<<" Enter the anniversary year";
cin>>temp->aday.year;
temp->next = first;
first=temp;
}
void AddressBook::insrt_Frontt(string nme1, string nme2,string add, string city, string st, int zp,int bdate,int byear, int bmon, int adate, int ayear, int amon)
{
Node *temp = (Node *)malloc(sizeof(Node));
temp->name1=nme1;
temp->name2=nme2;
temp->address=add;
temp->city=city;
temp->state=st;
temp->zip=zp;
temp->bday.date=bdate;
temp->bday.month=bmon;
temp->bday.year=byear;
temp->bday.date=adate;
temp->bday.month=amon;
temp->bday.year=ayear;
temp->next = first;
first=temp;
}
void AddressBook::sort()
{
Node *ptr, *s;
if (first == NULL)
{
cout<<"The List is empty"<<endl;
return;
}
ptr = first;
while (ptr != NULL)
{
for (s = ptr->next;s !=NULL;s = s->next)
{
if (ptr->name2.compare( s->name2)>0)
{
string tpname = ptr->name1;
ptr->name1 = s->name1;
s->name1 = tpname;
tpname = ptr->name2;
ptr->name2 = s->name2;
s->name2= tpname;
string tpadd=ptr->address;
ptr->address=s->address;
s->address=tpadd;
string tpcity=ptr->city;
ptr->city=s->city;
s->city=tpcity;
string tpstate=ptr->state;
ptr->state=s->state;
s->state=tpstate;
int tpzip=ptr->zip;
ptr->zip=s->zip;
s->zip=tpzip;
int tpdate=ptr->bday.date;
ptr->bday.date=s->bday.date;
s->bday.date=tpdate;
int tpyear=ptr->bday.year;
ptr->bday.year=s->bday.year;
s->bday.year=tpyear;
int tpmonth=ptr->bday.month;
ptr->bday.month=s->bday.month;
s->bday.month=tpmonth;
tpdate=ptr->aday.date;
ptr->aday.date=s->aday.date;
s->aday.date=tpdate;
tpyear=ptr->aday.year;
ptr->aday.year=s->aday.year;
s->aday.year=tpyear;
tpmonth=ptr->aday.month;
ptr->aday.month=s->aday.month;
s->aday.month=tpmonth;
}
}
ptr = ptr->next;
}
}
//Remove
bool AddressBook::remove_Nme(string name)
{
//check first is empty
if(first==NULL)
{
cout<<"EMPTY LIST"<<endl;
//return false
return false;
}
//if 1ly 1 node
else if(first->next==NULL)
{
if(name.compare(first->name2)==0)
{
free(first);
//set first & last to null
first = NULL;
//return true
return true;
}
else
return false;
}
Node *ptr, *s;
s=first;
while(s!=NULL )
{
ptr=s;
if((name.compare(s->name2)!=0))
{
ptr->next=s->next;
return true;
}
else
s=s->next;
}
return false;
}
void AddressBook::displayBirthCard(int date, int mon)
{
Node *ptr, *s;
s=first;
while(s!=NULL )
{
if(s->bday.date==date && s->bday.month==mon)
{
cout<<"Dear "<< s->name2<<","<<endl;
cout<<"Hope your birthday is really wonderful and this coming year is the best yet!"<<endl;
cout<<"Love,"<<endl;
cout<<"XXXX"<<endl;
}
else
s=s->next;
}
}
void AddressBook::displayAnniversaryCard(int date, int mon)
{
Node *ptr, *s;
s=first;
while(s!=NULL )
{
if(s->aday.date==date && s->aday.month==mon)
{
cout<<"Dear "<< s->name2<<","<<endl;
cout<<"Hope your Anniversary is really wonderful and this coming year is the best yet!"<<endl;
cout<<"Love,"<<endl;
cout<<"XXXX"<<endl;
}
else
s=s->next;
}
}
void menu()
{
cout<<"-------------------------------"<<endl;
cout<<"1. Enter a new name into the address book"<<endl;
cout<<"2. Delete a name from the address book"<<endl;
cout<<"3. Change name or date in the address book"<<endl;
cout<<"4. Display the whole address book"<<endl;
cout<<"5. Generate birthday cards"<<endl;
cout<<"6. Generate Anniversary cards"<<endl;
cout<<"7. Exit the card program"<<endl;
cout<<"Your choice:"<<endl;
}
int main()
{
int cc;
AddressBook myAddrBk;
string nme;
int date,month;
time_t nw=time(0);
tm *lltm=localtime(&nw);
while(1)
{
menu();
cin>>cc;
if(cc==7)
break;
switch(cc)
{
case 1:
myAddrBk.insrt_Front();
break;
case 2:
cout<<"Enter the name"<<endl;
cin>>nme;
myAddrBk.remove_Nme(nme);
break;
case 3:
break;
case 4:
myAddrBk.printAddress_Bk();
break;
case 5:
myAddrBk.displayBirthCard(lltm->tm_mday, 1+lltm->tm_mon);
break;
case 6:
myAddrBk.displayAnniversaryCard(lltm->tm_mday, 1+lltm->tm_mon);
break;
default:
cout<<"INVALID"<<endl;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.