- •What variable is?
- •When it is not known in advance how many times a set of statements will be repeated, a(n)_________value can be used to terminate the repetition
- •What is the difference between a local variable and a data member?
- •When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
- •In one statement, assign the sum of the current value of X and y to z and postincrement the value of X
- •Function ________ is used to produce random numbers
- •Function ________ is used to set the random number seed to randomize a program
- •For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
- •Find the error in the following program segment and correct the error: #include ;
- •Find the error(s) in the following and correct it (them). Assume the following prototype is declared in class Employee: int Employee( const char *, const char * );
- •Iostream.H
- •Int c, thisIsAVariable, q76354, number;
- •If…else
- •Infinite loop, z must be decremented so that it eventually becomes less than 0.
- •Int smallest( int X, int y, int z)
- •Void instructions( void )
- •Int g( void)
- •Int h( void ) {
- •Void f ( double a)
- •Void product( void )
- •Int result;
- •Int table[ arraySize ][ arraySize];
- •0, Null, an address
- •Void exchange( double *X, double *y )
- •Int evaluate( int X, int (*poly)( int ))
- •Int hour;
- •Int minute;
- •Int second;
- •Initialized
- •Is not allowed to access any non-static member of the class.
- •Istream
- •What variable is?
- •When it is not known in advance how many times a set of statements will be repeated, a(n)_________value can be used to terminate the repetition
- •What is the difference between a local variable and a data member?
- •When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
- •In one statement, assign the sum of the current value of X and y to z and postincrement the value of X
- •Function ________ is used to produce random numbers
- •Function ________ is used to set the random number seed to randomize a program
- •For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
- •Find the error in the following program segment and correct the error: #include ;
- •Find the error(s) in the following and correct it (them). Assume the following prototype is declared in class Employee: int Employee( const char *, const char * );
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
A (n) __________is a collection of related variables under one name.
Structure
A capability of objects as members of classes is called ___________
Composition
A class definition is typically stored in a file with the _________ filename extension.
.h
A constructor that accepts __________ parameters is called the default constructor
no
A function of a class is defined outside that class's scope, yet has the right to access the non-public (and public) members of the class. Stand-alone functions or entire classes may be declared to be friends of another class.
Friend
A function with the same name as the class, but preceded with a tilde character (~) is called __________ of that class.
Destructor
A function ________ enables a single function to be defined to perform a task on many different data types.
Template
A nonmember function must be declared as a( n ) __________ of a class to have access to that class's private data members.
Friend
A recursive function typically has two components: One that provides a means for the recursion to terminate by testing for a(n) ________ case and one that expresses the problem as a recursive call for a slightly simpler problem than the original call.
Base
A sequence of calls to ______ breaks a string into tokens that are separated by characters contained in a second string argument. The first call specifies the string to be tokenized as the first argument, and subsequent calls to continue tokenizing the same string specify NULL as the first argument. The function returns a pointer to the current token from each call. If there are no more tokens when _____ is called, NULL is returned.
Strtok
By default how the value are passed in c++?
Call by value
By default, all the elements of an integer ________ object are set to 0.
Vector
C++ provides ________ functions to help reduce function call overhead especially for small functions. Placing the qualifier ________ before a function's return type in the function definition "advises" the compiler to generate a copy of the function's code in place to avoid a function call.
Inline
Class members are accessed via the ________ operator in conjunction with the name of an object (or reference to an object) of the class or via the ___________ operator in conjunction with a pointer to an object of the class.
(Dot), -> (arrow)
Class members specified as _________ are accessible anywhere an object of the class is in scope.
Public
Class members specified as _________ are accessible only to member functions of the class and friends of the class.
Private
Which of the statement(s) below is (are) true regard to comments?
Comments are needed to document program.
Comments improve program readability.
Composition is sometimes referred to as a _______________.
Has-a relationship
Constructor is executed when _____.
An object is created
Constructors __________ to allow different approaches of object construction
Can be overloaded
Destructor has the same name as the constructor and it is preceded by ______
~
What does escape sequence \" do?
Used to print a double quote character
What does escape sequence \a do?
Sound the system bell
What does escape sequence \n do?
Position the screen cursor to the beginning of the next line
What does escape sequence \r do?
Position the screen cursor to the beginning of the current line; do not advance to the next line.
What does escape sequence \t do?
Move the screen cursor to the next tab stop
Every class definition contains keyword _________ followed immediately by the class's name.
Class
Find the error(s) in the following class and explain how to correct them:
class Example
{
public:
int y = 10
data( y )
{
// empty body
}
// end Example constructor
int getIncrementedData() const
{
return data++;
}
// end function getIncrementedData
private:
int data;
static int count;
};
// end class Example
Line 12 the function is declared const, but it modifies the object
Find the error(s) in the following portion of code. Assume the following prototype is declared in class Time:
Void ~Time (int);
Destructors are not allowed to return values (or even specify a return type) or take arguments.
For automatic objects, constructors and destructors are called each time the objects
was created and deleted
Function prototype contains
Function name
Parameters (number and data type)
Return type (void if returns nothing)
Only needed if function definition after function call
Function ______ appends its second string argument including the terminating null character to its first string argument. The first character of the second string replaces the null ('\0') character of the first string. The programmer must ensure that the target array used to store the first string is large enough to store both the first string and the second string.
strcat
Function _________ compares its first string argument with its second string argument character by character. The function returns zero if the strings are equal, a negative value if the first string is less than the second string and a positive value if the first string is greater than the second string.
strcmp
Function ______ copies its second argument a string into its first argument a character array. The programmer must ensure that the target array is large enough to store the string and its terminating null character.
strcpy
Function ________ is used to produce random numbers.
rand
Function ________ is used to set the random number seed to randomize a program.
srand
Function _________ from the <string> library reads characters until a newline character is encountered, then copies those characters into the specified string.
getline
Function ___________ finds the first occurrence of any character from a string.
find_first_of
How do you include a system header file called mylib.h in a C++ source file?
#include < mylib.h >
How do you include a user-defined header file called mylib.h in a C++ source file?
#include "mylib.h"
How is enum used to define the values of the American coins listed above?
penny = one
nickel = five
dime = ten
quarter = twenty-five
enum coin {penny=1,nickel=5,dime=10,quarter=25};
How many elements are in array by the definition above?
char text[20] = "Hello World!";
13
How many times the program will print "Midterm"?
int main()
{
cout << "Midterm\n";
main();
return 0;
}
Till stack overflows
How many ways of passing a parameter are there in c++?
3
How would you round off a value from 1.66 to 2.0?
ceil(1.66)
If the programmer does not explicitly provide a destructor, then which of the following creates an empty destructor?
Compiler
If the size of integer is 4bytes, what will be the output of the program?
#include<iostream>
using namespace std;
int main() {
int arr[] = {12, 13, 14, 15, 16};
cout<<sizeof(arr)<<' '<<sizeof(*arr)<<' '<<sizeof(arr[0]);
return 0;
}
20 4 4
If the two strings are identical, then strcmp() function returns 0
In terms of code generation, how do the two definitions of buf, both presented above, differ? char buf [] = "Hello world!";
char buf[] = {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\0'};
They do not differ - they are functionally equivalent.
int a [8] = { 0, 1, 2, 3 }; The definition of a above explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?
The remaining elements are initialized to zero(0)
A ____________ is a word in code that is reserved by C++ for a specific use.{
keyword
Keywords public, private and protected are _________.
access specifiers
Keyword__________introduces a structure declaration.
struct
Member function ______ of class template vector returns the number of elements in the vector on which it is invoked.
size
Placing a new value into a memory location is said to be ________
destructive
Point out the error in the following program
#include < iostream >
using namespace std;
int main()
{
display();
return 0;
}
void display()
{
cout << "Hi, there!\n";
}
display() is called before it is defined
Which of the statement(s) below is (are) true regard to preprocessor directive?
Begins with (#) hash sign
Processed before the program compiled
Preprocessor directives (like #include) do not end with a semicolon
I, II and III
Reading variables from memory is known as _________.
nondestructive
Suppose a and b are integer variables and we form the sum a + b. Now suppose c and d are floating-point variables and we form the sum c + d. The two + operators here are clearly being used for different purposes. This is an example of __________.
operating overloading
The elements of an array are related by the fact that they have the same ________ and ___________.
name, type
The function pointer point to which of the following?
function
The keyword used to transfer control from a function back to the calling function is
return
The number used to refer to a particular element of an array is called its ________. subscript (or index)
The only integer that can be assigned directly to a pointer is_____________.
0
The operator used for dereferencing or indirection is ____
*
The portion of a function prototype that includes the name of the function and the types of its arguments is called the function ____________
signature
The ________ enables access to a global variable with the same name as a variable in the current scope.
::
The ________ qualifier is used to declare read-only variables.
const
The __________ operator reclaims memory previously allocated by new.
delete
The ____________ compares each element of an array with a search key.
Linear search
There is an error in the below program. Which statement will you add to remove it?
#include <iostream>
using namespace std;
int main()
{
int a;
a = func(10, 3.14);
cout<< a;
return 0;
}
float func(int aa, float bb)
{
return ((float)aa + bb);
}
Add prototype: float func(int, float)
What Are Strings?
are a sequence of characters.
What can a pointer store?
All of the statements
What does the following statement mean?
int (*fp)(char*)
pointer to function taking a char* argument and returns an int
What does the unary scope resolution operator ( :: ) do?
Access global variable if local variable has same name
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
Compile-time error
What is a difference between a declaration and a definition of a variable?
A declaration occurs once, but a definition may occur many times
What is a function template?
creating a function without having to specify the exact type
What is argument coercion?
Force arguments to be of proper type
What is meaning of following declaration? int(*ptr[5])();
ptr is array of pointer to function
What is Pseudocode?
an artificial and informal language that helps programmers develop algorithms without having to worry about the strict details of C++ language syntax.
What is the output of the code below?
double mark = 6.0;
if(mark >= 6.5)
std::cout<<"excellent ";
if(mark >= 4.0)
std::cout<<"good ";
if(mark >= 3.0)
std::cout<<"satisfactory ";
else
std::cout<<"unsatisfactory ";
good satisfactory
What is the output of the code below?
#include <iostream>
using namespace std;
int main()
{
char *a = NULL;
char *b = 0;
if(a)
cout<<"a\n";
else
cout<<"Not a\n";
if(b)
cout<<"b\n";
else
cout<<"Not b\n";
return 0;
}
Not a
Not b
What is the output of the program
int a[5] = {2, 3};
cout<< a[2] << " " << a[3] << " " << a[4];
0 0 0
What is the output of the program given below ?
enum status { pass, fail, excellent};
status stud1, stud2, stud3;
stud1 = pass;
stud2 = excellent;
stud3 = fail;
cout << stud1 << " " << stud2 << " " << stud3;
0 2 1
What is the output of this program?
#include <iostream>
using namespace std;
max (int a, int b)
{
return (a > b ? a : b);
}
int main()
{
int I = 5;
int j = 7;
cout << max(i, j);
return 0;
}
7
What is the output of this program?
# include <iostream>
using namespace std;
int mult (int x, int y)
{
int result;
result = 0;
while(y !=0)
{
result = result + x;
y = y - 1;
}
return(result);
}
int main (){
int x = 5, y = 5;
cout<< mult (x, y);
return 0;
}
25
What is the output of this program?
#include <iostream>
using namespace std;
int gcd (int a, int b)
{
int temp;
while(b !=0){
temp = a % b;
a = b;
b = temp;
}
return (a);
}
int main () {
int x = 15, y = 25;
cout << gcd (x, y);
return 0;
}
5
What is the output of this program?
# include <iostream>
using namespace std;
void func (int a, bool flag = true)
{
if (flag == true)
{
cout << "Flag is true. a = “ << a;
}
else{
cout << "Flag is false. a \= "<< a;
}
}
int main(){
func(200,false);
return 0;
}
Flag is false. a = 200
What is the output of this program?
#include <iostream>;
using namespace std;
void Values(int n1, int n2 = 10)
{
using namespace std;
cout << "1st value\: " << n1;
cout << "2nd value\: " << n2;
}
int main() {
Values(1);
cout << endl;
Values (3, 4);
return 0;
}
1st value: 1
2nd value: 10
1st value: 3
2nd value: 4
What is the output of this program?
#include <iostream>
using namespace std;
int func(int m, int n)
{
int c;
c = m + n;
return c;
}
int main(){
cout << func(5);
return 0;
}
Compilation error
What is the output of this program?
#include <iostream>;
using namespace std;
void func(int x) {
cout << x;
}
int main(){
void(*n)(int);
n =&;
func(*n)(2);
n(2);
return 0;
}
22
What is the output of this program?
#include <iostream>
using namespace std;
template <class type>;
type Max(type Var1, type Var2){
return Var1>;
Var2 ? Var1:Var2;
}
int main()
{
int p;
p = Max(100,200);
cout << p << endl;
return 0;
}
200
What is the output of this program?
#include <iostream>
using namespace std;
template <class T>
inline T square(T x)
{
T result;
result = x * x;
return result;
};
int main()
{
int i, ii;
float x, xx;
double y, yy;
i = 2;
x = 2.2;
y = 2.2;
ii = square(i);
cout << i << "" << ii << endl;
yy = square(y);
cout << y << "" << yy << endl;
}
2 4
2.2 4.84
What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector <int> a (3, 0);
vector<int> b (5, 0);
b = a;
a = vector<int>();
cout <<"Size of a " << int(a.size()) <<'\n';
cout << "Size of b "<<int(b.size())<<'\n';
return 0;
}
Size of a 0
Size of b 3
What is the output of this program?
#include <iostream>
using namespace std;
int main(){
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout << arr[1];
return 0;
}
it will return memory address of integer b
What is the output of this program?
#include <iostream>
using namespace std;
int main(){
char arr[20];
int i;
for(i = 0; i < 10; i++)
*(arr + i) = 65 + i;
*(arr + i) = '\0';
cout << arr;
return(0);
}
ABCDEFGHIJ
What is the output of this program?
#include <iostream>
using namespace std;
int main(){
char *ptr;
char Str[] = "abcdefg";
ptr = Str;
ptr += 5;
cout << ptr;
return 0;
}
fg
What is the output of this program?
#include <iostream>
using namespace std;
void fun(int x, int y){
x = 20;
y = 10;
}
int main(){
int x = 10;
fun(x, x);
cout << x;
return 0;}
10
What is the output of this program?
#include <iostream>
using namespace std;
void copy (int &a, int &b, int &c){
a *= 2;
b *= 2;
c *= 2;
}
int main (){
int x =1, y=3, z = 7;
copy (x, y, z);
cout <<"x =" << x <<", y =" << y << ", z \=" << z;
return 0;
}
x =2, y =6, z =14
What is the output of this program?
#include <iostream>
using namespace std;
void square (int *x){
*x =(*x +1)*(*x);
}
int main(){
int num = 10;
square(&num);
cout << num;
return 0;
}
110
tion: 0 name: Switch category to $course$/По умолчанию для курс1 ( )/Chapter 6
What is the output of this program?
#include <iostream>
using namespace std;
int add(int a, int b);
int main(){
int i = 5, j = 6;
cout << add(i, j) << endl;
return 0;
}
int add(int a, int b){
int sum = a + b;
a = 7;
return a + b;
}
13
What is the output of this program?
#include <iostream>
using namespace std;
void Sum(int a, int b, int &c){
a = b + c;
b = a + c;
c = a + b;
}
int main(){
int x = 2, y = 3;
Sum(x, y, y);
cout << x <<" " << y;
return 0;
}
2 15
What is the output?(strlen)
cout << strlen("Quiz#3");
6
What is the output?(typedef)
#include <iostream>
using namespace std;
int main(){
typedef int arr[5];
arr iarr = {1, 2, 3, 4, 5};
int i;
for(i=0; i<4; i++)
cout << iarr[i] << ' ';
return 0;
}
1 2 3 4
What is the size of an array according to the code above?
int arr[] ={0, 4, 2, 6, 9, 0};
6
What is the value of myArray[1][0]; in the sample code above?
int i,j;
int counter = 0;
int arr[2][3];
for (i=0; i<3; i++) {
for (j=0; j<2; j++) {
arr[j][i] = counter;
++counter;
}
}
1
What is the value of myArray[1][1]; in the sample code above?
int i,j;
int counter = 0;
int arr[2][3];
for (i=0; i<3; i++) {
for (j=0; j<2; j++){
arr[j][i] = counter;
++counter;
}
}
3
What is the value of myArray[1][2]; in the sample code above?
int i,j;
int counter = 0;
int arr[2][3];
for (i=0; i<3; i++) {
for (j=0; j<2; j++){
arr[j][i] = counter;
++counter;
}
}
5
What number will z in the sample code below contain?
int z,x=5,y=-10,a=4,b=2;
z = x - y * b / a;
10
What value does testarray[2][1][0] in the sample code above contain?
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
11
What value will x contain when the sample code below is executed?
int x = 3;
if( x == 2 )
x = 0;
if( x == 3 )
x++;
else
x += 2;
2
What will be output when the code above executes?[Madam]
char str[] = "drama";
cout<< str[3]<< str[2]<< str[0]<< str[4]<< str[3];
madam
What will be printed when the sample code above is executed?
char *buffer = "0123456789";
char *ptr = buffer;
ptr += 5;
cout << ptr << ' ';
cout << buffer;
56789 0123456789
What will be printed when the sample code above is executed?
int x = 0;
for ( ; ; )
//infinite loop
{
if (x++ == 4)
break;
continue;
}
cout<< x;
5
What will be the output of the code below if we inputted 'm' when program run?
#include <iostream>
using namespace std;
int main(){
char m;
cin >> m;
switch(m){
case 'm':
cout << "Male\n";
case 'f':
cout << "Female\n";
}
return 0;
}
Male
Female
What will be the output of the code below:
int x=0,y=0;
cout << x-- <<' ' << x <<' ' << y--;
0 -1 0
What will be the output of the code below:
int x=2;
cout << x-- <<' ' << x <<' ' << ++x;
2 1 2
What will be the output of the code below:
int x=2,y=2;
cout << x+y;
cout << x;
cout << ++x + ++y + 1; 427
What will be the output of the code below:
int x=2,y=2;
cout << ++y;
cout << x+y;
cout << ++x + ++y;
357
What will be the output of the code below:
int x=2,y=2;
cout << ++y;
cout << x/y;
cout << ++x + ++y;
307
What will be the output of the code below? (For st.)
for(int i=1; I < 20; i+=4)
cout << i << ' ';
1 5 9 13 17
What will be the output of the code below? (For;)
int n=4;
for(; n <= 20; n+=4);
cout << n;
21
What will be the output of the code fragment?
int x = 10;
int &y = x;
x = 25;
y = 50;
cout << x << " " << --y;
50 49
What will be the output of the following code?
#include <iostream>
#include <string>
using namespace std;
int main(){
string a = "5";
string b = "4";
cout<< a+b;
return 0;
}
54
What will be the output of the following program if we inputted 84 when program run?
int g;
cin >> g;
if(g >=60);
cout << "Passed";
else cout << "Failed";
Compilation error
What will be the output of the following program?
#include <iostream>
using namespace std;
long FactFinder(long = 5);
int main(){
for(int i = 0; i<= 0; i++)
cout << FactFinder() << endl;
return 0;
}
long FactFinder(long x){
if(x < 2)
return 1;
long fact = 1;
for(long i = 1; i <= x-1; i++)
fact = fact * i;
return fact;
}
24
What will be the output of the following program?
#include <iostream>
using namespace std;
double foo(double, double, double = 0, double = 0, double = 0);
int main(){
double d = 2.3;
cout << foo(d, 7) << " ";
cout << foo(d, 7, 6) << endl;
return 0;
}
double foo(double x, double p, double q, double r, double s){
return p +(q +(r + s * x)* x) * x;
}
7 20.8
What will be the output of the following program?
#include <iostream>
using namespace std;
class Example\{
public:
int x;
};
int main(){
Example *p = new Example();
(*p).x = 15;
cout<< (*p).x << " " << p->x << " " ;
p->x = 30;
cout<< (*p).x << " " << p->x ;
return 0;
}
15 15 30 30
What will be the output of the following program?
#include <iostream>
using namespace std;
class Example{
int count;
public:
void First(void){
count = 10;
}
void Second(int x){
count = count + x;
}
void Display(void){
cout<< count << endl;
}
};
int main(){
Example obj;
obj.First();
obj.Second(5);
obj.Display();
return 0;
}
15
What will be the output of the following program?
#include <iostream>
using namespace std;
class Point{
int x, y;
public:
Point(int xx = 10, int yy = 20){
x = xx;
y = yy;
}
Point operator + (Point param){
Point temp;
temp.x = param.x * this->x;
temp.y = param.y * this->y;
return temp;
}
void Display(void){
cout<< x << " " << y;
}
};
int main(){
Point objP1;
Point objP2(1, 2);
Point objP3 = objP1 + objP2;
objP3.Display();
return 0;
}
10 40
What will be the output of the following program?
#include <iostream>
using namespace std;
class Example{
int x;
public:
Example(short ss){
cout<< "Short" << endl;
}
Example(int xx){
cout<< "Int" << endl;
}
Example(char ch){
cout<< "Char" << endl;
}
~Example(){
cout<< "Final";
}
};
int main(){
Example *ptr = new Example('B');
return 0;
}
Char
What will be the output of the following program?
#include <iostream>
using namespace std;
void MyFunction(int a, int b = 40){
cout<< " a = "<< a << " b = " << b << endl;
}
int main(){
MyFunction(20, 30);
return 0;
}
a = 20 b = 30
What will be the output of the following program?
#include <iostream>
using namespace std;
class Example{
public:
struct Struct{
int x;
float y;
void Function(void){
y = x = (x = 4*4);
y = --y * y;
}
void Display(){
cout<< y << endl;
}
}B;
}I;
int main(){
I.B.Display();
return 0;
}
0
What will be the output of the following program?
#include <iostream>
#include <string>
using namespace std;
class Example{
int val;
public:
void SetValue(char *str1, char *str2){
val = strcmp(str1, str2);
}
void ShowValue(){
cout << val;
}
};
int main(){
Example obj;
obj.SetValue((char*)"Hello ", (char*)"World");
obj.ShowValue();
return 0;
}
-1
What will be the output of the following program?
#include <iostream>
#includet <cstring>
using namespace std;
class Example{
char str[50];
char tmp[50];
public:
Example(char *s){
strcpy(str, s);
}
int Function(){
int i = 0, j = 0;
while(*(str + i)){
if(*(str + i++) == ' ')
*(tmp + j++) = *(str + i);
}
*(tmp + j) = 0;
return strlen(tmp);
}
};
int main(){
char txt[] = "Welcome to A&PL!";
Example obj(txt);
cout<< obj.Function();
return 0;
}
2
What will be the output of the following program?
#include <iostream>
using namespace std;
int main(){
int x = 0;
int &y = x;
y = 5;
while(x <= 5){
cout << y++ << " ";
x++;
}
cout << x;
return 0;
}
5 7
What will be the output of the following program?
#include <iostream>
using namespace std;
int main(){
int arr[] = {1, 2 ,3, 4, 5};
int &zarr = arr;
for(int i = 0; i <= 4; i++){
arr[i] += arr[i];
}
for(i = 0; i <= 4; i++)
cout << zarr[i];
return 0;
}
Compilation error
What will be the output of the following program?
#include <iostream>
using namespace std;
long maybeItsTrue(int x, int y = 5, float z = 5){
return(++x * ++y + (int)++z);
}
int main(){
cout << maybeItsTrue(20, 10);
return 0; } 237
What will be the output of the following program?
#include <iostream>
using namespace std;
int calc(int a, int b = 3, int c = 3){
cout << ++a * ++b * --c ;
return 0;
}
int main(){
cout << calc(5, 0, 0);
return 0;
}
-60
What will be the output of the following program?
#include <iostream>
using namespace std;
int calc(int a, int b = 3, int c = 3){
cout << ++a * ++b * --c ;
return 0;
}
int main(){
calc(5, 0, 0);
return 0;
}
-6
What will be the output of the following program?
#include <iostream>
using namespace std;
void foo(int a, int b = 40){
cout << " a = " << a << " b = " << b << endl;
}
int main(){
foo(20, 30);
return 0;
}
a = 20 b = 30
What will be the output of the program ?
#include <iostream>
using namespace std;
int main(){
char str[] = "peace";
char *s = str;
cout << s++ +3;
return 0;
}
ce
What will be the output of the program ?
#include <iostream>
using namespace std;
int main(){
static char mess[6][30] = {
"Don't walk in front of me...",
"I may not follow;",
"Don't walk behind me...",
"Just walk beside me...",
"And be my friend."
};
cout<< *(mess[2]+9)<< *(*(mess+2)+9);
return 0;
}
kk
What will be the output of the program ?
#include <iostream>
using namespace std;
int main(){
char str1[] = "Hello";
char str2[] = "Hello";
if(str1 == str2) cout<< "Equal\n";
else cout<< "Unequal\n";
return 0;
}
Equal (но пишет что правильный Unequal)
What will be the output of the program ?
#include <iostream>
using namespace std;
struct course{
int courseno;
char coursename[25];
};
int main(){
struct course c[] = {{102, "Java"},{103, "PHP"},{104, ".Net"}
};
cout<< c[1].courseno;
cout<< (*(c+2)).coursename;
return 0;
}
103 .Net
What will be the output of the program ?
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char str1[20] = "Hello",
str2[20] = " World";
cout<< strcpy(str2, strcat(str1, str2));
return 0;
}
Hello World
What will be the output of the program ?
#include <iostream>
using namespace std;
int main(){
cout<< 5+"Good Evening!";
return 0;
}
Evening!
What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?
#include <iostream>
using namespace std;
int main(){
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
cout << a[0]+1 << ' ' << *(a[0]+1) << ' ' << *(*(a+0)+1);
return 0;
}
1006 2 2
What will be the output of the program below?
#include <iostream>
using namespace std;
int main(){
int x = 10, y = 20;
int *ptr = &x;
int &ref = y;
ptr++;
ref++;
cout << x << " " << y;
return 0;
}
=<p>10 21</p>
What will be the output of the program below?
#include <iostream>
using namespace std;
int main(){
int x = 10, y = 20;
int *ptr = &x;
int &ref = y;
*ptr++;
ref++;
cout << x << " " << y;
return 0;
}
10 21
What will be the output of the program below?
#include <iostream>
using namespace std;
int main(){
int x = 10, y = 20;
int *ptr = &x;
int &ref = y;
(*ptr)++;
ref++;
cout << x << " " << y;
return 0;
}
11 21
What will be the output of the program if the size of pointer is 4-bytes?
#include <iostream>
using namespace std;
int main(){
cout << sizeof(NULL) <<"," << sizeof("");
return 0;
}
4, 1
What will be the output of the program?
#include <iostream>
using namespace std;
int main(){
int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};
int *p, *q;
p = &arr[1][1][1];
q = (int*) arr;
cout << *p << ' ' << *q;
return 0;
}
8 10
What will be the output of the program?
#include <iostream>
using namespace std;
int main(){
char *p;
p="hello";
cout << *&*&p;
return 0;
}
hello
What will be the output of the program?
float a=2.7;
cout << (int) a;
2
What will be the output of the program?
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
cout << b << " " << c;
100 200
What will be the output of the program?
int x = 3;
float y = 3.0;
if(x == y)
cout<< "x and y are equal";
else
cout << "x and y are not equal";
x and y are equal
What will be the output of the program?
#include <iostream>
using namespace std;
void fun(int*, int*);
int main(){
int i=5, j=2;
fun(&i, &j);
cout << I << ' ' << j;
return 0;
}
void fun(int *i, int *j){
*i = *i**i;
*j = *j**j;
}
25 4
What will be the output of the program?
#include <iostream>
using namespace std;
int i;
int fun();
int main(){
while(i){
fun();
main();
}
cout << "#3\n";
return 0;
}
int fun(){
cout << "Quiz";
}
#3
What will be the output of the program?
#include <iostream>
using namespace std;
int funX(int);
int main(){
int a, b;
a = funX(123);
b = funX(123);
cout << a << ' ' << b;
return 0;
}
int funX(int n){
int s, d;
if(n!=0){
d = n%10;
n = n/10;
s = d+funX( n );
}
else return 0;
return s;
}
6 6
What will be the output of the program?
#include <iostream>
using namespace std;
int main(){
void fun(char*);
char a[100];
a[0] = 'A';
a[1] = 'B';
a[2] = 'C';
a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a){
a++;
cout << *a;
a++;cout << *a;
}
BC
What will be the output of the sample code above?
int i = 4;
switch (i){
default: ;
case 3:
i += 5;
if ( i == 8){
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
cout<< i;
5
What will be the output?
#include <iostream>
using namespace std;
int fun(int);
int main(){
int i = fun(10);
cout << --i;
return 0;
}
int fun(int i){
return (i++);
}
9
What will be the output?
#include <iostream>
using namespace std;
int check(int);
int main(){
int i=45, c;
c = check(i);
cout << c;
return 0;
}
int check(int ch){
if(ch >= 45)
return 100;
else
return 10;
}
100
What will be the output?
#include <iostream>
using namespace std;
int funY(int(*)());
int main(){
funY(main);
cout << "Hi\n";
return 0;
}
int funY(int (*p)()){
cout << "Hello ";
return 0;
}
Hello Hi
What will be the output?
#include <iostream>
using namespace std;
int fun(int);
int fun(int i){
i++;
return i;
}
int main(){
int i=3;
fun(i);
cout << i;
return 0;
}
3
What will be the output?
#include <iostream>
int fun(int);
int fun(int i){
i++;
return i;
}
int main(){
int i=3;
i = fun(i);
cout << i;
return 0;
} 4
What will be the output?
#include <iostream>
using namespace std;
int fun(int);
int fun(int i){
i++;
return i;
}
int main(){
int i=3;
cout << fun(i);
return 0;
}
4
What will be the output?
#include <iostream>
using namespace std;
int main(){
enum color{red, green, blue};
typedef enum color mycolor;
mycolor m = red;
cout << m;
return 0;
}
0
What will be the output?
#include <iostream>
using namespace std;
int main(){
enum color{red, green, blue};
typedef enum color mycolor;
mycolor m = green;
cout << m;
return 0;
}
1
What will be the output?
#include <iostream>
using namespace std;
long func(int x, int y = 5, float z = 5){
return(++x * ++y + (int)++z);
}
int main(){
cout<< func(20, 10);
return 0;
}
237
What will be the output?
#include <iostream>
using namespace std;
long GetNumber(long int Number){
return --Number;
}
int GetNumber(int Number){
return ++Number;
}
int main(){
int x = 20;
int y = 30;
cout<< GetNumber( x ) << " ";
cout<< GetNumber( y ) ;
return 0;
}
21 31
What will be the output?
#include <iostream>
using namespace std;
int main(){
int m = 2, n = 6;
int &x = m;
int &y = n;
m = x++;
x = m++;
n = y++;
y = n++;
cout<< m << " " << n;
return 0;
}
4 8
What will be the output?
#include <iostream>
using namespace std;
int main(){
char s[] = "Hello\0World\0!\0";
cout<< s;
return 0;
}
Hello
What will be the output?
#include <iostream>
using namespace std;
int a = 10;
int main(){
int a = 5;
cout << (::a++ + ++::a)%a;
return 0;
}
2
What will be the output?(string)
#include <iostream>
using namespace std;
int main(){
char str1[20] = "Hello";
char str2[20] = " World";
cout << strcpy(str2, strcat(str1, str2));
return 0;
}
Hello World
What will be the result of the code fragment:
double number = 12.5;
std::cout << ”The result of is ” << number%5;
Compilation error.
What will be the value of c after the execution of portion of code below:
#include <iostream>
using namespace std;
int main(){
int c=1;
while(c <4){
c *= 2;
c +=2;
}
cout << c;
return 0;
}
4
What will be the value of c after the execution of the following statement: int a,b,c;a=2;b=7;c = (a >b) ? a : b;
7
What will be the value of product after the execution of portion of code below:
#include <iostream>
using namespace std;
int main(){
int product=1, i=0;
while(i < 10){
product *= product * i;
i+=2;
}
cout << product << endl;
return 0;
}
0
What will be the value of product after the execution of portion of code below:
#include <iostream>
using namespace std;
int main(){
int product=5;
int x = 2;
while(x <=25){
x *= 2;
}
product *=(x-8);
return 0;
}
120
What will be the value of x after the execution of the statement below: int x = 7 % 13 + 2 * 2 - 2 / 2;
10
What will be the value of x after the execution of the statement below: int x = 7 + 3 * 5 / 2 – 1;
13
What will be value of x and y after the execution of the code below:int x=10, y=15;x = x++;y = ++y;
10 16
What will happen in this code?
int a = 100, b = 200;
int *p = &a, *q = &b;
p = q;
p now points to b
What will happen when the program above is compiled and executed?
void increment( int i ){
i++;
}
int main(){
int i;
for( i = 0; i < 10; increment( i ) ){
//empty body
}
cout<< i;
return 0;
}
There is no output, because It causes infinite loop
What will happen when we use void in argument passing?
It will not return value to its caller
What will print when the sample code above is executed?
int i = 4;
int x = 6;
double z;
z = x / i;
cout<< z;
1
What will the code above print when executed?
double x = -3.5, y = 3.5;
cout<< ceil( x ) << ":" << ceil( y ) << endl;
cout<< floor( x ) << ":" << floor( y ) << endl;
-3 : 4
-4 : 3
What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
*(*(*(*(a+i)+j)+k)+l)
When a member function is defined outside the class definition, the function header must include the class name and the _________, followed by the function name to "tie" the member function to the class definition.
::
When an argument is passed by value, a copy of the argument's value is made and passed (on the function call stack) to the called function. Changes to the copy do not affect the original variable's value in the caller.
passed by value
When applied to a variable, what does the unary "&" operator yield?
The variable's address
When we mention the prototype of a function?
Declaring
When will we use the function overloading?
same function name but different number of arguments
Where does the allocaters are used?
a) Allocation of memory
b) Deallocation of memory
c) Used for pointers
I and II
Where does the execution of the program starts?
main function
Where the default value of parameter have to be specified?
Function prototype
Which is more effective while calling the functions?
Call by value
Call by reference
Call by reference with pointers
II only
Which is optional in the declaration of vector?
Number of elements
Which is used to keep the call by reference value as complete?
const
Which of the following access specifier is used as a default in a class definition? private
Which of the following access specifies is used in a class definition by default?
Private
Which of the following also known as an instance of a class?
Object
Which of the following can access private data members or member functions of a class?
Any member function of that class.
Which of the following can be overloaded?
Both functions and operators
Which of the following concept of OOP allows compiler to insert arguments in a function call if it is not specified?
Default arguments
Which of the following concepts provides facility of using object of one class inside another class?
Composition
Which of the following function declaration is/are incorrect?
A. int Sum(int a, int b = 2, int c = 3);
B. int Sum(int a = 5, int b);
C. int Sum(int a = 0, int b, int c = 3);
I and II
Which of the following functions are performed by a constructor?
Initialize objects
Which of the following is correct about function overloading?
The types of arguments are different.
The order of argument is different.
The number of argument is same.
I and II
Which of the following is illegal?
int i; double* dp = &i;
Which of the following is not the member of class?
friend functions
Which of the following is the correct way of declaring a function as constant?
const int ShowData(void) { /* statements */ }
int const ShowData(void) { /* statements */ }
int ShowData(void) const { /* statements */ }
Only III
Which of the following is the only technical difference between structures and classes in C++?
Member function and data are by default public in structures but private in classes.
Which of the following is valid identifier?
float int_2
Which of the following keyword is used to overload an operator?
operator
Which of the following keywords is used to control access to a class member?
Protected
Which of the following output is correct about the program given below?
#include <iostream>
#include <string>
using namespace std;
class Example{
public:
void GetData(char *s, int x, int y ){
int i = 0;
for (i = x-1; y>0; i++){
cout<< s[i];
y--;
}
}
};
int main(){
Example obj;
obj.GetData((char*)"Welcome!", 1, 3);
return 0;
}
Wel
Which of the following output is correct about the program given below?
#include <iostream>
using namespace std;
class Example{
int x;
float y;
public:
void Function(){
x \= 4;
y = 2.50;
delete this;
}
void Display(){
cout<< x << " " << y;
}
};
int main(){
Example *p = new Example();
p->Function();
p->Function();
p->Display();
return 0;
}
Runtime error.
Which of the following output is correct about the program given below?
#include<iostream>
using namespace std;
class Parent{
int x, y;
public:
Parent(int xx = 10, int yy = 10){
x = xx;
y = yy;
}
void Show(){
cout<< x * y << endl;
}
};
class Child{
private:
Parent obj;
public:
Child(int xx, int yy) : obj(xx, yy){
obj.Show();
}
};
int main(){
Child obj(10, 20);
return 0;
} 200
Which of the following statement is correct about the program given below?
#include <iostream>
using namespace std;
long GetNumber(long int Number){
return --Number;
}
float GetNumber(int Number){
return ++Number;
}
int main(){
int x = 20;
int y = 30;
cout << GetNumber(x) << " ";
cout << GetNumber(y) ;
return 0;
}
21 31
Which of the following statement is correct about the program given below?
#include <iostream>
using namespace std;
class Example{.
int x;
public:
void SetData(int xx){
x = xx;
}
void Display(){
cout<< x ;
}
};
int main(){
Example obj;
obj.x = 0;
obj.SetData(33);
obj.Display();
return 0;
}
The program will report compile time error.
Which of the following statement is correct about the program given below?
#include <iostream>
using namespace std;
class Example{
int x;
public:
void SetData(int xx){
this->x = xx;
}
void Display(){
cout<< this->x ;
}
};
int main(){
Example obj;
obj.SetData(33);
obj.Display();
return 0;
}
The program will print the output 33.
Which of the following statement is correct about the program given below?
#include <iostream>
using namespace std;
class Example{
int x, y, z;
public:
Example(int x, int y, int z){
this->x = ++x;
this->y = ++y;
this->z = ++z;
}
void display(){
cout<< "" << x++ << " " << y++ << " " << z++;
}
};
int main(){
Example obj(1, 2, 3);
obj.display();
return 0;
}
The program will print the output 2 3 4 .
Which of the following statement is correct about the program given below?
#include <iostream>
using namespace std;
class Example{
public:
Example(){
cout<< "Hi ";
}
~Example(){
cout<< "and Bye!";
}
};
int main(){
Example obj;
return 0;
}
The program will print the output Hi and Bye!.
Which of the following statement is correct about the program given below?
#include <iostream>
using namespace std;
int b = 0;
void DisplayData(int *x, int *y = &b){
cout<< *x << " " << *y;
}
int main(){
int a = 10, b = 20 ;
DisplayData(&a, &b);
return 0;
}
The program will print the output 10 20.
Which of the following statement is correct about the program given below?
#include <iostream>
using namespace std;
int main(){
int x = 80;
int &y = x;
x++;
cout << x << " " << --y;
return 0;
}
81 80
Which of the following statement is correct about the references?
A reference must always be initialized.
Which of the following statement is correct?
All arguments of an overloaded function can be default.
Which of the following statement is correct?
A function can be overloaded more than once.
Which of the following statement is correct?
The order of the default argument will be right to left.
Which of the following statement is correct?
Destructor destroys the complete object.
Which of the following statement is correct?
A function can be overloaded more than once.
Which of the following statement is correct?
Function prototype can have default parameters.
Which of the following statement is correct?
Overloaded functions can accept same number of arguments.
Which of the following statement is correct?
The order of the default argument will be right to left.
Which of the following statements are correct ?
1: A string is a collection of characters terminated by '\0'.
2: The length of the string can be obtained by strlen().
3: The pointer CANNOT work on string.{
1,2
Which of the following statements are correct about the below declarations?
char *p = "Sanjar"; char a[] = "Sanjar";
1: There is no difference in the declarations and both serve the same purpose.
2: p is a non-const pointer pointing to a non-const string,
3: The pointer p can be modified to point to another string, whereas the individual characters within array a can be changed.
4: In both cases the '\0' will be added at the end of the string "Sanjar".{
2,3,4
Which of the following statements are correct about the program below?
#include <iostream>
using namespace std;
int main(){
char str[20], *s;
cout<<"Enter a string\n";
cin>>str;
s=str;
while(*s != '\0'){
if(*s >= 97 && *s <= 122){
*s = *s-32;
s++;
}
}
cout<< str;
return 0;
}
The code converts lower case character to upper case
Which of the following statements is correct about the constructors and destructors?
Constructors can take arguments but destructors cannot.
Which of the following statements is correct in C++?
Structures can have functions as members.
Which of the following statements is correct?
Both data and functions can be either private or public.
Which of the following term is used for a function defined inside a class?
Member function
Which of the following ways are legal to access a class data member using this pointer?
this->x
Which one of the following options is correct?
Friend function can access public data members of the class.
Friend function can access protected data members of the class.
Friend function can access private data members of the class.
Friend function is not a member of the class.
All of the statements
Which one(s) is(are) correct according to template functions?
Only need to write one function, and it will work with many different types.
It will take a long time to execute.
Duplicate code is increased
I only
Which operator is used to allocate the memory?
new
Which return type will you use if you are not intended to get a return value?
void
Which statements enable programs to perform statements repeatedly as long as a condition remains true?
Repetition statements
Which value will it take when both user and default values are given?
user value
With __________, the caller gives the called function the ability to access the caller's data directly and to modify it if the called function chooses to do so.
passed by reference
__________ can be used to assign an object of a class to another object of the same class.
=
Add variable x to variable sum and assign the result to variable sum
sum+=x;
An expression containing the || operator is true if either or both of its operands are true
true
A function is invoked with a(n) ________.
function call
A variable that is known only within the function in which it is defined is called a(n) ________.
local variable
A(n)________ allows the compiler to check the number, types and order of the arguments passed to a function.
function prototype
A variable declared outside any block or function is a(n) ________ variable
global
A function that calls itself either directly or indirectly (i.e., through another function) is a(n) ________ function
recursive
A recursive function typically has two components: One that provides a means for the recursion to terminate by testing for a(n) ________ case and one that expresses the problem as a recursive call for a slightly simpler problem than the original call
Base
All programs can be written in terms of three types of control structures:_________, __________and_________.
Sequence, selection and repetition
Any source-code file that contains int main() can be used to execute a program
true
A class definition is typically stored in a file with the _________ filename extension
.h
A house is to a blueprint as a(n) _________ is to a class
object
A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator
false
All variables must be given a type when they are declared
true
All variables must be declared before they are used
true
A function ________ enables a single function to be defined to perform a task on many different data types
template
All arguments to function calls in C++ are passed by value
false
A(n) __________ should be used to declare the size of an array, because it makes the program more scalable
constant variable
An array that uses two subscripts is referred to as a(n) _________ array
two-dimensional
An array can store many different types of values
false
An array subscript should normally be of data type float
False
An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution
false
A pointer is a variable that contains as its value the____________ of another variable
address
A pointer that is declared to be of type void * can be dereferenced
false
Assuming that nPtr points to the beginning of array numbers (the starting address of the array is at location 1002500 in memory), what address is referenced by nPtr + 8?
The address is 1002500 + 8 * 8 = 1002564
A nonmember function must be declared as a(n) __________ of a class to have access to that class's private data members.
friend
A constant object must be __________; it cannot be modified after it is created
initialized
A(n) __________ data member represents class-wide information
static
An object's non-static member functions have access to a "self pointer" to the object called the __________ pointer
this
A member function should be declared static if it does not access __________ class members
non-static
A program must call function close explicitly to close a file associated with an ifstream, ofstream or fstream object.
false
A selection sort application would take approximately ________ times as long to run on a 128-element vector as on a 32-element vector.
16, because an O(n2) algorithm takes 16 times as long to sort four times as much information
By convention, function names begin with a capital letter and all subsequent words in the name begin with a capital letter
false
By default, memory addresses are displayed as long integers
false
Class members specified as _________ are accessible only to member functions of the class and friends of the class
private
Class members specified as _________ are accessible anywhere an object of the class is in scope
public
__________ can be used to assign an object of a class to another object of the same class
Default memberwise assignment (performed by the assignment operator).
Class members are accessed via the ________ operator in conjunction with the name of an object (or reference to an object) of the class or via the ___________ operator in conjunction with a pointer to an object of the class
dot (.), arrow (->)
Comments cause the computer to print the text after the // on the screen when the program is executed
false
C++ considers the variables number and NuMbEr to be identical
false
Calculate the remainder after q is divided by divisor and assign the result to q. Write this statement two different ways
q %= divisor; q = q % divisor;
Repeating a set of instructions a specific number of times is called_________repetition
Counter-controlled or definite
Return type _________ indicates that a function will perform a task but will not return any information when it completes its task
void
Read an integer from the user at the keyboard and store the value entered in integer variable age.
std::cin >> age;
Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr
numbers[ 3 ] *( numbers + 3 ) nPtr[ 3 ] *( nPtr + 3 )
Read an integer from the user at the keyboard and store the value entered in integer variable age.
std::cin >> age;
Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr
numbers[ 3 ] *( numbers + 3 ) nPtr[ 3 ] *( nPtr + 3 )
Records in random-access files must be of uniform length
false
Declare variables sum and x to be of type int
int sum, x;
Determine whether the value of the variable count is greater than 10. If it is, print "Count is greater than 10."
if ( count > 10) cout << "Count is greater than 10" << endl;
Data members or member functions declared with access specifier private are accessible to member functions of the class in which they are declared
true
Declare the variables c, thisIsAVariable, q76354 and number to be of type int.
int c, thisIsAVariable, q76354, number;
Declarations can appear almost anywhere in the body of a C++ function
true
Declare the array to be an integer array and to have 3 rows and 3 columns. Assume that the constant variable arraySize has been defined to be 3:
int table[ arraySize ][ arraySize];
Declare an array of type double called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9. Assume that the symbolic constant SIZE has been defined as 10
double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
Declare a pointer nPtr that points to a variable of type double
double *nPtr;
Data in sequential files always is updated without overwriting nearby data
false
Set variable x to 1
x=1;
Set variable sum to 0
sum=0;
State the values of the variable after the calculation is performed. Assume that, when a statement begins executing, all variables have the integer value 5: product *= x++;
product = 25, x = 6;
State the values of the variable after the calculation is performed. Assume that, when a statement begins executing, all variables have the integer value 5: quotient /= ++x;
quotient = 0, x = 6;
Storage-class specifier ________ is a recommendation to the compiler to store a variable in one of the computer's registers
register
Stream manipulator showpoint forces floating-point values to print with the default six digits of precision unless the precision value has been changed, in which case floating-point values print with the specified precision
true
Searching all records in a random-access file to find a specific record is unnecessary
true
Print "The sum is: " followed by the value of variable sum
cout << "The sum is: " << sum << end1;
Predecrement the variable x by 1, then subtract it from the variable total
total -= --x;
Print the message "This is a C++ program" with each word separated from the next by a tab
std::cout << "This\tis\ta\tC++\tprogram\n";
Program components in C++ are called ________ and ________.
functions, classes
Print the message "This is a C++ program" with each word on a separate line
std::cout << "This\nis\na\nC++\nprogram\n";
Print the message "This is a C++ program" on one line
std::cout << "This is a C++ program\n";
Prompt the user to enter an integer. End your prompting message with a colon (:) followed by a space and leave the cursor positioned after the space
Pointers of different types can never be assigned to one another without a cast operation
false
Write single C++ statements that input integer variable x with cin and >>
cin>>x;
Write single C++ statements that input integer variable y with cin and >>.
cin >> y;
Write single C++ statements that postincrement variable i by 1
i++;
Write single C++ statements that determine whether i is less than or equal to y
if (i<=y)
Write single C++ statements that output integer variable power with cout and <<
cout << power << endl;
What is wrong with the following while repetition statement? while ( z >= 0 ) sum += z;
The value of the variable z is never changed in the while statement. Therefore, if the loop continuation condition (z >= 0) is initially true, an infinite loop is created. To prevent the infinite loop, z must be decremented so that it eventually becomes less than 0.
Write a C++ statement or a set of C++ statements to sum the odd integers between 1 and 99 using a for statement. Assume the integer variables sum and count have been declared
sum = 0; for ( count = 1; count <= 99; count += 2 ) sum += count;
Write a C++ statement or a set of C++ statements to print the value 333.546372 in a field width of 15 characters with precisions of 1, 2 and 3. Print each number on the same line. Left-justify each number in its field.
cout << fixed << left << setprecision( 1 ) << setw( 15 ) << 333.546372 << setprecision( 2 ) << setw( 15 ) << 333.546372 << setprecision( 3 ) << setw( 15 ) << 333.546372 << endl;
Write a C++ statement or a set of C++ statements to calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions
cout << fixed << setprecision( 2 ) << setw( 10 ) << pow( 2.5, 3 ) << endl;
Write a C++ statement or a set of C++ statements to print the integers from 1 to 20 using a while loop and the counter variable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character; otherwise, print a tab character.]
x = 1; while ( x <= 20 ) { cout << x; if ( x % 5 == 0 ) cout << endl; else cout << '\t'; x++; }
What variable is?
named part in a memory
Write four different C++ statements that each add 1 to integer variable x
x =+ 1; x += 1; ++x; x++;
When it is not known in advance how many times a set of statements will be repeated, a(n)_________value can be used to terminate the repetition
Sentinel, signal, flag or dummy
What is the difference between a local variable and a data member?
A local variable is declared in the body of a function and can be used only from the point at which it is declared to the immediately following closing brace. A data member is declared in a class definition, but not in the body of any of the class's member functions. Every object (instance) of a class has a separate copy of the class's data members. Also, data members are accessible to all member functions of the class.
When a member function is defined outside the class definition, the function header must include the class name and the _________, followed by the function name to "tie" the member function to the class definition
binary scope resolution operator (::)
When each object of a class maintains its own copy of an attribute, the variable that represents the attribute is also known as a(n) _________.
data member
What statement is used to make decisions:
if
Write a declaration for the following: Integer count that should be maintained in a register. Initialize count to 0.
register int count = 0;
Write a declaration for the following: Double-precision, floating-point variable lastVal that is to retain its value between calls to the function in which it is defined.
static double lastVal;
Why would a function prototype contain a parameter type declaration such as double &?
This creates a reference parameter of type "reference to double" that enables the function to modify the original variable in the calling function
Write one or more statements that perform the following task for and array called “fractions”. Define a constant variable arraySize initialized to 10.
const int arraySize = 10;
Write one or more statements that perform the following task for and array called “fractions”. Declare an array with arraySize elements of type double, and initialize the elements to 0.
double fractions[ arraySize ] = { 0.0};
Write one or more statements that perform the following task for and array called “fractions”. Name the fourth element of the array
fractions[ 3 ]
Write one or more statements that perform the following task for and array called “fractions”. Refer to array element 4
fractions[ 4 ]
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 1.667 to array element 9
fractions[ 9 ] = 1.667;
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 3.333 to the seventh element of the array
fractions[ 6 ] = 3.333;
Write one or more statements that perform the following task for and array called “fractions”. Print array elements 6 and 9 with two digits of precision to the right of the decimal point.
cout << fixed << setprecision ( 2 ); cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl;
Write one or more statements that perform the following task for and array called “fractions”. Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop.
for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < i << "] = " << fractions[ i ] << endl;
Write a program segment to print the values of each element of array table in tabular format with 3 rows and 3 columns. Assume that the array was initialized with the declaration int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } }; and the integer variables i and j are declared as control variables.
cout << " [0] [1] [2]" << endl; for ( int i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( int j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ j ] << " "; cout << endl;
Write two separate statements that each assign the starting address of array numbers to the pointer variable nPtr.
nPtr = numbers; nPtr = &numbers[ 0 ];
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Declare the variable fPtr to be a pointer to an object of type double.
double *fPtr;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the value of the object pointed to by fPtr.
cout << "The value of *fPtr is " << *fPtr << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the value of the object pointed to by fPtr to variable number2.
number2 = *fPtr;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the value of number2.
cout << "The value of number2 is " << number2 << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address of number1.
cout << "The address of number1 is " << &number1 << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address stored in fPtr.
cout << "The address stored in fPtr is " << fPtr << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Copy the string stored in array s2 into array s1.
strcpy( s1, s2 );
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Compare the string in s1 with the string in s2, and print the result.
cout << "strcmp(s1, s2) = " << strcmp( s1, s2 ) << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Append the first 10 characters from the string in s2 to the string in s1.
strncat( s1, s2, 10 );
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Determine the length of the string in s1, and print the result.
cout << "strlen(s1) = " << strlen( s1 ) << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign to ptr the location of the first token in s2. The tokens delimiters are commas (,).
ptr = strtok( s2, ",");
Write the function header for a function called exchange that takes two pointers to double-precision, floating-point numbers x and y as parameters and does not return a value
void exchange( double *x, double *y )
Write the function header for a function called evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns an integer.
int evaluate( int x, int (*poly)( int ))
Write two statements that each initialize character array vowel with the string of vowels, "AEIOU".
char vowel[] = "AEIOU"; char vowel[] = { 'A', 'E', 'I', 'O', 'U', '\0' };
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strcpy( s3, s2 ) << endl;
jill
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strcat( strcat( strcpy( s3, s1 ), " and " ), s2 ) << endl;
jack and jill
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strlen( s1 ) + strlen( s2 ) << endl;
8
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strlen( s3 ) << endl;
13
When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
showpos
Identify and correct the errors in the following code: while ( c <= 5 ) { product *= c; c++;
while ( c <= 5 ) { product *= c; c++; }
Identify and correct the errors in the following code: if ( gender == 1 ) cout << "Woman" << endl; else; cout << "Man" << endl;
if ( gender == 1 ) cout << "Woman" << endl; else cout << "Man" << endl;
Identify and correct the errors in the following code: cin << value;
cin >> value;
In C++, it is possible to have various functions with the same name that operate on different types or numbers of arguments. This is called function ________.
overloading
In one statement, assign the sum of the current value of X and y to z and postincrement the value of X
z = x++ + y;
Identify and correct the errors in the following statement (assume that the statement using std::cout; is used): if ( c => 7 ) cout << "c is equal to or greater than 7\n";
if ( c >= 7 ) cout << "c is equal to or greater than 7\n";
Identify and correct the errors in the following statement (assume that the statement using std::cout; is used): if ( c < 7 ); cout << "c is less than 7\n";
if ( c < 7 ) cout << "c is less than 7\n";
If the variable number is not equal to 7, print "The variable number is not equal to 7"
if ( number != 7 ) std::cout << "The variable number is not equal to 7\n";
If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the initializer list
false
It is an error if an initializer list contains more initializers than there are elements in the array
true
If a member initializer is not provided for a member object of a class, the object's __________ is called
default constructor
Input/output in C++ occurs as ____________ of bytes
streams
Input operations are supported by class __________.
istream
Input with the stream extraction operator >> always skips leading white-space characters in the input stream, by default
true
If a nonrecoverable error occurs during a stream operation, the bad member function will return TRue
true
If the file-position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file
false
The default case is required in the switch selection statement
false
The break statement is required in the default case of a switch selection statement to exit the switch properly
false
The expression ( x > y && a < b ) is true if either the expression x > y is true or the expression a < b is true
false
The ________ statement in a called function passes the value of an expression back to the calling function
return
The keyword ________ is used in a function header to indicate that a function does not return a value or to indicate that a function contains no parameters
void
The ________ of an identifier is the portion of the program in which the identifier can be used
scope
The three ways to return control from a called function to a caller are ________, ________ and ________.
return, return expression or encounter the closing right brace of a function.
The storage-class specifiers are mutable, ________, ________, ________ and ________.
auto, register, extern, static
The six possible scopes of an identifier are ________, ________, ________, ________, ________ and ________.
function scope, file scope, block scope, function-prototype scope, class scope, namespace scope
The ________ enables access to a global variable with the same name as a variable in the current scope
unary scope resolution operator (::)
The_________selection statement is used to execute one action when a condition is true or a different action when that condition is false.
if…else
The types of arguments in a function call must match the types of the corresponding parameters in the function prototype's parameter list
true
The source-code file and any other files that use a class can include the class's header file via an _________ preprocessor directive
#include
The arithmetic operators *, /, %, + and all have the same level of precedence
false
The modulus operator (%) can be used only with integer operands
true
The escape sequence \n, when output with cout and the stream insertion operator, causes the cursor to position to the beginning of the next line on the screen
true
The ________ qualifier is used to declare read-only variables
const
The elements of an array are related by the fact that they have the same ________ and ___________.
name, type
The number used to refer to a particular element of an array is called its ________.
subscript (or index)
The process of placing the elements of an array in order is called ________ the array
sorting
The process of determining if an array contains a particular key value is called _________ the array
searching
the error in the following program segment and correct the error: Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } }; a[ 1, 1 ] = 5;
a[ 1, 1 ] = 5;
The three values that can be used to initialize a pointer are_____________,__________ and___________.
0, NULL, an address
The only integer that can be assigned directly to a pointer is_____________.
0
The address operator & can be applied only to constants and to expressions
false
The __________ operator dynamically allocates memory for an object of a specified type and returns a __________ to that type.
new, pointer
The keyword __________ specifies that an object or variable is not modifiable after it is initialized
const
The __________ operator reclaims memory previously allocated by new.
delete
The stream manipulators that format justification are_________, _________ and _______.
left, right and internal
The ostream member function ___________ is used to perform unformatted output
write
The symbol for the stream insertion operator is ____________.
<<
The four objects that correspond to the standard devices on the system include _________, _________, __________ and ___________.
cin, cout, cerr and clog
The symbol for the stream extraction operator is __________
>>
The stream manipulators ___________, __________ and ___________ specify that integers should be displayed in octal, hexadecimal and decimal formats, respectively
oct, hex and dec
The stream member function flags with a long argument sets the flags state variable to its argument and returns its previous value.
false
The stream extraction operator >> can be overloaded with an operator function that takes an istream reference and a reference to a user-defined type as arguments and returns an istream reference.
true
The stream insertion operator << can be overloaded with an operator function that takes an istream reference and a reference to a user-defined type as arguments and returns an istream reference
false
The stream member function rdstate returns the current state of the stream
true
The cout stream normally is connected to the display screen
true
The stream member function good returns TRUE if the bad, fail and eof member functions all return false
true
The cin stream normally is connected to the display screen
false
The ostream member function put outputs the specified number of characters
false
The stream manipulators dec, oct and hex affect only the next integer output operation
false
The programmer must create the cin, cout, cerr and clog objects explicitly
false
The ostream member function write can write to standard-output stream cout
true
The efficiency of merge sort is ______
O(n log n).
Variables declared in a block or in the parameter list of a function are assumed to be of storage class ________ unless specified otherwise
auto
Variables declared in the body of a particular member function are known as data members and can be used in all member functions of the class
false
Find the error(s) in the following code segment: x = 1; while ( x <= 10 ); x++; }
x = 1; while ( x <= 10 ) x++; }
Find the error(s) in the following code segment: for ( y = .1; y != 1.0; y += .1 ) cout << y << endl;
for ( y = 1; y != 10; y++ ) cout << ( static_cast< double >( y ) / 10 ) << endl;
Find the error(s) in the following code segment: switch ( n ) { case 1: cout << "The number is 1" << endl; case 2: cout << "The number is 2" << endl; break; default: cout << "The number is not 1 or 2" << endl; break; }
switch ( n ) { case 1: cout << "The number is 1" << endl; break; case 2: cout << "The number is 2" << endl; break; default: cout << "The number is not 1 or 2" << endl; break; }
Find the error(s) in the following code segment. The following code should print the values 1 to 10: n = 1; while ( n < 10 ) cout << n++ << endl;
n = 1; while ( n < 11 ) cout << n++ << endl;
Function ________ is used to produce random numbers
rand()
Function ________ is used to set the random number seed to randomize a program
srand()
For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
static
Find the error in the following program segment: int g( void) { cout << "Inside function g" << endl; int h( void ) { cout << "Inside function h" << endl; } }
int g( void) { cout << "Inside function g" << endl; } int h( void ) { cout << "Inside function h" << endl; }
Find the error in the following program segment: int sum( int x, int y ) { int result; result = x + y; }
int sum( int x, int y ) { return x + y; }
Find the error in the following program segment: int sum( int n ) { if ( n == 0 ) return 0; else n + sum( n - 1 ); }
int sum( int n ) { if ( n == 0 ) return 0; else return n + sum( n - 1 ); }
Find the error in the following program segment void f ( double a); { float a; cout << a << endl; }
void f ( double a) { cout << a << endl; }
Find the error in the following program segment: void product( void ) { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; cout << "Result is " << result; return result; }
void product( void ) { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; cout << "Result is " << result; }
Find the error in the following program segment and correct the error: #include ;
#include
Find the error in the following program segment and correct the error: arraySize = 10; // arraySize was declared const
const int arraySize=10;
Find the error in the following program segment and correct the error: Assume that int b[ 10 ] = { 0 }; for ( int i = 0; <= 10; i++ ) b[ i ] = 1;
for ( int i = 0; <= 9; i++ ) b[ i ] = 1;
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; ++zPtr; zPtr = z;
++zPtr;
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; // use pointer to get first value of array number = zPtr;
number = *zPtr;
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; // assign array element 2 (the value 3) to number number = *zPtr[ 2 ];
number = zPtr[ 2 ];
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; // print entire array z for ( int i = 0; i <= 5; i++ ) cout << zPtr[ i ] << endl;
for ( int i = 0; i < 5; i++ ) cout << zPtr[ i ] << endl;
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; // assign the value pointed to by sPtr to number number = *sPtr;
number = *static_cast< int * >( sPtr );
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; ++z;
++z[4];
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; char s[ 10 ]; cout << strncpy( s, "hello", 5 ) << endl;
cout << strncpy( s, "hello", 6 ) << endl;
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; char s[ 12 ]; strcpy( s, "Welcome Home");
char s[ 13 ]; strcpy( s, "Welcome Home");
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; if ( strcmp( string1, string2 ) ) cout << "The strings are equal" << endl;
if ( strcmp( string1, string2 ) == 0) cout << "The strings are equal" << endl;
Find the error(s) in the following and correct it (them). Assume the following prototype is declared in class Time: void ~Time( int );
~Time( );
Find the error(s) in the following and correct it (them). The following is a partial definition of class Time: class Time { public: // function prototypes private: int hour = 0; int minute = 0; int second = 0; }; // end class Time
class Time { public: // function prototypes Time (int my_hour, int my_minute, int my_second) { hour=my_hour; minute=my_minute; second=my_second; } private: int hour; int minute; int second; }; // end class Time
Find the error(s) in the following and correct it (them). Assume the following prototype is declared in class Employee: int Employee( const char *, const char * );
Employee( const char *, const char * );
Find the errors in the following class and explain how to correct them: class Example { public: Example( int y = 10 ) : data( y ) { // empty body } // end Example constructor int getIncrementedData() const { return data++; } // end function getIncrementedData static int getCount() { cout << "Data is " << data << endl; return count; } // end function getCount private: int data; static int count; }; // end class Example
Error: The class definition for Example has two errors. The first occurs in function getIncrementedData. The function is declared const, but it modifies the object. Correction: To correct the first error, remove the const keyword from the definition of getIncrementedData. Error: The second error occurs in function getCount. This function is declared static, so it is not allowed to access any non-static member of the class. Correction: To correct the second error, remove the output line from the getCount definition.
Explain the purpose of a function parameter. What is the difference between a parameter and an argument?
A parameter represents additional information that a function requires to perform its task. Each parameter required by a function is specified in the function header. An argument is the value supplied in the function call. When the function is called, the argument value is passed into the function parameter so that the function can perform its task
Every function's body is delimited by left and right braces ({ and }).
true
Empty parentheses following a function name in a function prototype indicate that the function does not require any parameters to perform its task
true
Each parameter in a function header should specify both a(n) _________ and a(n) _________.
type, name
Every class definition contains keyword _________ followed immediately by the class's name
class
Every C++ statement ends with a(n):
semicolon
Every C++ program begins execution at the function
main
Keyword public is a(n) _________.
access specifier
Give the function header for the following function. Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.
double hypotenuse( double side1, double side2)
Give the function header for the following function. Function smallest that takes three integers, x, y and z, and returns an integer.
int smallest( int x, int y, int z)
Give the function header for the following function. Function instructions that does not receive any arguments and does not return a value. [Note: Such functions are commonly used to display instructions to a user.]
void instructions( void )
Give the function header for the following function. Function intToDouble that takes an integer argument, number, and returns a double-precision, floating-point result.
double intToDouble( int number)
Lists and tables of values can be stored in __________ or __________.
arrays, vectors
Use a for statement to print the elements of array numbers using array subscript notation. Print each number with one position of precision to the right of the decimal point:
cout << fixed << showpoint << setprecision( 1 ); for ( int i = 0; i < SIZE; i++ ) cout << numbers[ i ] <<' ';
Use a for statement to print the elements of array numbers using pointer/offset notation with pointer nPtr
cout << fixed << showpoint << setprecision( 1 ); for ( int j = 0; j < SIZE; j++ ) cout << *( nPtr + j ) << ' ';
Use a for statement to print the elements of array numbers using pointer/offset notation with the array name as the pointer
cout << fixed << showpoint << setprecision( 1 ); for ( int k = 0; k < SIZE; k++ ) cout << *( numbers + k ) << ' '
Use a for statement to print the elements of array numbers using pointer/subscript notation with pointer nPtr
cout << fixed << showpoint << setprecision( 1 ); for ( int m = 0; m < SIZE; m++ ) cout << nPtr[ m ] << ' ';
Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters
cout << uppercase;
Use a stream manipulator to ensure floating-point values print in scientific notation
cout << scientific;
Use a stream manipulator such that, when integer values are output, the integer base for octal and hexadecimal values is displayed.
cout << showbase;
Use a stream member function to set the fill character to '*' for printing in field widths larger than the values being output. Write a separate statement to do this with a stream manipulator
cout.fill( '*' ); cout << setfill( '*' );
__________ must be used to initialize constant members of a class
Member initializers
Member objects are constructed __________ their enclosing class object
before
Member function _________ can be used to set and reset format state
flags
Member function read cannot be used to read data from the input object cin
False
Member functions seekp and seekg must seek relative to the beginning of a file
false
Outputs to the standard error stream are directed to either the ___________ or the ___________ stream object
cerr or clog
Output operations are supported by class ___________.
ostream
Output to cerr is unbuffered and output to clog is buffered
true
Output the string "Enter your name: "
cout << "Enter your name: ";
Output the address of the variable myString of type char *
cout << static_cast< void * >( myString );
Output the address in variable integerPtr of type int *.
cout << integerPtr;
Output the value pointed to by floatPtr of type float *.
cout << *floatPtr;
Output the characters '0' and 'K' in one statement with ostream function put
cout.put( '0' ).put( 'K' );
Question1
The only integer that can be assigned directly to a pointer is _____________..
0
Question4
Which of the following is the correct operator to compare two variables?
==
Question6
Repeating a set of instructions a specific number of times is called_________repetition
d. counter-controlled
Question7
Why can typecasting be dangerous?
a. You might temporarily lose part of the data - such as truncating a float when typecasting to an int.
Question8
Comments cause the computer to print the text after the // on the screen when the program is executed.
Ответ:
True
False
Question9
What does the program below output?
#include <iostream>
using namespace std;
int main() {
int a[6] = {3,5,2,6,8,2};
int result = 1;
for (int i=0; i<6; i++)
result *= a[i];
cout << result << endl;
return 0;
}
c. 2880
Question11
Find the error(s) in the following and correct it (them). Assume the following prototype is declared in class Time:
void ~Time( int );
c. ~Time( );
Question16
Print
the message "This is a C++ program" with each word
separated from the next by a tab:
Question17
What will this do: for(;;)?
. Loop forever
Question18
Find the error in the following program segment and correct the error:
arraySize = 10; // arraySize was declared const
b. const int arraySize=10;
Question19
Correct mistake in the statement below:
using namespase std;
. using namespace std;
Question22
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char *a = "international";
cout << a+5;
return 0;
}c. national
Question24
The
keyword
is
used in a function header to indicate that a function does not return
a value or to indicate that a function contains no parameters
Question25
The default case is required in the switch selection statement
Ответ:
True False
Question26
Class members specified as _________ are accessible anywhere an object of the class is in scope
public
Question27
Which of the following is a correct comment?
d. /* Comment */
Question29
When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
showpos
Question30
It is an error if an initializer list contains more initializers than there are elements in the array
. true
Question31
Which of the following is the proper keyword to allocate memory?
new
Question32
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char *a = "matador";
cout << "hello " << a[0] << a[5] << a[2] << a[5];
return 0;} d. hello moto
Question33
Find the error(s) in the following code segment. The following code should print the values 1 to 10: n = 1; while ( n < 10 )
cout << n++ << endl;
. n = 1; while ( n < 11 )
cout << n++ << endl;
Question34
Can a return statement be used into a void function?
Yes, and it will exit the function
Question36
Write single C++ statements that output integer variable power with cout and <<
b. cout << power << endl;
Question37
Any source-code file that contains int main() can be used to execute a program.
Ответ:
True False
Question39
In one statement, assign the sum of the current value of x and y to z and postincrement the value of x:
d. z = x++ + y;
Question40
The symbol for the stream insertion operator is ____________.
<<
Question41
All
programs can be written in terms of three types of control
structures:
Question42
Which of the following gives the memory address of integer variable a?
&a;
Question43
All arguments to function calls in C++ are passed by value
Ответ:
True False
Question44
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; ++zPtr;
a. zPtr = z; ++zPtr;
Question46
Is the following piece of code valid? #include <iostream> using namespace std; int main(){ int *steve; steve = &steve; return 0; }
Ответ:
True False
Question47
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char str[] = "Hello, World!!!";
cout << strlen(str);
return 0;
}
15
Question49
Баллов: 1
Identify and correct the errors in the following statement (assume that the statement using std::cout; is used): if ( c < 7 );
cout << "c is less than 7\n";
if ( c < 7 ) cout << "c is less than 7\n";
Question50
How many times is a do while loop guaranteed to loop?
1
Question51
Which one is correct?
int *a; a new int[20];
Question53
What is the output of the program?
#include <iostream> using namespace std; int main() { for (int a=10; a<91; a*=3) cout << a << " "; cout << endl; return 0; }
10 30 90
Question54
$$1 What is the output of the program below?
#include<iostream>
usingnamespace std;
int main() {
float a[7] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7};
cout << a[1] << endl;
return 0;
}
. 2.2
Question55
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
(count == 0) && (limit < 20)
. true
Question56
A
variable that is known only within the function in which it is
defined is called a
________.
. local variable
Question57
The ostream member function ___________ is used to perform unformatted output
write
Question59
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Compare the string in s1 with the string in s2, and print the result.
a. cout << "strcmp(s1, s2) = " << strcmp( s1, s2 ) << endl;
Question60
What is the index number of the last element of an array with 29 elements?
. 28
Question62
What is the output of the program?
#include <iostream> using namespace std; int main() { int a = 17; if (a<10) { cout << "A"; } if (a%17==0) { cout << "B"; } else { cout << "C"; } cout << endl; return 0; }
B
Question64
What value gets printed by the program?
#include <iostream>
int foo(int y);
int foo(int x)
{
return x+1;
}
int main(int argc, char** argv)
{
int x = 3;
int y = 6;
std::cout << foo(x) << std::endl;
return 0;}
4
Question67
Write single C++ statements that determine whether i is less than or equal to y
. if (i<=y)
Question69
Evaluate !(1 && !(0 || 1)).
Ответ:
True False
Question70
If I do not want to use return in my function myFunc() what I have to speciafy as return type?
void
Question72
The modulus operator (%) can be used only with integer operands.
Ответ:
True False
Question73
What statement is used to make decisions:
if
Question74
By default, memory addresses are displayed as long integers
Ответ:
True False
Question75
If a member initializer is not provided for a member object of a class, the object's __________ is called
default constructor
Question78
An array can store many different types of values
Ответ:
True False
Question79
What is required to avoid falling through from one case to the next?
break;
Question80
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int n = 1;
while (n<=5)
cout << ++n;
return 0;
}
23456
Question81
Write a C++ statement or a set of C++ statements to sum the odd integers between 1 and 99 using a for statement. Assume the integer variables sum and count have been declared.
sum = 0; for ( count = 1; count <= 99; count += 2 ) sum +=
Question83
An array subscript should normally be of data type float
Ответ:
True False
Question84
If ASCII code of 'd' is 100, what is the ASCII code of 'a'?
. 97
Question85
A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator.
Ответ:
True False
Question87
State
the values of the variable after the calculation is performed. Assume
that, when a statement begins executing, all variables have the
integer value 5: quotient /= ++x;
Result:
quotient
=
x
=
Question88
What value for y gets printed in the program below? #include <iostream> const int x = 12; int main(int argc, char** argv) { enum dog { x = x, y }; std::cout << y << std::endl; return 0; }
13
Question89
What does the program below output?
#include<iostream>
usingnamespace std;
int main() {
int a[6] = {3,5,1,6,8,2};
int idx = 0;
for (int i=0; i<6; i++)
if (a[idx]<a[i])
idx = i;
cout << a[idx] << endl;
return 0;
}
8
Question90
Set variable x to 1
Ответ:
Question91
Program components in C++ are called ________ and ________.
functions, classes
Question92
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 3.333 to the seventh element of the array
fractions[ 6 ] = 3.333;
Question93
What is the output of the program?
#include <iostream> using namespace std; int main() { int a = 10; for (a=32; a>=1; a/=2) cout << a << " "; cout << endl; return 0; }
32 16 8 4 2 1
Question96
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
int a = 1;
do {
cout << a;
a*=2;
} while (a<=5);
return 0;
}
124
Question97
For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
static
Question100
What is the only function all C++ programs must contain?
main()
1)Fin the erros in the following code segment
X=1 while(x<=10) ; x++; }
X=1 while(x<=10); x++; }
2) The_____ operator reclaims memory previously allocated by new
Delete
3) The number used to refer to a particular element of an array is called its
________. subscript (or index)
4) __________ must be used to initialize constant members of a class.
Member initializers
5) Question: Write a declaration for the following: Double-precision, floating-point variable lastVal that is to retain its value between calls to the function in which it is defined. static double lastVal;
6) Write single C++ statements that input integer variable x with cin and >>
cin>>x;
7) By convention, function names begin with a capital letter and all subsequent words in the name begin with a capital letter False
8) An array that uses two subscripts is referred to as a(n) _________ array
Two-dimensional
9) Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters cout<<uppercase;
10) Each parameter in a function header should specify both a(n) _________ and a(n) _________. Type,name;
11) the error in the following program segment and correct the error: Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } }; a[ 1,1]=5;
12) The process of determining if an array contains a particular key value is called _________.
searching
13) Read an integer from the user at the keyboard and store the value entered in integer variable age. std::cin >> age;
14) A function is invoked with a(n) ________.
function call
15) All arguments to function calls in C++ are passed by value
False
16) C++ considers the variables number and NuMbEr to be identical
False
17) The arithmetic operators *, /, %, + and all have the same level of precedence
False
18) The four objects that correspond to the standard devices on the system include _________, _________, __________ and ___________.
cin, cout, cerr and clog
19) Return type _________ indicates that a function will perform a task but will not return any information when it completes its task void
Question: Write a C++ statement or a set of C++ statements to calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions cout << fixed << setprecision( 2 ) << setw( 10 ) << pow( 2.5, 3 ) << endl;
Question: Write a C++ statement or a set of C++ statements to calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions cout << fixed << setprecision( 2 ) << setw( 10 ) << pow( 2.5, 3 ) << endl;
Начало формы
Question 1
The stream manipulators that format justification are_________, _________ and _______.
. left, right and internal
Question 2
An array that uses two subscripts is referred to as a ( n ) _________ array
. two-dimensional
Question 3
Give the function header for the following function. Function smallest that takes three integers, x, y and z, and returns an integer.
|
a. int smallest( int x, int y, int z) |
Question 4
Which lines of code below should cause the program to be undefined? 1 struct Foo 2 { 3 virtual ~Foo() {} 4 }; 5 6 struct Bar : public Foo 7 { 8 }; 9 10 int main(int argc, char** argv) 11 { 12 Foo* f = new Bar; 13 delete f; 14 f = 0; 15 delete f; 16 17 Foo* fa = new Bar[10]; 18 delete fa; 19 fa = 0; 20 delete fa; 21 22 return 0; 23 }
c. none
Question 8
The three values that can be used to initialize a pointer are_____________,__________ and___________.
|
d. 0, NULL, an address |
Question 10
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char str[] = "de_dust";
for (int i=strlen(str)-1; i>=0; i--)
cout << str[i];
cout << endl;
return 0;
}
|
d. tsud_ed |
Question 11
A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator.
Ответ:
True False
Question 13
Find the error in the following program segment:
void product( void ){
int a = 0 , b = 0 , c = 0;
int result = 0;
cout << "Enter three integers: ";
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is " << result;
return result;
}
|
c. void product( void ){ int a = 0 , b = 0 , c = 0; int result = 0; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; cout << "Result is " << result; } |
Question 17
Write a C++ statement or a set of C++ statements to calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions
|
a. cout << fixed << setprecision( 2 ) << setw( 10 ) << pow( 2.5, 3 ) << endl; |
Question 18
Which of the following lines should NOT compile? 1 int main() 2 { 3 int a = 2; 4 5 int* b = &a; 6 7 int const* c = b; 8 9 b = c; 10 11 return 0; 12 }
9
Question 19
What header file contains C++ file I/O instructions?
Iostream.H
Question 20
The ostream member function ___________ is used to perform unformatted output
c. write
Question 22
Use a for statement to print the elements of array numbers using pointer/offset notation with pointer nPtr
b. cout << fixed << showpoint << setprecision( 1 ); for ( int j = 0; j < SIZE; j++ )
cout << *( nPtr + j ) << ' ';
Question 24
How many times is Hello World printed by this program?
#include <iostream>
struct BS { BS() { std::cout << "Hello World" << std::endl; } unsigned int color; };
struct mid1 : virtual public BS { }; struct mid2 : virtual public BS { }; struct mid3 : public BS { }; struct mid4 : public BS { };
struct DR : public mid1, public mid2, public mid3, public mid4 { };
int main(int argc, char** argv) { DR d; return 0; }
3 Question 25
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address stored in fPtr.
d. cout << "The address stored in fPtr is " << fPtr << endl;
Question 28
What value gets printed by the program? #include <iostream> int main() { int x = 3; switch(x) { case 0: int x = 1; std::cout << x << std::endl; break; case 3: std::cout << x << std::endl; break; default: x = 2; std::cout << x << std::endl; } return 0; }
c. nothing, it is ill-formed |
|
Question 29
Write one or more statements that perform the following task for and array called “fractions”. Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop.
a. for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < arraySize << "] = " << fractions[arraySize ] << endl;
Question 30
By default, memory addresses are displayed as long integers
Ответ:
True False
Question 32
Declare variables sum and x to be of type int.
a. int sum, x;
Question 33
It is an error if an initializer list contains more initializers than there are elements in the array
c. true
Question 35
What is the output of the program? #include <iostream> using namespace std; int main() { int a = 10; for (a=1; a<=81; a*=3) cout << a << " "; cout << endl; return 0; }
. 1 3 9 27 81
Question 36
What statement is used to make decisions:
if
Question 37
What value gets printed by the program? #include <iostream> int main(int argc, char** argv) { int x = 0; int y = 0; if (x++ && y++) { y += 2; } std::cout << x + y << std::endl; return 0; }
. 1
Question 38
Explain the purpose of a function parameter. What is the difference between a parameter and an argument?
. A parameter represents additional information that a function requires to perform its task. Each parameter required by a function is specified in the function header. An argument is the value supplied in the function call. When the function is called, the argument value is passed into the function parameter so that the function can perform its task
Question 39
What will be the result of: cout << (5 << 3); ?
40
Question 41
The process of placing the elements of an array in order is called ________ the array
sorting
Question 42
Find the error(s) in the following code segment: x = 1; while ( x <= 10 );
x++;
}
. x = 1; while ( x <= 10 )
x++;
}
Question 43
What is the output of the program? #include <iostream> using namespace std; int main() { int a = 11; if (!(a<10)) { cout << "A"; } if (a%10==0) { cout << "B"; } else { cout << "C"; } cout << endl; return 0; } AC
Question 44
Output the address of the variable myString of type char *
b. cout << static_cast< void * >( myString );
Question 45
Use a for statement to print the elements of array numbers using pointer/subscript notation with pointer nPtr
|
c. cout << fixed << showpoint << setprecision( 1 ); for ( int m = 0; m < SIZE; m++ ) cout << nPtr[ m ] << ' '; |
Question 46
Which properly declares a variable of struct foo?
c. foo var;
Question 50
What value gets printed by the program?
#include <iostream>
int foo(int x, int y = x) { return x+y+1; }
int main(int argc, char** argv) { std::cout << foo(2) << std::endl; return 0; }. ill-formed Конец формы
Question 52
State
the values of the variable after the calculation is performed. Assume
that, when a statement begins executing, all variables have the
integer value 5: product *= x++;
Result:
product =
x
=
Question 53
The stream manipulators ___________, __________ and ___________ specify that integers should be displayed in octal, hexadecimal and decimal formats, respectively
. octi, hexi and deci
Question 54
What (if anything) prints when the following statement is performed?Assume the following variable declarations:
char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strlen( s1 ) + strlen( s2 ) << endl;
8
Question 55
Which functions will every class contain?
c. Both a constructor and a destructor |
|
Question 56
Find the error(s) in the following and correct it (them). Assume the following prototype is declared in class Employee: int Employee( const char *, const char * );
Employee( const char *, const char * );
Question 57
What will be the result after running this code:
for(int i=0;i<3;i++) { cout << i << " "; continue; cout << 7 << " "; break; for(int j=0;j<1;j++) cout << 5 << " "; }
b. 0 1 2
Question 58
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; if ( strcmp( string1, string2 ) ) cout << "The strings are equal" << endl;
b. if ( strcmp( string1, string2 ) == 0)
cout << "The strings are equal" << endl;
Question 59
The four objects that correspond to the standard devices on the system include _________, _________, __________ and ___________.
cin, cout, cerr and clog
Question 60
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the value of the object pointed to by fPtr to variable number2.
. number2 = *fPtr;
Question 61
What value does foo print out? #include <iostream> const int SIZE = 5; struct tester { void foo() { std::cout << SIZE << std::endl; } enum { SIZE = 3 }; }; int main(int argc, char** argv) { tester t; t.foo(); return 0; }
. 3
Question 62
Select the best answer to the output of the program:
#include<iostream>
usingnamespace std;
int main() {
double y = 10;
double *x = &y;
cout << x << " " << x-1 << " " << *x-1 << endl;
return 0;
}
e. None of the given choices. |
|
Question 63
Outputs to the standard error stream are directed to either the ___________ or the ___________ stream object
. cerr or clog
Question 64
Declare the array to be an integer array and to have 3 rows and 3 columns. Assume that the constant variable arraySize has been defined to be 3:
|
b. int table[ arraySize ][ arraySize]; |
Question 66
Class members are accessed via the ________ operator in conjunction with the name of an object (or reference to an object) of the class or via the ___________ operator in conjunction with a pointer to an object of the class
a. dot (.), arrow (->)
Question 67
Find the error in the following program segment. Assume the following declarations and statements: int *zPtr; // zPtr will reference array z int *aPtr = 0; void *sPtr = 0; int number; int z[ 5 ] = { 1, 2, 3, 4, 5 }; // assign the value pointed to by sPtr to number number = *sPtr;
|
a. number = *sPtr; |
Question 68
What is the output of the program?
#include <iostream> using namespace std; int main() { int n = 1; while (n<5) cout << n++; return 0; }
1234
Question 69
What punctuation ends most lines of C++ code?
|
a. ; |
Question 71
Declare an array of type double called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9. Assume that the symbolic constant SIZE has been defined as 10.
b. double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 }; |
|
Question 72
Input with the stream extraction operator >> always skips leading white-space characters in the input stream, by default
Ответ:
True False
Question 74
Write one or more statements that perform the following task for and array called “fractions”. Print array elements 6 and 9 with two digits of precision to the right of the decimal point.
d. cout << fixed << setprecision ( 2 ); cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl; |
|
Question 75
The modulus operator (%) can be used only with integer operands.
Ответ:
True False
Question 76
$$1 What is the output of the program below?
#include<iostream>
usingnamespace std;
int main() {
float a[7] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7};
cout << a[3] << endl;
return 0;
}
e. 4.4
Question 77
What (if anything) prints when the following statement is performed?Assume the following variable declarations:
char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ] = "\0"; cout << strlen( s3 ) << endl;
13
Question 78
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the address of variable number1 to pointer variable fPtr.
b. fPtr = &number1;
What does the program below output?
#include<iostream>
usingnamespace std;
int main() {
int a[6] = {3,5,1,6,8,2};
int result = 0;
for (int i=0; i<6; i++)
result *= a[i];
cout << result << endl;
return 0;
}0
Question 80
What value does size print out? #include <iostream> const int SIZE = 5; struct tester { int array[SIZE]; enum { SIZE = 3 }; void size() { std::cout << sizeof(array) / sizeof(int); } }; int main(int argc, char** argv) { tester t; t.size(); return 0; }
|
b. 5 |
Question 82
What will be at output? #include <iostream> using namespace std; int main() { int a = 5; a = *&*&*&*&a; cout << a << "\n"; return 0;
|
d. 5 |
Question 83
A constant object must be __________; it cannot be modified after it is created
|
c. initialized |
Question 84
What is the output of the program? #include <iostream> using namespace std; int main() { int a = 10; if (a<10) { cout << "A"; } if (a%10==0) { cout << "B"; } else { cout << "C"; } cout << endl; return 0; }
B
Question 85
Correct the mistakes
float a, b, c;
cin << a,b,c;
a. cin >> a >> b >> c;
Repeating a set of instructions a specific number of times is _____ called repetition.
Counter-controlled or definite
Question 87
Print the message "This is a C++ program" on one line:
|
e. std::cout << "This is a C++ program\n"; |
Question 88
What is the output of the program?
#include <iostream> using namespace std; int main() { for (int a=10; a<91; a*=3) cout << a-1 << " "; cout << endl; return 0; }
b. 9 29 89
Question 90
Which of the following is true?
|
d. 1 |
Question 91
What will be output ? #include <iostream> using namespace std; int main() { int x = 19; if (x == 19){ int y = 20; cout << x+y << endl; } y = 100; return 0; }
d. Compile-time error |
|
Question 92
When it is not known in advance how many times a set of statements will be repeated, a value can be used to terminate the repetition.
Question 93
What can be at output ? #include <iostream> using namespace std; int main(){ int a = 5; a = *&*&*&*&a; cout << *&*&*&*&a << " "; cout << &*&*&*&a << " "; return 0; } d. 5 0x22ff74
Question 94
Input/output in C++ occurs as ____________ of bytes
c. streams
Question 95
Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters
b. cout << uppercase; |
|
Question 96
Find the errors in the following class and explain how to correct them:
class Example {
public:
Example( int y = 10 )
: data( y ) {
// empty body
} // end Example constructor
int getIncrementedData() const {
return data++;
} // end function getIncrementedData
static int getCount() {
cout << "Data is " << data << endl;
return count;
} // end function getCount
private:
int data;
static int count;
}; // end class Example
|
c. Error: The class definition for Example has two errors. The first occurs in function getIncrementedData. The function is declared const, but it modifies the object. Correction: To correct the first error, remove the const keyword from the definition of getIncrementedData. Error: The second error occurs in function getCount. This function is declared static, so it is not allowed to access any non-static member of the class. Correction: To correct the second error, remove the output line from the getCount definition. |
Question 97
What output will be produced by the following code?
int count = 3;
while (count-- > 0)
cout << count << " ";
|
c. 2 1 0 |
Question 98
Which is not a loop structure?
d. Repeat Until |
|
Question 99
Write the function header for a function called evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns an integer.
|
a. int evaluate( int x, int (*poly)( int )) |
Question 100
What is the output of the program below?
#include <iostream>
using namespace std;
int main() {
int y = 99;
int *x = &y;
cout << 3+*x << endl;
return 0;
b. 102 |
|
Конец формы
Конец формы
Preparation for Final Exam MCQ Quiz BIG - Попытка 1
Страница: 1 2 3 4 5 6 7 8 9 10 (Далее)
Question 1
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
if ( strcmp( string1, string2 ) )
cout << "The strings are equal" << endl;
Выберите один ответ.
a. if ( strcmp( string1, string2 ) == 0)
cout << "The strings are equal" << endl;
Question 2
Баллов: 1
The stream manipulators dec, oct and hex affect only the next integer output operation
Ответ:
False
Question 3
Баллов: 1
Which of the following is the proper keyword to allocate memory?
Выберите один ответ. a. new
Question 4
Баллов: 1
Write a declaration for the following: Double-precision, floating-point variable lastVal that is to retain its value between calls to the function in which it is defined.
Выберите один ответ.
c. static double lastVal;
Question 5
Баллов: 1
$$1 Select the best answer to the output of the program:
#include<iostream>
usingnamespace std;
int main() {
double y = 3;
double *x = &y;
cout << x << " " << x+1 << " " << *x+1;
return 0;
}
Выберите один ответ.
e. 002BF7E4 002BF7E8 4
Question 6
Баллов: 1
The address operator & can be applied only to constants and to expressions
Ответ:
False
Question 7
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Compare the string in s1 with the string in s2, and print the result.
Выберите один ответ.
c. cout << "strcmp(s1, s2) = " << strcmp( s1, s2 ) << endl;
Question 8
Баллов: 1
Program components in C++ are called ________ and ________.
Выберите один ответ. a. functions, classes
Question 9
Question 10
Баллов: 1
If I do not want to use return in my function myFunc() what I have to speciafy as return type?
Выберите один ответ.
a. void
Question 12
Баллов: 1
Correct mistake in the statement below:
using namespase std;
Выберите один ответ. a. using namespace std;
Question 13
Баллов: 1
Find the error in the following program segment:
int sum( int n )
{
if ( n == 0 )
return 0;
else
n + sum( n - 1 );
}
Выберите один ответ.
c. int sum( int n )
{
if ( n == 0 )
return 0;
else
return n + sum( n - 1 );
}
Question 14
Баллов: 1
When using parameterized manipulators, the header file ____________ must be included
Выберите один ответ. a. <iomanip>
Question 15
Баллов: 1
Prompt the user to enter an integer. End your prompting message with a colon ( followed by a space and leave the cursor positioned after the space.
Выберите один ответ.
c. std::cout << "Enter an integer: ";
Question 16
Баллов: 1
The ________ qualifier is used to declare read-only variables
Выберите один ответ.
a. const
Question 17
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 10 ];
cout << strncpy( s, "hello", 5 ) << endl;
Выберите один ответ.
c. cout << strncpy( s, "hello", 6 ) << endl;
Question 20
Баллов: 1
Why would a function prototype contain a parameter type declaration such as double &?
Выберите один ответ.
c. This creates a reference parameter of type "reference to double" that enables the function to modify the original variable in the calling function
Question 22
Баллов: 1
Find the error(s) in the following code segment:
switch ( n )
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Выберите один ответ.
c. switch ( n )
{
case 1:
cout << "The number is 1" << endl;
break;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Question 23
Баллов: 1
Which of the following is the proper keyword to deallocate memory?
Выберите один ответ.
d. delete
Question 24
Баллов: 1
Assuming that nPtr points to the beginning of array numbers (the starting address of the array is at location 1002500 in memory), what address is referenced by nPtr + 8?
Выберите один ответ.
c. The address is 1002500 + 8 * 8 = 1002564
Question 25
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the value of the object pointed to by fPtr to variable number2.
Выберите один ответ.
c. number2 = *fPtr;
Question 26
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address of number1.
Выберите один ответ.
b. cout << "The address of number1 is " << &number1 << endl;
Question 28
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
!(count == 12)
Выберите один ответ. a. true
Question 29
Баллов: 1
__________ must be used to initialize constant members of a class
Выберите один ответ.
c. Member initializers
Question 31
Баллов: 1
Which of the following is not valid identifier?
Выберите один ответ.
c. namespace
Question 33
Баллов: 1
Which is not a protection level provided by classes in C++?
Выберите один ответ. a. hidden
Question 34
Баллов: 1
Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters
Выберите один ответ.
c. cout << uppercase;
Question 38
Баллов: 1
Write one or more statements that perform the following task for and array called “fractions”. Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop.
Выберите один ответ.
c. for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < i << "] = " << fractions[ i ] << endl;
Question 41
Баллов: 1
The expression ( x > y && a < b ) is true if either the expression x > y is true or the expression a < b is true
Ответ:
False
Question 42
Баллов: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 10;
for (a=1; a<81; a*=3)
cout << a << " ";
cout << endl;
return 0;
}
Выберите один ответ.
b. 1 3 9 27
Question 45
Баллов: 1
Calculate the remainder after q is divided by divisor and assign the result to q. Write this statement two different ways.
Выберите по крайней мере один ответ:
b. q %= divisor;
f. q = q % divisor;
Question 46
Баллов: 1
Correct the mistakes:
#include<iostream>
usingnamespace std;
double func();
{
double a = 3.14159;
cout << a << endl;
}
int main()
{
cout << "pi=" << func() << endl;
return 0;
}
Выберите один ответ.
e.
#include <iostream>
using namespace std;
double func()
{
double a = 3.14159;
return a;
}
int main()
{
cout << “pi=” << func() << endl;
return 0;
}
Question 47
Баллов: 1
Empty parentheses following a function name in a function prototype indicate that the function does not require any parameters to perform its task
Ответ:
True
Question 49
Баллов: 1
Which of the following is not valid identifier?
Выберите один ответ.
c. return
Question 50
Баллов: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 5;
do {
cout << a;
a--;
} while (a>0);
return 0;
}
Выберите один ответ.
d. 54321
Question 51
Баллов: 1
The escape sequence \n, when output with cout and the stream insertion operator, causes the cursor to position to the beginning of the next line on the screen.
Ответ:
True
Question 52
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// use pointer to get first value of array
number = zPtr;
Выберите один ответ.
c. number = *zPtr;
Question 54
Баллов: 1
The ostream member function ___________ is used to perform unformatted output
Выберите один ответ. a. write
Question 55
Баллов: 1
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 1.667 to array element 9
Выберите один ответ.
b. fractions[ 9 ] = 1.667;
Question 56
Баллов: 1
Find the error in the following program segment and correct the error:
Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
a[ 1, 1 ] = 5;
Выберите один ответ.
b. a[ 1 ][ 1 ] = 5;
Question 57
Баллов: 1
A pointer is a variable that contains as its value the____________ of another variable
Выберите один ответ. a. address
Question 58
Баллов: 1
Declare a pointer nPtr that points to a variable of type double
Выберите один ответ. a. double *nPtr;
Question 59
Баллов: 1
Which of the following is a two-dimensional array?
Выберите один ответ.
d. int anarray[20][20];
Question 61
Баллов: 1
Give the function header for the following function. Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.
Выберите один ответ.
d. double hypotenuse( double side1, double side2)
Question 63
Баллов: 1
Write single C++ statements that determine whether i is less than or equal to y
Выберите один ответ.
c. if (i<=y)
Question 64
Баллов: 1
The cout stream normally is connected to the display screen
Ответ:
True
Question 66
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign to ptr the location of the first token in s2. The tokens delimiters are commas (,).
Выберите один ответ. a. ptr = strtok( s2, ",");
Question 67
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Declare the variable fPtr to be a pointer to an object of type double.
Выберите один ответ.
b. double *fPtr;
Question 68
Баллов: 1
Write a C++ statement or a set of C++ statements to print the integers from 1 to 20 using a while loop and the countervariable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character; otherwise, print a tab character.]
Выберите один ответ. a. x = 1;
while ( x <= 20 )
{
cout << x;
if ( x % 5 == 0 )
cout << endl;
else
cout << '\t';
x++;
}
Question 69
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
(count == 1) && (x < y)
Выберите один ответ.
b. false
Question 70
Баллов: 1
Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr
Выберите один ответ.
b.
numbers[ 3 ]
*( numbers + 3 )
nPtr[ 3 ]
*( nPtr + 3 )
Question 71
Баллов: 1
Declare an array of type double called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9.
Assume that the symbolic constant SIZE has been defined as 10.
Выберите один ответ.
b. double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
Question 72
Баллов: 1
Find the error(s) in the following and correct it (them).
Assume the following prototype is declared in class Employee:
int Employee( const char *, const char * );
Выберите один ответ. a. Employee( const char *, const char * );
Question 73
Баллов: 1
Output operations are supported by class ___________.
Выберите один ответ.
c. ostream
Question 78
Баллов: 1
Which of the following accesses a variable in structure b?
Выберите один ответ.
c. b.var;
Question 79
Баллов: 1
All variables must be given a type when they are declared.
Ответ:
True
Question 80
Баллов: 1
Output the address of the variable myString of type char *
Выберите один ответ.
c. cout << static_cast< void * >( myString )
Question 81
Баллов: 1
Every function's body is delimited by left and right braces ({ and }).
Ответ:
True
Question 83
Баллов: 1
Which of the following is not valid identifier?
Выберите один ответ.
b. class
Question 84
Баллов: 1
Which of the following is a correct comment?
Выберите один ответ.
b. /* Comment */
Question 86
Баллов: 1
A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator.
Ответ:
False
Question 90
Баллов: 1
What value gets printed by the program?
#include <iostream>
int foo(int y);
int foo(int x)
{
return x+1;
}
int main(int argc, char** argv)
{
int x = 3;
int y = 6;
std::cout << foo(x) << std::endl;
return 0;
}
Выберите один ответ.
b. 4
Question 92
Баллов: 1
Which of the following is a properly defined struct?
Выберите один ответ. a. struct a_struct {int a;};
Question 93
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++zPtr;
Выберите один ответ.
b.
zPtr = z;
++zPtr;
Question 94
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 12 ];
strcpy( s, "Welcome Home");
Выберите один ответ. a.
char s[ 13 ];
strcpy( s, "Welcome Home");
Question 96
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// assign array element 2 (the value 3) to number
number = *zPtr[ 2 ];
Выберите один ответ.
b. number = zPtr[ 2 ];
Question 97
Баллов: 1
Each parameter in a function header should specify both a TYPE and a NAME .
Question 98
Баллов: 1
All variables must be declared before they are used.
Ответ:
True
Question 99
Баллов: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char str[] = "fresh meat";
cout << strlen(str);
return 0;
}
Выберите один ответ.
d. 10
Question 100
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
!( ((count < 10) || (x < y)) && (count >= 0) )
Выберите один ответ. a. false
Preparation for Final Exam MCQ Quiz BIG - Попытка 1
Страница: 1 2 3 4 5 6 7 8 9 10 (Далее)
Question 1
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
if ( strcmp( string1, string2 ) )
cout << "The strings are equal" << endl;
Выберите один ответ.
a. if ( strcmp( string1, string2 ) == 0)
cout << "The strings are equal" << endl;
Question 2
Баллов: 1
The stream manipulators dec, oct and hex affect only the next integer output operation
Ответ:
False
Question 3
Баллов: 1
Which of the following is the proper keyword to allocate memory?
Выберите один ответ. a. new
Question 4
Баллов: 1
Write a declaration for the following: Double-precision, floating-point variable lastVal that is to retain its value between calls to the function in which it is defined.
Выберите один ответ.
c. static double lastVal;
Question 5
Баллов: 1
$$1 Select the best answer to the output of the program:
#include<iostream>
usingnamespace std;
int main() {
double y = 3;
double *x = &y;
cout << x << " " << x+1 << " " << *x+1;
return 0;
}
Выберите один ответ.
e. 002BF7E4 002BF7E8 4
Question 6
Баллов: 1
The address operator & can be applied only to constants and to expressions
Ответ:
False
Question 7
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Compare the string in s1 with the string in s2, and print the result.
Выберите один ответ.
c. cout << "strcmp(s1, s2) = " << strcmp( s1, s2 ) << endl;
Question 8
Баллов: 1
Program components in C++ are called ________ and ________.
Выберите один ответ. a. functions, classes
Question 9
Question 10
Баллов: 1
If I do not want to use return in my function myFunc() what I have to speciafy as return type?
Выберите один ответ.
a. void
Question 12
Баллов: 1
Correct mistake in the statement below:
using namespase std;
Выберите один ответ. a. using namespace std;
Question 13
Баллов: 1
Find the error in the following program segment:
int sum( int n )
{
if ( n == 0 )
return 0;
else
n + sum( n - 1 );
}
Выберите один ответ.
c. int sum( int n )
{
if ( n == 0 )
return 0;
else
return n + sum( n - 1 );
}
Question 14
Баллов: 1
When using parameterized manipulators, the header file ____________ must be included
Выберите один ответ. a. <iomanip>
Question 15
Баллов: 1
Prompt the user to enter an integer. End your prompting message with a colon ( followed by a space and leave the cursor positioned after the space.
Выберите один ответ.
c. std::cout << "Enter an integer: ";
Question 16
Баллов: 1
The ________ qualifier is used to declare read-only variables
Выберите один ответ.
a. const
Question 17
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 10 ];
cout << strncpy( s, "hello", 5 ) << endl;
Выберите один ответ.
c. cout << strncpy( s, "hello", 6 ) << endl;
Question 20
Баллов: 1
Why would a function prototype contain a parameter type declaration such as double &?
Выберите один ответ.
c. This creates a reference parameter of type "reference to double" that enables the function to modify the original variable in the calling function
Question 22
Баллов: 1
Find the error(s) in the following code segment:
switch ( n )
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Выберите один ответ.
c. switch ( n )
{
case 1:
cout << "The number is 1" << endl;
break;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Question 23
Баллов: 1
Which of the following is the proper keyword to deallocate memory?
Выберите один ответ.
d. delete
Question 24
Баллов: 1
Assuming that nPtr points to the beginning of array numbers (the starting address of the array is at location 1002500 in memory), what address is referenced by nPtr + 8?
Выберите один ответ.
c. The address is 1002500 + 8 * 8 = 1002564
Question 25
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the value of the object pointed to by fPtr to variable number2.
Выберите один ответ.
c. number2 = *fPtr;
Question 26
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address of number1.
Выберите один ответ.
b. cout << "The address of number1 is " << &number1 << endl;
Question 28
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
!(count == 12)
Выберите один ответ. a. true
Question 29
Баллов: 1
__________ must be used to initialize constant members of a class
Выберите один ответ.
c. Member initializers
Question 31
Баллов: 1
Which of the following is not valid identifier?
Выберите один ответ.
c. namespace
Question 33
Баллов: 1
Which is not a protection level provided by classes in C++?
Выберите один ответ. a. hidden
Question 34
Баллов: 1
Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters
Выберите один ответ.
c. cout << uppercase;
Question 38
Баллов: 1
Write one or more statements that perform the following task for and array called “fractions”. Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop.
Выберите один ответ.
c. for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < i << "] = " << fractions[ i ] << endl;
Question 41
Баллов: 1
The expression ( x > y && a < b ) is true if either the expression x > y is true or the expression a < b is true
Ответ:
False
Question 42
Баллов: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 10;
for (a=1; a<81; a*=3)
cout << a << " ";
cout << endl;
return 0;
}
Выберите один ответ.
b. 1 3 9 27
Question 45
Баллов: 1
Calculate the remainder after q is divided by divisor and assign the result to q. Write this statement two different ways.
Выберите по крайней мере один ответ:
b. q %= divisor;
f. q = q % divisor;
Question 46
Баллов: 1
Correct the mistakes:
#include<iostream>
usingnamespace std;
double func();
{
double a = 3.14159;
cout << a << endl;
}
int main()
{
cout << "pi=" << func() << endl;
return 0;
}
Выберите один ответ.
e.
#include <iostream>
using namespace std;
double func()
{
double a = 3.14159;
return a;
}
int main()
{
cout << “pi=” << func() << endl;
return 0;
}
Question 47
Баллов: 1
Empty parentheses following a function name in a function prototype indicate that the function does not require any parameters to perform its task
Ответ:
True
Question 49
Баллов: 1
Which of the following is not valid identifier?
Выберите один ответ.
c. return
Question 50
Баллов: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 5;
do {
cout << a;
a--;
} while (a>0);
return 0;
}
Выберите один ответ.
d. 54321
Question 51
Баллов: 1
The escape sequence \n, when output with cout and the stream insertion operator, causes the cursor to position to the beginning of the next line on the screen.
Ответ:
True
Question 52
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// use pointer to get first value of array
number = zPtr;
Выберите один ответ.
c. number = *zPtr;
Question 54
Баллов: 1
The ostream member function ___________ is used to perform unformatted output
Выберите один ответ. a. write
Question 55
Баллов: 1
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 1.667 to array element 9
Выберите один ответ.
b. fractions[ 9 ] = 1.667;
Question 56
Баллов: 1
Find the error in the following program segment and correct the error:
Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
a[ 1, 1 ] = 5;
Выберите один ответ.
b. a[ 1 ][ 1 ] = 5;
Question 57
Баллов: 1
A pointer is a variable that contains as its value the____________ of another variable
Выберите один ответ. a. address
Question 58
Баллов: 1
Declare a pointer nPtr that points to a variable of type double
Выберите один ответ. a. double *nPtr;
Question 59
Баллов: 1
Which of the following is a two-dimensional array?
Выберите один ответ.
d. int anarray[20][20];
Question 61
Баллов: 1
Give the function header for the following function. Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.
Выберите один ответ.
d. double hypotenuse( double side1, double side2)
Question 63
Баллов: 1
Write single C++ statements that determine whether i is less than or equal to y
Выберите один ответ.
c. if (i<=y)
Question 64
Баллов: 1
The cout stream normally is connected to the display screen
Ответ:
True
Question 66
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign to ptr the location of the first token in s2. The tokens delimiters are commas (,).
Выберите один ответ. a. ptr = strtok( s2, ",");
Question 67
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Declare the variable fPtr to be a pointer to an object of type double.
Выберите один ответ.
b. double *fPtr;
Question 68
Баллов: 1
Write a C++ statement or a set of C++ statements to print the integers from 1 to 20 using a while loop and the countervariable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character; otherwise, print a tab character.]
Выберите один ответ. a. x = 1;
while ( x <= 20 )
{
cout << x;
if ( x % 5 == 0 )
cout << endl;
else
cout << '\t';
x++;
}
Question 69
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
(count == 1) && (x < y)
Выберите один ответ.
b. false
Question 70
Баллов: 1
Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr
Выберите один ответ.
b.
numbers[ 3 ]
*( numbers + 3 )
nPtr[ 3 ]
*( nPtr + 3 )
Question 71
Баллов: 1
Declare an array of type double called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9.
Assume that the symbolic constant SIZE has been defined as 10.
Выберите один ответ.
b. double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
Question 72
Баллов: 1
Find the error(s) in the following and correct it (them).
Assume the following prototype is declared in class Employee:
int Employee( const char *, const char * );
Выберите один ответ. a. Employee( const char *, const char * );
Question 73
Баллов: 1
Output operations are supported by class ___________.
Выберите один ответ.
c. ostream
Question 78
Баллов: 1
Which of the following accesses a variable in structure b?
Выберите один ответ.
c. b.var;
Question 79
Баллов: 1
All variables must be given a type when they are declared.
Ответ:
True
Question 80
Баллов: 1
Output the address of the variable myString of type char *
Выберите один ответ.
c. cout << static_cast< void * >( myString )
Question 81
Баллов: 1
Every function's body is delimited by left and right braces ({ and }).
Ответ:
True
Question 83
Баллов: 1
Which of the following is not valid identifier?
Выберите один ответ.
b. class
Question 84
Баллов: 1
Which of the following is a correct comment?
Выберите один ответ.
b. /* Comment */
Question 86
Баллов: 1
A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator.
Ответ:
False
Question 90
Баллов: 1
What value gets printed by the program?
#include <iostream>
int foo(int y);
int foo(int x)
{
return x+1;
}
int main(int argc, char** argv)
{
int x = 3;
int y = 6;
std::cout << foo(x) << std::endl;
return 0;
}
Выберите один ответ.
b. 4
Question 92
Баллов: 1
Which of the following is a properly defined struct?
Выберите один ответ. a. struct a_struct {int a;};
Question 93
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++zPtr;
Выберите один ответ.
b.
zPtr = z;
++zPtr;
Question 94
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 12 ];
strcpy( s, "Welcome Home");
Выберите один ответ. a.
char s[ 13 ];
strcpy( s, "Welcome Home");
Question 96
Баллов: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// assign array element 2 (the value 3) to number
number = *zPtr[ 2 ];
Выберите один ответ.
b. number = zPtr[ 2 ];
Question 97
Баллов: 1
Each parameter in a function header should specify both a TYPE and a NAME .
Question 98
Баллов: 1
All variables must be declared before they are used.
Ответ:
True
Question 99
Баллов: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char str[] = "fresh meat";
cout << strlen(str);
return 0;
}
Выберите один ответ.
d. 10
Question 100
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
!( ((count < 10) || (x < y)) && (count >= 0) )
Выберите один ответ. a. false
Question: Every C++ program begins execution at the function:
main
Question: Every C++ statement ends with a(n):
semicolon
Question: What statement is used to make decisions:
if
Question: Comments cause the computer to print the text after the // on the screen when
the program is executed:
false
Question: The escape sequence \n, when output with cout and the stream insertion
operator, causes the cursor to position to the beginning of the next line on the screen
true
Question: All variables must be declared before they are used
true
Question: All variables must be given a type when they are declared
true
Question: C++ considers the variables number and NuMbEr to be identical
false
Question: Declarations can appear almost anywhere in the body of a C++ function
true
Question: The modulus operator (%) can be used only with integer operands
true
Question: The arithmetic operators *, /, %, + and all have the same level of precedence
false
Question: A C++ program that prints three lines of output must contain three statements
using cout and the stream insertion operator
false
Question: Declare the variables c, thisIsAVariable, q76354 and number to be of type int.
Int c, thisIsAVariable, q76354, number;
Question: Prompt the user to enter an integer. End your prompting message with a colon
(:) followed by a space and leave the cursor positioned after the space
std::cout << "Enter an integer: ";
Question: Read an integer from the user at the keyboard and store the value entered in
integer variable age.
std::cin >> age;
Question: If the variable number is not equal to 7, print "The variable number is not
equal to 7".
if ( number != 7 ) std::cout << "The variable number is not equal to 7\n";
Question: Print the message "This is a C++ program" on one line.
std::cout << "This is a C++ program\n";
Question: Print the message "This is a C++ program" with each word on a separate line.
std::cout << "This\nis\na\nC++\nprogram\n";
Question: Print the message "This is a C++ program" with each word separated from the
next by a tab. std::cout << "This\tis\ta\tC++\tprogram\n";
Question: Identify and correct the errors in the following statement (assume that the
statement using std::cout; is used):
if ( c < 7 );
cout << "c is less than 7\n";.
if ( c < 7 ) cout << "c is less than 7\n";
Question: Identify and correct the errors in the following statement (assume that the
statement using std::cout; is used):
if ( c => 7 ) cout << "c is equal to or greater than 7\n";
if ( c >= 7 ) cout << "c is equal to or greater than 7\n";
Question: A house is to a blueprint as a(n) _________ is to a class
object
Question: Every class definition contains keyword _________ followed immediately by
the class's name
class
Question: A class definition is typically stored in a file with the _________ filename
extension
.h
Question: Each parameter in a function header should specify both a(n) _________ and
a(n) _________.
type, name
Question: When each object of a class maintains its own copy of an attribute, the
variable that represents the attribute is also known as a(n) _________.
data member
Question: Keyword public is a(n) _________.
access specifier
Question: Return type _________ indicates that a function will perform a task but will
not return any information when it completes its task
void
Question: Function _________ from the <string> library reads characters until a newline
character is encountered, then copies those characters into the specified string
getline
Question: When a member function is defined outside the class definition, the function
header must include the class name and the _________, followed by the function name to
"tie" the member function to the class definition
binary scope resolution operator (::)
Question: The source-code file and any other files that use a class can include the class's
header file via an _________ preprocessor directive
#include
Question: By convention, function names begin with a capital letter and all subsequent
words in the name begin with a capital letter
false
Question: Empty parentheses following a function name in a function prototype indicate
that the function does not require any parameters to perform its task
true
Question: Data members or member functions declared with access specifier private are
accessible to member functions of the class in which they are declared
true
Question: Variables declared in the body of a particular member function are known as
data members and can be used in all member functions of the class
false
Question: Every function's body is delimited by left and right braces ({ and }).
true
Question: Any source-code file that contains int main() can be used to execute a program
true
Question: The types of arguments in a function call must match the types of the
corresponding parameters in the function prototype's parameter list
true
Question: What is the difference between a local variable and a data member?
A local variable is declared in the body of a function and can be used only from the point
at which it is declared to the immediately following closing brace. A data member is
declared in a class definition, but not in the body of any of the class's member functions.
Every object (instance) of a class has a separate copy of the class's data members. Also,
data members are accessible to all member functions of the class.
Question: Explain the purpose of a function parameter. What is the difference between a
parameter and an argument?
A parameter represents additional information that a function requires to perform its task.
Each parameter required by a function is specified in the function header. An argument is
the value supplied in the function call. When the function is called, the argument value is
passed into the function parameter so that the function can perform its task
Question: All programs can be written in terms of three types of control
structures:_________, __________and_________.
Sequence, selection and repetition
Question: The_________selection statement is used to execute one action when a
condition is true or a different action when that condition is false.
If…else
Question: Repeating a set of instructions a specific number of times is
called_________repetition
Counter-controlled or definite
Question: When it is not known in advance how many times a set of statements will be
repeated, a(n)_________value can be used to terminate the repetition
Sentinel, signal, flag or dummy
Question: Write four different C++ statements that each add 1 to integer variable x
x =+ 1; x += 1; ++x; x++;
Question: In one statement, assign the sum of the current value of x and y to z and
postincrement the value of x
z = x++ + y;
Question: Determine whether the value of the variable count is greater than 10. If it is,
print "Count is greater than 10."
if ( count > 10) cout << "Count is greater than 10" << endl;Question: Predecrement the variable x by 1, then subtract it from the variable total
total -= --x;
Question: Calculate the remainder after q is divided by divisor and assign the result to q.
Write this statement two different ways
q %= divisor;
q = q % divisor;
Question: Declare variables sum and x to be of type int
int sum, x;
Question: Set variable x to 1
x=1;
Question: Set variable sum to 0
sum=0;
Question: Add variable x to variable sum and assign the result to variable sum
sum+=x;
Question: Print "The sum is: " followed by the value of variable sum
cout << "The sum is: " << sum << end1;
Question: State the values of the variable after the calculation is performed. Assume that,
when a statement begins executing, all variables have the integer value 5:
product *= x++;
product = 25, x = 6;
Question: State the values of the variable after the calculation is performed. Assume that,
when a statement begins executing, all variables have the integer value 5:
quotient /= ++x;
quotient = 0, x = 6;
Question: Write single C++ statements that input integer variable x with cin and >>
cin>>x;
Question: Write single C++ statements that input integer variable y with cin and >>.cin >> y;
Question: Write single C++ statements that postincrement variable i by 1
i++;
Question: Write single C++ statements that determine whether i is less than or equal to y
if (i<=y)
Question: Write single C++ statements that output integer variable power with cout and
<<
cout << power << endl;
Question: Identify and correct the errors in the following code:
while ( c <= 5 )
{
product *= c;
c++;
while ( c <= 5 )
{
product *= c;
c++;
}
Question: Identify and correct the errors in the following code:
if ( gender == 1 )
cout << "Woman" << endl;
else;
cout << "Man" << endl;
if ( gender == 1 )
cout << "Woman" << endl;
else cout << "Man" << endl;
Question: Identify and correct the errors in the following code:
cin << value;
cin >> value;
Question: What is wrong with the following while repetition statement?
while ( z >= 0 )
sum += z;
The value of the variable z is never changed in the while statement. Therefore, if the loop
continuation condition (z >= 0) is initially true, an infinite loop is created. To prevent the
Infinite loop, z must be decremented so that it eventually becomes less than 0.
Question: The default case is required in the switch selection statement
false
Question: The break statement is required in the default case of a switch selection
statement to exit the switch properly
false
Question: The expression ( x > y && a < b ) is true if either the expression x > y is true
or the expression a < b is true
false
Question: An expression containing the || operator is true if either or both of its operands
are true
true
Question: Write a C++ statement or a set of C++ statements to sum the odd integers
between 1 and 99 using a for statement. Assume the integer variables sum and count have
been declared
sum = 0;
for ( count = 1; count <= 99; count += 2 ) sum += count;
Question: Write a C++ statement or a set of C++ statements to print the value
333.546372 in a field width of 15 characters with precisions of 1, 2 and 3. Print each
number on the same line. Left-justify each number in its field.
cout << fixed << left
<< setprecision( 1 ) << setw( 15 ) << 333.546372
<< setprecision( 2 ) << setw( 15 ) << 333.546372
<< setprecision( 3 ) << setw( 15 ) << 333.546372
<< endl;
Question: Write a C++ statement or a set of C++ statements to calculate the value of 2.5
raised to the power 3 using function pow. Print the result with a precision of 2 in a field
width of 10 positions
cout << fixed << setprecision( 2 ) << setw( 10 ) << pow( 2.5, 3 ) << endl;
Question: Write a C++ statement or a set of C++ statements to print the integers from 1
to 20 using a while loop and the counter variable x. Assume that the variable x has been
declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x %
5. When the value of this is 0, print a newline character; otherwise, print a tab character.]
x = 1;
while ( x <= 20 )
{
cout << x;
if ( x % 5 == 0 )
cout << endl;
else
cout << '\t';
x++;
}
Question: Find the error(s) in the following code segment:
x = 1;
while ( x <= 10 );
x++;
}x = 1;
while ( x <= 10 )
x++;
}
Question: Find the error(s) in the following code segment:
for ( y = .1; y != 1.0; y += .1 ) cout << y << endl;
for ( y = 1; y != 10; y++ ) cout << ( static_cast< double >( y ) / 10
) << endl;
Question: Find the error(s) in the following code segment:
switch ( n )
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
switch ( n )
{
case 1:
cout << "The number is 1" << endl;
break;
case 2: cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Question: Find the error(s) in the following code segment. The following code should
print the values 1 to 10:
n = 1;
while ( n < 10 ) cout << n++ << endl;
n = 1;
while ( n < 11 ) cout << n++ << endl;
Question: What variable is?
named part in a memory
Question: Program components in C++ are called ________ and ________.
functions, classes
A function is invoked with a(n) ________.
function call
Question: A variable that is known only within the function in which it is defined is
called a(n) ________.
local variable
Question: The ________ statement in a called function passes the value of an expression
back to the calling function
return
Question: The keyword ________ is used in a function header to indicate that a function
does not return a value or to indicate that a function contains no parameters
void
Question: The ________ of an identifier is the portion of the program in which the
identifier can be used
scope
Question: The three ways to return control from a called function to a caller are
________, ________ and ________.
return, return expression or encounter the closing right brace of a function.
Question: A(n)________ allows the compiler to check the number, types and order of
the arguments passed to a function.
function prototype
Question: Function ________ is used to produce random numbers
rand()
Question: Function ________ is used to set the random number seed to randomize a
program
srand()
Question: The storage-class specifiers are mutable, ________, ________, ________ and
________.
auto, register, extern, static
Question: Variables declared in a block or in the parameter list of a function are assumed
to be of storage class ________ unless specified otherwise
auto
Question: Storage-class specifier ________ is a recommendation to the compiler to store
a variable in one of the computer's registers
register
Question: A variable declared outside any block or function is a(n) ________ variable
global
Question: For a local variable in a function to retain its value between calls to the
function, it must be declared with the ________ storage-class specifier
static
Question: The six possible scopes of an identifier are ________, ________, ________,
________, ________ and ________.
function scope, file scope, block scope, function-prototype scope, class scope, namespace
scope
Question: A function that calls itself either directly or indirectly (i.e., through another
function) is a(n) ________ function
recursive
Question: A recursive function typically has two components: One that provides a means
for the recursion to terminate by testing for a(n) ________ case and one that expresses
the problem as a recursive call for a slightly simpler problem than the original call
base
Question: In C++, it is possible to have various functions with the same name that
operate on different types or numbers of arguments. This is called function ________.
overloading
Question: The ________ enables access to a global variable with the same name as a
variable in the current scope
unary scope resolution operator (::)
Question: The ________ qualifier is used to declare read-only variables
const
Question: A function ________ enables a single function to be defined to perform a task
on many different data types
template
Question: Give the function header for the following function. Function hypotenuse that
takes two double-precision, floating-point arguments, side1 and side2, and returns a
double-precision, floating-point result.
double hypotenuse( double side1, double side2)
Question: Give the function header for the following function. Function smallest that
takes three integers, x, y and z, and returns an integer.
Int smallest( int X, int y, int z)
Question: Give the function header for the following function. Function instructions that
does not receive any arguments and does not return a value. [Note: Such functions are
commonly used to display instructions to a user.]
Void instructions( void )
Question: Give the function header for the following function. Function intToDouble
that takes an integer argument, number, and returns a double-precision, floating-point
result.
double intToDouble( int number)
Question: Write a declaration for the following: Integer count that should be maintained
in a register. Initialize count to 0.
register int count = 0;
Question: Write a declaration for the following: Double-precision, floating-point
variable lastVal that is to retain its value between calls to the function in which it is
defined.
static double lastVal;
Question: Find the error in the following program segment:
int g( void)
{
cout << "Inside function g" << endl;
int h( void )
{
cout << "Inside function h" << endl;
}
}
Int g( void)
{
cout << "Inside function g" << endl;
}
Int h( void ) {
cout << "Inside function h" << endl;
}
Question: Find the error in the following program segment:
int sum( int x, int y )
{
int result;
result = x + y;
}
int sum( int x, int y )
{
return x + y;
}
Question: Find the error in the following program segment:
int sum( int n )
{
if ( n == 0 )
return 0;
else
n + sum( n - 1 );
}
int sum( int n )
{
if ( n == 0 )
return 0; else
return n + sum( n - 1 );
}
Question: Find the error in the following program segment
void f ( double a);
{
float a;
cout << a << endl;
}
Void f ( double a)
{
cout << a << endl;
}
Question: Find the error in the following program segment:
void product( void )
{
int a;
int b;
int c;
int result;
cout << "Enter three integers: ";
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is " << result;
return result;}
Void product( void )
{
int a;
int b;
int c;
Int result;
cout << "Enter three integers: ";
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is " << result;
}
Question: Why would a function prototype contain a parameter type declaration such as
double &?
This creates a reference parameter of type "reference to double" that enables the function
to modify the original variable in the calling function
Question: All arguments to function calls in C++ are passed by value
false
Question: Lists and tables of values can be stored in __________ or __________.
arrays, vectors
Question: The elements of an array are related by the fact that they have the same
________ and ___________.
name, type
Question: The number used to refer to a particular element of an array is called its
________.
subscript (or index)
Question: A(n) __________ should be used to declare the size of an array, because it
makes the program more scalable
constant variable
Question: The process of placing the elements of an array in order is called ________
the array
sorting
The process of determining if an array contains a particular key value is called
_________ the array
searching
Question: An array that uses two subscripts is referred to as a(n) _________ array
two-dimensional
Question: An array can store many different types of values
false
Question: An array subscript should normally be of data type float
false
Question: If there are fewer initializers in an initializer list than the number of elements
in the array, the remaining elements are initialized to the last value in the initializer list
false
Question: It is an error if an initializer list contains more initializers than there are
elements in the array
true
Question: An individual array element that is passed to a function and modified in that
function will contain the modified value when the called function completes execution
false
Question: Write one or more statements that perform the following task for and array
called “fractions”. Define a constant variable arraySize initialized to 10.
const int arraySize = 10;
Question: Write one or more statements that perform the following task for and array
called “fractions”. Declare an array with arraySize elements of type double, and initialize
the elements to 0.
double fractions[ arraySize ] = { 0.0};
Question: Write one or more statements that perform the following task for and array
called “fractions”. Name the fourth element of the array
fractions[ 3 ]
Question: Write one or more statements that perform the following task for and array
called “fractions”. Refer to array element 4
fractions[ 4 ]
Question: Write one or more statements that perform the following task for and array
called “fractions”. Assign the value 1.667 to array element 9
fractions[ 9 ] = 1.667;
Question: Write one or more statements that perform the following task for and array
called “fractions”. Assign the value 3.333 to the seventh element of the array
fractions[ 6 ] = 3.333;
Question: Write one or more statements that perform the following task for and array
called “fractions”. Print array elements 6 and 9 with two digits of precision to the right of
the decimal point.
cout << fixed << setprecision ( 2 ); cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl;
Question: Write one or more statements that perform the following task for and array
called “fractions”. Print all the array elements using a for statement. Define the integer
variable i as a control variable for the loop.
for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < i << "] = " << fractions[ i ] <<
endl;
Question: Declare the array to be an integer array and to have 3 rows and 3 columns.
Assume that the constant variable arraySize has been defined to be 3:
Int table[ arraySize ][ arraySize];
Question: Write a program segment to print the values of each element of array table in
tabular format with 3 rows and 3 columns. Assume that the array was initialized with the
declaration
int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } };
and the integer variables i and j are declared as control variables.
cout << " [0] [1] [2]" << endl;
for ( int i = 0; i < arraySize; i++ ) { cout << '[' << i << "] ";
for ( int j = 0; j < arraySize; j++ )
cout << setw( 3 ) << table[ i ][ j ] << " ";
cout << endl;
Question: Find the error in the following program segment and correct the error:
#include <iostream>;
#include <iostream>
Question: Find the error in the following program segment and correct the error:
arraySize = 10; // arraySize was declared const
const int arraySize=10;
Question: Find the error in the following program segment and correct the error:
Assume that int b[ 10 ] = { 0 };
for ( int i = 0; <= 10; i++ )
b[ i ] = 1;
for ( int i = 0; <= 9; i++ )
b[ i ] = 1;
Question: the error in the following program segment and correct the error:
Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
a[ 1, 1 ] = 5;
a[ 1, 1 ] = 5;
Question: A pointer is a variable that contains as its value the____________ of another
variable
address
Question: The three values that can be used to initialize a pointer
are_____________,__________ and___________.
0, Null, an address
Question: The only integer that can be assigned directly to a pointer is_____________.
0
Question: The address operator & can be applied only to constants and to expressions
false
Question: A pointer that is declared to be of type void * can be dereferenced
false
Question: Pointers of different types can never be assigned to one another without a cast
operation
false
Question: Declare an array of type double called numbers with 10 elements, and
initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9. Assume that the symbolic
constant SIZE has been defined as 10
double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
Question: Declare a pointer nPtr that points to a variable of type double
double *nPtr;
Question: Use a for statement to print the elements of array numbers using array
subscript notation. Print each number with one position of precision to the right of the
decimal point:
cout << fixed << showpoint << setprecision( 1 );
for ( int i = 0; i < SIZE; i++ )
cout << numbers[ i ] <<' ';
Question: Write two separate statements that each assign the starting address of array
numbers to the pointer variable nPtr.
nPtr = numbers;
nPtr = &numbers[ 0 ];
Question: Use a for statement to print the elements of array numbers using pointer/offset
notation with pointer nPtr
cout << fixed << showpoint << setprecision( 1 );
for ( int j = 0; j < SIZE; j++ )
cout << *( nPtr + j ) << ' ';
Question: Use a for statement to print the elements of array numbers using pointer/offset
notation with the array name as the pointer
cout << fixed << showpoint << setprecision( 1 );
for ( int k = 0; k < SIZE; k++ )
cout << *( numbers + k ) << ' ';
Question: Use a for statement to print the elements of array numbers using
pointer/subscript notation with pointer nPtr
cout << fixed << showpoint << setprecision( 1 );
for ( int m = 0; m < SIZE; m++ )
cout << nPtr[ m ] << ' ';
Question: Refer to the fourth element of array numbers using array subscript notation,
pointer/offset notation with the array name as the pointer, pointer subscript notation with
nPtr and pointer/offset notation with nPtr
numbers[ 3 ]
*( numbers + 3 )
nPtr[ 3 ]
*( nPtr + 3 )
Question: Assuming that nPtr points to the beginning of array numbers (the starting
address of the array is at location 1002500 in memory), what address is referenced by
nPtr + 8?
The address is 1002500 + 8 * 8 = 1002564
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Declare
the variable fPtr to be a pointer to an object of type double.
double *fPtr;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Assign the
address of variable number1 to pointer variable fPtr.
fPtr = &number1;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Print the
value of the object pointed to by fPtr.
cout << "The value of *fPtr is " << *fPtr << endl;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Assign the
value of the object pointed to by fPtr to variable number2.
number2 = *fPtr;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Print the
value of number2.
cout << "The value of number2 is " << number2 << endl;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Print the
address of number1.
cout << "The address of number1 is " << &number1 << endl;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Print the
address stored in fPtr.
cout << "The address stored in fPtr is " << fPtr << endl;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Copy the
string stored in array s2 into array s1.
strcpy( s1, s2 );
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Compare
the string in s1 with the string in s2, and print the result.
cout << "strcmp(s1, s2) = " << strcmp( s1, s2 ) << endl;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Append
the first 10 characters from the string in s2 to the string in s1.
strncat( s1, s2, 10 );
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Determine
the length of the string in s1, and print the result.
cout << "strlen(s1) = " << strlen( s1 ) << endl;
Question: Write a single statement that performs the specified task. Assume that
floating-point variables number1 and number2 have been declared and that number1 has
been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1
and s2 are each 100-element char arrays that are initialized with string literals. Assign to
ptr the location of the first token in s2. The tokens delimiters are commas (,).
ptr = strtok( s2, ",");
Question: Write the function header for a function called exchange that takes two
pointers to double-precision, floating-point numbers x and y as parameters and does not
return a value
Void exchange( double *X, double *y )
Question: Write the function header for a function called evaluate that returns an integer
and that takes as parameters integer x and a pointer to function poly. Function poly takes
an integer parameter and returns an integer.
Int evaluate( int X, int (*poly)( int ))
Question: Write two statements that each initialize character array vowel with the string
of vowels, "AEIOU".
char vowel[] = "AEIOU";
char vowel[] = { 'A', 'E', 'I', 'O', 'U', '\0' };
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++zPtr;
zPtr = z;
++zPtr;
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// use pointer to get first value of array
number = zPtr;
number = *zPtr;
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// assign array element 2 (the value 3) to number
number = *zPtr[ 2 ];
number = zPtr[ 2 ];
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// print entire array z
for ( int i = 0; i <= 5; i++ ) cout << zPtr[ i ] << endl;
for ( int i = 0; i < 5; i++ ) cout << zPtr[ i ] << endl;
Question: Find the error in the following program segment. Assume the following
declarations and statements:int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// assign the value pointed to by sPtr to number
number = *sPtr;
number = *static_cast< int * >( sPtr );
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++z;
++z[4];
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 10 ];
cout << strncpy( s, "hello", 5 ) << endl;
cout << strncpy( s, "hello", 6 ) << endl;
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 12 ];
strcpy( s, "Welcome Home");
char s[ 13 ];
strcpy( s, "Welcome Home");
Question: Find the error in the following program segment. Assume the following
declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
if ( strcmp( string1, string2 ) )
cout << "The strings are equal" << endl;
if ( strcmp( string1, string2 ) == 0)
cout << "The strings are equal" << endl;
Question: What (if anything) prints when the following statement is performed?Assume
the following variable declarations:char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strcpy( s3, s2 ) << endl;
jill
Question: What (if anything) prints when the following statement is performed?Assume
the following variable declarations:
char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strcat( strcat( strcpy( s3, s1 ), " and " ), s2 ) << endl;
jack and jill
Question: What (if anything) prints when the following statement is performed?Assume
the following variable declarations:
char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strlen( s1 ) + strlen( s2 ) << endl;
8
Question: What (if anything) prints when the following statement is performed?Assume
the following variable declarations:
char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strlen( s3 ) << endl;
13
Question: Class members are accessed via the ________ operator in conjunction with the
name of an object (or reference to an object) of the class or via the ___________ operator
in conjunction with a pointer to an object of the class
dot (.), arrow (->)
Question: Class members specified as _________ are accessible only to member
functions of the class and friends of the class
private
Question: Class members specified as _________ are accessible anywhere an object of
the class is in scope
public
Question: __________ can be used to assign an object of a class to another object of the
same class
Default memberwise assignment (performed by the assignment operator).
Question: Find the error(s) in the following and correct it (them).
Assume the following prototype is declared in class Time:
void ~Time( int );
~Time( );
Question: Find the error(s) in the following and correct it (them).
The following is a partial definition of class Time:
class Time
{
public:
// function prototypes
private:
int hour = 0;
int minute = 0;
int second = 0;
}; // end class Time
class Time
{
public:
// function prototypes
Time (int my_hour, int my_minute, int my_second)
{
hour=my_hour;
minute=my_minute;
second=my_second;
}
private:
Int hour;
Int minute;
Int second;
}; // end class Time
Question: Find the error(s) in the following and correct it (them).
Assume the following prototype is declared in class Employee:
int Employee( const char *, const char * );
Employee( const char *, const char * );
Question: __________ must be used to initialize constant members of a class
Member initializers
Question: A nonmember function must be declared as a(n) __________ of a class to
have access to that class's private data members.
Friend
Question: The __________ operator dynamically allocates memory for an object of a
specified type and returns a __________ to that type.
new, pointer
Question: A constant object must be __________; it cannot be modified after it is
created
Initialized
Question: A(n) __________ data member represents class-wide information
static
Question: An object's non-static member functions have access to a "self pointer" to the
object called the __________ pointer
this
Question: The keyword __________ specifies that an object or variable is not modifiable
after it is initialized
const
Question: If a member initializer is not provided for a member object of a class, the
object's __________ is called
default constructor
Question: A member function should be declared static if it does not access __________
class members
non-static
Question: Member objects are constructed __________ their enclosing class object
before
Question: The __________ operator reclaims memory previously allocated by new.
delete
Question: Find the errors in the following class and explain how to correct them:
class Example
{
public: Example( int y = 10 )
: data( y )
{
// empty body
} // end Example constructor
int getIncrementedData() const
{
return data++;
} // end function getIncrementedData
static int getCount()
{
cout << "Data is " << data << endl;
return count;
} // end function getCount
private:
int data;
static int count;
}; // end class Example
Error: The class definition for Example has two errors. The first occurs in function
getIncrementedData. The function is declared const, but it modifies the object.
Correction: To correct the first error, remove the const keyword from the definition of
getIncrementedData.
Error: The second error occurs in function getCount. This function is declared static, so it
Is not allowed to access any non-static member of the class.
Correction: To correct the second error, remove the output line from the getCount
definition.
Question: Input/output in C++ occurs as ____________ of bytes
streams
Question: The stream manipulators that format justification are_________, _________
and _______.
left, right and internal
Question: Member function _________ can be used to set and reset format state
flags
Question: Most C++ programs that do I/O should include the _________ header file that
contains the declarations required for all stream-I/O operations.
<iostream>
Question: When using parameterized manipulators, the header file ____________ must
be included
<iomanip>
Question: Header file __________ contains the declarations required for user-controlled
file processing
<fstream>
Question: The ostream member function ___________ is used to perform unformatted
output
write
Question: Input operations are supported by class __________.
Istream
Question: Outputs to the standard error stream are directed to either the ___________ or
the ___________ stream object
cerr or clog
Question: Output operations are supported by class ___________.
ostream
Question: The symbol for the stream insertion operator is ____________.
<<
Question: The four objects that correspond to the standard devices on the system include
_________, _________, __________ and ___________.
cin, cout, cerr and clog
Question: The symbol for the stream extraction operator is __________
>>
Question: The stream manipulators ___________, __________ and ___________
specify that integers should be displayed in octal, hexadecimal and decimal formats,
respectively
oct, hex and dec
Question: When used, the _________ stream manipulator causes positive numbers to
display with a plus sign.
showpos
Question: The stream member function flags with a long argument sets the flags state
variable to its argument and returns its previous value.
false
Question: The stream insertion operator << and the stream-extraction operator >> are
overloaded to handle all standard data typesincluding strings and memory addresses
(stream-insertion only)and all user-defined data types.
false
Question: The stream member function flags with no arguments resets the stream's
format state
false
Question: The stream extraction operator >> can be overloaded with an operator function
that takes an istream reference and a reference to a user-defined type as arguments and
returns an istream reference.
true
Question: The stream insertion operator << can be overloaded with an operator function
that takes an istream reference and a reference to a user-defined type as arguments and
returns an istream reference
false
Question: Input with the stream extraction operator >> always skips leading white-space
characters in the input stream, by default
true
Question: The stream member function rdstate returns the current state of the stream
true
Question: The cout stream normally is connected to the display screen
true
Question: The stream member function good returns TRUE if the bad, fail and eof
member functions all return false
true
Question: The cin stream normally is connected to the display screen
false
Question: If a nonrecoverable error occurs during a stream operation, the bad member
function will return TRue
true
Question: Output to cerr is unbuffered and output to clog is buffered
true
Question: Stream manipulator showpoint forces floating-point values to print with the
default six digits of precision unless the precision value has been changed, in which case
floating-point values print with the specified precision
true
Question: The ostream member function put outputs the specified number of characters
false
Question: The stream manipulators dec, oct and hex affect only the next integer output
operation
false
Question: By default, memory addresses are displayed as long integers
falseQuestion: Output the string "Enter your name: "
cout << "Enter your name: ";
Question: Use a stream manipulator that causes the exponent in scientific notation and
the letters in hexadecimal values to print in capital letters
cout << uppercase;
Question: Output the address of the variable myString of type char *
cout << static_cast< void * >( myString );
Question: Use a stream manipulator to ensure floating-point values print in scientific
notation
cout << scientific;
Question: Output the address in variable integerPtr of type int *.
cout << integerPtr;
Question: Use a stream manipulator such that, when integer values are output, the
integer base for octal and hexadecimal values is displayed.
cout << showbase;
Question: Output the value pointed to by floatPtr of type float *.
cout << *floatPtr;
Question: Use a stream member function to set the fill character to '*' for printing in field
widths larger than the values being output. Write a separate statement to do this with a
stream manipulator
cout.fill( '*' );
cout << setfill( '*' );
Question: Output the characters '0' and 'K' in one statement with ostream function put
cout.put( '0' ).put( 'K' );
Question: Member function read cannot be used to read data from the input object cin
false
Question: The programmer must create the cin, cout, cerr and clog objects explicitly
false
Question: A program must call function close explicitly to close a file associated with an
ifstream, ofstream or fstream object.
false
Question: If the file-position pointer points to a location in a sequential file other than
the beginning of the file, the file must be closed and reopened to read from the beginning
of the file
false
Question: The ostream member function write can write to standard-output stream cout
true
Question: Data in sequential files always is updated without overwriting nearby data
false
Question: Searching all records in a random-access file to find a specific record is
unnecessary
true
Question: Records in random-access files must be of uniform length
false
Question: Member functions seekp and seekg must seek relative to the beginning of a
file
false
Question: A selection sort application would take approximately ________ times as long
to run on a 128-element vector as on a 32-element vector.
16, because an O(n2) algorithm takes 16 times as long to sort four times as much
information
Question: The efficiency of merge sort is ______
O(n log n).
Add variable x to variable sum and assign the result to variable sum
sum+=x;
An expression containing the || operator is true if either or both of its operands are true
true
A function is invoked with a(n) ________.
function call
A variable that is known only within the function in which it is defined is called a(n) ________.
local variable
A(n)________ allows the compiler to check the number, types and order of the arguments passed to a function.
function prototype
A variable declared outside any block or function is a(n) ________ variable
global
A function that calls itself either directly or indirectly (i.e., through another function) is a(n) ________ function
recursive
A recursive function typically has two components: One that provides a means for the recursion to terminate by testing for a(n) ________ case and one that expresses the problem as a recursive call for a slightly simpler problem than the original call
Base
All programs can be written in terms of three types of control structures:_________, __________and_________.
Sequence, selection and repetition
Any source-code file that contains int main() can be used to execute a program
true
A class definition is typically stored in a file with the _________ filename extension
.h
A house is to a blueprint as a(n) _________ is to a class
object
A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator
false
All variables must be given a type when they are declared
true
All variables must be declared before they are used
true
A function ________ enables a single function to be defined to perform a task on many different data types
template
All arguments to function calls in C++ are passed by value
false
A(n) __________ should be used to declare the size of an array, because it makes the program more scalable
constant variable
An array that uses two subscripts is referred to as a(n) _________ array
two-dimensional
An array can store many different types of values
false
An array subscript should normally be of data type float
False
An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution
false
A pointer is a variable that contains as its value the____________ of another variable
address
A pointer that is declared to be of type void * can be dereferenced
false
Assuming that nPtr points to the beginning of array numbers (the starting address of the array is at location 1002500 in memory), what address is referenced by nPtr + 8?
The address is 1002500 + 8 * 8 = 1002564
A nonmember function must be declared as a(n) __________ of a class to have access to that class's private data members.
friend
A constant object must be __________; it cannot be modified after it is created
initialized
A(n) __________ data member represents class-wide information
static
An object's non-static member functions have access to a "self pointer" to the object called the __________ pointer
this
A member function should be declared static if it does not access __________ class members
non-static
A program must call function close explicitly to close a file associated with an ifstream, ofstream or fstream object.
false
A selection sort application would take approximately ________ times as long to run on a 128-element vector as on a 32-element vector.
16, because an O(n2) algorithm takes 16 times as long to sort four times as much information
By convention, function names begin with a capital letter and all subsequent words in the name begin with a capital letter
false
By default, memory addresses are displayed as long integers
false
Class members specified as _________ are accessible only to member functions of the class and friends of the class
private
Class members specified as _________ are accessible anywhere an object of the class is in scope
public
__________ can be used to assign an object of a class to another object of the same class
Default memberwise assignment (performed by the assignment operator).
Class members are accessed via the ________ operator in conjunction with the name of an object (or reference to an object) of the class or via the ___________ operator in conjunction with a pointer to an object of the class
dot (.), arrow (->)
Comments cause the computer to print the text after the // on the screen when the program is executed
false
C++ considers the variables number and NuMbEr to be identical
false
Calculate the remainder after q is divided by divisor and assign the result to q. Write this statement two different ways
q %= divisor; q = q % divisor;
Repeating a set of instructions a specific number of times is called_________repetition
Counter-controlled or definite
Return type _________ indicates that a function will perform a task but will not return any information when it completes its task
void
Read an integer from the user at the keyboard and store the value entered in integer variable age.
std::cin >> age;
Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr
numbers[ 3 ] *( numbers + 3 ) nPtr[ 3 ] *( nPtr + 3 )
Read an integer from the user at the keyboard and store the value entered in integer variable age.
std::cin >> age;
Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr
numbers[ 3 ] *( numbers + 3 ) nPtr[ 3 ] *( nPtr + 3 )
Records in random-access files must be of uniform length
false
Declare variables sum and x to be of type int
int sum, x;
Determine whether the value of the variable count is greater than 10. If it is, print "Count is greater than 10."
if ( count > 10) cout << "Count is greater than 10" << endl;
Data members or member functions declared with access specifier private are accessible to member functions of the class in which they are declared
true
Declare the variables c, thisIsAVariable, q76354 and number to be of type int.
int c, thisIsAVariable, q76354, number;
Declarations can appear almost anywhere in the body of a C++ function
true
Declare the array to be an integer array and to have 3 rows and 3 columns. Assume that the constant variable arraySize has been defined to be 3:
int table[ arraySize ][ arraySize];
Declare an array of type double called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9. Assume that the symbolic constant SIZE has been defined as 10
double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
Declare a pointer nPtr that points to a variable of type double
double *nPtr;
Data in sequential files always is updated without overwriting nearby data
false
Set variable x to 1
x=1;
Set variable sum to 0
sum=0;
State the values of the variable after the calculation is performed. Assume that, when a statement begins executing, all variables have the integer value 5: product *= x++;
product = 25, x = 6;
State the values of the variable after the calculation is performed. Assume that, when a statement begins executing, all variables have the integer value 5: quotient /= ++x;
quotient = 0, x = 6;
Storage-class specifier ________ is a recommendation to the compiler to store a variable in one of the computer's registers
register
Stream manipulator showpoint forces floating-point values to print with the default six digits of precision unless the precision value has been changed, in which case floating-point values print with the specified precision
true
Searching all records in a random-access file to find a specific record is unnecessary
true
Print "The sum is: " followed by the value of variable sum
cout << "The sum is: " << sum << end1;
Predecrement the variable x by 1, then subtract it from the variable total
total -= --x;
Print the message "This is a C++ program" with each word separated from the next by a tab
std::cout << "This\tis\ta\tC++\tprogram\n";
Program components in C++ are called ________ and ________.
functions, classes
Print the message "This is a C++ program" with each word on a separate line
std::cout << "This\nis\na\nC++\nprogram\n";
Print the message "This is a C++ program" on one line
std::cout << "This is a C++ program\n";
Prompt the user to enter an integer. End your prompting message with a colon (:) followed by a space and leave the cursor positioned after the space
