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

Hello! I have a few short questions on C++! Thanks for helping out! 1. The next

ID: 666363 • Letter: H

Question

Hello! I have a few short questions on C++! Thanks for helping out!

1. The next 4 questions are based upon the following material:

struct nameType
{
   string first;
   string last;
};

struct courseType
{
   string courseName;
   int callNum;
   int credits;
   char grade;
};

struct studentType
{
   nameType name;
   double gpa;
   courseType course;
};

//**********************************************
//Variables defined using the above defined structs

studentType student;
studentType classList[100];
courseType course;
nameType name;

//************************************************

i)The following is a valid C++ statement: student.course.callNum = 123; true or false?

ii) The following is a valid C++ statement:cin >> student.name; true or false?

iii)The following is a valid C++ statement: classList[0] = name; true or false?

iv) The following is a valid C++ program segment:

true or false?

2.

The next 6 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;
}

i) Consider the following small piece of code:

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

iii) Will the following compile:

iv) Will the following compile:

v) Will the following compile:

vi) Will the following compile:

3. An identifier can use letters, digits or underscores but it must not start with a digit. true or false?

4.The statement: getline(cin,text); reads one complete line of input into the string variable text. true or false?

5.Given the statement: int list[25]; The index can go from 0 to 25 inclusive without going beyond the end of the array. true or false?

6.Given the declaration : int list[50];the statement: cout<<list<<endl; outputs all 50 components of the array list on one line. true or false?

7. Given the following declarations and initializations:

a. y[SIZE] = 42.0; b. x[0] = 14.0; c. x = y; d. cin >> y >> z; e. x[8-i] = y[i] + z;

8.Given the function prototype: int testBeta(int x, char v, int y); the following statement in the main program is legal. cout<<testBeta(5, char 'A', int 2); true or false?

THANK YOU SO MUCH FOR THE HELP!

Explanation / Answer

i)The following is a valid C++ statement: student.course.callNum = 123; true or false? FALSE
ii) The following is a valid C++ statement:cin >> student.name; true or false? TRUE
iii)The following is a valid C++ statement: classList[0] = name; true or false? TRUE
iv) The following is a valid C++ program segment:
for (int j=0; j < 100; j++)
classList[j].name = name;

true or false? . TRUE

2.Output will be berries fred 13.4

ii. Line 8 Animal(string n, double w, string ff); is necessary

iii. No it will not compile because incrementWeight is private member

iv it will compile

v.it will not compile

vi it will complie

3.TRUE
4.TRUE
5.FALSE

6.FALSE

7.b. x[0] = 14.0

8.true


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