SlideShare a Scribd company logo
// READ BEFORE YOU START: // You are given a partially completed program that creates a
list of pets with their list of checkups. // Each pet has the corresponding information: name,
breed, and a linked list of checkups. // To begin, you should trace through the given code and
understand how it works. // Please read the instructions above each required function and follow
the directions carefully. // If you modify any of the given code, the return types, or the
parameters, you risk failing the automated test cases. // // You are to assume that all input is
valid: // Valid name: String containing alphabetical letters beginning with a capital letter // Valid
breed: String containing alphabetical letters beginning with a capital letter // Valid date: String
in the following format: "MM/DD/YYYY" ex: "01/01/2010" // All input will be a valid length
and no more than the allowed amount of memory will be used // // Q1 : CLASS METHODS Part
1 : Constructor and Accessor Methods for Pet class in Pet.cpp file ( 5 points) // Q2 : CLASS
METHODS Part 2 : Class methods for Pet class in Pet.cpp file (10
points) // Q3 : Add Function in hw09.cpp file
( 5 points) // Q4 : Search Function in hw09.cpp file
(10 points) // Q5 : Remove One Function in hw09.cpp
file (15 points) // Q6 : Implement
cin / cout for the lines in main without modifying the functionality ( 5 points)
#include #include #include #include "Container.h" #include "Pet.h" #include "Checkup.h"
using namespace std; // forward declarations void flush(); void branching(char); void
helper(char); void add_pet(string, string); Pet* search_pet(string, string); void
remove_pet(string, string); void clean_up(Pet*); void print_all(); void remove_all(); Container*
list = NULL; // global list int main() { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF |
_CRTDBG_LEAK_CHECK_DF); // Use to check for memory leaks in VS char ch = 'i';
do { // Q6: Implement cin / cout for the lines below without modifying the
functionality (5 points) // (change all printf statements to cout and read the next char
using cin) printf("Please enter your selection "); printf("ta: add a new pet
to the list "); printf("tc: add a new checkup for a pet "); printf("tr:
remove a pet from the list "); printf("tp: print all pets on the list ");
printf("tq: quit "); ch = getchar(); // End Q6 flush();
branching(ch); } while (ch != 'q'); remove_all(); list = NULL; return 0; }
void flush() { int c; do c = getchar(); while (c != ' ' && c != EOF); } void
branching(char c) { switch (c) { case 'a': case 'c': case 'r': case 'p':
helper(c); break; case 'q': break; default:
printf(" Invalid input!  "); } } // The helper function is used to determine how much data
is needed and which function to send that data to. // It uses pointers and values that are returned
from some functions to produce the correct ouput. // There is no implementation needed here, but
you should study this function and know how it works. // It is always helpful to understand how
the code works before implementing new features. // Do not change anything in this function or
you risk failing the automated test cases. void helper(char c) { string name, breed; if (c
== 'p') print_all(); else { cout << endl << "Please enter the pet's
name: " << endl; cin >> name; cout << "Please enter the pet's breed: " <<
endl; cin >> breed; flush(); Pet* pet_result = search_pet(name, breed);
if (c == 'a') // add pet { if (pet_result == NULL) {
add_pet(name, breed); cout << endl << "Pet added." <<
endl << endl; } else cout << endl << "Pet
already on list." << endl << endl; } else if (c == 'c') // add checkup
{ if (pet_result == NULL) { cout << endl <<
"Pet not found." << endl << endl; return; }
string date; cout << "Please enter the date of the checkup: " << endl;
cin >> date; flush(); pet_result->addCheckup(date); cout <<
endl << "Checkup added." << endl << endl; } else if (c == 'r') // remove
pet { if (pet_result == NULL) { cout
<< endl << "Pet not found." << endl << endl; return; }
remove_pet(name, breed); cout << endl << "Pet removed from the list."
<< endl << endl; } } } // Q3: Add Pet (5 points) // This function will be used to
add a new pet to the head of you linked list of containers, no need for sorting. // The search
function is called before this function, therefore you can assume the pet is not already on the list.
// If the pet is added to the list, return 1. If the pet already exists on the list (not added), return 0.
void add_pet(string name, string breed) { } // Q4: Search (10 points) // This function will be
used to search for a pet on the list. // Pets on the list may have the same name OR the same
breed, but should not have the same name AND breed. // Therefore, you must traverse the list
and return a pointer to a 'Pet' with the desired name AND breed. // If the pet does not exist on
the list, return NULL. (See helper function for use of this function). Pet* search_pet(string name,
string breed) { return NULL; } // Q5: Remove Pet (15 points) // This function will be used
to remove a pet from the list. // Traverse the list and use the parameters to remove the pet. // Use
proper memory management to ensure no memory leaks. void remove_pet(string name, string
breed) { } // This function is already implemented for you. It traverses the list and removes all
pets to ensure no memory leaks. void remove_all() { while (list != NULL) {
Container* container_to_be_removed = list; list = list->next; while
(container_to_be_removed->pet->checkups != NULL) { Checkup
*checkup_to_be_removed = container_to_be_removed->pet->checkups;
container_to_be_removed->pet->checkups = container_to_be_removed->pet->checkups->next;
delete checkup_to_be_removed; } delete
container_to_be_removed->pet; delete container_to_be_removed; } } // This
function is already implemented for you. It prints all of the pets in the list in an organized format.
void print_all() { if (list == NULL) cout << endl << "List is empty!" << endl << endl;
Container *container_traverser = list; while (container_traverser != NULL) {
cout << endl << "Name: " << container_traverser->pet->getName() << endl <<
"Breed: " << container_traverser->pet->getBreed() << endl; string
last_checkup = container_traverser->pet->lastCheckup(); if (last_checkup.empty())
cout << "Last Checkup: " << "N/A" << endl << endl; else
cout << "Last Checkup: " << last_checkup << endl << endl; container_traverser =
container_traverser->next; } }
Solution
Dear Asker,
Note/Important: Following solution is as correct as possible, without looking at code of
'Container.h', 'Pet.h' and 'Checkup.h'. This solution WAS NOT tested becuase the three files
are needed to test it.
There may be some functions of Pet class missing in this solution [Q2], since definition of 'Pet'
class is not supplied, the difinitions of 'Pet' class methods are given in this solution which can
be cut-pasted into Pet.cpp carefully.
Please share these 3 files as well, to receive complete executable code. In any case, following
solution will give you an idea to approach the problem.
Here is the solution:
// READ BEFORE YOU START:
// You are given a partially completed program that creates a list of pets with their list of
checkups.
// Each pet has the corresponding information: name, breed, and a linked list of checkups.
// To begin, you should trace through the given code and understand how it works.
// Please read the instructions above each required function and follow the directions carefully.
// If you modify any of the given code, the return types, or the parameters, you risk failing the
automated test cases.
//
// You are to assume that all input is valid:
// Valid name: String containing alphabetical letters beginning with a capital letter
// Valid breed: String containing alphabetical letters beginning with a capital letter
// Valid date: String in the following format: "MM/DD/YYYY" ex: "01/01/2010"
// All input will be a valid length and no more than the allowed amount of memory will be used
//
// Q1 : CLASS METHODS Part 1 : Constructor and Accessor Methods for Pet class in Pet.cpp
file ( 5 points)
// Q2 : CLASS METHODS Part 2 : Class methods for Pet class in Pet.cpp file (10 points)
// Q3 : Add Function in hw09.cpp file ( 5 points)
// Q4 : Search Function in hw09.cpp file (10 points)
// Q5 : Remove One Function in hw09.cpp file (15 points)
// Q6 : Implement cin / cout for the lines in main without modifying the functionality ( 5 points)
#include
#include
#include
#include "Container.h"
#include "Pet.h"
#include "Checkup.h"
using namespace std;
// forward declarations
void flush();
void branching(char);
void helper(char);
void add_pet(string, string);
Pet* search_pet(string, string);
void remove_pet(string, string);
void clean_up(Pet*);
void print_all();
void remove_all();
Container* list = NULL; // global list
Pet::Pet(string petName, string petBreed){
name = petName;
breed = petBreed;
}
//Q1 answer
string Pet::getName(){
return name;
}
string Pet::getBreed(){
return breed;
}
Checkup* Pet::getCheckups()
{
return checkups;
}
//Q1 answer complete
//Q2 answer
string Pet::lastCheckup()
{
//ensure checkup list is not empty
if (checkups!=NULL)
{
return checkups->date;
}
//if there have never been any checkup, return empty strin
return "";
}
void Pet::addCheckup(string date)
{
Checkup c(date);
c->next = checkups;
checkups = c;
}
//Q2 answer complete
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use to
check for memory leaks in VS
char ch = 'i';
do {
// Q6: Implement cin / cout for the lines below without modifying the functionality (5 points)
// (change all printf statements to cout and read the next char using cin)
cout<<"Please enter your selection ";
cout<<"ta: add a new pet to the list ";
cout<<"tc: add a new checkup for a pet ";
cout<<"tr: remove a pet from the list ";
cout<<"tp: print all pets on the list ";
cout<<"tq: quit ");
cin>>ch;
// End Q6
flush();
branching(ch);
} while (ch != 'q');
remove_all();
list = NULL;
return 0;
}
void flush()
{
int c;
do c = getchar(); while (c != ' ' && c != EOF);
}
void branching(char c)
{
switch (c) {
case 'a':
case 'c':
case 'r':
case 'p':
helper(c);
break;
case 'q':
break;
default:
printf(" Invalid input!  ");
}
}
// The helper function is used to determine how much data is needed and which function to send
that data to.
// It uses pointers and values that are returned from some functions to produce the correct ouput.
// There is no implementation needed here, but you should study this function and know how it
works.
// It is always helpful to understand how the code works before implementing new features.
// Do not change anything in this function or you risk failing the automated test cases.
void helper(char c)
{
string name, breed;
if (c == 'p')
print_all();
else
{
cout << endl << "Please enter the pet's name: " << endl;
cin >> name;
cout << "Please enter the pet's breed: " << endl;
cin >> breed; flush();
Pet* pet_result = search_pet(name, breed);
if (c == 'a') // add pet
{
if (pet_result == NULL)
{
add_pet(name, breed);
cout << endl << "Pet added." << endl << endl;
}
else
cout << endl << "Pet already on list." << endl << endl;
}
else if (c == 'c') // add checkup
{
if (pet_result == NULL)
{
cout << endl << "Pet not found." << endl << endl;
return;
}
string date;
cout << "Please enter the date of the checkup: " << endl;
cin >> date; flush();
pet_result->addCheckup(date);
cout << endl << "Checkup added." << endl << endl;
}
else if (c == 'r') // remove pet
{
if (pet_result == NULL)
{
cout << endl << "Pet not found." << endl << endl;
return;
}
remove_pet(name, breed);
cout << endl << "Pet removed from the list." << endl << endl;
}
}
}
// Q3: Add Pet (5 points)
// This function will be used to add a new pet to the head of you linked list of containers, no
need for sorting.
// The search function is called before this function, therefore you can assume the pet is not
already on the list.
// If the pet is added to the list, return 1. If the pet already exists on the list (not added), return 0.
void add_pet(string name, string breed)
{
Container c;
Pet p(name, breed);
C->pet = p;
c->next = list;
list = c;
}
// Q4: Search (10 points)
// This function will be used to search for a pet on the list.
// Pets on the list may have the same name OR the same breed, but should not have the same
name AND breed.
// Therefore, you must traverse the list and return a pointer to a 'Pet' with the desired name
AND breed.
// If the pet does not exist on the list, return NULL. (See helper function for use of this function).
Pet* search_pet(string name, string breed)
{
Container* temp = list;
while(temp!=NULL){
if(temp->pet->getName()==name && temp->pet->getBreed()==bread){
return temp->pet;
}
temp = temp->next;
}
return NULL;
}
// Q5: Remove Pet (15 points)
// This function will be used to remove a pet from the list.
// Traverse the list and use the parameters to remove the pet.
// Use proper memory management to ensure no memory leaks.
void remove_pet(string name, string breed)
{
//if container is empty
if(list==NULL){
return
}
//if container has only one element and the first container has to be removed
else if(list->next==NULL)
{
if(list->pet->getName()==name && list->pet->getBreed()=bread)
{
//delete the checkups first
while(list->pet->checkups!=NULL)
{
Checkup* temp_checkup = list->pet->checkups->checkup;
list->pet->checkups = list->pet->checkups->next;
delete temp_checkup;
}
delete list->pet;
delete list;
list = NULL;
return;
}
}
//if container has more than one pets and first container has to be removed
else if(list->next!=NULL){
Container* listnext=list->next;
if(list->pet->getName()==name && list->pet->getBreed()=bread)
{
//delete the checkups first
while(list->pet->checkups!=NULL)
{
Checkup* temp_checkup = list->pet->checkups->checkup;
list->pet->checkups = list->pet->checkups->next;
delete temp_checkup;
}
delete list->pet;
list=listnext;
return;
}
}
//last possibility is that the pet to be removed is in 2nd or later container
Container* current = list;
Container* current_next= list->next;
while(current_next!=NULL){
if(current_next->pet->getName()==name && current_next->pet->getBreed()==bread){
//delete the checkups first
while(current_next->pet->checkups!=NULL)
{
Checkup* temp_checkup = current_next->pet->checkups->checkup;
current_next->pet->checkups = current_next->pet->checkups->next;
delete temp_checkup;
}
current->next=curent_next->next;
delete current_next->pet;
delete current_next;
return;
}
current=current_next;
current_next=current_next->next;
}
}
// This function is already implemented for you. It traverses the list and removes all pets to
ensure no memory leaks.
void remove_all()
{
while (list != NULL)
{
Container* container_to_be_removed = list;
list = list->next;
while (container_to_be_removed->pet->checkups != NULL)
{
Checkup *checkup_to_be_removed = container_to_be_removed->pet->checkups;
container_to_be_removed->pet->checkups = container_to_be_removed->pet->checkups->next;
delete checkup_to_be_removed;
}
delete container_to_be_removed->pet;
delete container_to_be_removed;
}
}
// This function is already implemented for you. It prints all of the pets in the list in an organized
format.
void print_all()
{
if (list == NULL) cout << endl << "List is empty!" << endl << endl;
Container *container_traverser = list;
while (container_traverser != NULL)
{
cout << endl <<
"Name: " << container_traverser->pet->getName() << endl <<
"Breed: " << container_traverser->pet->getBreed() << endl;
string last_checkup = container_traverser->pet->lastCheckup();
if (last_checkup.empty())
cout << "Last Checkup: " << "N/A" << endl << endl;
else
cout << "Last Checkup: " << last_checkup << endl << endl;
container_traverser = container_traverser->next;
}
}

