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

C++11 Coding question Assignment Requirements .The name of your compiled binary

ID: 3918202 • Letter: C

Question

C++11 Coding question

Assignment Requirements .The name of your compiled binary shall be exam2 .You will be submitting a minimum of 13 files . 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 - 1 file for a List class - 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 cont ain 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 requirer requirements:

Explanation / Answer

Code:

Main.cpp:

template<class T>

class LinkedList{

private:

Node<T> *HEAD;

Node<T> *TAIL;

int Cap;

public:

LinkedList<T>(){

   HEAD = NULL;

   TAIL = NULL;

Cap = 0;

}

LinkedList(T arr[],int items):LinkedList<T>(){

   for(int i = 0;i<items;i++){

    inserted(arr[i]);

   }

   cout<<Cap;

}

~LinkedList<T>(){

   madeEmpty();

}

void inserted(const T &items){

   if(HEAD == NULL){

    HEAD = new Node<T>();

    HEAD->NEXT = NULL;

    HEAD->data = items;

    TAIL = HEAD;

    Cap = 1;

    return;

   }

   Node<T> *cur = HEAD;

   Node<T> *prev = NULL;

   Node<T> *newNode = new Node<T>();

   newNode->NEXT = NULL;

   newNode->data = items;

   while(cur != NULL){

    if(cur->data >= items){

     if(prev == NULL){

      newNode->NEXT = HEAD;

      HEAD = newNode;

      Cap++;

      return;

     }

     prev->NEXT = newNode;

     newNode->NEXT = cur;

     Cap++;

     return;

    }else{

     prev = cur;

     cur = cur->NEXT;

    }

   }

   prev->NEXT = newNode;

   TAIL = newNode;

   Cap++;

}

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 &items){

   if(HEAD == NULL){

    return false;

   }

   else{

    Node<T> *TEMP = HEAD;

    while(TEMP != NULL){

     if(TEMP->data == items){

      return true;

     }

     TEMP = TEMP->NEXT;

    }

    return false;

   }

}

void removedNode(int i){

   if(i >= Cap){

    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;

     }

    }

   

   }

   Cap--;

}

void madeEmpty(){

   Node<T> *NEXT;

   while(HEAD != NULL){

    NEXT = HEAD->NEXT;

    delete HEAD;

    HEAD = NEXT;

   }

   HEAD = NULL;

   Cap = 0;

}

int getsize(){

   return Cap;

}

void DisplayListed(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 != Cap-1){

      ous<<" -> ";

     }

     TEMP = TEMP->NEXT;

    }

   }

   else{

    ous<<" List Is Empty";

   }

}

};

Book.h:

#ifndef BOOK_H

#define BOOK_H

#include<iostream>

using namespace std;

// implement class

class Book{

// private variable

private:

string Author;

string Titles;

int years;

// public variables

public:

// methods

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);

};

#endif

Book.cpp:

Book::Book(){

Authors = "";

Titles = "";

years = 0;

}

Book::Book(string auth,string titl,int years){

setAuthors(auth);

setTitle(titl);

setYear(years);

}

void Book::setAuthors(string auth){

Authors = auth;

}

void Book::setTitle(string tit){

Titles = tit;

}

void Book::setYear(int y){

years = y;

}

string Book::getAuthors()const{

return Authors;

}

string Book::getTitle()const{

return Titles;

}

int Book::getYear()const{

return years;

}

bool Book::operator>=(const Book &b)const{

return Authors >= b.Authors;

}

Book& Book::operator=(const Book& b){

if(this == &b){

return *this;

}

Authors = b.getAuthor();

Titles = b.getTitle();

years = b.getYear();

return *this;

}

ostream& operator<<(ostream& ous,const Book&b){

ous<<b.getAuthor()<<"  "<<b.getTitle()<<"  "<<b.getYear();

return ous;

}

Cat.h:

#ifndef CAT_H

#define CAT_H

// defintion class

#include "Pet.h"

class Cat:public Pet{

// declare method

public:

Cat();

Cat(string);

void taught()const;

};

#endif

Cat.cpp:

Cat::Cat():Pet(){

}

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

}

void Cat::taught()const{

cout << "Mewwo Mewwo Mewwo Mewww....";

}

Dog.h:

#ifndef DOG_H

#define DOG_H

#include "Pet.h"

class Dog:public Pet{

// define a variable

public:

// declare call

Dog();

Dog(string);

void Bark()const;

};

#endif

Dog.cpp:

Dog::Dog():Pet(){

}

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

}

void Dog::Bark()const{

cout << "Baww Baww Baww Baww ....";

}

Goldfish.h:

#ifndef GOLDFISH_H

#define GOLDFISH_H

#include "Pet.h"

// implement class

class GoldFish:public Pet{

// declare method

public:

GoldFish();

GoldFish(string);

void Swallo()const;

};

#endif

Goldfish.cpp:

GoldFish::GoldFish():Pet(){

}

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

}

void GoldFish::Swallo()const{

cout << "Humsss Humsss Humsss Humsss....";

}

LinkList.h:

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

#include<iostream>

using namespace std;

template<class T>

struct Node{

   T data;

   Node *next;

};

// implemnet a class for array class

class OutOfBoundsError{

public:

OutOfBoundsError(){

   cout<<" Index Out Of the Bound ";

}

};

Pet.h:

#ifndef PET_H

#define PET_H

#include<iostream>

using namespace std;

// implement a class

class Pet{

// define a variable

private:

string name;

public:

Pet();

Pet(string);

// method function

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);

};

#endif

Pet.cpp:

Pet::Pet(){

Names = "";

}

Pet::Pet(string n){

setName(n);

}

Pet& Pet::operator=(const Pet& p){

if(this == &b){

return *this;

}

Names = p.getName();

return *this;

}

void Pet::setName(string n){

Names = n;

}

string Pet::getName()const{

return Names;

}

bool Pet::operator>=(const Pet &p)const{

return Names >= p.Names;

}

ostream& operator<<(ostream& ous,const Pet&p){

ous<<Names<<" ";

return ous;

}

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