Address Book-Card Generator Program Using a Linked List This program will have n
ID: 3548699 • Letter: A
Question
Address Book-Card Generator Program Using a Linked List 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. 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 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. For this project, 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 S-21 Deliverables: Your
C++ source code with any header files Your executable code
Explanation / Answer
All the required functions:
Second Part :
node* DeleteNode(node* start)
{
int node_num,
count=2,
found=0;
node* current1=start; //current1 is holding address of 1st node
node* current2=current1->ptr; //current2 is holding address of 2nd node
if(start==NULL) //i.e if there is no node in the linked list
{
cout<<" SORRY! there is no node in the linked list";
getch();
}//ending if(start==NULL)
else
{
cout<<" ---SHOWING ALL NODE--- ";
DisplayAll(start);
cout<<" Input node # you want to update: ";
cin>>node_num;
if(node_num==1)
{
start=current1->ptr;
delete current1;
current1=NULL;
}//ending if(node_num==1)
else
{
while(current2!=NULL) //pPre!=NULL
{
cout<<count<<" ";
if(count==node_num)
{
current1->ptr=current2->ptr;
delete current2;
current2=NULL;
found=1;
}//ending if(count==node_number)
else
{
current1=current1->ptr;
current2=current2->ptr;
count++;
}//ending else
}//ending while
if(found==0)
{
clrscr();
cout<<" SORRY! the node # you have entered dose not exit.";
getch();
}
}// ending else(node_num==1)
}//ending else
return start;
}
void CheckPosition(node* start)
{
if(start==NULL) //checking that linked list have nodes or
{
cout<<" SORRY! there is no node in the linked list";
}//ending if
else
{
int value,
node_num,
node_num_aa,
node_num_ad,
found=0,
count=1;
node* current=start;
cout<<" Input value you want to check: ";
cin>>value;
/* Searching for the value in the linked list */
while(current!=NULL)
{
if(value==current->data)
{
node_num=count;
found=1;
current=NULL; //to terminate the loop
}
else
{
current=current->ptr;
count++;
}
}
if(found==0)
{
clrscr();
cout<<" SORRY! the number you have entered does not exist in the linked list";
}
else
{
cout<<" The number' "<<value<<" is at index "<<node_num<<" before sorting";
sort(start, DES);
count=1;
current=start;
while(current!=NULL)
{
if(value==current->data)
{
node_num_aa=count;
found=1;
current=NULL; //to terminate the loop
}
else
{
current=current->ptr;
count++;
}
}
cout<<" The number' "<<value<<" is at index "<<node_num_aa<<" after ascending sort";
sort(start, ASSEN);
count=1;
current=start;
while(current!=NULL)
{
if(value==current->data)
{
node_num_ad=count;
found=1;
current=NULL; //to terminate the loop
}
else
{
current=current->ptr;
count++;
}
}
cout<<" The number' "<<value<<" is at index "<<node_num_ad<<" after ascending sort";
}
}//ending else start==NULL
}//ending function
void sort(node* start,int order) //sort descending...
{
int min=0, temp;
node* current1;
node* current2;
current1=current2=start;
if(start==NULL) //checking that linked list have nodes or
{
cout<<" SORRY! there is no node in the linked list";
}//ending if
else
{
if(order==DES)
{
while(current1!=NULL)
{
while(current2->ptr!=NULL) //or we can sort lists
{
if(current2->data > current2->ptr->data)
{
temp=current2->data;
current2->data=current2->ptr->data;
current2->ptr->data=temp;
}//
current2=current2->ptr;
}
current2=start;
current1=current1->ptr;
}//ending outer while
}//ending if(order==DES)
else if(order==ASSEN)
{
while(current1!=NULL)
{
while(current2->ptr!=NULL) //or we can sort lists
{
if(current2->data < current2->ptr->data)
{
temp=current2->data;
current2->data=current2->ptr->data;
current2->ptr->data=temp;
}//
current2=current2->ptr;
}
current2=start;
current1=current1->ptr;
}//ending outer while
}
cout<<" Nodes have been sorted.";
}//ending else
}
void updateNode(node* start)
{
if(start==NULL) //i.e if there is no node in the linked list
{
cout<<" SORRY! there is no node in the linked list";
}//ending if(start==NULL)
else
{
int node_number, count=1, found=0;
node* current=start;
cout<<" ---SHOWING ALL NODE--- ";
DisplayAll(start);
cout<<" Input node # you want to update: ";
cin>>node_number;
while(current!=NULL)
{
if(count==node_number)
{
cout<<" ---CURRENT DATA IN NODE---";
cout<<" Node #: "
<<count<<" Data: "<<current->data;
cout<<" Input new value to store in the node: ";
cin>>current->data;
current=NULL; //to break the while loop.
}//ending if(count==node_number)
else
{
current=current->ptr;
count++;
}//ending else
}//ending while
}//ending else
}
int getLength(node* start) // This function will return
{ //current length of the linked
node* current=start; //list. The start pointer of the
int count=0; //list will be passed as argument
while(current!=NULL) //to this function to find the
{ //length of total linked list.
current=current->ptr; // However, the length of the
count++; //linked list from a specific
}//ending while //to onward can also be found by
return count; //passing the address of that
} //specific node to this function.
//
node* SearchNode(node* start)
{
if(start==NULL) //i.e if there is no node in the linked list
{
cout<<" SORRY! there is no node in the linked list";
}//ending if( NULL == 0)
else
{
node* current;
node* temp;
current=start;
int found=0, count=1, value;
cout<<" Input value you want to search: ";
cin>>value;
while(current!=NULL)
{
if(value==current->data)
{
cout<<" Data "
<<"found at node # "<<count;
temp=current;
current=current->ptr;
found++;
count++;
}
else
{
current=current->ptr;
count++;
}
}//ending while
if(found==0)
{
cout<<"The value could not found.";
}
return temp;
}//ending else
}
void DisplayAll(node* start)
{
node* temp;
temp=start;
int count=1;
if(start==NULL)
{
cout<<" WARRNING! there is no node.";
getch();
}
else
{
while(temp!=NULL)
{
cout<<"Node #:"<<count<<" Data:"<<temp->data<<" ";
temp=temp->ptr;
count++;
}
}
}
node* AddNode(node* start, node* current) // new function to Add last
{ // node in the list, because
int data; // AddNode function is also
// doing the duty of adding
cout<<" Input value to store " // a node at the end of the
<<"in node: "; // linked list.
cin>>data; //
//
if(start==NULL) // IF NO NODE IS CREATED YET
{
start=current=new node;
current->data=data;
current->ptr=NULL;
return start;
}
else
{
current->ptr=new node;
current=current->ptr;
current->data=data;
current->ptr=NULL;
return current; //
}
}
node* Add1stNode(node* start)
{
int data;
cout<<" Input value to store in node: ";
cin>>data;
node* temp=new node;
temp->ptr=start;
temp->data=data;
start=temp;
return start;
}
void AddSpecific(node* start)
{
node* current=start;
int count=1, node_number, found=0;
cout<<" ---SHOWING ALL NODE--- ";
DisplayAll(start);
cout<<" Input the node # after "
<<"which you want to insert new node: ";
cin>>node_number;
while(current!=NULL)
{
if(count==node_number)
{
node* newNode;
newNode->ptr=current->ptr;
current->ptr=newNode;
cout<<" Input value to store in node: ";
cin>>newNode->data;
found=1;
current=NULL; //to break the while loop.
}
else
{
current=current->ptr;
count++;
}
}//ending while
if(found==0)
{
cout<<" The Node does not exits.";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.