More Related Content

Similar to READ BEFORE YOU START You are given a partially completed pr.pdf

Ive posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdfIve posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdf
deepaarora22
 
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docxRightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
joellemurphey
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
calderoncasto9163
 
I need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docxI need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docx
hendriciraida
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
MAYANKBANSAL1981
 
For C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdfFor C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdf
fathimafancyjeweller
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
ajoy21
 
First C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdfFirst C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdf
ankit482504
 
The java program that display a menu of choices and p.pdf
   The java program that display a menu of choices  and p.pdf   The java program that display a menu of choices  and p.pdf
The java program that display a menu of choices and p.pdf
annaistrvlr
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
J On The Beach
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
Nicola Pedot
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018
Codemotion
 
Lazy java
Lazy javaLazy java
Lazy java
Mario Fusco
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
anandf0099
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
support58
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
braycarissa250
 

Similar to READ BEFORE YOU START You are given a partially completed pr.pdf (20)

Ive posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdfIve posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdf
 
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docxRightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
 
I need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docxI need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docx
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
For C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdfFor C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdf
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
 
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
 
First C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdfFirst C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdf
 
The java program that display a menu of choices and p.pdf
   The java program that display a menu of choices  and p.pdf   The java program that display a menu of choices  and p.pdf
The java program that display a menu of choices and p.pdf
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018
 
