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

THIS IS A C++ ASSIGNMENT I DO HAVE CODE TO WORK WITH (2 cpp files and 2 header f

ID: 3583526 • Letter: T

Question

THIS IS A C++ ASSIGNMENT

I DO HAVE CODE TO WORK WITH (2 cpp files and 2 header files, but it says i can't find the .h files when I run it so it's not working)

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. Someone recently posted some code that looked better than this but it had a bunch of header files that I don't have. 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

Here's the code so far, it is very long: (there is a main.cpp and header files in this code, you probably need to separate them inside your compiler to get it to work)

main.cpp

#include <iostream>

#include <stdlib.h>

#include <LinkedList.h>

#include <AddressBook.h>

#include <limits>

using namespace std;

void mainMenu(AddressBook& addresses);

void enterName(AddressBook& addresses);

void deleteName(AddressBook& addresses);

void changeName(AddressBook& addresses);

void generateBirthdayCards(AddressBook& addresses);

void generateAnniversaryCards(AddressBook& addresses);

void resetInput();

int main()

{

// Load the address book

AddressBook addresses;

addresses.load();

// Start the mainMenu loop

mainMenu(addresses);

return 0;

}

void mainMenu(AddressBook& addresses)

{

// Display main menu

cout << "------------------Main 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]: Save and exit the card program" << endl;

cout << "[7]: Print address book." << endl;

// Prompt for user input.

cout << "Enter code here: ";

// Cleanup to make sure cin is working before gathering user input

resetInput();

int code;

cin >> code;

cout << endl;

// If their input failed, as they entered a word instead of a number

while(cin.fail())

{

// Cleanup to make sure cin is working before gathering user input

resetInput();

// Prompts that input failed, trys to recollect input

cout << "Input failed. Enter code here: ";

cin >> code;

cout << endl;

}

// Start the corresponding function the code that was entered.

switch(code)

{

case 1:

cout << "-----------------Enter Name------------------" << endl;

enterName(addresses);

break;

case 2:

cout << "-----------------Delete Name-----------------" << endl;

deleteName(addresses);

break;

case 3:

cout << "-----------------Change Name-----------------" << endl;

changeName(addresses);

break;

case 4:

cout << "---------------Birthday Cards----------------" << endl;

generateBirthdayCards(addresses);

break;

case 5:

cout << "-------------Anniversary Cards---------------" << endl;

generateAnniversaryCards(addresses);

break;

// Saves and exits the program

case 6:

cout << "Now closing..." << endl;

addresses.save();// Saves the addresses to the text file

exit(0);// Exits the program

break;

case 7:

cout << "----------------Address List-----------------" << endl;

addresses.print();

break;

default:

// The default operation will print wrong number.

cerr << "Sorry, wrong number." << endl;

break;

};

mainMenu(addresses);

}

void enterName(AddressBook& addresses)

{

// Cleanup to make sure cin is working before gathering user input

resetInput();

// Fill out form, for name, address, anniversary date, and birthday

Address cur;

cout << "Enter name:";

getline(cin, cur.name);

cout << "Enter Address:";

getline(cin, cur.streetAddress);

cout << "Enter Anniversary Date:";

getline(cin, cur.anniversaryDate);

cout << "Enter Birthday Date:";

getline(cin, cur.birthdayDate);

cout << endl;

// We then add the newly created address to the address book

addresses.add(cur);

}

void deleteName(AddressBook& addresses)

{

// Cleanup to make sure cin is working before gathering user input

resetInput();

// Get name to delete

string name;

cout << "Enter name to delete: ";

getline(cin, name);

cout << endl;

// Remove it from the address book

addresses.remove(name);

}

void changeName(AddressBook& addresses)

{

// Cleanup to make sure cin is working before gathering user input

resetInput();

// Get name to rename

string name;

cout << "Enter name to rename: ";

getline(cin, name);

// Get the address with the specific name

Address addressToBeDeleted = addresses.get(name);

// If the address is NULL, the entered name doesn't exist. Exit the function.

if(addressToBeDeleted.name == "NULL")

{

cerr << "Entered name does not exist!" << endl;

return;

}

// New Address that is being formed

Address* changeAddress = new Address;

changeAddress->streetAddress = addressToBeDeleted.streetAddress;

changeAddress->anniversaryDate = addressToBeDeleted.anniversaryDate;

changeAddress->birthdayDate = addressToBeDeleted.birthdayDate;

// Remove the old address

addresses.remove(name);

// Get the new name

cout << "Enter new name: ";

getline(cin, name);

cout << endl;

changeAddress->name = name;

// Add the new address to the address book

addresses.add(*changeAddress);

}

void generateBirthdayCards(AddressBook& addresses)

{

// Cleanup to make sure cin is working before gathering user input

resetInput();

// Get date

string date;

cout << "Enter date: ";

cin >> date;

// Generate birthday cards for the date

addresses.generateBirthdayCards(date);

}

void generateAnniversaryCards(AddressBook& addresses)

{

// Cleanup to make sure cin is working before gathering user input

resetInput();

// Get date

string date;

cout << "Enter date: ";

cin >> date;

// Generate anniversary cards for the date

addresses.generateAnniversaryCards(date);

}

// Cleanup to make sure cin is working before gathering user input

void resetInput()

{

// If it's failed, ignore the whole line

if(cin.fail())

{

// Removes any information user entered.

cin.clear();

// cin.ignore(std::numeric_limits<std::streamsize>::max(), ' ');

}

// If the next character is a newline, ignore it.

if(cin.peek() == ' ')

{

cin.ignore();

}

}

LinkedList.h

#ifndef LINKEDLIST_H

#define LINKEDLIST_H

#include <stdio.h>

#include <iostream>

template <typename Type>

class LinkedList

{

public:

LinkedList();

virtual ~LinkedList();

int getLength();

virtual void print();

void add(Type value);

void remove(Type value);

protected:

int length;

struct Node

{

Type val;

Node* next;

};

Node* head, *tail;

};

/**

* Sets head and tail to null, sets length to be empty.

*/

template <typename Type>

LinkedList<Type>::LinkedList()

{

head = tail = NULL;

length = 0;

}

/**

* Destructor for the Linked List.

*/

template <typename Type>

LinkedList<Type>::~LinkedList()

{

Node* prev = NULL;

Node* it = head;

while(it != NULL)

{

prev = it;

it = it->next;

delete prev;

}

}

/**

* Prints the whole linked list.

*/

template <typename Type>

void LinkedList<Type>::print()

{

int index = 0;

Node* it = head;

while(it != NULL)

{

std::cout << "{" << index << ":" << it->val << "}";

if(it->next != NULL)

{

std::cout << ", ";

}

it = it->next;

}

}

/**

* @return the number of nodes in the linked list.

*/

template <typename Type>

int LinkedList<Type>::getLength()

{

return length;

}

template <typename Type>

void LinkedList<Type>::add(Type value)

{

Node* newNode = new Node;

newNode->val = value;

newNode->next = NULL;

if(head == NULL)

{

head = tail = newNode;

}

else

{

tail->next = newNode;

tail = newNode;

}

length++;

}

/**

* Removes all nodes that have the value passed in.

* @param value The value you want to remove.

*/

template <typename Type>

void LinkedList<Type>:: remove(Type value)

{

Node* it = head;

Node* prev = NULL;

while(it->next != NULL)

{

if(it->val == value)

{

if(prev == NULL)

{

head = it->next;

delete it;

}

else

{

prev->next = it->next;

delete it;

}

}

prev = it;

it = it ->next;

}

length--;

}

#endif // LINKEDLIST_H

AddressBook.h

#ifndef ADDRESSBOOK_H

#define ADDRESSBOOK_H

#include <LinkedList.h>

#include <Address.h>

class AddressBook : public LinkedList<Address>

{

public:

AddressBook();

virtual ~AddressBook();

void print();// Print the Address Book

void add(Address curAddress);// Add an address

void remove(std::string name);// Remove an address associated with the name passed in

Address get(std::string name);// Get an address by passing in the name of that address

void generateBirthdayCards(std::string date);// Generate bday cards

void generateAnniversaryCards(std::string date);// Generate anniversary cards

void load();// Load the address book

void save();// Save the address book

protected:

private:

void printBirthdayCard(Address currAdress);

void printAnniversaryCard(Address currAdress);

};

#endif // ADDRESSBOOK_H

Address.h

#ifndef ADDRESS_H

#define ADDRESS_H

#include <iostream>

class Address

{

public:

// Create an Address using these 4 params

Address(std::string name = "Not Entered",

std::string streetAddress = "Not Entered",

std::string anniversaryDate = "XX-XX-XXXX",

std::string birthdayDate = "XX-XX-XXXX");

virtual ~Address();

// Let other files print out addresses

friend std::ostream& operator<<(std::ostream& os, const Address& curAddress);

std::string name;

std::string streetAddress;

std::string anniversaryDate;

std::string birthdayDate;

protected:

private:

};

#endif // ADDRESS_H

AddressBook.cpp

#include "AddressBook.h"

#include <iostream>

#include <stdlib.h>

#include <fstream>

AddressBook::AddressBook()

{

//ctor

}

AddressBook::~AddressBook()

{

//dtor

}

// Print all of the elements in the address book

void AddressBook::print()

{

Node* it = head;

while(it != NULL)

{

std::cout << it->val << std::endl;

it = it->next;

}

}

// Removes the passed in name

void AddressBook::remove(std::string name)

{

// start the iterator at the head

Node* it = head;

Node* prev = NULL;

// While our iterator isnt null

while(it != NULL)

{

// Get the current name out of the node

std::string curName = ((Address)it->val).name;

// If the current name and nameToBeDeleted are the same

if(curName == name)

{

// If we are at the head, set it's next node to the iterators next value

if(prev == NULL)

{

head = it->next;

delete it;

}

// Else set the previous values next value to the iterators next value

else

{

prev->next = it->next;

delete it;

}

// Decrease the length on removal

length--;

}

// Set the previous node to be the iterator

prev = it;

// Set the iterator to the next value

it = it ->next;

}

}

// Returns the address at the name passed in, or an address whose name is NULL if the name isn't in the address book

Address AddressBook::get(std::string name)

{

// Set the iterator to the head of the linked list

Node* it = head;

// While our name isn't found, and we haven't gone through the whole list

while(it != NULL)

{

// Extract the iterators name

std::string curName = ((Address)it->val).name;

// If the iterators name is equal to the wanted name, then the value is found and returned

if(curName == name)

{

return it->val;

}

it = it ->next;

}

// If the address wasn't found, return the address with the name of NULL

Address nullAdd;

nullAdd.name = "NULL";

return nullAdd;

}

// Go through every address, print out birthday cards with the same date as string passed in

void AddressBook::generateBirthdayCards(std::string date)

{

// Go through every address

Node* it = head;

while(it != NULL)

{

// If it's birthday is equal to the date passed in, print it's birthday card

Address curAddress = ((Address)it->val);

if(date == curAddress.birthdayDate)

{

printBirthdayCard(curAddress);

}

it = it->next;

}

}

void AddressBook::printBirthdayCard(Address curAddress)

{

std::cout << "-------------------------------------" << std::endl;

std::cout << "Dear " << curAddress.name << "," << std::endl << std::endl;

std::cout << "Hope your birthday is really wonderful and this coming year is the best yet!" << std::endl;

std::cout << "Love," << std::endl << std::endl;

std::cout << "John Doe" << std::endl;

}

// Go through every address, print out anniversary cards with the same date as string passed in

void AddressBook::generateAnniversaryCards(std::string date)

{

// Go through every address

Node* it = head;

while(it != NULL)

{

// If it's anniversary is equal to the date passed in, print it's birthday card

Address curAddress = ((Address)it->val);

if(date == curAddress.anniversaryDate)

{

printAnniversaryCard(curAddress);

}

it = it->next;

}

}

// Add an address to the book, make sure it is sorted alphabetically

void AddressBook::add(Address newAddress)

{

// Create a new node with our address

Node* newNode = new Node;

newNode->val = newAddress;

newNode->next = NULL;

// IF the head is null, the head and tail are both the new node

if(head == NULL)

{

head = tail = newNode;

}

else

{

// Create an iterator, and previous iterator

Node* prev = NULL;

Node* it = head;

// Go through each element

while(it != NULL)

{

// If the current name is greater than the new name,

std::string curName = ((Address)it->val).name;

if(curName > newAddress.name)

{

// Add the new node at the last location, then rewire the list

if(prev == NULL)

{

head = newNode;

newNode->next = it;

}

else

{

prev->next = newNode;

newNode->next = it;

}

return;

}

else

{

// Else we go to the next node

if(it->next == NULL)

{

it->next = newNode;

it = newNode->next;

}

else

{

prev = it;

it = it ->next;

}

}

}

}

// Increment the length when an item is added

length++;

}

void AddressBook::printAnniversaryCard(Address curAddress)

{

std::cout << "-------------------------------------" << std::endl;

std::cout << "Dear " << curAddress.name << "," << std::endl << std::endl;

std::cout << "Hope your anniversary is really wonderful and this coming year is the best yet!" << std::endl;

std::cout << "Love," << std::endl << std::endl;

std::cout << "John Doe" << std::endl;

}

// Loads the address book from a properties file

void AddressBook::load()

{

// Attempt to open the address file

std::ifstream in;

in.open("addresses.properties");

// If the file didn't open, print an error message

if(!in.good())

{

std::cerr << "Cannot open addresses.properties" << std::endl;

return;

}

// While we can read without an error, keep adding addresses to our book

while(in.good())

{

// Create new address, get all 4 elements

Address* curAddress = new Address;

std::string temp;

getline(in, temp);

curAddress->name = temp;

getline(in, temp);

curAddress->streetAddress = temp;

getline(in, temp);

curAddress->anniversaryDate = temp;

getline(in, temp);

curAddress->birthdayDate = temp;

// If our input is still good after adding those 4 elements, add the new address.

if(in.good())

{

add(*curAddress);

}

}

// Close the file stream

in.close();

}

// Save the address book

void AddressBook::save()

{

// Open the properties file for our address book

std::ofstream out;

out.open("addresses.properties");

// If it failed to open, print an error and end.

if(!out.good())

{

std::cerr << "Cannot open addresses.properties" << std::endl;

return;

}

// For every address

Node* it = head;

while(it != NULL)

{

// Print it's information to a new line of the text file

Address curAddress = (Address)it->val;

out << curAddress.name << std::endl;

out << curAddress.streetAddress << std::endl;

out << curAddress.anniversaryDate << std::endl;

out << curAddress.birthdayDate << std::endl;

// Go to the next node

it = it->next;

}

// Close the outstream

out.close();

}

Address.cpp

#include "Address.h"

// Can be created with name, address, aniv date, and bday

Address::Address(std::string name, std::string streetAddress, std::string anniversaryDate, std::string birthdayDate)

{

this->name = name;

this->streetAddress = streetAddress;

this->anniversaryDate = anniversaryDate;

this->birthdayDate = birthdayDate;

}

Address::~Address()

{

//dtor

}

// Can be printed out by an overloaded operator.

std::ostream& operator<<(std::ostream& outStream, const Address& curAddress)

{

outStream.clear();

outStream << "Name: " << curAddress.name << std::endl

<< "Address: "<< curAddress.streetAddress << std::endl

<< "Anniversary Date: " << curAddress.anniversaryDate << std::endl

<< "Birthday Date: " << curAddress.birthdayDate << std::endl;

return outStream;

}

Explanation / Answer

Few points to keep in mind while including header files.
1.   Compile your header files and remove compilation errors.
2.   Keep the header files in the same folder as in .Cpp files. And use
#include < AddressBook.h>

3.   Or else use absolute path like is the header files are in any foder eg   
C/headers/ AddressBook.h
Then use
#include< C/headers/ AddressBook.h>
4.   Use relative path if the header files are in sub folders like if your main file is in
c/file/main.cpp
and .h files are in
c/file/header/AddressBook.h
then use
#include<../header/AddressBook.h