Question

C++ : Please include complete source code in answer This program will have names and addresses...

C++ : Please include complete source code in answer

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//main.cpp

#include <iostream>
#include "addresslist.hpp"

using namespace std;
void printMenu();
int main(void)
{
AddressList addresses;
int choice;
printMenu();
cin>>choice;
while(choice != 6)
{
switch (choice)
{
case 1:
addresses.addAddress();
break;
case 2:
addresses.delAddress();
break;
case 3:
addresses.editAddress();
break;
case 4:
addresses.genBcards();
break;
case 5:
addresses.genAcards();
break;
default:
cout<<"invalid input";
break;
}
printMenu();
cin>>choice;
}
}
void printMenu()
{
cout<<"Menu"<<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 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<<"Please select from menu: ";
}

==========================================================================

//addresslist.cpp
#include "addresslist.hpp"
#include "address.hpp"
#include <ctype.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <ctime>
#include <limits.h>

void getDate(string& dt);

using namespace std;
bool checkDay(string date);

AddressList::AddressList()
{
}

AddressList::~AddressList()
{
addressbook.empty();
}

void AddressList::addAddress()
{
string temp;
Address* newadd = new Address;

// get first name
cout<<"Please enter first name: ";
cin>>temp;
newadd->addField(Address::FIRSTNAME, temp);

// get last name
cout<<"Please enter last name: ";
cin>>temp;
newadd->addField(Address::LASTNAME, temp);
int choice;
cout<<"Please choose one of the following options (q to quit)."<<endl;
cout<<"Enter Address -- 1"<<endl<<"Enter email -- 2"<<endl;
cout<<"Enter Phone -- 3"<<endl<<"Enter Birthday -- 4"<<endl;
cout<<"Enter Aniversary Date -- 5 "<<endl;
cin>>choice;
switch (choice + 1) // skip first and last name
{
case Address::ADDRESS:
cout<<"Please enter address: "<<endl;
cin>>temp;
newadd->addField(Address::ADDRESS, temp);
break;
case Address::EMAIL:
cout<<"Please enter email: ";
cin>>temp;
newadd->addField(Address::EMAIL, temp);
break;
case Address::PHONE:
cout<<"Please enter phone number: ";
cin>>temp;
newadd->addField(Address::PHONE, temp);
break;
case Address::BIRTHDAY:
cout<<"Please enter Birthday (mm/dd/yyyy): ";
cin>>temp;
if(checkDay(temp))
{
newadd->addField(Address::BIRTHDAY, temp);
}
else
{
cout<<"Wrong Date Format"<<endl;
}
break;
case Address::ANNIVERSARY:
cout<<"Please enter Anniversary date (mm/dd/yyyy): ";
cin>>temp;
if(checkDay(temp))
{
newadd->addField(Address::ANNIVERSARY, temp);
}
else
{
cout<<"Wrong Date Format"<<endl;
}
break;
}

}

void AddressList::editAddress()
{
string firstname, lastname;
cout<<"Please enter first name: ";
cin>>firstname;
cout<<"Please enter last name: ";
cin>>lastname;
Address Addr;
addressbook.reset();
bool found = false;
while( addressbook.next(Addr) == true)
{
// declare first and last name fields
Address::Field fn, ln;

// find firstname
Addr.find(&fn, Address::FIRSTNAME);
if(firstname.compare(fn.info) == 0)
{
Addr.find(&ln, Address::LASTNAME);
if(lastname.compare(ln.info) == 0)
{
found = true;
break;
}
}
}
if(found)
{
int choice;
cout<<"Please choose what field you want to edit: "<<endl;
cout<<"Address -- 1"<<endl<<"Email -- 2"<<endl;
cout<<"Phone -- 3"<<endl<<"Birthday -- 4"<<endl;
cout<<"Aniversary Date -- 5 "<<endl;
cin>>choice;

Address::Field fld;
if( Addr.find(&fld, Address::fieldtype(choice+1)) )
{
string input;
cout<<"Please enter value of field: ";
getline(cin, input);
if( (fld.type == Address::BIRTHDAY) || (fld.type == Address::ANNIVERSARY))
{
if( checkDay(input) )
{
fld.info = input;
}
else
{
cout<<"Invalid Input"<<endl;
}
}
else
{
fld.info = input;
}
}
}
else
{
cout<<"The name you entered was not found."<<endl;
}
}
void AddressList::delAddress()
{
string firstname, lastname;
cout<<"Please enter first name: ";
cin>>firstname;
cout<<"Please enter last name: ";
cin>>lastname;
Address Addr;
addressbook.reset();
bool found = false;
while( addressbook.next(Addr) == true)
{
// declare first and last name fields
Address::Field fn, ln;

// find firstname
Addr.find(&fn, Address::FIRSTNAME);
if(firstname.compare(fn.info) == 0)
{
Addr.find(&ln, Address::LASTNAME);
if(lastname.compare(ln.info) == 0)
{
found = true;
break;
}
}
}
if(found)
{
if ( addressbook.del(Addr) )
{
cout<<"Address Has Been Deleted !!"<<endl;
}
else
{
cout<<"Error While deleting"<<endl;
}
}
else
{
cout<<"Could find person with that name."<<endl;
}
}

