Answer to Question #246215 in C++ for Boo

Question #246215
Create a class named Horse that includes data fields that hold the name, color, and birth year.
Include only a non-default constructor that initializes all of the data fields, and a function that
displays detailed information about the Horse.
Create another class, RaceHorse which inherits from Horse. RaceHorse has an additional data
field that holds the number of races won. Include a constructor that will initialize races won,
and a method that displays detailed information about the RaceHorse.
Write a main() function demonstrating that classes and functions work correctly.
1
Expert's answer
2021-10-04T00:50:25-0400
#include <iostream>
#include <string>
using namespace std;


class Horse
{
public:
	void viewInfo()
	{
		cerr << "Name: " << name << "\n";
		cerr << "Color: " << color << "\n";
		cerr << "Birth Year: " << birthYear << "\n";
	}
	Horse(string n, string c, double y)
		: name (n),
		  color (c),
		  birthYear(y)
	{
	}
	Horse() {};
	string name;
	string color;
	double birthYear{ 0 };
private:
};
class RaceHorse :public Horse 
{
public:
	void viewInfo() 
	{
		Horse::viewInfo();
		cerr << "Raced Won: " << racesWon;
	}
	RaceHorse(string n, string c, double y, int r) 
	   : Horse(n,c, y),
		 racesWon(r)
	{
	}
	RaceHorse() {};
	int racesWon{ 0 };
};


int main()
{
	Horse bucefal("Bucefal","brown",2015);
	bucefal.viewInfo();
	RaceHorse rossinat("Rossinat","white",2018,6);
	rossinat.viewInfo();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS