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

Need help ASAP please I have code just need help question I have the code but it

ID: 3700618 • Letter: N

Question

Need help ASAP please I have code just need help

question

I have the code but it is not compiling and has many error messages could someone help, I need to compile the 3 cpp files with the g++ and it will not work... Please show its working thank you!

CODE:

lab8dog.h

#include <iostream>
using namespace std;

class Dog
{
protected:
   string name;
   string color;
   double weight;

public:
   Dog();
   Dog(string,double,string);
   virtual void displayDog();
   virtual ~Dog();
};

lab8show.h

class ShowDog:public Dog
{
private:
   int noContests;
   int winContests;

public:
   ShowDog();
   ShowDog(string,double,string,int,int);
   void displayDog();
};

lab8dog.cpp

#include "lab8dog.h"
Dog::Dog(){
   name="unknown";
   color="unknown";
   weight=0.0;
}
Dog::Dog(string n,double w,string c){
   name=n;
   color=c;
   weight=w;
}
void Dog::displayDog(){
   cout<<" Dog's name: "<<this->name;
   cout<<" Dog's color: "<<color;
   cout<<" Dog's weight: "<<weight;
}
Dog::~Dog(){
   // cout<<"Destructor called"<<endl;
}

lab8show.cpp

#include "lab8show.h"
#include <iostream>
using namespace std;

ShowDog::ShowDog():Dog()
{
   noContests=0;
   winContests=0;
}
ShowDog::ShowDog(string n,double w,string c,int total,int win): Dog(n,w,c)
{
   noContests=total;
   winContests=win;
}
void ShowDog::displayDog()
{
   cout<<" ";
   Dog::displayDog();
   cout<<" "<<name<<" entered in "<<noContests<<" contests";
   cout<<" " << name<<" won "<<winContests<<" contests ";
}

lab8client.cpp

#include "lab8show.cpp"
int main(){
Dog D("Bolt", 20,"White");
D.displayDog();

ShowDog SD("Uggie", 30, "Blk/Wht", 3, 1 );
SD.displayDog();

Dog *dogList[4];

Dog *temp;
// temp=new Dog("Bingo", 20, "Tan");
dogList[0]=new Dog("Bingo", 20, "Tan");;

dogList[1]= new ShowDog("Beethoven", 200, "Brown",3,1);

dogList[2]= new ShowDog("Marley", 80, "Yellow",10,3);

dogList[3]= new Dog("Fido", 50, "Rust");

for(int i=0;i<4;i++){
dogList[i]->displayDog();
cout<<" ";
}

return 0;
}

Mandatory Instructions 1. The base class Dog is a class with general information about dogs Store the declaration for this class in a file called labSdog.h. The class has three protected data members to store dog's name, color and weight Include a prototype fora default constructor that sets the name and color to the value "Unknown" and the weight to 0.0. Include a second prototype for a constructor that accepts values for the dog's name, color and weight and assigns them to the data members. Also, include a prototype for a function called displayDog to display the values of each data member. 2. Implement all member fiunctions for the Dog class in the file called lab8dog.cpp 3. Class ShowDog will be a derived class with additional information about dogs who have been entered in dog shows so a ShowDog"is a" Dog which means it will inherit from the Dog base class. Store the declaration for the ShowDog class in the file lab8show.h and define the functions in the file lab8show.cpp This class has two private data members -the number of contests a dog has been entered in and the number of contests it has won. Define a default constructor that sets these two fields to zero and invokes the Dog default constructor to initialize the inherited data members. Define a second constructor that accepts a dog's name, color, weight, number of contests entered and number won. Pass the first three arguments to the Dog constructor and use the last two to set the ShowDog's data members. Include a prototype for a function called displayDog. It should first call the base class version of the function (to display the dog's name, color and weight) and then display the mmber of contests entered by the dog and the number won. This function is redefining the base class version of displayDog. The function should produce an output like this: Dog's name: Toto Dog's weight: 25 Dog's color: Grey (first three lines are printed by base class displayDog function) Toto was entered in 5 contests, Toto won 2 of the contests. 4. Write a client program called labSclient.cpp to demonstrate the use of Dog and ShowDog classes. Define a Dog object initializing the name, color and weight with "Bolt", "White" and 20 Define a ShowDog object with arguments for all five data members using the values "Uggie", "Blk/Wht", 30, 3, 1

Explanation / Answer

Solution:

Please try this working code:

lab8dog.h

#ifndef LAB8DOG_H
#define LAB8DOG_H
#include <string>

class lab8dog
{
protected:
// Data members
std::string name;
std::string color;
double weight;
public:
lab8dog(); // Default constructor
// Parametrized constructor with 3 arguments
lab8dog(std::string n, std::string c, double w);
void displayDog();

};

#endif // LAB8DOG_H

lab8dog.cpp

#include "lab8dog.h"
#include<iostream>
#include<iomanip>
using namespace std;

// Set default values to data members
lab8dog::lab8dog()
{
name="unknown";
color="unknown";
weight =0.0;
}

// Set passed values to data members
lab8dog::lab8dog(string n, string c, double w)
{
name=n;
color=c;
weight=w;
}

void lab8dog::displayDog()
{
// Display dog's name, color and weight
cout<<"Dog's Name: "<<name<<endl;
cout<<"Dog's Color: "<<color<<endl;
cout<<"Dog's Weight: "<<fixed<<setprecision(2)<<weight<<endl;
}

lab8show.h

#ifndef LAB8SHOW_H
#define LAB8SHOW_H
#include "lab8dog.h"

// Inherit lab8dog class
class lab8show:public lab8dog
{
public:
lab8show(); // Default constructor

// Parametrized constructor with 5 arguments
lab8show(std::string name, std::string color, double weight,int numberOfContests , int contestWon);
void displayDog();

private:
// Data members
int numberOfContests;
int contestWon;
};

#endif // LAB8SHOW_H

lab8show.cpp

#include "lab8show.h"
#include<iostream>
using namespace std;

// Set default values to data members
// call base class constructor as well
lab8show::lab8show():lab8dog()
{
numberOfContests =0;
contestWon = 0;
}

// Set passed values to data members
// Call base class constructor with 3 arguments
lab8show::lab8show(string name, string color, double weight,int n, int won):lab8dog(name,color,weight)
{
numberOfContests = n;
contestWon = won;
}

void lab8show::displayDog(){

// Display details
lab8dog::displayDog(); // call base class method
cout<<lab8dog::name<<" was entered in "<<numberOfContests<<" contests,"<<endl;
cout<<lab8dog::name<<" won "<<contestWon<<" of the contests"<<endl;

}

main.cpp

#include <iostream>
#include "lab8dog.h"
#include "lab8show.h"
using namespace std;

int main()
{
// Make several objects of both classes and
// call function displayDog on them
lab8dog d1{"Bolt","White",20};
d1.displayDog();
cout<<endl;

lab8show s1{"Uggie","Blk/Wht",30,3,1};
s1.displayDog();
cout<<endl;

lab8dog d2{"Bingo","Tan",20};
d2.displayDog();
cout<<endl;

lab8show s2{"Beethoven","Brown",200,3,1};
s2.displayDog();
cout<<endl;

lab8show s3{"Marley","Yellow",80,10,3};
s3.displayDog();
cout<<endl;


lab8dog d3{"Fido","Rust",50};
d3.displayDog();
cout<<endl;

return 0;
}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

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