Lazy java
Lazy javaLazy java
Lazy java
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 

More from arkurkuri

Find an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdfFind an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdf
arkurkuri
 
A researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdfA researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdf
arkurkuri
 
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdfDate Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdf
arkurkuri
 
Compare and contrast passive transport and active transport Compare .pdf
Compare and contrast passive transport and active transport  Compare .pdfCompare and contrast passive transport and active transport  Compare .pdf
Compare and contrast passive transport and active transport Compare .pdf
arkurkuri
 
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
arkurkuri
 
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
arkurkuri
 
Use the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdfUse the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdf
arkurkuri
 
What is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdfWhat is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdf
arkurkuri
 
2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdf2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdf
arkurkuri
 
Write the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdfWrite the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdf
arkurkuri
 
Which osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdfWhich osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdf
arkurkuri
 
What types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdfWhat types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdf
arkurkuri
 
Which of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdfWhich of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdf
arkurkuri
 
What are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdfWhat are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdf
arkurkuri
 
What is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdfWhat is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdf
arkurkuri
 
Use your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdfUse your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdf
arkurkuri
 
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
arkurkuri
 
This homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdfThis homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdf
arkurkuri
 
this is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdfthis is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdf
arkurkuri
 
The Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdfThe Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdf
arkurkuri
 

More from arkurkuri (20)

Find an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdfFind an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdf
 
A researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdfA researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdf
 
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdfDate Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdf
 
Compare and contrast passive transport and active transport Compare .pdf
Compare and contrast passive transport and active transport  Compare .pdfCompare and contrast passive transport and active transport  Compare .pdf
Compare and contrast passive transport and active transport Compare .pdf
 
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
 
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
 
Use the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdfUse the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdf
 
What is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdfWhat is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdf
 
2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdf2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdf
 
Write the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdfWrite the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdf
 
Which osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdfWhich osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdf
 
What types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdfWhat types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdf
 
Which of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdfWhich of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdf
 
What are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdfWhat are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdf
 
What is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdfWhat is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdf
 
Use your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdfUse your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdf
 
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
 
This homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdfThis homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdf
 
this is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdfthis is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdf
 
The Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdfThe Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdf
 

Recently uploaded

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

READ BEFORE YOU START You are given a partially completed pr.pdf

  • 1. // READ BEFORE YOU START: // You are given a partially completed program that creates a list of pets with their list of checkups. // Each pet has the corresponding information: name, breed, and a linked list of checkups. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you risk failing the automated test cases. // // You are to assume that all input is valid: // Valid name: String containing alphabetical letters beginning with a capital letter // Valid breed: String containing alphabetical letters beginning with a capital letter // Valid date: String in the following format: "MM/DD/YYYY" ex: "01/01/2010" // All input will be a valid length and no more than the allowed amount of memory will be used // // Q1 : CLASS METHODS Part 1 : Constructor and Accessor Methods for Pet class in Pet.cpp file ( 5 points) // Q2 : CLASS METHODS Part 2 : Class methods for Pet class in Pet.cpp file (10 points) // Q3 : Add Function in hw09.cpp file ( 5 points) // Q4 : Search Function in hw09.cpp file (10 points) // Q5 : Remove One Function in hw09.cpp file (15 points) // Q6 : Implement cin / cout for the lines in main without modifying the functionality ( 5 points) #include #include #include #include "Container.h" #include "Pet.h" #include "Checkup.h" using namespace std; // forward declarations void flush(); void branching(char); void helper(char); void add_pet(string, string); Pet* search_pet(string, string); void remove_pet(string, string); void clean_up(Pet*); void print_all(); void remove_all(); Container* list = NULL; // global list int main() { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use to check for memory leaks in VS char ch = 'i'; do { // Q6: Implement cin / cout for the lines below without modifying the functionality (5 points) // (change all printf statements to cout and read the next char using cin) printf("Please enter your selection "); printf("ta: add a new pet to the list "); printf("tc: add a new checkup for a pet "); printf("tr: remove a pet from the list "); printf("tp: print all pets on the list "); printf("tq: quit "); ch = getchar(); // End Q6 flush(); branching(ch); } while (ch != 'q'); remove_all(); list = NULL; return 0; } void flush() { int c; do c = getchar(); while (c != ' ' && c != EOF); } void branching(char c) { switch (c) { case 'a': case 'c': case 'r': case 'p': helper(c); break; case 'q': break; default: printf(" Invalid input! "); } } // The helper function is used to determine how much data is needed and which function to send that data to. // It uses pointers and values that are returned
  • 2. from some functions to produce the correct ouput. // There is no implementation needed here, but you should study this function and know how it works. // It is always helpful to understand how the code works before implementing new features. // Do not change anything in this function or you risk failing the automated test cases. void helper(char c) { string name, breed; if (c == 'p') print_all(); else { cout << endl << "Please enter the pet's name: " << endl; cin >> name; cout << "Please enter the pet's breed: " << endl; cin >> breed; flush(); Pet* pet_result = search_pet(name, breed); if (c == 'a') // add pet { if (pet_result == NULL) { add_pet(name, breed); cout << endl << "Pet added." << endl << endl; } else cout << endl << "Pet already on list." << endl << endl; } else if (c == 'c') // add checkup { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return; } string date; cout << "Please enter the date of the checkup: " << endl; cin >> date; flush(); pet_result->addCheckup(date); cout << endl << "Checkup added." << endl << endl; } else if (c == 'r') // remove pet { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return; } remove_pet(name, breed); cout << endl << "Pet removed from the list." << endl << endl; } } } // Q3: Add Pet (5 points) // This function will be used to add a new pet to the head of you linked list of containers, no need for sorting. // The search function is called before this function, therefore you can assume the pet is not already on the list. // If the pet is added to the list, return 1. If the pet already exists on the list (not added), return 0. void add_pet(string name, string breed) { } // Q4: Search (10 points) // This function will be used to search for a pet on the list. // Pets on the list may have the same name OR the same breed, but should not have the same name AND breed. // Therefore, you must traverse the list and return a pointer to a 'Pet' with the desired name AND breed. // If the pet does not exist on the list, return NULL. (See helper function for use of this function). Pet* search_pet(string name, string breed) { return NULL; } // Q5: Remove Pet (15 points) // This function will be used to remove a pet from the list. // Traverse the list and use the parameters to remove the pet. // Use proper memory management to ensure no memory leaks. void remove_pet(string name, string breed) { } // This function is already implemented for you. It traverses the list and removes all pets to ensure no memory leaks. void remove_all() { while (list != NULL) { Container* container_to_be_removed = list; list = list->next; while (container_to_be_removed->pet->checkups != NULL) { Checkup *checkup_to_be_removed = container_to_be_removed->pet->checkups;
  • 3. container_to_be_removed->pet->checkups = container_to_be_removed->pet->checkups->next; delete checkup_to_be_removed; } delete container_to_be_removed->pet; delete container_to_be_removed; } } // This function is already implemented for you. It prints all of the pets in the list in an organized format. void print_all() { if (list == NULL) cout << endl << "List is empty!" << endl << endl; Container *container_traverser = list; while (container_traverser != NULL) { cout << endl << "Name: " << container_traverser->pet->getName() << endl << "Breed: " << container_traverser->pet->getBreed() << endl; string last_checkup = container_traverser->pet->lastCheckup(); if (last_checkup.empty()) cout << "Last Checkup: " << "N/A" << endl << endl; else cout << "Last Checkup: " << last_checkup << endl << endl; container_traverser = container_traverser->next; } } Solution Dear Asker, Note/Important: Following solution is as correct as possible, without looking at code of 'Container.h', 'Pet.h' and 'Checkup.h'. This solution WAS NOT tested becuase the three files are needed to test it. There may be some functions of Pet class missing in this solution [Q2], since definition of 'Pet' class is not supplied, the difinitions of 'Pet' class methods are given in this solution which can be cut-pasted into Pet.cpp carefully. Please share these 3 files as well, to receive complete executable code. In any case, following solution will give you an idea to approach the problem. Here is the solution: // READ BEFORE YOU START: // You are given a partially completed program that creates a list of pets with their list of checkups. // Each pet has the corresponding information: name, breed, and a linked list of checkups. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you risk failing the automated test cases. // // You are to assume that all input is valid: // Valid name: String containing alphabetical letters beginning with a capital letter
  • 4. // Valid breed: String containing alphabetical letters beginning with a capital letter // Valid date: String in the following format: "MM/DD/YYYY" ex: "01/01/2010" // All input will be a valid length and no more than the allowed amount of memory will be used // // Q1 : CLASS METHODS Part 1 : Constructor and Accessor Methods for Pet class in Pet.cpp file ( 5 points) // Q2 : CLASS METHODS Part 2 : Class methods for Pet class in Pet.cpp file (10 points) // Q3 : Add Function in hw09.cpp file ( 5 points) // Q4 : Search Function in hw09.cpp file (10 points) // Q5 : Remove One Function in hw09.cpp file (15 points) // Q6 : Implement cin / cout for the lines in main without modifying the functionality ( 5 points) #include #include #include #include "Container.h" #include "Pet.h" #include "Checkup.h" using namespace std; // forward declarations void flush(); void branching(char); void helper(char); void add_pet(string, string); Pet* search_pet(string, string); void remove_pet(string, string); void clean_up(Pet*); void print_all(); void remove_all(); Container* list = NULL; // global list Pet::Pet(string petName, string petBreed){ name = petName; breed = petBreed; } //Q1 answer string Pet::getName(){ return name;
  • 5. } string Pet::getBreed(){ return breed; } Checkup* Pet::getCheckups() { return checkups; } //Q1 answer complete //Q2 answer string Pet::lastCheckup() { //ensure checkup list is not empty if (checkups!=NULL) { return checkups->date; } //if there have never been any checkup, return empty strin return ""; } void Pet::addCheckup(string date) { Checkup c(date); c->next = checkups; checkups = c; } //Q2 answer complete int main() { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use to check for memory leaks in VS char ch = 'i'; do { // Q6: Implement cin / cout for the lines below without modifying the functionality (5 points) // (change all printf statements to cout and read the next char using cin) cout<<"Please enter your selection ";
  • 6. cout<<"ta: add a new pet to the list "; cout<<"tc: add a new checkup for a pet "; cout<<"tr: remove a pet from the list "; cout<<"tp: print all pets on the list "; cout<<"tq: quit "); cin>>ch; // End Q6 flush(); branching(ch); } while (ch != 'q'); remove_all(); list = NULL; return 0; } void flush() { int c; do c = getchar(); while (c != ' ' && c != EOF); } void branching(char c) { switch (c) { case 'a': case 'c': case 'r': case 'p': helper(c); break; case 'q': break; default: printf(" Invalid input! "); } } // The helper function is used to determine how much data is needed and which function to send that data to.
  • 7. // It uses pointers and values that are returned from some functions to produce the correct ouput. // There is no implementation needed here, but you should study this function and know how it works. // It is always helpful to understand how the code works before implementing new features. // Do not change anything in this function or you risk failing the automated test cases. void helper(char c) { string name, breed; if (c == 'p') print_all(); else { cout << endl << "Please enter the pet's name: " << endl; cin >> name; cout << "Please enter the pet's breed: " << endl; cin >> breed; flush(); Pet* pet_result = search_pet(name, breed); if (c == 'a') // add pet { if (pet_result == NULL) { add_pet(name, breed); cout << endl << "Pet added." << endl << endl; } else cout << endl << "Pet already on list." << endl << endl; } else if (c == 'c') // add checkup { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return; } string date; cout << "Please enter the date of the checkup: " << endl;
  • 8. cin >> date; flush(); pet_result->addCheckup(date); cout << endl << "Checkup added." << endl << endl; } else if (c == 'r') // remove pet { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return; } remove_pet(name, breed); cout << endl << "Pet removed from the list." << endl << endl; } } } // Q3: Add Pet (5 points) // This function will be used to add a new pet to the head of you linked list of containers, no need for sorting. // The search function is called before this function, therefore you can assume the pet is not already on the list. // If the pet is added to the list, return 1. If the pet already exists on the list (not added), return 0. void add_pet(string name, string breed) { Container c; Pet p(name, breed); C->pet = p; c->next = list; list = c; } // Q4: Search (10 points) // This function will be used to search for a pet on the list. // Pets on the list may have the same name OR the same breed, but should not have the same name AND breed. // Therefore, you must traverse the list and return a pointer to a 'Pet' with the desired name AND breed.
  • 9. // If the pet does not exist on the list, return NULL. (See helper function for use of this function). Pet* search_pet(string name, string breed) { Container* temp = list; while(temp!=NULL){ if(temp->pet->getName()==name && temp->pet->getBreed()==bread){ return temp->pet; } temp = temp->next; } return NULL; } // Q5: Remove Pet (15 points) // This function will be used to remove a pet from the list. // Traverse the list and use the parameters to remove the pet. // Use proper memory management to ensure no memory leaks. void remove_pet(string name, string breed) { //if container is empty if(list==NULL){ return } //if container has only one element and the first container has to be removed else if(list->next==NULL) { if(list->pet->getName()==name && list->pet->getBreed()=bread) { //delete the checkups first while(list->pet->checkups!=NULL) { Checkup* temp_checkup = list->pet->checkups->checkup; list->pet->checkups = list->pet->checkups->next; delete temp_checkup; } delete list->pet; delete list;
  • 10. list = NULL; return; } } //if container has more than one pets and first container has to be removed else if(list->next!=NULL){ Container* listnext=list->next; if(list->pet->getName()==name && list->pet->getBreed()=bread) { //delete the checkups first while(list->pet->checkups!=NULL) { Checkup* temp_checkup = list->pet->checkups->checkup; list->pet->checkups = list->pet->checkups->next; delete temp_checkup; } delete list->pet; list=listnext; return; } } //last possibility is that the pet to be removed is in 2nd or later container Container* current = list; Container* current_next= list->next; while(current_next!=NULL){ if(current_next->pet->getName()==name && current_next->pet->getBreed()==bread){ //delete the checkups first while(current_next->pet->checkups!=NULL) { Checkup* temp_checkup = current_next->pet->checkups->checkup; current_next->pet->checkups = current_next->pet->checkups->next; delete temp_checkup; } current->next=curent_next->next; delete current_next->pet; delete current_next;
  • 11. return; } current=current_next; current_next=current_next->next; } } // This function is already implemented for you. It traverses the list and removes all pets to ensure no memory leaks. void remove_all() { while (list != NULL) { Container* container_to_be_removed = list; list = list->next; while (container_to_be_removed->pet->checkups != NULL) { Checkup *checkup_to_be_removed = container_to_be_removed->pet->checkups; container_to_be_removed->pet->checkups = container_to_be_removed->pet->checkups->next; delete checkup_to_be_removed; } delete container_to_be_removed->pet; delete container_to_be_removed; } } // This function is already implemented for you. It prints all of the pets in the list in an organized format. void print_all() { if (list == NULL) cout << endl << "List is empty!" << endl << endl; Container *container_traverser = list; while (container_traverser != NULL) { cout << endl << "Name: " << container_traverser->pet->getName() << endl << "Breed: " << container_traverser->pet->getBreed() << endl; string last_checkup = container_traverser->pet->lastCheckup();
  • 12. if (last_checkup.empty()) cout << "Last Checkup: " << "N/A" << endl << endl; else cout << "Last Checkup: " << last_checkup << endl << endl; container_traverser = container_traverser->next; } }