Write a line of code for the declaration of getgpa

Assignment Help Programming Languages
Reference no: EM131734354

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::endl;
std::cout << myParent.getDoubleValue() <<std::endl ;
std::cout << myChild.getValue() <<std::endl ;
std::cout << myChild.getDoubleValue() <<std::endl ;

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 <string>
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!].

Reference no: EM131734354

Questions Cloud

What is the npv of an investment in the property : Consider the building described in Question. Suppose everything is the same except that, since the time the current lease was signed, the market for office.
How serious is the public debt situation in the usa : If we paid off the debt would that solve most of our other economic problems, such as unemployment?
Proposals in response to rfps : Iron Butterfly Company submits proposals in response to RFPs and faces three possible outcomes: N1, Iron Butterfl y gets a full contract
Example of anaphora in a speech : Give an example of anaphora in a speech, then an example of epistrophe. You do not need to use existing speeches
Write a line of code for the declaration of getgpa : Write a line of code for the declaration of getGPA from question 8 to make it a virtual function. What about the protected members?
Define leadership style and the health of the organization : An analysis of the relationship between your chosen leader's leadership style and the health of the organization
Bureau of labor statistics inflation calculator : However, since the Great Recession and the bursting of the housing bubble in 2007, many families consider owning a home a risky investment.
What is the expected property before-tax cash flow forecast : You are a financial analyst constructing a multiyear proforma to value a potential property acquisition. As part of the analysis, you are considering.
The levels that would meet the iucn vulnerability criteria : deplete any dependent predator population to levels that would meet the IUCN vulnerability criteria

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd