Test #3
0
no permissions
The function that accepts pointers to two C-strings and an integer argument that indicates how many characters to copy from the second string to the first is
strncpy
In C++11, you can use a new type of enum known as a(n) __________ (also known as anenum class) to have multiple enumerators with the same name, within the same scope.
strongly typed enum
A library function that can find one C-string inside another is
strstr
Objects in an array are accessed with _________.
subscripts
2
write
3
write and execute
grep
Searches files for particular pattern (word, string in single quotes, or a regular expression); grep <what looking for>
What is the output of the following statement?cout << tolower(toupper('Z')) << endl;
lowercase z
A function ______ return a structure.
may
A pointer variable is designed to store
memory address
The ________ and ________ operators can be used to increment or decrement a pointer variable.
++,--
What will the following code output? int number = 22; int *var = &number; cout << *var << endl;
22
Given the string shown below, if the delimiter is a space, how many tokens are in the string?"Tony's email address is [email protected]"
5
If Circle is a a structure, what does the following statement do? Circle *pcirc = nullptr;
It declares a structure pointer called pcirc initialized with a null pointer.
cd
Move between directories, change directory, cd <directory name or ~> (home)'
pwd
Prints current working directory; which directory you are currently working in; shows you the absolute path (from the root) to the present working directly; type 'pwd'
Which code segment is more efficient? Segment 1 int num =0; cout<< "Enter in a number..."; cin>> num; Segment 2 int num =0; cout<< "Enter in a number..."; cin>> num; num *= 1;
Segment 1
Which code segment is more efficient? Segment 1int num =0; cout<< "Enter in a number..."; cin>> num; cout<<"num divide by 2 is = "<<num/2; Segment 2 int num =0; cout<< "Enter in a number..."; cin>> num; num /= 2; cout<<"num divide by 2 is = "<<num;
Segment 1
Which code segment is more efficient? Segment 1 bool bIsSenior = True; int grade; cout<< "Enter in your grade..."; cin>> grade; if (( grade >= 90) || bIsSenior) cout << "Congrats"; Segment 2 bool bIsSenior = True; int grade; cout<< "Enter in your grade..."; cin>> grade; if (bIsSenior || ( grade >= 90)) cout << "Congrats";
Segment 2
Which code segment is more efficient? Segment 1 int grade; cout<< "Enter in your grade..."; cin>> grade; if ( grade >= 90) cout << "A"; else if ((grade >= 70)&&(grade < 80) cout << "C"; else if ((grade >= 80)&&(grade < 90) cout << "B "; Segment 2 int grade; cout<< "Enter in your grade..."; cin>> grade; if ( grade >= 90) cout << "A"; else if (grade >= 80) cout << "B"; else if (grade >= 70) cout << "C";
Segment 2
Which code segment is more efficient? Segment 1 int grade; cout<< "Enter in your grade..."; cin>> grade; while ( grade < 0) { while !( grade >= 0) { cout<< "Enter in your grade..."; cin>> grade; } } Segment 2 int grade; cout<< "Enter in your grade..."; cin>> grade; while ( grade < 0) { cout<< "Enter in your grade..."; cin>> grade; }
Segment 2
You may use a pointer to a structure as a
Structure member, function return type, function parameter ALL OF THESE
When you work with a dereferenced pointer, you are actually working with
The actual value of the variable whose address is stored in the pointer variable
What will the following code output? int number = 22; int *var = &number; cout << var << endl;
The address of the number variable
If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with
The integer 0 or the value NULL
Which of the following is TRUE about this statement? sum += *array++;
This statement assigns the dereferenced pointer's value, then increments the pointer's address.
Destructor functions are often used to free memory that was allocated by the object.
True
If you do not declare a destructor function, the compiler will furnish one automatically.
True
In object-oriented programming, the object encapsulates both the data and the functions that operate on the data.
True
More than one constructor function may be defined for a class.
True
When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.
True
Given the following structure decaration, idNum is struct Employee { string name; int idNum; };
a member
Given the following structure decaration, Employee is struct Employee { string name; int idNum; };
a tag
A pointer variable may be initialized with
a valid address in the computer's memory
A ________ search is more efficient than a ________ search.
binary, linear
When a structure is passed ______ to a function, its members are NOT copied.
by reference
Which of the following statements appropriately defines a C-string that stores names of up to 25 characters?
char name[26];
Assuming dataFile is a file stream object, the following statement:dataFile.close();
closes a file
In C++11 you can have one constructor call another constructor in the same class by using
constructor delegation
A ________ is a member function that is automatically called when a class object is ________.
constructor, created
cp
copy a file or directory, cp <sourcefile> (name of source file alone, or the path and filename of the source ) <destination file> (new destination filename, a new destination location, or combo of both), cp sourcefile destinationfile
Which of the following statements deletes memory that has been dynamically allocated for an array?
delete [] array;
Members of the class object are accessed with the
dot operator
The C-string company[12] can hold
eleven characters and the null terminator
Which of the following assigns a value to the hourlyWage member of employee[2]?
employee[2].hourlyWage = 75.00
Given the following decaration: enum Tree { OAK, MAPLE, PINE }; What is the value of the following relational expression? OAK > PINE
false
Passing a structure as a constant reference parameter to a function
guarantees not to result in changes to the structure's members
To write read data from a file, you define an object of the ________ data type.
ifstream
With pointer variables you can ________ manipulate data stored in other variables.
indirectly
When the body of a member function is defined inside a class declaration, it is said to be
inline
Which of the following statements is NOT valid C++ code?
int ptr = &num1; int ptr = int num1; *float num1 = &ptr2; ALL OF THESE ARE INVALID
mv
move a file or directory, mv sourcefile destinationfile
In C++ a C-string is a sequence of characters stored in consecutive memory, terminated by a
null character
Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?
outFile << number;
If you do NOT declare an access specification, the default for members of a class is
private
Which type of member function may only be called from a function that is a member of the same class?
private
Examples of access specifiers are the key words
private and public
In the following statement, what does int mean? int *ptr = nullptr;
ptr is a pointer variable and will store the address of an integer variable.
After the code shown executes, which of the following statements is TRUE? int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers; ptr++;
ptr will hold the address ofnumbers[1]
The type of member function that may be called from a statement outside the class is
public
rmdir
remove directory; rmdir dirname (name of new directory you want to delete)
If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used.
scope
A function may return a pointer but the programmer must ensure that the pointer
still points to a valid object after the function ends
The following statement ________. cin >> *num3;
stores the keyboard input into the variable pointed to by num3
The ________ function concatenates the contents of one C-string with another C-string.
strcat
The function that accepts a pointer to a C-string as an argument and returns the length of the C-string, not including the null terminator is
strlen
A C++ class is similar to a(n)
structure
To dereference a structure pointer, the appropriate operator is
the -> operator
A structure pointer contains
the address of a structure variable
If a variable uses more than one byte of memory, for pointer purposes its address is
the address of the first byte of storage
Which of the following is automatically called when an object is destroyed?
the destructor function
Which of the following will allow you to access structure members?
the dot operator
In C++11, assuming mychar is a char variable and mystring is a string, what is the value of mychar after the following statement executes?mychar = mystring.front();
the first character of mystring
Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;
the value stored in the variable whose address is contained in ptr
A good reason to pass a structure as a constant reference is
to prevent changes to the structure's members
The arguments of the strcpy function are
two addresses
Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int?
unique_ptr uniq( new int );
The following statement __________. bookList[2].publisher[3] = 't';
will store the character 't' in the fourth element of the publisher member ofbookList[2]
grep patterns: special symbols
? - the preceding item is optional and matched at most once * - the preceding item will be matched zero or more times + - the preceding item will be matched one or more times . - this matches any single character
tar
A utility for creating and extracting archives, useful for archiving files on disk, sending a set of files over the network, and for compactly making backups; tar options filenames
Which of the following describes only the general characteristics of an object?
Abstraction
file permissions - chmod
Change file permissions, limit permissions to just yourself, or allow other people to access and run programs; chmod <permission list> <file or directory name>
1
execute
The null terminator stands for ASCII code
0
To determine whether a character entered is a letter of the alphabet, use the ________ function.
isalpha
To test whether a character is a printable character, use the ________ function.
isprint
Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once?
#ifndef
To allow file access in a program, you must use _________ in the header file.
#include fstream
tar command commonly used options
-c insert files into a tar file -f use the name of the tar file that is specified -v output the name of each file as it is inserted into or extracted from a tar file -x extract the files from a tar file -t list contents of an archive -z will gzip / gunzip if necessary tar -cvf test.tar *.txt (.tar file is a compressed file that contains all .txt files)
grep options
-i ignore case -n display the line numbers -l display only names of files and not actual lines grep -n est *.txt (shows line numbers for files that end in est.txt) grep '[T]' *.txt (uppercase t)
After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree { OAK, MAPLE, PINE };
1
What is the value stored in num after the following statement executes?num = atoi("1000");
1000
What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl;
2
Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ________ elements must be compared.
20,000
Which of the following will return true if the argument is a printable character other than a digit, letter or space?
ispunct
clear
Clears the current screen and displays the prompt at the top of the screen; only type 'clear'
The ________ sort usually performs fewer exchanges than the ________ sort.
selection, bubble
What does the following statement do? double *num2;
Declares a pointer variable named num2
diff
Differential file comparator; compares two text files/directories and prints the lines for which the files differ; diff [-options] <original file> <new file>
ls
Displays information about file, lists the contents of a directory; type 'ls', or 'ls -l' long file
Class objects can be defined prior to the class declaration.
False
More than one destructor function may be defined for a class.
False
The constructor function may not accept arguments.
False
If Circle is a structure, what does the following statement do? Circle *pcirc = nullptr;
It declares a structure pointer called pcirc initialized with a null pointer.
mkdir
Make a new directory: mkdir dirname (new directory you want to create)
What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) { val = x; } }; int main() { TestClass test(77); test.showVal(); return 0; }
The program will not compile
using wild cards
Wild card characters are the ? and * ; ? can be substituted in a filename, and it will represent any character in that position; ls a?.out (replace single character, list); * represents any number of characters in that position, ls a* (any file that begin with letter a), ls *.cpp (any can be in beginning, but cpp has to be at end)
Options for diff
[-b] Treats groups of spaces as one [-i] ignores case [-r] includes directories in comparison [-w] ignores all spaces and tabs diff -i test.txt test2.txt (won't show differences), diff test.txt test2.txt (will show case is different)
grep patterns
[1357] -matches one of these numbers [^1357] - does not match one of these numbers range expressions [b-g] - matches b,c,d,e,f,g named classes of expressions - [:digit:], [:alnum:]
man
\manual", and unix systems provide pages of the manual that can be accessed from the command prompt; man <command name>, contain all necessary info about the usage of a command, including the available parameters
more grep patterns
^ - matches the begining of the line $ - matches the end of line \< - matches the beginning of a workd \> - matches the end of a word | or operator grep '\<t' *.txt (word that begins w/ t that are type txt) if put -i, not case specific
Data types that are created by the programmer are known as
abstract data types (ADTs)
Every byte in the computer's memory is assigned a unique
address
Which of the following can be used as pointers?
array names
The function that accepts a C-string containing a number as its argument and returns the integer equivalent is
atoi
The function that converts a C-string to an integer and returns the integer value is
atoi
Which of the following converts the string "10" to the integer value 10?
atoi("10");
The function that accepts a C-string as an argument and converts the string to a long integer is
atol
In OOP terminology, an object's member variables are often called its ________ and its member functions can be referred to as its behaviors or its ________.
attributes, methods
When a constructor has a member initialization list, the initializations take place
before any statements in the body of the constructor execute.
A file _______ is a small holding section of memory that file-bound information is first written to.
buffer
A structure __________ contain members of the same data type.
can
Use the delete operator only on pointers that were
created with the new operator
Objects are created from abstract data types that encapsulate _______ and ________ together.
data, functions
A declaration for an enumerated type begins with the _________ key word.
enum
The following code shows an example of _________ class Point { private: double y = 5.70; double z = 3.0; public: //Public member functions go here };
in-place initialization
more/less
more - allows you to display a file one screenful at a time, scroll down not up;, less - allows the viewing of a file but also allows backware movement thru the file while viewing, as well as forward movement; more <file name>, less <file name>
Not all arithmetic operations can be performed on pointers. For example, you cannot _______ or ________ pointers.
multiply, divide
In C++11, the ________ keyword was introduced to represent address 0.
nullptr
How many default constructors can a class have?
only one
File permissions
r- read permission is allow w- write permission is allowed x- execute permission is allowed {r,w,e} chmod (_43) - owner chmod (2_3) - group chmod (24_) - other chmod 731 (owner full access, group write and execute, others execute)
4
read
5
read and execute
6
read and write
7
read, write, and execute
rm
remove files or directories; rm filename
To help prevent memory leak from occurring in C++11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used.
smart pointer
To write information to a file, use the
stream insertion operator
If Circle is a structure tag, then the following statement can be the header line for a function that ________. Circle doSomething(Circle c2)
takes a Circle structure as a parameter, does something, and returns a Circle structure
What is the result after the following statement executes? char var1 = tolower('A');
var1 stores the ASCII value for lowercase 'a'
For the following code, which statement is NOT true? class Point { private: double y; double z; public: double x; };
z is not available to code that is written outside the class.