Quiz
Intro to Prog. Final
This quiz has question types that open in the usual player.
Questions in this quiz (96)
1Which of the following is a valid variable name?
- Aspot 1
- B100bottles
- C_integerval1
- Dhello*tommy!
- Eteaminfo.name
- F!chosen
2Which way of initializing variables is incorrect?
- Aint x;
x = 10; - Bdouble amt(112.55);
- Cchar spot('a');
- Dconst int value;
value = 10; - Echar letter = 'C';
- Aint x;
3What const declaration is meaningful?
- Aconst int length;
- Bconst double value;
- Cconst bool = true;
4What is a literal?
- AA variable
- BConstant literal values written through code
- COnly an octal or hexadecimal value
- DA character or string
5Which of the following is not an escape sequence?
- A\r
- B\t
- C\n
- D\b
6When is a good time to use an escape sequence?
- AIntegers
- BC strings
- CDoubles
- DStructs
7What is the showpoint flag used for?
- ATo display decimals to the 2 place
- BSo decimal point will always be shown
- CSpecifies fixed point notation
- DTo change the bool operator
8What is the correct notation for adding a variable to another variable and setting it equal to the new value?
- Ax =+ y
- Bx += y
9What is pre-incrementing? ex. ++x
- ARuns before the rest of code on the line and returns new value to x for the rest of the code to execute
- BChanges the value of x by 1 before the code runs for the line
10What is post-incrementing? ex. x--
- AIncrements the x by 1 down after the code runs and returns the value to x
- BChanges the value of x by 1 on the next line
11Which of the following type conversions is illegal?
- Aint to double
- Bdouble to int
- Cdouble + int to double
12Which static cast conversion is legal & necessary?
- Achar c = static_cast<char>(int x)
- Bdouble d = static_cast<char>(int x)
- Cint x = static_cast<double>(char c)
13What is the difference between L and R operator
- AL is what is being given value, R is the value
- BR is what is being given value, L is the value
14Which of the following is the answer for the modulus 9 % 3?
- A3
- B1
- C0
15What are the values of q & r?
int x = 19, y = 5, q, r;
q = x / y;
r = x % y;- Aq is 3, r is 3
- Bq is 4, r is 4
- Cq is 3, r is 4
16After the following lines of code, what are q & r?
int x = 6, y = 7, q, r;
q = x + y % x;
r = q + x % y;
q %= r;- Aq is 7, r is 7
- Bq is 13, r is 7
- Cr is 13, q is 7
- Dq is 13, r is 13
- Eq is 6, r is 6
17What is an example of short-circuit evaluation?
- Abool x = true;
bool y = false;
if ( x && y)
cout << "run"; - Bbool x = true;
bool y = false;
if ( y && x)
cout << "run";
- Abool x = true;
18What is the modulus / % answer/output?
- AHow many times a number goes into another number
- BThe remainder after a number goes into another number fully as many times as it can without exceeding it
19What is wrong with the following code?
if (x == 1 || 2 || 3)- ANo ;
- BOnly needs one =
- CAsking if x equals 1, or 2 or 3 is true, which are always true instead of if x is equal to 1, 2, or 2 which requires x== in each ||
20Which of the following case labels is legal in a switch block?
- Acase 1.2:
- Bcase (3 || 4):
- Ccase 'a':
- Dcase 2-7:
21A do while loop only executes the body of the loop if the while statement is true
- ATrue
- BFalse
22A while loop always executes the body at least once
- ATrue
- BFalse
23A const variable must be initialized the same time it is declared
- ATrue
- BFalse
24All switch statements must have a default case
- ATrue
- BFalse
25Names of variables are required in the function prototype, but types are optional
- ATrue
- BFalse
26An int + a double will result in type double
- ATrue
- BFalse
27int x = 10, y = 4, z =2, w;
w = x - y * z;
cout << w;
This prints 4- ATrue
- BFalse
28Variables in the declaration of for loops are declared within the scope of what the for loop is declared in
- ATrue
- BFalse
29if ( 2 == 2 || 2 > 1) is an example of short circuit evaluation
- ATrue
- BFalse
30It is legal to initialize a variable equal to what a function
- ATrue
- BFalse
31int x = 5;
cout << 3 + x;
Is this a legal operation?- ATrue
- BFalse
32It is illegal to cout a void function
- ATrue
- BFalse
33What happens after a case if a break is not included in it?
- AIt runs all the cases below it
- BIt runs the cases below it until it ends the switch case or runs a break statement
34Which of the following will evaluate to a random integer in the range of 20-50?
- Arand() % 20
- Brand() % 30
- Crand() % 31 + 20
35What library is pow and sqrt in?
- A<iostream>
- B<fstream>
- C<cmath>
- D<math>
36What must be in a declaration of a function?
- AFunction name, parameter list, definition
- BFunction name, return type, function header
- CFunction name, parameter list, return type
- DFunction name, definition, return type
37What must each parameter of a function have?
- AValue
- BName
- CType
- DComma after it
38Each function prototype must have what after it?
- APeriod
- BSemi-colon
- CReturn type
- DBracket
39A builder of a function is the declaration and definition, while the caller is what summons the function to use
- ATrue
- BFalse
40A void function never returns anything
- ATrue
- BFalse
41A void function never prints anything out, while other kinds always do
- ATrue
- BFalse
42What is necessary to have in a functions when they share a name?
- ADifferent return type
- BDifferent parameter list
- CSame return type
- DDifferent function definitions
43How are default parameters given value?
- ABy initiliazing the variables value within main
- BBy initiliazing the variables within the function prototype
44Where must multiple default parameters lie in the parameter list?
- AThe beginning
- BThe middle
- CThe end
45Which of the default parameters makes the overloaded functions illegal?
- Aint DoSomething (int x, double y = 10);
int Do Something (int z, double k); - Bint DontDo (char z, char k = 'a');
int DontDo (char z, double t2); - Cdouble DoIt (int x);
int DoIt (int x, double y);
- Aint DoSomething (int x, double y = 10);
46What is needed to randomly generate a number?
- A#include <cstdlib>, #include <ctime>, srand(time(0)), rand()
- Bsrand(time(0)), rand()
- C#include <cstdlib>, srand(), rand()
- Dsrand(), rand(0
47How do you pass a variable by reference to a function?
- ABy passing the function a variable that is a reference variable
- BBy setting variable passed to function as a reference variable to same variable within function
- CBy putting a & after parameter type in prototype and definition
48If a variable is passed by reference to a function, if changes are made to the variable it is in the function, it is changed in the original variable
- ATrue
- BFalse
49Passing by value to a function will change the original variable
- ATrue
- BFalse
50What does passing by value to a function do to original variable?
- AMake a copy
- BSend its location to the function
- CReduce its storage
51An array is
- AAny set of any types of data that uses consecutive memory locations
- BAn indexed list of ints, doubles, and character values
- Ca set of data, under one name, that can contain anything
- DAn indexed collection of data elements of the same type
52Are any of the following illegal?
int things [5];
things[0] = 2;
things[3] = 1000;
things[5] = 4;- ATrue
- BFalse
53What does toupper and tolower need to have to return a char?
- AFunction
- BVariable to store the value
- CStatic cast
- DArray
54Array storage is consecutive
- ATrue
- BFalse
55Which of the following statements declares a character array that can be used as a c-string?
- Achar arr[] = {'t', 'o', 'm'}
- Bchar arr[] = "tommy";
56int things[7] = {1, 2, 3, 4, 5, 23, 22};
Which of the following is illegal?- Adouble x = things[1] - things[0];
- Bthings [1] = things[3] * things[4];
- Ccin >> things[7];
- Dthings[2] = -10288;
57What must the last character of a c string be?
- A'\n'
- B'\0'
- C'\N'
- D'0'
58Which extracts and discards the delimiter?
- AGet
- BGetline
59The format for getline/get is cin.get(where to store, length, char delimiter)
- ATrue
- BFalse
60What is the default delimiter or get/getline
- A/t
- B/0
- C/n
- D/o
61The >> operator stops at any blank space, including a space or new line when reading in
- ATrue
- BFalse
62Which of the following is the last character of a c string/char array?
- A'\n'
- B'\N'
- C'\0'
- D'\o'
63What kind of type is the name of an array act as?
- Aint
- Bchar
- C[]
- Dpointer
64Arrays are passed by reference to functions because they are just memory addresses
- ATrue
- BFalse
65Passing an array to a function and putting const in front of it will not guarantee the array will be changed
- ATrue
- BFalse
66string a = "cop3014";
cout << a + " rocks" << '/t' << a;- Acop3014 rocks a
- Ba rocks a
- Ccop3014 rocks cop3014 rocks
- Dcop3014 rocks cop3014
67string s1 = "Fish";
string s2 = "bait";
string s3;
s3 = s1 + s2;
cout << s3 //prints Fishbait
Is this true?- ATrue
- BFalse
68string s1 = "Hello, how are you?";
cout << s1[5];
What does this print?- Al
- Bo
- C,
- D"space"
69What are the four ways to initialize a pointer?
- AThrough a pointer of a same type
- BNull pointer
- CThrough a pointer of a different type
- DAn int
- EAddress of operator '&'
- FDynamically allocated memory of the same type
70When a pointer is passed to a function, it is by value
- ATrue
- BFalse
71Passing something by address to a function makes whatever happen to it in the function, occurs to the actual data
- ATrue
- BFalse
72An array's variable is a pointer to the first object of the array
- ATrue
- BFalse
73*ptr = 1000;
cout << *ptr + 10;
What does this print out?- A1040
- B1010
- C990
74If a function's parameter calls for a pointer, an array may also be passed
- ATrue
- BFalse
75Any array is a pointer to which value in it?
- AAll
- BFirst
- CLast
- DNone
76Passing a pointer by const to a function serves what purpose?
- AAllows parameter passing w/o anything but an address
- BMakes the variable the pointer points to const
- CMakes the data unchangeable through the pointer
- DProtects against the data from changing in the function
77A null pointer stores the address of 1 and has a valid target
- ATrue
- BFalse
78Which of the following choices is the correct way to initialize dynamically allocated array?
- Aint * ptr = new int [size];
- Bint ptr = new int;
- Cnew int * ptr = int[size];
- Dnew arr int[size];
79Which of the following steps are wrong in dynamically resizing an array that is declared as int arr.
- Aint * temp[size +addon] = new int;
- Bfor (int i = 0; i < size; i++)
- C{
temp[i] = arr[i] - Ddelete arr [];
- Earr = temp;
80What's the difference between formatted text and binary files?
- AA text file has different fonts, styles and formatting while binary files are made up of raw text
- BA text file has different stylization while binary files are made up of 1s and 0s
- CA text file is made up of readable text characters, while a binary file is composed of unformatted data in raw memory format
81The difference between a sequential file and random access file is that seqeuntial files can read or write records in place w/o affecting the rest of the file while random access reads from start to finish
- ATrue
- BFalse
82Pair the objects cout and cin with the correct classes
- Acout: ifstream
cin: iostream - Bcout: ostream
cin: istream - Ccout: iostream
cin: ifstream
- Acout: ifstream
83ofstream is used for files to be read and ifstream is used for files to be changed
- ATrue
- BFalse
84Which is the correct way to attach a file to an ofstream or ifstream object called object1?
- Aopen.object1("file.txt")
- Bopen("file.txt").object1
- Copen.object1.file.txt
- Dobject1.open("file.txt')
85If in1 is an ifstream object, if(!in1) runs only if there is not a valid input file attached to in1.
- ATrue
- BFalse
86If file is an ostream object, file << "hello" saves hello into the file variable
- ATrue
- BFalse
87What does the following code do?
ifstream file;
file.open("txtfile.txt")
int x, x2, x3;
file >> x >> x2 >> x3;- ASaves x, x2, and x3 into the text file
- BSaves x, x2 and x3 into file
- CSaves 3 integers from the attached text file into x, x2, and x3
- DSaves the next 3 user entered integers into x, x2 and x3 and then into the text file
88ofstream fout; // create file stream
fout.open("file.txt", ios::app);
This code will open a file in append mode. If a file is not opened in append mode, if something is written to it, the entire old file will be replaced before that occurs- ATrue
- BFalse
89What is a struct?
- AAn array of arrays
- BA collection of data units encapsulated into one unit
- CMultiple types of data in one variable
- DA variable used to store multiple other variables
90The name of the structure becomes a new type
- ATrue
- BFalse
91What is the correct way to initialize the int size in the struct info?
- Ainfo.size = 10;
- Bint size = 10;
- Csize.info = 10;
92Fraction f1 = {3, 5};
Is this a valid way to initialize the struct f1?- ATrue
- BFalse
93struct fraction;
fraction f1;
fraction * ptr = &f1;
How would one initialize the name element of f1 by using the pointer ptr?- Aptr.name = "data";
- Bname.ptr = "data";
- C*ptr.name="data";
- D(*ptr).name = "data";
94ptr->num = is the same as coding (*ptr).num =
- ATrue
- BFalse
95If the code is present below, how do you define the manager's last name? [blank_start]__[blank_end]
struct name
{
string first;
string last;
};
struct person
{
name personal;
name manager;
}
person tom;- Atom.manager.last =
96What should be placed as the functions parameter in the prototype to pass a struct name to it?
- A(name)
- B(struct name)
- C(struct)
- D(name tommy)
Information
- Description
- Quiz on Intro to Prog. Final, created by Tommy McDonald on 04/12/2015.
- Author
- Tommy McDonald
- Language
- English
- Views
- 0
- Rating
- No ratings yet Rate this quiz