SlideShare a Scribd company logo
1 of 17
Download to read offline
Can someoen help me to write c++ program including C++ inheritance, polymorphism, virtual
function, containment, file operations, and exception handling.
// Q1a: Create Dog Class
// Part 1: Create a child class of the Pet class named 'Dog'
// See the add function in hw10.cpp for proper use of this function.
// Part2: Declare constructor which accepts the same 3 parameters as the parent class Pet.
// Pass the 3 parameters to the super constructor in the Pet class.
// Part 3: Re-declare the method display (virtual method found inside of parent class Pet)
// Q2a: Define Display for Dog class
// Define the method display that you declared within the Dog class in the header file
// Information should be printed in the following format:
// Name:
// Breed:
// Type: Dog
// (See the print_all function in hw10.cpp for proper use of this function.)
// READ BEFORE YOU START:
// You are given a partially completed program that creates a list of pets.
// Each pet has the corresponding information: name, breed, and type.
// In the Pet.h file, you will find the definition for this enum 'type'.
// Pets on the list can be 2 different 'types' : either a dog or a cat.
// The classes Dog and Cat are subclasses of the Pet class (found in Pet.h).
// Both of these classes will have their own use of the virtual display method.
//
// 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
// All input will be a valid length and no more than the allowed amount of memory will be used
#include "Container.h"
#include "Pet.h"
#include "Dog.h"
#include "Cat.h"
#include
#include
#include
using namespace std;
// forward declarations
void flush();
void branching(char);
void helper(char);
void add_pet(string, string, Type);
Pet* search_pet(string, string, Type);
void remove_pet(string, string, Type);
void remove_all();
void print_all();
void save(string); // 10 points
void load(string); // 10 points
Container* list = NULL; // global list
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use
to check for memory leaks in VS
load("Pets.txt");
char ch = 'i';
do {
cout << "Please enter your selection" << endl;
cout << "ta: add a new pet to the list" << endl;
cout << "tc: change the breed of a pet" << endl;
cout << "tr: remove a pet from the list" << endl;
cout << "tp: print all pets on the list" << endl;
cout << "tq: quit and save list of pets" << endl;
cin >> ch;
flush();
branching(ch);
} while (ch != 'q');
save("Pets.txt");
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;
Type type;
int type_check = -1;
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;
while (!(type_check == 0 || type_check == 1))
{
cout << endl << "Please select one of the following: " << endl;
cout << "0. Dog " << endl;
cout << "1. Cat" << endl;
cin >> type_check;
}
type = (Type)type_check;
Pet* pet_result = search_pet(name, breed, type);
if (c == 'a') // add pet
{
if (pet_result == NULL)
{
add_pet(name, breed, type);
cout << endl << "Pet added." << endl << endl;
}
else
cout << endl << "Pet already on list." << endl << endl;
}
else if (c == 'c') // change pet breed
{
if (pet_result == NULL)
{
cout << endl << "Pet not found." << endl << endl;
return;
}
cout << endl << "Please enter the new breed for this pet: " << endl;
cin >> breed; flush();
// Q3c: Call Change Breed Function
cout << endl << "Pet's breed changed." << endl << endl;
}
else if (c == 'r') // remove pet
{
if (pet_result == NULL)
{
cout << endl << "Pet not found." << endl << endl;
return;
}
remove_pet(name, breed, type);
cout << endl << "Pet removed from the list." << endl << endl;
}
}
}
// Q3b: Define Friend Function Change Breed
// Define the function changeBreed that is declared within the Pet.h file.
// This function sets the breed value of the Pet pointer to the value of the string parameter.
// Q4: Add Pet
// This function will be used to add a new pet to the tail of the global linked list.
// You will need to use the enum ëtypeí variable to determine which constructor to use.
// Remember that search is called before this function, therefore, the new pet is not on the list.
void add_pet(string name, string breed, Type type)
{
}
// No implementation needed here, however it may be helpful to review this function
Pet* search_pet(string name, string breed, Type type)
{
Container* container_traverser = list;
while (container_traverser != NULL)
{
if (container_traverser->pet->getName() == name
&& container_traverser->pet->getBreed() == breed
&& container_traverser->pet->getType() == type)
return container_traverser->pet;
container_traverser = container_traverser->next;
}
return NULL;
}
// No implementation needed here, however it may be helpful to review this function
void remove_pet(string name, string breed, Type type)
{
Container* to_be_removed;
if (list->pet->getName() == name
&& list->pet->getBreed() == breed
&& list->pet->getType() == type)
{
to_be_removed = list;
list = list->next;
delete to_be_removed->pet;
delete to_be_removed;
return;
}
Container* container_traverser = list->next;
Container* container_follower = list;
while (container_traverser != NULL)
{
if (container_traverser->pet->getName() == name
&& container_traverser->pet->getBreed() == breed
&& container_traverser->pet->getType() == type)
{
to_be_removed = container_traverser;
container_traverser = container_traverser->next;
container_follower->next = container_traverser;
delete to_be_removed->pet;
delete to_be_removed;
return;
}
container_follower = container_traverser;
container_traverser = container_traverser->next;
}
}
// No implementation needed here, however it may be helpful to review this function
void remove_all()
{
while (list != NULL)
{
Container* temp = list;
list = list->next;
delete temp->pet;
delete temp;
}
}
// This function uses the virtual display() method of the Dog and Cat classes to print all Pets in an
oragnized format.
void print_all()
{
Container *container_traverser = list;
if (list == NULL)
cout << endl << "List is empty!" << endl << endl;
while (container_traverser != NULL)
{
container_traverser->pet->display();
container_traverser = container_traverser->next;
}
}
// Q5a: Save (5 points)
// Save the linked list of pets to a file using ofstream.
// You will need to come up with a way to store the amount of Containers in linked list.
// Hint: You may want to cast the enum 'type' to an int before writing it to the file.
void save(string fileName)
{
}
// Q5b: Load (5 points)
// Load the linked list of pets from a file using ifstream.
// You will need to create the linked list in the same order that is was saved to a file.
// You will need to create a new node for the linked list, then add it to the tail of the list.
// Hint: If you casted the enum 'type' to an int, you will need to cast it back to a 'Type'.
// You will use the 'type' variable read from the file to determine which constructor to use.
void load(string fileName)
{
}
Can someoen help me to write c++ program including C++ inheritance, polymorphism, virtual
function, containment, file operations, and exception handling.
// Q1a: Create Dog Class
// Part 1: Create a child class of the Pet class named 'Dog'
// See the add function in hw10.cpp for proper use of this function.
// Part2: Declare constructor which accepts the same 3 parameters as the parent class Pet.
// Pass the 3 parameters to the super constructor in the Pet class.
// Part 3: Re-declare the method display (virtual method found inside of parent class Pet)
// Q2a: Define Display for Dog class
// Define the method display that you declared within the Dog class in the header file
// Information should be printed in the following format:
// Name:
// Breed:
// Type: Dog
// (See the print_all function in hw10.cpp for proper use of this function.)
// READ BEFORE YOU START:
// You are given a partially completed program that creates a list of pets.
// Each pet has the corresponding information: name, breed, and type.
// In the Pet.h file, you will find the definition for this enum 'type'.
// Pets on the list can be 2 different 'types' : either a dog or a cat.
// The classes Dog and Cat are subclasses of the Pet class (found in Pet.h).
// Both of these classes will have their own use of the virtual display method.
//
// 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
// All input will be a valid length and no more than the allowed amount of memory will be used
#include "Container.h"
#include "Pet.h"
#include "Dog.h"
#include "Cat.h"
#include
#include
#include
using namespace std;
// forward declarations
void flush();
void branching(char);
void helper(char);
void add_pet(string, string, Type);
Pet* search_pet(string, string, Type);
void remove_pet(string, string, Type);
void remove_all();
void print_all();
void save(string); // 10 points
void load(string); // 10 points
Container* list = NULL; // global list
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use
to check for memory leaks in VS
load("Pets.txt");
char ch = 'i';
do {
cout << "Please enter your selection" << endl;
cout << "ta: add a new pet to the list" << endl;
cout << "tc: change the breed of a pet" << endl;
cout << "tr: remove a pet from the list" << endl;
cout << "tp: print all pets on the list" << endl;
cout << "tq: quit and save list of pets" << endl;
cin >> ch;
flush();
branching(ch);
} while (ch != 'q');
save("Pets.txt");
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;
Type type;
int type_check = -1;
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;
while (!(type_check == 0 || type_check == 1))
{
cout << endl << "Please select one of the following: " << endl;
cout << "0. Dog " << endl;
cout << "1. Cat" << endl;
cin >> type_check;
}
type = (Type)type_check;
Pet* pet_result = search_pet(name, breed, type);
if (c == 'a') // add pet
{
if (pet_result == NULL)
{
add_pet(name, breed, type);
cout << endl << "Pet added." << endl << endl;
}
else
cout << endl << "Pet already on list." << endl << endl;
}
else if (c == 'c') // change pet breed
{
if (pet_result == NULL)
{
cout << endl << "Pet not found." << endl << endl;
return;
}
cout << endl << "Please enter the new breed for this pet: " << endl;
cin >> breed; flush();
// Q3c: Call Change Breed Function
cout << endl << "Pet's breed changed." << endl << endl;
}
else if (c == 'r') // remove pet
{
if (pet_result == NULL)
{
cout << endl << "Pet not found." << endl << endl;
return;
}
remove_pet(name, breed, type);
cout << endl << "Pet removed from the list." << endl << endl;
}
}
}
// Q3b: Define Friend Function Change Breed
// Define the function changeBreed that is declared within the Pet.h file.
// This function sets the breed value of the Pet pointer to the value of the string parameter.
// Q4: Add Pet
// This function will be used to add a new pet to the tail of the global linked list.
// You will need to use the enum ëtypeí variable to determine which constructor to use.
// Remember that search is called before this function, therefore, the new pet is not on the list.
void add_pet(string name, string breed, Type type)
{
}
// No implementation needed here, however it may be helpful to review this function
Pet* search_pet(string name, string breed, Type type)
{
Container* container_traverser = list;
while (container_traverser != NULL)
{
if (container_traverser->pet->getName() == name
&& container_traverser->pet->getBreed() == breed
&& container_traverser->pet->getType() == type)
return container_traverser->pet;
container_traverser = container_traverser->next;
}
return NULL;
}
// No implementation needed here, however it may be helpful to review this function
void remove_pet(string name, string breed, Type type)
{
Container* to_be_removed;
if (list->pet->getName() == name
&& list->pet->getBreed() == breed
&& list->pet->getType() == type)
{
to_be_removed = list;
list = list->next;
delete to_be_removed->pet;
delete to_be_removed;
return;
}
Container* container_traverser = list->next;
Container* container_follower = list;
while (container_traverser != NULL)
{
if (container_traverser->pet->getName() == name
&& container_traverser->pet->getBreed() == breed
&& container_traverser->pet->getType() == type)
{
to_be_removed = container_traverser;
container_traverser = container_traverser->next;
container_follower->next = container_traverser;
delete to_be_removed->pet;
delete to_be_removed;
return;
}
container_follower = container_traverser;
container_traverser = container_traverser->next;
}
}
// No implementation needed here, however it may be helpful to review this function
void remove_all()
{
while (list != NULL)
{
Container* temp = list;
list = list->next;
delete temp->pet;
delete temp;
}
}
// This function uses the virtual display() method of the Dog and Cat classes to print all Pets in
an oragnized format.
void print_all()
{
Container *container_traverser = list;
if (list == NULL)
cout << endl << "List is empty!" << endl << endl;
while (container_traverser != NULL)
{
container_traverser->pet->display();
container_traverser = container_traverser->next;
}
}
// Q5a: Save (5 points)
// Save the linked list of pets to a file using ofstream.
// You will need to come up with a way to store the amount of Containers in linked list.
// Hint: You may want to cast the enum 'type' to an int before writing it to the file.
void save(string fileName)
{
}
// Q5b: Load (5 points)
// Load the linked list of pets from a file using ifstream.
// You will need to create the linked list in the same order that is was saved to a file.
// You will need to create a new node for the linked list, then add it to the tail of the list.
// Hint: If you casted the enum 'type' to an int, you will need to cast it back to a 'Type'.
// You will use the 'type' variable read from the file to determine which constructor to use.
void load(string fileName)
{
}
Solution
Answers to Q1, Q2, Q3.
Implement parent class Pet. Derive child classes dog and cat from pet. Implement the virtual
function display(). Implement a friend function whih acts as bridge between classes.
// pet.h
#include
#include
using namespace std;
enum Type {dog, cat}; //type can be only of 2 types cat and dog
// Parent class
class Pet { //3 parameters of parent class pet
public:
string name;
string breed;
Type type;
//constructor
Pet( string n, string b, Type t) {
name = n;
breed = b;
type = t;
}
virtual void display(){}; //virtual display function
};
// Derived child Dog class
//Q1a
class Dog: public Pet { //Q1a PART 2
public:
Dog(string n,string b, Type t) : Pet(n, b, dog) {};
//Q2a
void display() { //Q1a PART 3
cout << "Name :" << name << endl;
cout << "Breed :" << breed << endl;
cout << "Type :Dog" << endl << endl;
}
friend void changeBreed(Pet*, string); //friend function
};
// Derived child Cat class
class Cat: public Pet {
public:
Cat(string n, string b, Type t) : Pet(n, b, cat) {};
void display() {
cout << "Name :" << name << endl;
cout << "Breed :" << breed << endl;
cout << "Type :Cat" << endl << endl;
}
friend void changeBreed(Pet*, string); //friend function
};
//Q3b
//friend function implementation
void changeBreed(Pet *p, string newBreed) {
p->breed = newBreed; //set breed value to new value from parameter
}
int main()
{
//Examples
Pet* p;
Dog dog1("Alfa", "Pug", dog);
Cat cat1("Purry", "Persian", cat);
dog1.display();
cat1.display();
p = &dog1;
changeBreed(p, "Bulldog");
dog1.display();
return 0;
}
Output :
Name :Alfa
Breed :Pug
Type :Dog
Name :Purry
Breed :Persian
Type :Cat
Name :Alfa
Breed :Bulldog
Type :Dog

More Related Content

Similar to Can someoen help me to write c++ program including C++ inheritance, .pdf

In this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdfIn this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdffathimaoptical
 
Note Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdfNote Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdfsharnapiyush773
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxBlake0FxCampbelld
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfadmin463580
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfsravi07
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfIan5L3Allanm
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfsravi07
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfsravi07
 
Brief Summary Of C++
Brief Summary Of C++Brief Summary Of C++
Brief Summary Of C++Haris Lye
 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdfSpam92
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxcgraciela1
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docxAdamq0DJonese
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfeyebolloptics
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdfganisyedtrd
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfmallik3000
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
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.pdfdeepaarora22
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfrajkumarm401
 

Similar to Can someoen help me to write c++ program including C++ inheritance, .pdf (20)

In this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdfIn this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdf
 
Note Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdfNote Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdf
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
 
Brief Summary Of C++
Brief Summary Of C++Brief Summary Of C++
Brief Summary Of C++
 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdf
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdf
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
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
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
 

More from arrowvisionoptics

Every day when she first wakes up, Elena takes three foul shots on a.pdf
Every day when she first wakes up, Elena takes three foul shots on a.pdfEvery day when she first wakes up, Elena takes three foul shots on a.pdf
Every day when she first wakes up, Elena takes three foul shots on a.pdfarrowvisionoptics
 
Be more apt to have a mentor than men.        Have dreams (.pdf
Be more apt to have a mentor than men.        Have dreams (.pdfBe more apt to have a mentor than men.        Have dreams (.pdf
Be more apt to have a mentor than men.        Have dreams (.pdfarrowvisionoptics
 
Answer the following questions. EMB is considered to be both a _ medi.pdf
Answer the following questions. EMB is considered to be both a _ medi.pdfAnswer the following questions. EMB is considered to be both a _ medi.pdf
Answer the following questions. EMB is considered to be both a _ medi.pdfarrowvisionoptics
 
A. The statement Evolutionists cannot point to any transitional fo.pdf
A. The statement Evolutionists cannot point to any transitional fo.pdfA. The statement Evolutionists cannot point to any transitional fo.pdf
A. The statement Evolutionists cannot point to any transitional fo.pdfarrowvisionoptics
 
Culture of bacteria is having trouble dividing. Choose from the list.pdf
Culture of bacteria is having trouble dividing. Choose from the list.pdfCulture of bacteria is having trouble dividing. Choose from the list.pdf
Culture of bacteria is having trouble dividing. Choose from the list.pdfarrowvisionoptics
 
Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfarrowvisionoptics
 
You identify four mutant strains that cannot synthesize Compound E. E.pdf
You identify four mutant strains that cannot synthesize Compound E. E.pdfYou identify four mutant strains that cannot synthesize Compound E. E.pdf
You identify four mutant strains that cannot synthesize Compound E. E.pdfarrowvisionoptics
 
9. Identify at least two factors that influence the degree of stoc.pdf
9. Identify at least two factors that influence the degree of stoc.pdf9. Identify at least two factors that influence the degree of stoc.pdf
9. Identify at least two factors that influence the degree of stoc.pdfarrowvisionoptics
 
What are the fuctional need of a roadWhat is road building system.pdf
What are the fuctional need of a roadWhat is road building system.pdfWhat are the fuctional need of a roadWhat is road building system.pdf
What are the fuctional need of a roadWhat is road building system.pdfarrowvisionoptics
 
Why does Germany have to be assertive in the EUSolutionAnswer.pdf
Why does Germany have to be assertive in the EUSolutionAnswer.pdfWhy does Germany have to be assertive in the EUSolutionAnswer.pdf
Why does Germany have to be assertive in the EUSolutionAnswer.pdfarrowvisionoptics
 
What is the link between wealth and welfare Do governments have a r.pdf
What is the link between wealth and welfare Do governments have a r.pdfWhat is the link between wealth and welfare Do governments have a r.pdf
What is the link between wealth and welfare Do governments have a r.pdfarrowvisionoptics
 
Which of the following are ways nutrients can enter the root cells .pdf
Which of the following are ways nutrients can enter the root cells  .pdfWhich of the following are ways nutrients can enter the root cells  .pdf
Which of the following are ways nutrients can enter the root cells .pdfarrowvisionoptics
 
What is E coliSolutionE.coli is a bacteria that normally live.pdf
What is E coliSolutionE.coli is a bacteria that normally live.pdfWhat is E coliSolutionE.coli is a bacteria that normally live.pdf
What is E coliSolutionE.coli is a bacteria that normally live.pdfarrowvisionoptics
 
Where does mitosis occur in the bodies of vascular plantsSoluti.pdf
Where does mitosis occur in the bodies of vascular plantsSoluti.pdfWhere does mitosis occur in the bodies of vascular plantsSoluti.pdf
Where does mitosis occur in the bodies of vascular plantsSoluti.pdfarrowvisionoptics
 
Which of the following are the three properties of dataA. mean, m.pdf
Which of the following are the three properties of dataA. mean, m.pdfWhich of the following are the three properties of dataA. mean, m.pdf
Which of the following are the three properties of dataA. mean, m.pdfarrowvisionoptics
 
What is the range of clinical signssymptoms of C. difficile infecti.pdf
What is the range of clinical signssymptoms of C. difficile infecti.pdfWhat is the range of clinical signssymptoms of C. difficile infecti.pdf
What is the range of clinical signssymptoms of C. difficile infecti.pdfarrowvisionoptics
 
What was Kants ideas regarding retributive punishmentSolution.pdf
What was Kants ideas regarding retributive punishmentSolution.pdfWhat was Kants ideas regarding retributive punishmentSolution.pdf
What was Kants ideas regarding retributive punishmentSolution.pdfarrowvisionoptics
 
What are the major events that occur during each stage in the life cy.pdf
What are the major events that occur during each stage in the life cy.pdfWhat are the major events that occur during each stage in the life cy.pdf
What are the major events that occur during each stage in the life cy.pdfarrowvisionoptics
 
What challenges do corporations face with regards to social media.pdf
What challenges do corporations face with regards to social media.pdfWhat challenges do corporations face with regards to social media.pdf
What challenges do corporations face with regards to social media.pdfarrowvisionoptics
 
Use De Moivres theorem to change the given complex number to the fo.pdf
Use De Moivres theorem to change the given complex number to the fo.pdfUse De Moivres theorem to change the given complex number to the fo.pdf
Use De Moivres theorem to change the given complex number to the fo.pdfarrowvisionoptics
 

More from arrowvisionoptics (20)

Every day when she first wakes up, Elena takes three foul shots on a.pdf
Every day when she first wakes up, Elena takes three foul shots on a.pdfEvery day when she first wakes up, Elena takes three foul shots on a.pdf
Every day when she first wakes up, Elena takes three foul shots on a.pdf
 
Be more apt to have a mentor than men.        Have dreams (.pdf
Be more apt to have a mentor than men.        Have dreams (.pdfBe more apt to have a mentor than men.        Have dreams (.pdf
Be more apt to have a mentor than men.        Have dreams (.pdf
 
Answer the following questions. EMB is considered to be both a _ medi.pdf
Answer the following questions. EMB is considered to be both a _ medi.pdfAnswer the following questions. EMB is considered to be both a _ medi.pdf
Answer the following questions. EMB is considered to be both a _ medi.pdf
 
A. The statement Evolutionists cannot point to any transitional fo.pdf
A. The statement Evolutionists cannot point to any transitional fo.pdfA. The statement Evolutionists cannot point to any transitional fo.pdf
A. The statement Evolutionists cannot point to any transitional fo.pdf
 
Culture of bacteria is having trouble dividing. Choose from the list.pdf
Culture of bacteria is having trouble dividing. Choose from the list.pdfCulture of bacteria is having trouble dividing. Choose from the list.pdf
Culture of bacteria is having trouble dividing. Choose from the list.pdf
 
Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdf
 
You identify four mutant strains that cannot synthesize Compound E. E.pdf
You identify four mutant strains that cannot synthesize Compound E. E.pdfYou identify four mutant strains that cannot synthesize Compound E. E.pdf
You identify four mutant strains that cannot synthesize Compound E. E.pdf
 
9. Identify at least two factors that influence the degree of stoc.pdf
9. Identify at least two factors that influence the degree of stoc.pdf9. Identify at least two factors that influence the degree of stoc.pdf
9. Identify at least two factors that influence the degree of stoc.pdf
 
What are the fuctional need of a roadWhat is road building system.pdf
What are the fuctional need of a roadWhat is road building system.pdfWhat are the fuctional need of a roadWhat is road building system.pdf
What are the fuctional need of a roadWhat is road building system.pdf
 
Why does Germany have to be assertive in the EUSolutionAnswer.pdf
Why does Germany have to be assertive in the EUSolutionAnswer.pdfWhy does Germany have to be assertive in the EUSolutionAnswer.pdf
Why does Germany have to be assertive in the EUSolutionAnswer.pdf
 
What is the link between wealth and welfare Do governments have a r.pdf
What is the link between wealth and welfare Do governments have a r.pdfWhat is the link between wealth and welfare Do governments have a r.pdf
What is the link between wealth and welfare Do governments have a r.pdf
 
Which of the following are ways nutrients can enter the root cells .pdf
Which of the following are ways nutrients can enter the root cells  .pdfWhich of the following are ways nutrients can enter the root cells  .pdf
Which of the following are ways nutrients can enter the root cells .pdf
 
What is E coliSolutionE.coli is a bacteria that normally live.pdf
What is E coliSolutionE.coli is a bacteria that normally live.pdfWhat is E coliSolutionE.coli is a bacteria that normally live.pdf
What is E coliSolutionE.coli is a bacteria that normally live.pdf
 
Where does mitosis occur in the bodies of vascular plantsSoluti.pdf
Where does mitosis occur in the bodies of vascular plantsSoluti.pdfWhere does mitosis occur in the bodies of vascular plantsSoluti.pdf
Where does mitosis occur in the bodies of vascular plantsSoluti.pdf
 
Which of the following are the three properties of dataA. mean, m.pdf
Which of the following are the three properties of dataA. mean, m.pdfWhich of the following are the three properties of dataA. mean, m.pdf
Which of the following are the three properties of dataA. mean, m.pdf
 
What is the range of clinical signssymptoms of C. difficile infecti.pdf
What is the range of clinical signssymptoms of C. difficile infecti.pdfWhat is the range of clinical signssymptoms of C. difficile infecti.pdf
What is the range of clinical signssymptoms of C. difficile infecti.pdf
 
What was Kants ideas regarding retributive punishmentSolution.pdf
What was Kants ideas regarding retributive punishmentSolution.pdfWhat was Kants ideas regarding retributive punishmentSolution.pdf
What was Kants ideas regarding retributive punishmentSolution.pdf
 
What are the major events that occur during each stage in the life cy.pdf
What are the major events that occur during each stage in the life cy.pdfWhat are the major events that occur during each stage in the life cy.pdf
What are the major events that occur during each stage in the life cy.pdf
 
What challenges do corporations face with regards to social media.pdf
What challenges do corporations face with regards to social media.pdfWhat challenges do corporations face with regards to social media.pdf
What challenges do corporations face with regards to social media.pdf
 
Use De Moivres theorem to change the given complex number to the fo.pdf
Use De Moivres theorem to change the given complex number to the fo.pdfUse De Moivres theorem to change the given complex number to the fo.pdf
Use De Moivres theorem to change the given complex number to the fo.pdf
 

Recently uploaded

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesSHIVANANDaRV
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 

Can someoen help me to write c++ program including C++ inheritance, .pdf

  • 1. Can someoen help me to write c++ program including C++ inheritance, polymorphism, virtual function, containment, file operations, and exception handling. // Q1a: Create Dog Class // Part 1: Create a child class of the Pet class named 'Dog' // See the add function in hw10.cpp for proper use of this function. // Part2: Declare constructor which accepts the same 3 parameters as the parent class Pet. // Pass the 3 parameters to the super constructor in the Pet class. // Part 3: Re-declare the method display (virtual method found inside of parent class Pet) // Q2a: Define Display for Dog class // Define the method display that you declared within the Dog class in the header file // Information should be printed in the following format: // Name: // Breed: // Type: Dog // (See the print_all function in hw10.cpp for proper use of this function.) // READ BEFORE YOU START: // You are given a partially completed program that creates a list of pets. // Each pet has the corresponding information: name, breed, and type. // In the Pet.h file, you will find the definition for this enum 'type'. // Pets on the list can be 2 different 'types' : either a dog or a cat. // The classes Dog and Cat are subclasses of the Pet class (found in Pet.h). // Both of these classes will have their own use of the virtual display method. // // 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 // All input will be a valid length and no more than the allowed amount of memory will be used #include "Container.h" #include "Pet.h" #include "Dog.h"
  • 2. #include "Cat.h" #include #include #include using namespace std; // forward declarations void flush(); void branching(char); void helper(char); void add_pet(string, string, Type); Pet* search_pet(string, string, Type); void remove_pet(string, string, Type); void remove_all(); void print_all(); void save(string); // 10 points void load(string); // 10 points Container* list = NULL; // global list int main() { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use to check for memory leaks in VS load("Pets.txt"); char ch = 'i'; do { cout << "Please enter your selection" << endl; cout << "ta: add a new pet to the list" << endl; cout << "tc: change the breed of a pet" << endl; cout << "tr: remove a pet from the list" << endl; cout << "tp: print all pets on the list" << endl; cout << "tq: quit and save list of pets" << endl; cin >> ch; flush(); branching(ch); } while (ch != 'q'); save("Pets.txt"); remove_all();
  • 3. 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; Type type; int type_check = -1; if (c == 'p')
  • 4. print_all(); else { cout << endl << "Please enter the pet's name: " << endl; cin >> name; cout << "Please enter the pet's breed: " << endl; cin >> breed; while (!(type_check == 0 || type_check == 1)) { cout << endl << "Please select one of the following: " << endl; cout << "0. Dog " << endl; cout << "1. Cat" << endl; cin >> type_check; } type = (Type)type_check; Pet* pet_result = search_pet(name, breed, type); if (c == 'a') // add pet { if (pet_result == NULL) { add_pet(name, breed, type); cout << endl << "Pet added." << endl << endl; } else cout << endl << "Pet already on list." << endl << endl; } else if (c == 'c') // change pet breed { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return; } cout << endl << "Please enter the new breed for this pet: " << endl; cin >> breed; flush(); // Q3c: Call Change Breed Function
  • 5. cout << endl << "Pet's breed changed." << endl << endl; } else if (c == 'r') // remove pet { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return; } remove_pet(name, breed, type); cout << endl << "Pet removed from the list." << endl << endl; } } } // Q3b: Define Friend Function Change Breed // Define the function changeBreed that is declared within the Pet.h file. // This function sets the breed value of the Pet pointer to the value of the string parameter. // Q4: Add Pet // This function will be used to add a new pet to the tail of the global linked list. // You will need to use the enum ëtypeí variable to determine which constructor to use. // Remember that search is called before this function, therefore, the new pet is not on the list. void add_pet(string name, string breed, Type type) { } // No implementation needed here, however it may be helpful to review this function Pet* search_pet(string name, string breed, Type type) { Container* container_traverser = list; while (container_traverser != NULL) { if (container_traverser->pet->getName() == name && container_traverser->pet->getBreed() == breed && container_traverser->pet->getType() == type) return container_traverser->pet; container_traverser = container_traverser->next; }
  • 6. return NULL; } // No implementation needed here, however it may be helpful to review this function void remove_pet(string name, string breed, Type type) { Container* to_be_removed; if (list->pet->getName() == name && list->pet->getBreed() == breed && list->pet->getType() == type) { to_be_removed = list; list = list->next; delete to_be_removed->pet; delete to_be_removed; return; } Container* container_traverser = list->next; Container* container_follower = list; while (container_traverser != NULL) { if (container_traverser->pet->getName() == name && container_traverser->pet->getBreed() == breed && container_traverser->pet->getType() == type) { to_be_removed = container_traverser; container_traverser = container_traverser->next; container_follower->next = container_traverser; delete to_be_removed->pet; delete to_be_removed; return; } container_follower = container_traverser; container_traverser = container_traverser->next; } } // No implementation needed here, however it may be helpful to review this function
  • 7. void remove_all() { while (list != NULL) { Container* temp = list; list = list->next; delete temp->pet; delete temp; } } // This function uses the virtual display() method of the Dog and Cat classes to print all Pets in an oragnized format. void print_all() { Container *container_traverser = list; if (list == NULL) cout << endl << "List is empty!" << endl << endl; while (container_traverser != NULL) { container_traverser->pet->display(); container_traverser = container_traverser->next; } } // Q5a: Save (5 points) // Save the linked list of pets to a file using ofstream. // You will need to come up with a way to store the amount of Containers in linked list. // Hint: You may want to cast the enum 'type' to an int before writing it to the file. void save(string fileName) { } // Q5b: Load (5 points) // Load the linked list of pets from a file using ifstream. // You will need to create the linked list in the same order that is was saved to a file. // You will need to create a new node for the linked list, then add it to the tail of the list. // Hint: If you casted the enum 'type' to an int, you will need to cast it back to a 'Type'.
  • 8. // You will use the 'type' variable read from the file to determine which constructor to use. void load(string fileName) { } Can someoen help me to write c++ program including C++ inheritance, polymorphism, virtual function, containment, file operations, and exception handling. // Q1a: Create Dog Class // Part 1: Create a child class of the Pet class named 'Dog' // See the add function in hw10.cpp for proper use of this function. // Part2: Declare constructor which accepts the same 3 parameters as the parent class Pet. // Pass the 3 parameters to the super constructor in the Pet class. // Part 3: Re-declare the method display (virtual method found inside of parent class Pet) // Q2a: Define Display for Dog class // Define the method display that you declared within the Dog class in the header file // Information should be printed in the following format: // Name: // Breed: // Type: Dog // (See the print_all function in hw10.cpp for proper use of this function.) // READ BEFORE YOU START: // You are given a partially completed program that creates a list of pets. // Each pet has the corresponding information: name, breed, and type. // In the Pet.h file, you will find the definition for this enum 'type'. // Pets on the list can be 2 different 'types' : either a dog or a cat. // The classes Dog and Cat are subclasses of the Pet class (found in Pet.h). // Both of these classes will have their own use of the virtual display method. // // 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
  • 9. // All input will be a valid length and no more than the allowed amount of memory will be used #include "Container.h" #include "Pet.h" #include "Dog.h" #include "Cat.h" #include #include #include using namespace std; // forward declarations void flush(); void branching(char); void helper(char); void add_pet(string, string, Type); Pet* search_pet(string, string, Type); void remove_pet(string, string, Type); void remove_all(); void print_all(); void save(string); // 10 points void load(string); // 10 points Container* list = NULL; // global list int main() { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use to check for memory leaks in VS load("Pets.txt"); char ch = 'i'; do { cout << "Please enter your selection" << endl; cout << "ta: add a new pet to the list" << endl; cout << "tc: change the breed of a pet" << endl; cout << "tr: remove a pet from the list" << endl; cout << "tp: print all pets on the list" << endl; cout << "tq: quit and save list of pets" << endl; cin >> ch; flush();
  • 10. branching(ch); } while (ch != 'q'); save("Pets.txt"); 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) {
  • 11. string name, breed; Type type; int type_check = -1; 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; while (!(type_check == 0 || type_check == 1)) { cout << endl << "Please select one of the following: " << endl; cout << "0. Dog " << endl; cout << "1. Cat" << endl; cin >> type_check; } type = (Type)type_check; Pet* pet_result = search_pet(name, breed, type); if (c == 'a') // add pet { if (pet_result == NULL) { add_pet(name, breed, type); cout << endl << "Pet added." << endl << endl; } else cout << endl << "Pet already on list." << endl << endl; } else if (c == 'c') // change pet breed { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return;
  • 12. } cout << endl << "Please enter the new breed for this pet: " << endl; cin >> breed; flush(); // Q3c: Call Change Breed Function cout << endl << "Pet's breed changed." << endl << endl; } else if (c == 'r') // remove pet { if (pet_result == NULL) { cout << endl << "Pet not found." << endl << endl; return; } remove_pet(name, breed, type); cout << endl << "Pet removed from the list." << endl << endl; } } } // Q3b: Define Friend Function Change Breed // Define the function changeBreed that is declared within the Pet.h file. // This function sets the breed value of the Pet pointer to the value of the string parameter. // Q4: Add Pet // This function will be used to add a new pet to the tail of the global linked list. // You will need to use the enum ëtypeí variable to determine which constructor to use. // Remember that search is called before this function, therefore, the new pet is not on the list. void add_pet(string name, string breed, Type type) { } // No implementation needed here, however it may be helpful to review this function Pet* search_pet(string name, string breed, Type type) { Container* container_traverser = list; while (container_traverser != NULL) { if (container_traverser->pet->getName() == name && container_traverser->pet->getBreed() == breed
  • 13. && container_traverser->pet->getType() == type) return container_traverser->pet; container_traverser = container_traverser->next; } return NULL; } // No implementation needed here, however it may be helpful to review this function void remove_pet(string name, string breed, Type type) { Container* to_be_removed; if (list->pet->getName() == name && list->pet->getBreed() == breed && list->pet->getType() == type) { to_be_removed = list; list = list->next; delete to_be_removed->pet; delete to_be_removed; return; } Container* container_traverser = list->next; Container* container_follower = list; while (container_traverser != NULL) { if (container_traverser->pet->getName() == name && container_traverser->pet->getBreed() == breed && container_traverser->pet->getType() == type) { to_be_removed = container_traverser; container_traverser = container_traverser->next; container_follower->next = container_traverser; delete to_be_removed->pet; delete to_be_removed; return; } container_follower = container_traverser;
  • 14. container_traverser = container_traverser->next; } } // No implementation needed here, however it may be helpful to review this function void remove_all() { while (list != NULL) { Container* temp = list; list = list->next; delete temp->pet; delete temp; } } // This function uses the virtual display() method of the Dog and Cat classes to print all Pets in an oragnized format. void print_all() { Container *container_traverser = list; if (list == NULL) cout << endl << "List is empty!" << endl << endl; while (container_traverser != NULL) { container_traverser->pet->display(); container_traverser = container_traverser->next; } } // Q5a: Save (5 points) // Save the linked list of pets to a file using ofstream. // You will need to come up with a way to store the amount of Containers in linked list. // Hint: You may want to cast the enum 'type' to an int before writing it to the file. void save(string fileName) { } // Q5b: Load (5 points)
  • 15. // Load the linked list of pets from a file using ifstream. // You will need to create the linked list in the same order that is was saved to a file. // You will need to create a new node for the linked list, then add it to the tail of the list. // Hint: If you casted the enum 'type' to an int, you will need to cast it back to a 'Type'. // You will use the 'type' variable read from the file to determine which constructor to use. void load(string fileName) { } Solution Answers to Q1, Q2, Q3. Implement parent class Pet. Derive child classes dog and cat from pet. Implement the virtual function display(). Implement a friend function whih acts as bridge between classes. // pet.h #include #include using namespace std; enum Type {dog, cat}; //type can be only of 2 types cat and dog // Parent class class Pet { //3 parameters of parent class pet public: string name; string breed; Type type; //constructor Pet( string n, string b, Type t) { name = n; breed = b; type = t; } virtual void display(){}; //virtual display function };
  • 16. // Derived child Dog class //Q1a class Dog: public Pet { //Q1a PART 2 public: Dog(string n,string b, Type t) : Pet(n, b, dog) {}; //Q2a void display() { //Q1a PART 3 cout << "Name :" << name << endl; cout << "Breed :" << breed << endl; cout << "Type :Dog" << endl << endl; } friend void changeBreed(Pet*, string); //friend function }; // Derived child Cat class class Cat: public Pet { public: Cat(string n, string b, Type t) : Pet(n, b, cat) {}; void display() { cout << "Name :" << name << endl; cout << "Breed :" << breed << endl; cout << "Type :Cat" << endl << endl; } friend void changeBreed(Pet*, string); //friend function }; //Q3b //friend function implementation void changeBreed(Pet *p, string newBreed) { p->breed = newBreed; //set breed value to new value from parameter } int main() { //Examples
  • 17. Pet* p; Dog dog1("Alfa", "Pug", dog); Cat cat1("Purry", "Persian", cat); dog1.display(); cat1.display(); p = &dog1; changeBreed(p, "Bulldog"); dog1.display(); return 0; } Output : Name :Alfa Breed :Pug Type :Dog Name :Purry Breed :Persian Type :Cat Name :Alfa Breed :Bulldog Type :Dog