void AddressList::genBcards()
{
string sdate;
getDate(sdate);
Address Addr;
while(addressbook.next(Addr) == true)
{
Address::Field fld;
if(Addr.find(&fld, Address::BIRTHDAY))
{
if(fld.info == sdate)
{
Addr.printB();
}
}
}

}

void AddressList::genAcards()
{
string sdate;
getDate(sdate);
Address Addr;
while(addressbook.next(Addr) == true)
{
Address::Field fld;
if(Addr.find(&fld, Address::ANNIVERSARY))
{
if(fld.info == sdate)
{
Addr.printA();
}
}
}
}
bool checkDay(string date)
{
//return value
bool rv = true;

for(int i=0; i<10; ++i)
{
if( (i != 2) && (i != 5) )
{
if( isdigit(date[i]) == 0 )
{
rv = false;
break;
}
}
else
{
if( date[i] != '/')
{
rv = false;
break;
}
}
}

return rv;
}

void getDate(string& dt)
{
time_t tsec;

struct tm* date;

tsec = time(NULL);

date= localtime(&tsec);

char pls[11];
if(date->tm_mday < 10)
{
pls[0] = '0';
sprintf(&pls[1], "%d", date->tm_mday);
}
else
{
sprintf(&pls[0], "%d", date->tm_mday);
}

pls[2] = '/';
if((date->tm_mon+1) < 10)
{
pls[3] = '0';
sprintf(&pls[4], "%d", date->tm_mon + 1);
}
else
{
sprintf(&pls[3], "%d", date->tm_mon + 1);
}
pls[5] = '/';

sprintf(&pls[6], "%d", date->tm_year+1900);
pls[10] = '\0';

dt = pls;
}

========================================================================

//addresslist.hpp

#ifndef ADDRESSLIST_HPP
#define ADDRESSLIST_HPP

#include "linkedlist.hpp"
#include "address.hpp"

class AddressList
{
public:

AddressList();

~AddressList();

void addAddress();
void editAddress();

void delAddress();
void genBcards();

void genAcards();

private:

LinkedList<Address> addressbook;
};

#endif // ADDRESSLIST_HPP

========================================================================

//address.cpp
#include "address.hpp"
#include <iostream>

using namespace std;


//----------------------------------------------------------------------------------------------------------------
/// constructor
//----------------------------------------------------------------------------------------------------------------
Address::Address()
{
}

//----------------------------------------------------------------------------------------------------------------
/// destructor
//----------------------------------------------------------------------------------------------------------------
Address::~Address()
{
fields.empty();
}

//----------------------------------------------------------------------------------------------------------------
/// addField
//----------------------------------------------------------------------------------------------------------------
void Address::addField(fieldtype type, string value)
{
Field temp;
temp.type = type;
temp.info = value;
fields.put(temp);
}

//----------------------------------------------------------------------------------------------------------------
/// rmField
//----------------------------------------------------------------------------------------------------------------
bool Address::rmField(fieldtype type, string value)
{
Field temp;
temp.type = type;
temp.info = value;
fields.del(temp);
}

//----------------------------------------------------------------------------------------------------------------
/// find
//----------------------------------------------------------------------------------------------------------------
bool Address::find(Field* fld, fieldtype type)
{
//return value
bool rc;

Field tmp;
fields.reset();
while( fields.next(tmp) == true)
{
if(tmp.type == type)
{
rc = true;
fld = &tmp;
break;
}
}

return rc;
}

//----------------------------------------------------------------------------------------------------------------
/// operator >
//----------------------------------------------------------------------------------------------------------------
bool Address::operator >(Address addr)
{
//return value
bool rv = false;

Field fld1, fld2;

this->find(&fld1, FIRSTNAME);
addr.find(&fld2, FIRSTNAME);
if(fld1 > fld2)
{
rv = true;
}
else if(fld1 == fld2)
{
this->find(&fld1, LASTNAME);
addr.find(&fld2, LASTNAME);
if(fld1 > fld2)
{
rv = true;
}
}

return rv;

}

//----------------------------------------------------------------------------------------------------------------
/// operator ==
//----------------------------------------------------------------------------------------------------------------
bool Address::operator ==(Address addr)
{
//return value
bool rv = false;

Field fld1, fld2;

this->find(&fld1, FIRSTNAME);
addr.find(&fld2, FIRSTNAME);
if(fld1 == fld2)
{
this->find(&fld1, LASTNAME);
addr.find(&fld2, LASTNAME);
if(fld1 == fld2)
{
rv = true;
}
}

return rv;

}

//----------------------------------------------------------------------------------------------------------------
/// printA
//----------------------------------------------------------------------------------------------------------------
void Address::printB()
{
Field fld;
cout<<endl<<"Dear ";
this->find(&fld, FIRSTNAME);
cout<<fld.info<<" ";
this->find(&fld, LASTNAME);
cout<<fld.info<<","<<endl<<endl;
cout<<"Hope your Birthday is really Wonderful and this coming year is the best yet!"<<endl;
cout<<endl<<"Love, "<<endl<<endl<<"Henok "<<endl;
}

//----------------------------------------------------------------------------------------------------------------
/// printB
//----------------------------------------------------------------------------------------------------------------
void Address::printA()
{
Field fld;
cout<<endl<<"Dear ";
this->find(&fld, FIRSTNAME);
cout<<fld.info<<" ";
this->find(&fld, LASTNAME);
cout<<fld.info<<","<<endl<<endl;
cout<<"Hope your Annivarsary is really Wonderful and this coming year is the best yet!"<<endl;
cout<<endl<<"Love, "<<endl<<endl<<"Henok "<<endl;
}

==============================================================================

//address.hpp

#ifndef ADDRESS_HPP
#define ADDRESS_HPP

#include "linkedlist.hpp"
#include <string>

using namespace std;

class Address
{
public:
//----------------------------------------------------------------------------------------------------------------
/// constructor
//----------------------------------------------------------------------------------------------------------------
Address();

//----------------------------------------------------------------------------------------------------------------
/// destructor
//----------------------------------------------------------------------------------------------------------------
~Address();

enum fieldtype {FIRSTNAME, LASTNAME, ADDRESS, PHONE, EMAIL, BIRTHDAY, ANNIVERSARY};

struct Field
{
fieldtype type;
string info;

bool operator>(Field f)
{
return ( (this->type) > f.type );
}

bool operator==(Field f)
{
return ( (this->type) == f.type);
}
};

void addField(fieldtype type, string value);

bool rmField(fieldtype type, string value);

bool find(Field* fld, fieldtype type);

bool operator>(Address addr);

bool operator==(Address addr);

void printB();

void printA();

private:
LinkedList<Field> fields;

friend class AddressList;
};

#endif // ADDRESS_HPP

===========================================================================

//linkedlist.cpp
#ifndef LINKEDLIST_CPP
#define LINKEDLIST_CPP

#include "linkedlist.hpp"
#include <stdint.h>
#include <cstddef>

//----------------------------------------------------------------------------------------------------------------
// this is the definition of the LinkedListClass
//----------------------------------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------------------------------
// constructor
//----------------------------------------------------------------------------------------------------------------
template<typename T>
LinkedList<T>::LinkedList(): list(NULL), current(NULL), size(0)
{
}

//----------------------------------------------------------------------------------------------------------------
// destructor
//----------------------------------------------------------------------------------------------------------------
template<typename T>
LinkedList<T>::~LinkedList()
{
this->empty();
}

//----------------------------------------------------------------------------------------------------------------
/// put
//----------------------------------------------------------------------------------------------------------------
template<typename T>
void LinkedList<T>::put(T item)
{
node* curr = list;
node* prev = NULL;

while(true)
{
// if last element in the list
if(curr == NULL)
{
curr = new node;
curr->data = item;
curr->next = NULL;

// if list was empty, initialize iterator
if(size == 0)
{
current = list;
}
size++;
break;
}
else if(item > curr->data) // finding right place
{
curr = curr->next;
prev = curr;
}
else // puts the item in between prev and curr
{
node* temp = new node;
temp->data = item;
temp->next = curr;
prev->next = temp;
size++;
break;
}
}
}

//----------------------------------------------------------------------------------------------------------------
/// empty
//----------------------------------------------------------------------------------------------------------------
template<typename T>
void LinkedList<T>::empty()
{
node* temp;
while(list != NULL)
{
temp = list;
list = list->next;
delete temp;
}
size = 0;
}

//----------------------------------------------------------------------------------------------------------------
/// isEmpty
//----------------------------------------------------------------------------------------------------------------
template<typename T>
bool LinkedList<T>::isEmpty()
{
return (size == 0);
}

//----------------------------------------------------------------------------------------------------------------
/// reset
//----------------------------------------------------------------------------------------------------------------
template<typename T>
void LinkedList<T>::reset()
{
current = list;
}

//----------------------------------------------------------------------------------------------------------------
/// next
//----------------------------------------------------------------------------------------------------------------
template<typename T>
bool LinkedList<T>::next(T& item)
{
item = current->data;
if(current->next != NULL)
{
current = current->next;
return true;
}
return false;
}

//----------------------------------------------------------------------------------------------------------------
/// del
//----------------------------------------------------------------------------------------------------------------
template<typename T>
bool LinkedList<T>::del(T& item)
{
// return value
bool rc = false;

node* prev = NULL;
for(node* curr = list; curr != NULL; curr = curr->next)
{
if(item == curr->data)
{
if(curr == list)
{
list = list->next;
}
else
{
prev->next = curr->next;
}
delete curr;
rc = true;
break;
}
prev = curr;
}
return rc;
}

#endif

==========================================================================

//linkedlist.hpp

#ifndef LINKEDLIST_H
#define LINKEDLIST_H

#include <stdint.h>


template<typename T>
class LinkedList
{
public:
LinkedList();

~LinkedList();

void put(T item);

//----------------------------------------------------------------------------------------------------------------
/// @brief
/// empties list
//----------------------------------------------------------------------------------------------------------------
void empty();

bool isEmpty();

void reset();

bool next(T& item);

bool del(T& item);

private:
struct node
{
T data;
node* next;
};

// points to the first element of the list
node* list;

// points to current element for the iterator
node* current;

// number of elements in the list
int32_t size;


};

#include "linkedlist.cpp"

#endif // LINKEDLIST_H

=======================================================================

sample output:

ぐ > C https://www.tutorialspoint.com/compile_cpp0x_online.php codingground COM PILE AND EXECUTE C++ ONLI Default Term sh-4.2$

Add a comment
Know the answer?
Add Answer to:
C++ : Please include complete source code in answer This program will have names and addresses...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ program: Write an address book program that will accomplish the following: 1. Read name and...

    C++ program: Write an address book program that will accomplish the following: 1. Read name and address data from the user from the keyboard. 2. While reading the names and addresses, put the names into an appropriate data structure. 3. After reading names and addresses, allow user to search for names and change the names or addresses in the container data structure. 4. Allow user to write out the container data structure to a comma delimited file. The input file...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • c++ and please add tables and everything and make sure program is complete. Write a menu...

    c++ and please add tables and everything and make sure program is complete. Write a menu driven program, which would compute compound interest and a monthly payment for a loan. The user will be given a choice to display the info on the screen or to a filo Menu will be the following Enter (1) to calculate your loan monthly payment Enter (2) to calculate your loan monthly payment & write to a file Tips: Compound Interest Formula A =...

  • Write a program in C++: Using classes, design an online address book to keep track of the names f...

    Write a program in C++: Using classes, design an online address book to keep track of the names first and last, addresses, phone numbers, and dates of birth. The menu driven program should perform the following operations: Load the data into the address book from a file Write the data in the address book to a file Search for a person by last name or phone number (one function to do both) Add a new entry to the address book...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • Write a C program as follows: Single source code file Calls a function with an arbitrary...

    Write a C program as follows: Single source code file Calls a function with an arbitrary name (i.e. you name it) that accepts two arrays of the same size The function should add each element in the arrays together and place the values in a third array Each array element, each array address, and the sum are printed to the screen in tabulated format with headersI also would like to request that LOTS of comments be included, as I need...

  • write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last...

    write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last name and first name of the owner). Ask the user to input up to 10 Contacts (It may be less. The user should have the ability to stop inputting Contacts whenever he wishes). 3.This class will store a list of Contacts in a stack allocated array of default capacity 10. 4.You must be able to add new contacts to a list, delete old contacts,...

  • I've done all questions except question 6. how do I do this? please help. code needs...

    I've done all questions except question 6. how do I do this? please help. code needs to be java 1. You need to be able to open and read the text files that have been provided for the project. Write a Java program that reads the driver.txt file and displays each data value for each line from the file to the screen in the following format: Licence Number: Licence Class: First Name: Last Name: Address: Suburb: Postcode: Demerit Points: Licence...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT