Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ All must be documented Example Code: // the Person class - this is the class from assignment 1 class Person { // the private

image text in transcribed

C++ All must be documented

Example Code:

// the Person class - this is the class from assignment 1

class Person

{

// the private data members

private:

string firstName;

string lastName;

string address;

// the public data members

public:

// the constructor - default constructor

Person()

{

// set all the data members to empty

setFirstName("");

setLastName("");

setAddress("");

}

// the constructor - that takes in the first name and the last name

Person(string firstName, string lastName)

{

setFirstName(firstName);

setLastName(lastName);

// set the address to blank

setAddress("");

}

// the constructor - that takes in the first name and the last name and address

Person(string firstName, string lastName, string address)

{

setFirstName(firstName);

setLastName(lastName);

// set the address to blank

setAddress(address);

}

// getters

string getFirstName() { return firstName; }

string getLastName() { return lastName; }

string getAddress() { return address; }

// setters

void setFirstName(string firstName) { this->firstName = firstName; }

void setLastName(string lastName) { this->lastName = lastName; }

void setAddress(string address) { this->address = address; }

// the print function

virtual void print()

{

cout

}

};

// The address book that extends the vector class - Task1

class AddressBook : public vector

{

// the private data members

private:

int index = 0;

public:

// the default constructor

AddressBook() {}

//Constructor to add address details from file

AddressBook(string filename) {

ifstream in(filename);

if (!in) {

cout

exit(0);

}

string line;

while (getline(in, line)) {

stringstream ss(line);

string token, fName, lName, address;

int i = 0;

while (getline(ss, token, ',')) {

if (i == 0) {

fName = token;

i++;

}

else if (i == 1) {

lName = token;

i++;

}

else {

address = token;

i = 0;

}

}

setPerson(fName, lName, address);

}

in.close();

}

// the constructor that takes in a first name and the last name

AddressBook(string first, string last) { push_back(new Person(first, last, "")); }

// the constructor that takes in a first name, the last name and the address

AddressBook(string first, string last, string address) { push_back(new Person(first, last, address)); }

// the mutator

void setPerson(string first, string last, string address) { push_back(new Person(first, last, address)); }

// returns the next person

Person* getPerson()

{

// if there is no person to return - return null

if (size() == 0)

return NULL;

// return the next person

Person* nextPerson = at(index);

// move the index forward

index = (index + 1) % size();

// return the next person

return nextPerson;

}

// find the person with this last name

Person* findPerson(string last)

{

// find the person with this last name

for (int i = 0; i

{

// if this has the same last name, return this person

if (at(i)->getLastName() == last)

return at(i);

}

// return null pointer

return NULL;

}

// find the person with this first name and last name

Person* findPerson(string first, string last)

{

// find the person with this last name

for (int i = 0; i

{

// if this has the same last name, return this person

if (at(i)->getLastName() == last && at(i)->getFirstName() == first)

return at(i);

}

// return null pointer

return NULL;

}

// print the entire address book

void print()

{

// print all the persons

for (int i = 0; i

{

at(i)->print();

}

}

//Write into file

void writeToFile(string filename) {

ofstream out(filename);

for (int i = 0; i

{

out getFirstName() getLastName() getAddress()

}

out.close();

}

};

// using the same main as in previous part - no changes to the main

// works the same

int main()

{

// create an address Book

AddressBook addressBook1("address.txt");

// since this is empty right now, there is no person inside this

if (addressBook1.findPerson("Wayne") != NULL)

cout

else

cout

// add members to this address book 1

addressBook1.setPerson("Bruce", "Wayne", "Wayne Tower");

addressBook1.setPerson("Clark", "Kent", "Daily Mail");

addressBook1.setPerson("Thor", "Son of Odin", "Asgard");

// look for last name "Wayne"

if (addressBook1.findPerson("Wayne") != NULL)

cout

else

cout

// look for first name and last name - to be found

if (addressBook1.findPerson("Clark", "Kent") != NULL)

cout

else

cout

// look for first name and last name - not to be found

if (addressBook1.findPerson("Bruce", "Banner") == NULL)

cout

else

cout

// change line

cout

// print the address book

addressBook1.print();

// change line

cout

//Call function to write into file

addressBook1.writeToFile("address.txt");

}

You will be requi o have an understanding of opening anle closing anle, reading at a time. You will also be This assignment is intended as a means for you to practice le from a text file and formatting output to be written to a text file Activity Objectives This activity is designed to support the following learning Objectives 1. Compose computer programs using a high level programming langages as a means of problem solving. This includes Abstract data types, inheritance, and polymorphism 2. Evaluate the advanced features of an object oriented programming language including any pointer manipulation, recursion, and object oriented programming. i Instructions This small project is gested to test your understanding of File 10 Address Book Exception Create an Aduressbuuk Caveplion class you can use lothrow exceptions in your duress book. Your class should have constructor that will allow you lose the particular message that corresponds to the error. You should use your custum exception class to throw an error in the indPerson method if the person being searched for anmol be found in the set Personnehod if the AduressDuok is empty. You should also throw an error any time that the addressbuuk file that you are attempting to read or write from carnot be opened. In main test your Address Book exception class by placing a try catch around a code that could possibly throw an arrar Supply a catch block to catch the Address Book ception and provide a catch all block ust in case an exception is thrown the you may have missed. Canvas Guides Submi s sion . Please note: This course Uses Modules for r ation, scroll down to Submit Assignment for instruction Grading Rubric This assignment is worth 10 points. The following rubric will be used to grade your assignment. Please note if viewing the course via the Canvas mobile app, uhrics are not currently available 3096 - All Directions Are Followed 15% - If it compiles without error 306 It runs to completion with proper input and output 259 - Program Correctness Getting Help If you are having dificulty with the concepts in this assignment or just want to discuss a few things about it then you should use the discussion board for this unit. If you have questions that are of a personal nature use the Canvas Inbox to email me. Feedback / Grading You can n ot this assignment to he graded within four days of the ci date. Fredback will be in the contents section of the signment submission You will be requi o have an understanding of opening anle closing anle, reading at a time. You will also be This assignment is intended as a means for you to practice le from a text file and formatting output to be written to a text file Activity Objectives This activity is designed to support the following learning Objectives 1. Compose computer programs using a high level programming langages as a means of problem solving. This includes Abstract data types, inheritance, and polymorphism 2. Evaluate the advanced features of an object oriented programming language including any pointer manipulation, recursion, and object oriented programming. i Instructions This small project is gested to test your understanding of File 10 Address Book Exception Create an Aduressbuuk Caveplion class you can use lothrow exceptions in your duress book. Your class should have constructor that will allow you lose the particular message that corresponds to the error. You should use your custum exception class to throw an error in the indPerson method if the person being searched for anmol be found in the set Personnehod if the AduressDuok is empty. You should also throw an error any time that the addressbuuk file that you are attempting to read or write from carnot be opened. In main test your Address Book exception class by placing a try catch around a code that could possibly throw an arrar Supply a catch block to catch the Address Book ception and provide a catch all block ust in case an exception is thrown the you may have missed. Canvas Guides Submi s sion . Please note: This course Uses Modules for r ation, scroll down to Submit Assignment for instruction Grading Rubric This assignment is worth 10 points. The following rubric will be used to grade your assignment. Please note if viewing the course via the Canvas mobile app, uhrics are not currently available 3096 - All Directions Are Followed 15% - If it compiles without error 306 It runs to completion with proper input and output 259 - Program Correctness Getting Help If you are having dificulty with the concepts in this assignment or just want to discuss a few things about it then you should use the discussion board for this unit. If you have questions that are of a personal nature use the Canvas Inbox to email me. Feedback / Grading You can n ot this assignment to he graded within four days of the ci date. Fredback will be in the contents section of the signment submission

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

Do Problem 3.75, but for the substance ammonia.

Answered: 1 week ago

Question

CL I P COL Astro- L(1-cas0) Lsing *A=2 L sin(0/2)

Answered: 1 week ago

Question

Distinguish between poor and good positive and neutral messages.

Answered: 1 week ago

Question

Describe the four specific guidelines for using the direct plan.

Answered: 1 week ago