Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi! I need help with a C++ assignment The next 10 questions are based upon the f

ID: 666280 • Letter: H

Question

Hi! I need help with a C++ assignment

The next 10 questions are based upon the following material:

//Animal.h

#include <string>
using namespace std;

class Animal
{
public:
   string favoriteFood;

   Animal();
   Animal(string n, double w, string ff);

   void setName(string n);
   void setWeight(int w);
   string getName();
   double getWeight();

private:
   string name;
   double weight;
   void incrementWeight(double inc);
};

//Animal.cpp

#include <string>
using namespace std;
#include "Animal.h"

Animal::Animal()
{
   name = "unknown_name";
   weight = 0.0;
   favoriteFood = "unknown_food";
}

Animal::Animal(string n, double w, string ff)
{
   name = n;
   weight = w;
   favoriteFood = ff;
}

void Animal::setName(string n)
{
   name = n;
}
void Animal::setWeight(int w)
{
   weight = w;
}
string Animal::getName()
{
   return name;
}
double Animal::getWeight()
{
   return weight;
}

void Animal::incrementWeight(double inc)
{
   weight += inc;
}

The questions are:

1. Which line number from Animal.h above is necessary for the following line of code: Animal animal1;

2.Which line number from Animal.h above is necessary for the following line of code:

3.Which line number from Animal.h above is necessary for the following line of code:

4.Which line number from Animal.h above is necessary for the following line of code:Animal animal1();

5. Consider the following small piece of code:

6.Which line number from Animal.h above is necessary for the following line of code: Animal animal1('spike', 20, 'grub');

7.Will the following compile:

8.Will the following compile:

9.Will the following compile:

10.Will the following compile:

PLEASE HELP! THANK YOU

Explanation / Answer

1.
Animal();
(default constructor is being called)

2.
Animal(string n, double w, string ff);
(constructor with string, double, string parameter is being called)

3.
None
(There is no constructor accepting parameters string, double)

4.
None
This line actually declares a method named animal1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote