Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include using namespace std; struct Cat { double length; double height; double tailLength; string eyeColour; string furClassification; //long,

In C++

***//Cat.h//***

#ifndef __Cat_h__ #define __Cat_h__ #include using namespace std;

struct Cat { double length; double height; double tailLength; string eyeColour; string furClassification; //long, medium, short, none string furColours[5]; };

void initCat (Cat&, double, double, double, string, string, const string[]); void readCat (Cat&); void printCat (const Cat&); bool isCalico (const Cat&); bool isTaller (const Cat&, const Cat&);

#endif

***//Cat.cpp//***

#include "Cat.h" #include using namespace std;

void initCat (Cat& cat, double l, double h, double tL, string eC, string fCl, const string furCol[]) { int i = 0; cat.length = l; cat.height = h; cat.tailLength = tL; cat.eyeColour = eC; cat.furClassification = fCl; //long, medium, short, none while (furCol[i] != "") { cat.furColours[i] = furCol[i]; i++; } cat.furColours[i] = "";

}

void readCat (Cat& cat) { int i = 0; cout << "Please decribe the cat" << endl; cout << "Please enter a length: "; cin >> cat.length; cout << "Please enter a height: "; cin >> cat.height; cout << "Please enter a tail length: "; cin >> cat.tailLength; cout << "Please enter an eye colour: "; cin >> cat.eyeColour; cout << "Please enter a description of the fur (long, medium, short, none): "; cin >> cat.furClassification; cout << "Please enter the colours of the fur (separated by a space or a newline character). "; cout << "Add \"done\" at the end: "; cin >> cat.furColours[i]; while (cat.furColours[i] != "done") { i++; cin >> cat.furColours[i]; } cat.furColours[i] = ""; }

void printCat (const Cat& cat) { int i = 0; cout << "Length: "<< cat.length << " Height: "<< cat.height << " Tail Length: " << cat.tailLength << endl; cout << "Eye Colour: " << cat.eyeColour << " Fur Classification: " << cat.furClassification << endl; cout << "Cat Colours: "; while (cat.furColours[i] != "") { cout << cat.furColours[i++] << " "; } cout << endl; }

bool isCalico (const Cat& cat) { if (cat.furColours[3] != "") return false; for (int i=0; i< 3; i++) { if (cat.furColours[i] != "black" && cat.furColours[i] != "orange" && cat.furColours[i] != "white") return false; } return true; }

bool isTaller (const Cat& cat1, const Cat& cat2) { return (cat1.height > cat2.height); }

***// main.cpp //***

#include "Cat.h" #include using namespace std;

int main() { Cat averageCat, myCat;

string colours[5]; colours[0] = "brown"; colours[1] = ""; initCat (averageCat, 46, 24, 30, "green", "medium", colours);

readCat (myCat);

cout << "The average cat has height " << averageCat.height << endl;

cout << "-------------------------------------------------------"<< endl; cout << "This is myCat:" << endl; printCat (myCat); if (isTaller (myCat, averageCat)) { cout << "My cat is taller than the average cat "; } else { cout << "My cat is shorter than the average cat "; } if (isCalico (myCat)) { cout << "My cat is a calico "; }

return 0; }

1) Modify all of the functions so that they are member functions. Use the scope resolution operator (::) to show that an implementation of a function is part of a class

2) Change the initialization function into a constructor with arguments.

3) Add a default constructor that initializes things to 0 or empty string.

4) Add one getter to return the height.

5) Modify the calls in main to reflect the change in the functions.

6) Be sure to add the keyword const after functions that do not change the data.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions