Write a line of code for the declaration of getgpa from


Assignment

QUESTION 1

What is the difference between overloading an inherited function and redefining an inherited function?

QUESTION 2

What is the difference between static and late binding of a function definition and how does this relate to redefining and overriding functions?

QUESTION 3

In what ways are constructors and destructors of a base class accessible to the child class? (They aren't inherited exactly, but...)

QUESTION 4

Where / how can the public members of a base class be invoked by a child class?
What about the protected members?
What about the private members?

QUESTION 5

Suppose that the class Parent and its derived class Child have the following member function definitions:

int Child::getValue(){
return 5;
}
int Parent::getValue(){
return 7;
}
int Parent::getDoubleValue(){
returngetValue()*2;
}

Assuming that getValue is not a virtual function, what will be output by the following code snippet in the main function (assuming everything else is written / libraries are included properly)?
Child myChild;
Parent myParent;

std::cout << myParent.getValue() <std::cout << myParent.getDoubleValue() <std::cout << myChild.getValue() <std::cout << myChild.getDoubleValue() <

QUESTION 6

True or False: Two children of the same base class will share the members they define for themselves in addition to the members defined by the base class.
True
False

QUESTION 7

True or False: If C inherits from B and B inherits from A (C is a grandchild of A and a child of B), then by default C has the same access to the A's members that B does .
True
False

QUESTION 8

Write the complete interface file (Student.h) for a Student class which inherits from the Person class defined bellow. The Student class should have private data for qualityPoints (double) and numCredits (int). It should have an accessor getQP which returns the qualityPoints and an accessor getCreds which returns the numCredits. It should have an also have an accessor getGPA which computes the gpa using the private qualityPoints and numCredits and returns this value as a double. None of these accessors should need any parameters. Use const as appropriate to prevent modification of the calling object when calling an accessor function (see getName in the Person class for example). Finally, you should have a default constructor and a constructor which takes arguments for all of the private data of the class object (name, qualityPoints, and numCredits).

Assume that the Person class's interface file is stored locally under the file name Person.h
#ifndef PERSON_H
#define PERSON_H
#include
class Person{
public:
Person();
Person(std::string theName);
std::string getName() const;
std::string setName();

private:
std::string name;
};

#endif

QUESTION 9

Write the definitions of the two Student constructors from Question 8. They should invoke the necessary constructors from the base class.

QUESTION 10

1) Write a line of code for the declaration of getGPA from question 8 to make it a virtual function. (Remember to prevent the calling object from being modified, since this is an accessor).

2) Write a line of code for the declaration of getGPA from question 8 modified to be a pure virtual function. (Remember to prevent the calling object from being modified, since this is an accessor).

QUESTION 11

1) What is the purpose of an abstract class.
2) What makes a class "abstract?"
3) What prevents a derived class of an abstract class from also being abstract?

QUESTION 12

Consider the definitions of Person and Student from question 8. Suppose we have the following code:
Student myStudent("Matt", 5, 7);

Person myPerson = myStudent;

This causes what is called the "slicing problem." Exactly what is the problem? (Describe the potential semantic error caused by this code).

QUESTION 13

Consider the code from Question 5. Assuming that getValue is virtual function, what will now be output by the code snippets in question 5?

QUESTION 14

Assume that HighSchoolStudent inherits from the Student class from question 8 and that the Student class has a pure virtual function definition for getGPA.

Write a declaration statement for getGPA in the HighSchoolStudent class which will override the definition from Student and prevent derived classes of HighSchoolStudent from further overriding the definition of getGPA.

QUESTION 15

Write a definition for the getGPA function for the HighSchoolStudent class. It should return the value of qualityPoints / numCredits if that value is positive and does not exceed 5; otherwise getGPA should return -1.0.

Note: qualityPoints and numCredits should have both been defined as private data within the Student class.

QUESTION 16

Consider the following proposed functions of a 2DShape class. We have four options for each one: A) make it a normal function, B) make it a virtual function, C) make it a pure virtual function, D) don't include it at all.

Choose one of these four options for each proposed functions and explain why that is the proper choice.

1) getArea()
2) getRadius()
3) getColor()

QUESTION 17

Tough Question: Suppose you want to define a function in a base class (it's not inheriting from anyone) and you want to prevent anyone from redefining it. How could you accomplish that?

QUESTION 18

Write a template function definition for a function named swap. It will take two generic objects of the same type and swap them using the = operator. The end result is that the data stored in val1 will be stored in val2 and vice-versa (as per their type's definition of the = operator).
[Blackboard Note: If you put a space after the < character blackboard wont make it vanish when you try to type it in here.]

QUESTION 19

Write a class template definition (just the definition, no implementation) for BTNode.

It should have private data for each of the following:

1) one variable for storing a data object of the generic type
2) a pointer to a parent of type BTNode
3) a pointer to a leftChild of type BTNode
4) a pointer to a rightChild of type BTNode

It should have a default constructor.
It should have a constructor which takes arguments for each of the four private members.
It should have an accessor method getData which return the data of the generic type.

[Note: On exam 2 I am planning to avoid asking pointer-based questions, but this made for a more natural example here. This might make a good final exam question as-is, though.]

QUESTION 20

Modify this code (you do not need to add the commented out part) so that specialBTNode is derived from the class template BTNode defined in Question 19.

classspecialBTNode{
/* you don't need to add this part of the code */
};

QUESTION 21

Why is the concept of a "deck" a good example application of a class template?

QUESTION 22

Write a definition for the getData member function declared in the BTNode class definition from question 19. It should return the genericly typed private data value.

QUESTION 23

Other than Overwatch, because he is already thinking about getting that, which PC game would you like Dr. Spradling to get if it is on sale for black friday / cyber monday? [If you don't care or don't have any requests that's fine, but answer "don't care" or something rather than skipping the question or else I wont be able to give credit for skipping it!].

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Write a line of code for the declaration of getgpa from
Reference No:- TGS02529869

Expected delivery within 24 Hours