//header files
#ifndef Contact_H // header files should always have this to
avoid
#define Contact_H // multiple inclusion in other
files
#include <string>
// this is the only programming assignment which will use this
statement.
// normally "using namespace std" is looked down upon because
it
// introduces many common keywords that could be accidentally used,
but
// it identifies useful types such as string and would normally be
used
// std::string or std::vector.
using namespace std;
class Contact {
public:
Contact(string _name = "", int _phoneNumber =
0);
Contact(string _name, int _phoneNumber,
Contact &
_emergencyContact);
// accessors for Contact
string getName() const;
int getPhoneNumber() const;
bool verifyPhoneNumber() const;
Contact* getEmergencyContact() const;
int number;
string name;
// mutators for Contact
void changeNumber(const int newNumber);
void changeNumber(const Contact * newContact);
void changeName(const string newName);
void changeName(const Contact * newContact);
void setEmergencyContact(Contact &
_emergencyContact);
private:
//int number;
int phoneNumber;
Contact * emergencyContact;
};
#endif
#ifndef PhoneBook_H
#define PhoneBook_H
#include "Contact.h"
class PhoneBook {
public:
PhoneBook(Contact * contacts = NULL, int numContacts = 0);
// search accessors
string getNameByNumber(const int phoneNumber) const;
int getNumberByName(const string name) const;
void printAllContacts() const;
// mutators
void verifyAllContacts();
private:
Contact * contactList;
int numContacts;
int num_contacts;
Contact* contactList1;
int num_contact;
};
#endif
#include "PhoneBook.h"
#include "Contact.h"
#include <iostream>
// constructor -----------
PhoneBook::PhoneBook(Contact * contacts, int _numContacts){
if (_numContacts){
numContacts = _numContacts;
contactList = new Contact
[numContacts];
for (int i = 0; i < numContacts;
i++){
contactList[i] =
Contact((contacts+i)->getName(),
(contacts+i)->getPhoneNumber(),
*(contacts+i)->getEmergencyContact());
}
}
}
// accessors ---------------------
int PhoneBook::getNumberByName(const string _name) const {
// steps through the list of contacts and compares
each name to the
// parameter _name and returns the phone number if
found.
// if not found, return -1.
// NOTE: remember that '==' is not sufficient for
string compare.
//
// CODE HERE
return -1; // None found
}
string PhoneBook::getNameByNumber(const int _number) const
{
// steps through the list of contacts and compares
each number to the
// parameter _number and returns the name if
found.
// if not found, return NULL.
//
// CODE HERE
return NULL; // None found
}
// call to print all Contacts from the given PhoneBook
// print format is a different contact on each line, and each
// line contains:
// name
phoneNumber emergencyContact
void PhoneBook::printAllContacts() const {
std::cout << "\nnum contacts: " <<
numContacts << std::endl;
for (int i = 0; i < numContacts; i++){
std::cout <<
contactList[i].getName() << " " <<
contactList[i].getPhoneNumber() << " " <<
contactList[i].getEmergencyContact() << std::endl;
}
}
void PhoneBook::verifyAllContacts(){
// From the given PhoneBook object, call the
verifyPhoneNumber()
// from each of the Contacts contained in the private
variable
// contactList, and also on the emergency contacts
from each of
// the contacts.
// Remove all Contacts that do not have a valid
phoneNumber from the
// array (and just remove invalid emergencyContacts
from valid Contacts,
// do not remove entire Contact from array) and resize
the array so
// that there are no gaps after removing the
Contacts.
// HINT: resizing an array is hard... it is sometimes
easier to simply
// make a new one.
//
// CODE GOES HERE
}
//PhoneBook.cpp
#include "PhoneBook.h"
#include "Contact.h"
#include <iostream>
// constructor -----------
PhoneBook::PhoneBook(Contact * contacts, int _numContacts) {
if (_numContacts) {
numContacts = _numContacts;
contactList = new Contact[numContacts];
for (int i = 0; i < numContacts; i++) {
contactList[i] = Contact((contacts + i)->getName(),
(contacts + i)->getPhoneNumber(),
*(contacts + i)->getEmergencyContact());
}
}
}
// accessors ---------------------
int PhoneBook::getNumberByName(const string _name) const {
// steps through the list of contacts and compares each name to the
// parameter _name and returns the phone number if found.
// if not found, return -1.
// NOTE: remember that '==' is not sufficient for string compare.
//
for (int i = 0; i < numContacts; i++) {
if (contactList[i].getName().compare(_name) == 0) {
return contactList[i].getPhoneNumber();
}
}
return -1; // None found
}
string PhoneBook::getNameByNumber(const int _number) const {
// steps through the list of contacts and compares each number to the
// parameter _number and returns the name if found.
// if not found, return NULL.
//
for (int i = 0; i < numContacts; i++) {
if (contactList[i].getPhoneNumber() == _number) {
return contactList[i].getName();
}
}
return NULL; // None found
}
// call to print all Contacts from the given PhoneBook
// print format is a different contact on each line, and each
// line contains:
// name phoneNumber emergencyContact
void PhoneBook::printAllContacts() const {
std::cout << "\nnum contacts: " << numContacts << std::endl;
for (int i = 0; i < numContacts; i++) {
std::cout << contactList[i].getName() << " " <<
contactList[i].getPhoneNumber() << " " <<
contactList[i].getEmergencyContact() << std::endl;
}
}
void PhoneBook::verifyAllContacts() {
// From the given PhoneBook object, call the verifyPhoneNumber()
// from each of the Contacts contained in the private variable
// contactList, and also on the emergency contacts from each of
// the contacts.
// Remove all Contacts that do not have a valid phoneNumber from the
// array (and just remove invalid emergencyContacts from valid Contacts,
// do not remove entire Contact from array) and resize the array so
// that there are no gaps after removing the Contacts.
// HINT: resizing an array is hard... it is sometimes easier to simply
// make a new one.
//
contactList1 = new Contact[numContacts];
num_contact = 0;
// Pushing valid contacts to the contactList1 temporarily
for (int i = 0; i < numContacts; i++) {
if (!contactList[i].verifyPhoneNumber()){
delete &contactList[i];
continue;
}
else if(!contactList[i].getEmergencyContact()->verifyPhoneNumber()){
delete contactList[i].getEmergencyContact();
}
contactList1[num_contact] = contactList[i];
num_contact++;
}
// Now resize the original contactList and push valid contacts inside it
numContacts = num_contact;
contactList = new Contact[numContacts];
for (int i = 0; i < numContacts; i++) {
contactList[i] = contactList1[i];
}
}
//header files #ifndef Contact_H // header files should always have this to avoid #define Contact_H ...
#include "name.h" #include "contact.h" using namespace std; class ContactList; typedef class Node* NodePtr; class Node { Contact item; NodePtr next; friend class ContactList; }; class ContactList { public: ContactList(char* clfile) ; ~ContactList(); void display (ostream & output) const; int insert (Contact record_to_insert); int insert (ContactList contact_list); int remove (Contact record_to_delete); int size () const; int save () const; void find_by_lname (ostream & output, string lname) const; void...
#ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: // default constructor procReqRec() {} // constructor procReqRec(const string& nm, int p); // access functions int getPriority(); string getName(); // update functions void setPriority(int p); void setName(const string& nm); // for maintenance of a minimum priority queue friend bool operator< (const procReqRec& left, const procReqRec& right); // output a process request record in the format // name: priority friend ostream& operator<< (ostream& ostr, const procReqRec&...
/ Animal.hpp
#ifndef ANIMAL_H_
#define ANIMAL_H_
#include <string>
class Animal
{
public:
Animal();
Animal(std::string, bool domestic=false, bool
predator=false);
std::string getName() const;
bool isDomestic() const;
bool isPredator() const;
void setName(std::string);
void setDomestic();
void setPredator();
protected: // protected so that derived class can directly
access them
std::string name_;
bool domestic_;
bool predator_;
};
#endif /* ANIMAL_H_ */
//end of Animal.h
//
/////////////////////////////////////////////////////////////////Animal.cpp
#include "Animal.h"
Animal::Animal(): name_(""),domestic_(false),
predator_(false){
}
Animal::Animal(std::string name, bool domestic, bool
predator):
name_(name),domestic_(domestic), predator_(predator)
{
}
std::string Animal::getName() const{
return...
This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone book using a linked list to keep people's names and phone numbers organized in alphabetical order. 1. Define a structure to hold the contact information including: name, phone number, a pointer to the next node in the list. Example: struct ContactNode { string name; string phoneNumber; ContactNode *next; } 2. Define a class containing the structure and the appropriate methods to update and retrieve...
USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...
C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp) Print out the customer’s name, address, account number and balance using whatever formatting you would like Sort on account balance (hint: you can overload the < operator and use sort from the...
Declare and define TtuStudentNode in TtuStudentNode.h and TtuStudentNode.cpp file. TtuStudentNode has its unique string variable "studentEmail" which contains email address. TtuStudentNode has its unique function member GetEmail() which returns the string variable "studentEmail". TtuStudentNode has its overriding "PrintContactNode()" which has the following definition. void TtuStudentNode::PrintContactNode() { cout << "Name: " << this->contactName << endl; cout << "Phone number: " << this->contactPhoneNum << endl; cout << "Email : " << this->studentEmail << endl; return; } ContactNode.h needs to have the function...
Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...
// Name.h #ifndef __NAME_H__ #define __NAME_H__ #include <iostream> #include <string> using namespace std; #define MAXLENGTH 12 #define NAME_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'" namespace Errors { struct InvalidName { }; } class Name { public: Name ( string first_name = "", string last_name = ""); string first() const; string last() const; void set_first( string fname ); void set_last( string lname); friend ostream& operator<< ( ostream & os, Name name ); friend bool operator== (Name name1, Name...