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

C++ Object-Oriented Programming The files required include: – 2 files for a base

ID: 3917343 • Letter: C

Question

C++ Object-Oriented Programming

The files required include: – 2 files for a base Pet class – 6 files (2 each) for three pet classes derived from Pet – 2 files for a Book class – 1fileforaListclass – 1 file for your main function – 1 file for your makefile • 10 of the files are “trivial” in that they will be classes with just enough functionality to work within a List • The grading focus on this assignment is mostly with the List class, although a sizable portion will also go towards properly deriving from Pet • Pet class requirements: – The class shall be abstract – The class shall contain a pure virtual function called speak – Any data common to all pets shall be placed in this class * All pets shall have a name
• Derived from Pet requirements:
Derive 3 classes from Pet – You may choose what types of Pets to derive – Examples include: Dog, Cat, Goldfish, Rock, Iguana, Tarantula, SugarGlider, etc. • Book class requirements: – A book must contain the following data: * author * title * year • List class requirements: – This is a template class – You may hold the list in whatever structure you want (with one exception) * Linked List, dynamic array, vectors are all acceptable * You may NOT use a statically allcoated array – This is a sorted list * Pets are sorted by their name * Books are sorted by their author (no need to sort by last name first, just the value of author is sufficient) • main.cpp requirements: • I will not provide test files • Inside your main function, you shall declare two lists – One to hold your pets – One to hold your books • Add 5 items to each list • Print each list to their own file – The Pet file shall be called pets.txt – The Book file shall be called library.txt
C++ Object-Oriented Programming

The files required include: – 2 files for a base Pet class – 6 files (2 each) for three pet classes derived from Pet – 2 files for a Book class – 1fileforaListclass – 1 file for your main function – 1 file for your makefile • 10 of the files are “trivial” in that they will be classes with just enough functionality to work within a List • The grading focus on this assignment is mostly with the List class, although a sizable portion will also go towards properly deriving from Pet • Pet class requirements: – The class shall be abstract – The class shall contain a pure virtual function called speak – Any data common to all pets shall be placed in this class * All pets shall have a name
• Derived from Pet requirements:
Derive 3 classes from Pet – You may choose what types of Pets to derive – Examples include: Dog, Cat, Goldfish, Rock, Iguana, Tarantula, SugarGlider, etc. • Book class requirements: – A book must contain the following data: * author * title * year • List class requirements: – This is a template class – You may hold the list in whatever structure you want (with one exception) * Linked List, dynamic array, vectors are all acceptable * You may NOT use a statically allcoated array – This is a sorted list * Pets are sorted by their name * Books are sorted by their author (no need to sort by last name first, just the value of author is sufficient) • main.cpp requirements: • I will not provide test files • Inside your main function, you shall declare two lists – One to hold your pets – One to hold your books • Add 5 items to each list • Print each list to their own file – The Pet file shall be called pets.txt – The Book file shall be called library.txt
C++ Object-Oriented Programming

The files required include: – 2 files for a base Pet class – 6 files (2 each) for three pet classes derived from Pet – 2 files for a Book class – 1fileforaListclass – 1 file for your main function – 1 file for your makefile • 10 of the files are “trivial” in that they will be classes with just enough functionality to work within a List • The grading focus on this assignment is mostly with the List class, although a sizable portion will also go towards properly deriving from Pet • Pet class requirements: – The class shall be abstract – The class shall contain a pure virtual function called speak – Any data common to all pets shall be placed in this class * All pets shall have a name
• Derived from Pet requirements:
Derive 3 classes from Pet – You may choose what types of Pets to derive – Examples include: Dog, Cat, Goldfish, Rock, Iguana, Tarantula, SugarGlider, etc. • Book class requirements: – A book must contain the following data: * author * title * year • List class requirements: – This is a template class – You may hold the list in whatever structure you want (with one exception) * Linked List, dynamic array, vectors are all acceptable * You may NOT use a statically allcoated array – This is a sorted list * Pets are sorted by their name * Books are sorted by their author (no need to sort by last name first, just the value of author is sufficient) • main.cpp requirements: • I will not provide test files • Inside your main function, you shall declare two lists – One to hold your pets – One to hold your books • Add 5 items to each list • Print each list to their own file – The Pet file shall be called pets.txt – The Book file shall be called library.txt Derive 3 classes from Pet – You may choose what types of Pets to derive – Examples include: Dog, Cat, Goldfish, Rock, Iguana, Tarantula, SugarGlider, etc. • Book class requirements: – A book must contain the following data: * author * title * year • List class requirements: – This is a template class – You may hold the list in whatever structure you want (with one exception) * Linked List, dynamic array, vectors are all acceptable * You may NOT use a statically allcoated array – This is a sorted list * Pets are sorted by their name * Books are sorted by their author (no need to sort by last name first, just the value of author is sufficient) • main.cpp requirements: • I will not provide test files • Inside your main function, you shall declare two lists – One to hold your pets – One to hold your books • Add 5 items to each list • Print each list to their own file – The Pet file shall be called pets.txt – The Book file shall be called library.txt

Explanation / Answer

here is your files : --------------->>>>>>>>>>>

#ifndef PET_H
#define PET_H
#include<iostream>

using namespace std;

class Pet{
private:
  string name;
public:
  Pet();
  Pet(string);
  virtual void speak()const=0;
  void setName(string);
  string getName()const;
  Pet& operator=(const Pet &p);
  bool operator>=(const Pet &p)const;
  friend ostream& operator<<(ostream& ous,const Pet &p);
};
#include "Pet.cpp"
#endif

Pet.cpp :


Pet::Pet(){
name = "";
}

Pet::Pet(string n){
setName(n);
}
Pet& Pet::operator=(const Pet& p){
if(this == &b){
  return *this;
}
name = p.getName();
return *this;
}
void Pet::setName(string n){
name = n;
}

string Pet::getName()const{
return name;
}

bool Pet::operator>=(const Pet &p)const{
return name >= p.name;
}

ostream& operator<<(ostream& ous,const Pet& p){
ous<<name<<" ";
return ous;
}

Cat.h : --------

#ifndef CAT_H
#define CAT_H
#include "Pet.h"

class Cat:public Pet{
public:
  Cat();
  Cat(string);
  void speak()const;
};
#include "Cat.cpp"
#endif

Cat.cpp : -----------


Cat::Cat():Pet(){

}

Cat::Cat(string n):Pet(n){

}

void Cat::speak()const{
cout << "Mew Mew Mew Mew....";
}

Dog.h : ----------

#ifndef DOG_H
#define DOG_H
#include "Pet.h"

class Dog:public Pet{
public:
  Dog();
  Dog(string);
  void speak()const;
};
#include "Dog.cpp"
#endif

Dog.cpp : ---------


Dog::Dog():Pet(){

}

Dog::Dog(string n):Pet(n){

}

void Dog::speak()const{
cout << "Baw Baw Baw Baw ....";
}

GoldFish.h : -----------

#ifndef GOLDFISH_H
#define GOLDFISH_H
#include "Pet.h"

class GoldFish:public Pet{
public:
  GoldFish();
  GoldFish(string);
  void speak()const;
};
#include "GoldFish.cpp"
#endif

GoldFish.cpp : ----------


GoldFish::GoldFish():Pet(){

}

GoldFish::GoldFish(string n):Pet(n){

}

void GoldFish::speak()const{
cout << "Hums Hums Hums Hums....";
}

Book.h : -----------

#ifndef BOOK_H
#define BOOK_H
#include<iostream>

using namespace std;

class Book{
private:
  string author;
  string title;
  int year;
public:
  Book();
  Book(string,string,int);
  void setTitle(string);
  string getTitle()const;
  void setAuthor(string);
  string getAuthor()const;
  void setYear(int);
  int getYear()const;
  Book& operator=(const Book& b);
  bool operator>=(const Book &p)const;
  friend ostream& operator<<(ostream& ous,const Book &b);
};
#include "Book.cpp"
#endif

Book.cpp : ----------


Book::Book(){
author = "";
title = "";
year = 0;
}

Book::Book(string auth,string titl,int year){
setAuthor(auth);
setTitle(titl);
setYear(year);
}

void Book::setAuthor(string auth){
author = auth;
}

void Book::setTitle(string tit){
title = tit;
}

void Book::setYear(int y){
year = y;
}

string Book::getAuthor()const{
return author;
}

string Book::getTitle()const{
return title;
}

int Book::getYear()const{
return year;
}

bool Book::operator>=(const Book &b)const{
return author >= b.author;
}
Book& Book::operator=(const Book& b){
if(this == &b){
  return *this;
}
author = b.getAuthor();
title = b.getTitle();
year = b.getYear();
return *this;
}
ostream& operator<<(ostream& ous,const Book &b){
ous<<b.getAuthor()<<"   "<<b.getTitle()<<"   "<<b.getYear();

return ous;
}

LinkList.h : ----------

#include<iostream>

using namespace std;

template<class T>
struct Node{
   T data;
   Node *next;
};

class OutOfBoundsError{
public:
  OutOfBoundsError(){
   cout<<" Index out Of Bound ";
  }
};

template<class T>
class LinkedList{
private:
  Node<T> *head;
  Node<T> *tail;
  int size;
public:
  LinkedList<T>(){
   head = NULL;
   tail = NULL;
   size = 0;
  }
  LinkedList(T arr[],int item):LinkedList<T>(){
   for(int i = 0;i<item;i++){
    insert(arr[i]);
   }
   cout<<size;
  }
  ~LinkedList<T>(){
   makeEmpty();
  }
  void insert(const T &item){
   if(head == NULL){
    head = new Node<T>();
    head->next = NULL;
    head->data = item;
    tail = head;
    size = 1;
    return;
   }
   Node<T> *cur = head;
   Node<T> *prev = NULL;
   Node<T> *newNode = new Node<T>();
   newNode->next = NULL;
   newNode->data = item;
   while(cur != NULL){
    if(cur->data >= item){
     if(prev == NULL){
      newNode->next = head;
      head = newNode;
      size++;
      return;
     }
     prev->next = newNode;
     newNode->next = cur;
     size++;
     return;
    }else{
     prev = cur;
     cur = cur->next;
    }
   }
   prev->next = newNode;
   tail = newNode;
   size++;
  }
  T* getFront(){
   if(head == NULL){
    return NULL;
   }
   else{
    return &head->data;
   }
  }
  T* getBack(){
   if(head == NULL){
    return NULL;
   }
   else{
    return &tail->data;
   }
  }
  bool contains(const T &item){
   if(head == NULL){
    return false;
   }
   else{
    Node<T> *temp = head;
    while(temp != NULL){
     if(temp->data == item){
      return true;
     }
     temp = temp->next;
    }
    return false;
   }
  }
  
  void removeNode(int i){
   if(i >= size){
    throw new OutOfBoundsError();
   }
   else{
    Node<T> *temp = head;
    if(i == 0){
     if(head == tail){
      head = tail = NULL;
      delete temp;
     }
     else{
      head = head->next;
      delete temp;
     }
    }
    else{
     for(int j = 0;j<i;j++){
      temp = temp->next;
     }
     if(tail == temp->next){
      tail = temp;
      delete temp->next;
     }
     else{
      Node<T> *tmp = temp->next;
      temp->next = tmp->next;
      delete tmp;
     }
    }
    
   }
   size--;
  }
  
  void makeEmpty(){
   Node<T> *next;
   while(head != NULL){
    next = head->next;
    delete head;
    head = next;
   }
   head = NULL;
   size = 0;
  }
  
  int getsize(){
   return size;
  }
  
  void printList(ostream &ous){
   if(head != NULL){
    Node<T> *temp = head;
    for(int i = 0;i<size;i++){
     if(temp == NULL){
      break;
     }
     ous<<"["<<temp->data<<"]";
     if(i != size-1){
      ous<<" -> ";
     }
     temp = temp->next;
    }
   }
   else{
    ous<<" List Is Empty";
   }
  }  
};

Main.cpp : ------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote