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

QUESTION 11 In C++, you can pass a variable by reference and still prevent the f

ID: 3857954 • Letter: Q

Question

QUESTION 11

In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the formal parameter declaration.

automatic

private

static

const

1 points   

QUESTION 12

The word ____ at the end of several the member functions in the accompanying figure class clockType specifies that these functions cannot modify the member variables of a clockType object.

static

automatic

private

const

1 points   

QUESTION 13

class rectangleType
{
public:
void setLengthWidth(double x, double y);
//Postcondition: length = x; width = y;
void print() const;
//Output length and width;
double area();
//Calculate and return the area of the rectangle;
double perimeter();
//Calculate and return the parameter;
rectangleType();
//Postcondition: length = 0; width = 0;
rectangleType(double x, double y);
//Postcondition: length = x; width = y;

private:

  double length;
  double width;
};

Consider the accompanying class definition. Which of the following variable declarations is correct?

rectangle rectangleType;

class rectangleType rectangle;

rectangleType rectangle;

rectangle rectangleType.area;

1 points   

QUESTION 14

If a function of a class is static, it is declared in the class definition using the keyword static in its ____.

return type

parameters

heading

main function

1 points   

QUESTION 15

In C++, the scope resolution operator is ____.

:

::

.

$

a.

automatic

b.

private

c.

static

d.

const

Explanation / Answer

NOTE:

* In c++ const is a keyword used to specify given identifier is a constant i.e it's value cannot be changed.

* like in mathematics =>

x is a variable hence it can take any value, but

10, 99, 100 etc have their value fixed and their value cannot be changed ex 10 remain 10 , i.e whenever we see a value like this then we know it's exact value and is constant.

to apply the same effect in C++ programming we have the keyword "const".

const is also used to specify a variable value cannot be changed.

example => const int x = 10;

now above value of x cannot be modified.

* if the keyword const used in function definition then it give the user an assurance that it not going to change any value passed to it.

ANSWER 11

(d) const

if you are passing a parameter which is constant then its function must not be changed

example void function (const int &x);

in above function if function would try to change the value to which x refering then compiler will throw an error.

ANSWER 12

const

whenever const keyword used in function definition then it gives user assuarence that it's not going to change any member variable. hence answer is "const"

ANSWER 13

(c) rectangleType rectangle; is correct answer

this is the prototype to declare a variable of any type in C++ for example

if we want to declare a variable of type (or class) int then we do it like

int xyz;

similarly to declare a variable of type rectangleType we have to follow the standard, and standard is

rectangleType rectangle;

NOTE

rectangleType is a user defined data type and int , float etc are predefined data type

C++ gives us flexibility to define our own data type in the form of class or struct

ANSWER 14

(c) heading is correct

example

static int getvalue(){ //Here static tells the compiler that getvalue is a static function and it is declared in in the //function definition header

return 10;

}

ANSWER 15

(b) :: is correct answer

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