I have the code but it is not compiling and has many error messages could someon
ID: 3700596 • Letter: I
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;
}
Explanation / Answer
All the compilation errors are removed. That's what you have asked for.
lab8dog.h
#ifndef __lab8_dog_h
#include<string>
using namespace std;
class Dog
{
protected:
string name;
string color;
double weight;
public:
Dog();
Dog(string,double,string);
virtual void displayDog();
virtual ~Dog();
};
#endif
lab8show.h
#ifndef lab8_show_dog_h
#include "lab8dog.h"
#include<string>
using namespace std;
class ShowDog:public Dog
{
private:
int noContests;
int winContests;
public:
ShowDog();
ShowDog(string,double,string,int,int);
void displayDog();
};
#endif
lab8dog.cpp
#include<iostream>
#include "lab8dog.h"
using namespace std;
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.h"
#include<iostream>
using namespace std;
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;
}
NOTE: Compile all these .cpp files. There are not any compilation errors. I haven't checked for runtime errors. I hope there might not be any runtime errors.