#code for creature.cpp
#include <iostream>
using namespace std;
class Creature {
public:
Creature();
void run() const;
protected:
int distance;
};
Creature::Creature(): distance(10)
{}
void Creature::run() const
{
cout << "running " << distance << " meters!\n";
}
class Wizard : public Creature {
public:
Wizard();
void hover() const;
private:
int distFactor;
};
Wizard::Wizard() : distFactor(3)
{}
void Wizard::hover() const
{
cout << "hovering " << (distFactor * distance) << " meters!\n";
}
//Created new derived class from Creature
class Widget : public Creature{
public:
//constructor
Widget();
//new method added as click
void click() const;
private:
//new data member
int clickedDistance;
};
//constructor implementation
Widget::Widget() : clickedDistance(5)
{
cout << "\nCreating a Widget.\n";
}
//click method implementation
void Widget::click() const
{
cout << "Clicked " << clickedDistance + distance << " meters\n";
}
//Created new derived class from Creature
class TextCreature : public Creature{
public:
//constructor
TextCreature();
//new method added as Moved
void moved() const;
private:
//new data member
int byDistance;
};
//implementation of TextCreature methods including constructor
TextCreature::TextCreature() : byDistance(3)
{
cout <<"\nCreating a text Creature.\n";
}
void TextCreature::moved() const
{
cout << "moved " << byDistance + distance << " meters\n";
}
//-------------------------------------------------------------------------
int main()
{
cout << "\nCreating an Creature.\n";
Creature c;
c.run();
cout << "\nCreating a Wizard.\n";
Wizard w;
w.run();
w.hover();
//create an object of Widget class
Widget wdg;
//calling base class method
wdg.run();
//calling newly added method
wdg.click();
//create an object of TextCreature class
TextCreature txt;
//calling base class method
txt.run();
//calling newly added method
txt.moved();
return 0;
}
Creature.h
#ifndef CREATURES_H
#define CREATURES_H
#include <iostream>
using namespace std;
class Creature {
public:
Creature();
void run() const;
protected:
int distance;
};
class Wizard : public Creature {
public:
Wizard();
void hover() const;
private:
int distFactor;
};
//Created new derived class from Creature
class Widget : public Creature{
public:
//constructor
Widget();
//new method added as click
void click() const;
private:
//new data member
int clickedDistance;
};
//Created new derived class from Creature
class TextCreature : public Creature{
public:
//constructor
TextCreature();
//new method added as Moved
void moved() const;
private:
//new data member
int byDistance;
};
#endif
----------------------------------------------------------------------------------------------------
Creature.cpp
#include <iostream>
#include "Creature.h"
using namespace std;
//constructor implementation
Widget::Widget() : clickedDistance(5)
{
cout << "\nCreating a Widget.\n";
}
//click method implementation
void Widget::click() const
{
cout << "Clicked " << clickedDistance + distance << " meters\n";
}
//implementation of TextCreature methods including constructor
TextCreature::TextCreature() : byDistance(3)
{
cout <<"\nCreating a text Creature.\n";
}
void TextCreature::moved() const
{
cout << "moved " << byDistance + distance << " meters\n";
}
Creature::Creature(): distance(10)
{}
void Creature::run() const
{
cout << "running " << distance << " meters!\n";
}
Wizard::Wizard() : distFactor(3)
{}
void Wizard::hover() const
{
cout << "hovering " << (distFactor * distance) << " meters!\n";
}
//-------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
testcreature.cpp
//#code for creature.cpp
#include <iostream>
using namespace std;
#include "Creature.h"
int main()
{
cout << "\nCreating an Creature.\n";
Creature c;
c.run();
cout << "\nCreating a Wizard.\n";
Wizard w;
w.run();
w.hover();
//create an object of Widget class
Widget wdg;
//calling base class method
wdg.run();
//calling newly added method
wdg.click();
// //create an object of TextCreature class
TextCreature txt;
//calling base class method
txt.run();
//calling newly added method
txt.moved();
return 0;
}
--------------------------------------------------------------------------------------------------------
SEE OUTPUT

PLEASE COMMENT if there is any concern.
==============================
#code for creature.cpp #include <iostream> using namespace std; class Creature { public: Creature(); void run() const;...
Extend the example program creature.cpp by adding two other type of creatures (i.e., two new classes derived from Creature) with some example properties and methods (use your imagination for doing this). Use/implement at least one property and at least one method for each derived class. Each constructor, destructor and method should be implemented in such a way that each call is being documented via messages printed on the screen. Create one instance of Wizard, two instances of the two other...
#include <iostream> #include <string> #include <stdio.h> using namespace std; /** The FeetInches class holds distances measured in feet and inches. */ class FeetInches { private: int feet; // The number of feet int inches; // The number of inches /** The simplify method adjusts the values in feet and inches to conform to a standard measurement. */ void simplify() { if (inches > 11) { feet = feet + (inches / 12); inches = inches % 12; } } /**...
Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...
Here is the code from the previous three steps:
#include <iostream>
using namespace std;
class Student
{
private:
//class variables
int ID;
string firstName,lastName;
public:
Student(int ID,string firstName,string lastName)
//constructor
{
this->ID=ID;
this->firstName=firstName;
this->lastName=lastName;
}
int getID() //getter method
{
return ID;
}
virtual string getType() = 0; //pure virtual function
virtual void printInfo() //virtual function to print basic details
of a student
{
cout << "Student type: " << getType() <<
endl;
cout << "Student ID: " << ID...
Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass { public: void print() const; baseClass(string s = " ", int a = 0); //Postcondition: str = s; x = a; protected: int x; private: string str; }; class derivedClass: public baseClass { public: void print() const; derivedClass(string s = "", int a = 0, int b = 0); //Postcondition: str = s; x = a; y = b; private: int y; }; int...
use c++ and complete this lab #include <iostream> using namespace std; class FibObj { public: void setSize() { cout << "Enter an integer larger than 2: "; cin >> size; } int getSize() { return size; } void fibTerms(int x) // Write a recursive function { } explicit FibObj() // Default constructor was made explicit to avoid possible implicit type conversion { setSize(); int *arr; arr = new int[getSize()]; arr[0] = 1; arr[1] = 1; // Call recursive function here...
Given the following code: #include <iostream> #include <iomanip> using namespace std; class Animal{ private: int height; int weight; public: void setHeight(int h){ height = h; } int getHeight(){ return height; } void setWeight(int w){ weight = w; } int getWeight(){ return weight; } virtual void makeSound() = 0; virtual void eat(); }; class Dog: public Animal{ public: void makeSound(){ cout << "Bow Bow\n"; } void eat (){ cout <<"The dog is eating\n"; } void Catch(){ cout << "The dog is...
#ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: // default constructor procReqRec() {} // constructor procReqRec(const string& nm, int p); // access functions int getPriority(); string getName(); // update functions void setPriority(int p); void setName(const string& nm); // for maintenance of a minimum priority queue friend bool operator< (const procReqRec& left, const procReqRec& right); // output a process request record in the format // name: priority friend ostream& operator<< (ostream& ostr, const procReqRec&...
#include <iostream>
#include <queue>
using namespace std;
class Graph {
public:
Graph(int n);
~Graph();
void addEdge(int src, int tar);
void BFTraversal();
void DFTraversal();
void printVertices();
void printEdges();
private:
int vertexCount;
int edgeCount;
bool** adjMat;
void BFS(int n, bool marked[]);
void DFS(int n, bool marked[]);
};
Graph::Graph(int n=0) {
vertexCount = n;
edgeCount = 0;
if(n == 0)
adjMat = 0;
else {
adjMat = new bool* [n];
for(int i=0; i < n; i++)
adjMat[i] = new bool [n];
for(int i=0;...
C++ comment code Comment the following code #include <iostream> using namespace std; class Node { public: Node(int val); int value; Node* next; }; Node::Node(int val){ value = val; } class List { public: List(); // Uncomment the line below once you're ready List(List &other); void push_front(int value); bool pop_front(int &value); void push_back(int value); bool pop_back(int &value); int at(int index); void insert_at(int index, int value); void remove_at(int index); int size(); private: // other members you may have used Node* head; Node*...