This is C++;

You will need to create a project to successfully compile all three files (or compile them from the
command line as specified on the slides).
a) Comment out the using namespace std; and then take your time, read and interpret
the error messages.
b) Also remove the Critter:: prefix in one of the methods in Critter.cpp, read and interpret
the error message.
Then create a file called explanations.txt. This file should be uploaded together with the
other files and should contain your descriptions and interpretations of the errors as well as your
comments on potential alternative solutions.
You can assume that the input will be valid.

These are the following files:

First 1;
#include <string> // defines standard C++ string class

/* First C++ class */
class Critter
private: // data members are private
std::string name;
int hunger;
int boredom;
double height;

public: // business logic methods are public
// setter methods
void setName(std::string& newname);
void setHunger(int newhunger);
void setBoredom(int newboredom);
// getter method
int getHunger();
// service method
void print();

Second 2;
#include <iostream>
#include "Critter.h"

using namespace std;

void Critter::setName(string& newname) {
name = newname;

void Critter::setHunger(int newhunger) {
hunger = newhunger;

void Critter::print() {
cout << "I am " << name << ". My hunger level is " << hunger << "." << endl;

int Critter::getHunger() {
return hunger;

Third 3;
#include <iostream>
#include <cstdlib>
#include "Critter.h"

using namespace std;

int main(int argc, char** argv)
Critter c;

string name;
int hunger;

cout << endl << "Please enter data: " << endl;
cout << "Name: ";
// cin >> name; will not work if name contains
// spaces
getline(cin, name);
cout << "Hunger: ";
cin >> hunger;

cout << "You have created:" << endl;
return 0;

Public Answer

ZZR7ZB The First Answerer