CMPSCI 121 Flashcards

1
Q

Ch1 - Both main memory and secondary storage are types of memory. Describe the difference between the two.

A

Main memory, or RAM, is volatile, which means its contents are erased when power is removed from the computer. Secondary memory, such as a disk, does not lose its contents when power is removed from the computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Ch1- What is the difference between system software and application software?

A

An OPERATING SYSTEM is a set of programs that manages the computer’s hardware devices and controls their processes. Application software consists of programs that users use to solve specific problems or perform general operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Ch1- What type of software controls the internal operations of the computers hardware?

A

An operating system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Ch1- Why must program written in a high-level language be translated into machine language before they can be run?

A

Because the computer only processes machine language instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Ch1- Why is it easier to write a program in a high-level language than in machine language?

A

Because high level languages are more like natural language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

h1- Explain the difference between an object file and an executable file?

A

An object file contains machine language instructions, but it does not contain code for any library routines that may be necessary. An executable file is a program, ready to run. It contains the machine language code translated from the programmer’s source file, as well as the code for any necessary library routines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Ch1- What is the difference between a syntax error and a logical error?

A

A syntax error is the misuse of a key word, operator, punctuation, or other part of the programming language. A logical error is a mistake that causes the program to produce the wrong results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Ch1- Computers can do many different jobs because they can be _____

A

programmed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Ch1- The job of the ______ is to fetch instructions, carry out the operations commanded by the instructions, and produce some outcome or resultant information.

A

CPU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Ch1- Internally, the CPU consists of the _____ and the ______

A

Arithmetic Logic Unit and Control Unit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Ch1- A(n) _____ is an example of a secondary storage device.

A

disk

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Ch1- The two general categories of software are _____ and_____

A

Operating Systems and Application Software

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Ch1- A program is a set of _____

A

instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Ch1- Since computers can’t be programmed in natural human language, algorithms must be written in a(n)_____ language.

A

programming language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Ch1- ________ is the only language computers really process>

A

machine language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Ch1- ______ languages are close to the level of humans in terms of vocabulary

A

high-level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Ch1- ______ languages are close to the level of the computer

A

Low-level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Ch1- A program’s ability to run on several different types of computer systems is called_____

A

portability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Ch1- Words that have special meaning in a programming language are called

A

Key Words

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Ch1- Words or names defined by the programmer called

A

programmer-defined symbols

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Ch1- _____ are characters or symbols that perform operations on one or more operands

A

operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Ch1- _____ characters or symbols mark the beginning or end of programming statements, or separate items in a lint

A

punctuation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Ch1- The rules that must be followed when constructing a program are called ____

A

syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Ch1- A(n) ____ is named storage location

A

variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Ch1- A variable must be ____ before it can be used in a program
defined
26
Ch1- The three primary activities of a program _____, ____, and _____.
input, processing, output
27
Ch1- _____ is information a program gather from the outside world
input
28
Ch1- _____ is information a program sends to the outside world
output
29
Ch1- A(n) ____ is a diagram that graphically illustrates the structure of a program
Hierarchy Chart
30
Ch2- How many operands does each of the following types of operators require?
1 unary 2 binary 3 Ternary
31
Ch2- How may the double variables temp, weight, and age be defined in one statement?
double temp, weight, age;
32
Ch2- How may the int variables months, days, and years be defined in one statement, with months initialized to 2 and years initialized to 3?
int months = 2, days, years = 3;
33
Ch2- Write assignment statements that perform the following operations with the variables a, b, and c; A) Adds 2 to a and stores the result in b B) Multiples b by 4 and stores the result in a C) Divides a by 3.14 and stores the result in b D) Subtracts 8 from b and stores the result in a E) Stores the value 27 in a F) Stores the character 'K' in c G) Stores the ASC2 code for 'B' in c
``` A)b = a + 2; B)a = b * 4; C)b = a / 3.14; D)a = b - 8; E)a = 27; F)c = 'K'; G)c = 66; ```
34
``` Ch2- Is the following comment written using single-line or multi-line comment symbols? */ This program was written by M. A, Codewriter*/ ```
Multi-single line
35
``` Ch2- Is the following comment written using single line or multi line comment symbols // This program was written by M. A Codewriter ```
Single Line
36
Ch2- Modify the following program so it prints two blank lines between each line of text #include using namespace std; int main () { cout << " Two mandolins like creatures in the"; cout << "dark"; cout << " Creating the agony of ecstasy."; cout << " - George Barker"; return 0; }
``` #include int main() { cout << "Two mandolins like creatures in the\n\n\n"; cout << "dark\n\n\n"; cout << "Creating the agony of ecstasy.\n\n\n"; cout << " - George Barker\n\n\n"; return 0; } ```
37
Ch2- What will the following programs print out the screen? A) #include using namespace std; ``` int main () { int x = 0, y = 2; x = y * 4; cout << x << endl << y << endl; return 0; } ``` C) #include using namespace std; ``` int main () { cout << " I am the incredible"; cout << "computing\nmachine" ; cout << "\nand I will \namaze\n"; cout << "you."; return 0; } ``` D) #include using namespace std; ``` int main () { cout << " Be careful\n"; cout << " This might /n be a trick"; return 0; } ``` E) #include using namespace std; ``` int main () { int a, x = 23; a = x % 2; cout << x << endl << a << endl; return 0; } ```
A) 0 100 B) 8 2 ``` C) I am the incrediblecomputing machine and I will amaze you. ``` D) Be careful This might/n be a trick question E) 23 1
38
Ch2- Every complete statement ends with a(n) _____ A) Period B) #symbol C) semicolon D) ending brace
C
39
``` Ch2- Which of the following statements is correct A) #include (iostream) B) #include (iostream} C) #include D) # include {iostream} E) All of the above ```
C
40
Ch2- Every C++ Program must have a _____
function main
41
Ch2- Preprocessor directors begin with
#
42
``` Ch2- The following data 72 'A' " Hello World" 2.8712 are all examples of ```
Literals or constants
43
Ch2- A group of statements such as the contents of a function, is enclosed in ____
Braces
44
``` Ch2- Which of the following are NOT valid assignment statements? Select all that apply) A) total = 9; B) 72 = amount; C) profit = 129 D) letter = 'W; ```
B,C
45
Ch2- Assume w= 5, x = 4, y = 8, and z = 2. What value will be stored in result in each of the following statements? ``` A) result = x + y; B) result = z * 2; C) result = y / x; D) result = y - z; E) result = w % 2; ```
``` A) 12 B) 4 C) 2 D) 6 E) 1 ```
46
``` Ch2- How would each of the following numbers be represented in E notation? A) 3.287 x 10^6 B) -978.65 x 10^12 C) 7.65491 x 10^-3 D) -58710.23 x 10^-4 ```
A) 3.287E6 B) -978.65E12 C) 7.65491E-3 D)-58710.23E-4
47
``` Ch2- The negation operator is _____ A) unary B) binary C) ternary D) none of the above ```
A
48
Ch2- A(n) ______ is like a variable, but it's value is read-only and cannot be changed during the program's execution.
named constant
49
Ch2- When do preprocessor directives execute ?
A
50
Ch2- T/F | A variable must be defined before it can be used
True
51
Ch2- T/F | Variable names may begin with a number
False
52
Ch2- T/F | Variable names may be up to 31 characters long
True
53
Ch2- A left brace in a C++ program should always be followed by a right brace later
True
54
Ch2- You cannot initialize a named constant that is declared with the const modifier.
false
55
Ch2- Convert the following pseucode to C++ code. Be sure to define the appropriate variables - store 20 in the speed variable - store 10 in the time variable - multiply speed by time and store the result in the distance variable - display the contents of the
``` int speed, time, distance; speed = 20; time = 10; distance = speed * time; cout << distance << endl; ```
56
Ch2- Convert the following pseudocode to C++ code. Be sure to define the appropriate variables - store 172.5 in the force variable - store 27.5 in the area variable - Divide area by force and store the result in the pressure variable - Display the contents of the pressure variable
``` double force, area, pressure; force = 172.5; area = 27.5; pressure = force / area; cout << pressure << endl; ```
57
Ch2- There are a number of syntax errors in the following program. Locate as many as you can. ``` */ What's wrong with this program? /* #include iostream using namespace std; int main (): } int a, b, c \\ Three integers a = 3 b = 4 c = a + b Cout < "The value of c is %d" < C; return 0; { ```
The C-style comments symbols are backwards iostream should be enclosed in angle brackets.There shouldn’t be a semicolon after int main. The opening and closing braces of function main are reversed. There should be a semicolon after int a, b, c. The comment \\ Three integers should read // Three integers. There should be a semicolon at the end of the following lines: a = 3 b= 4 c = a + b cout begins with a capital letter. The stream insertion operator (that appears twice in the cout statement) should read << instead of
58
Ch3- Assume the following variables are defined: int age; double pay; char section; Write a single cin statement that will read input into each of these variables
in >> age >> pay >> section;
59
Ch3 Assume a string object has been defined as follows: string description A) Write a cin statement that reads in a one word string B) Write a statement that reads in a one word string.
A) cin >> description; | B) getline(cin, description);
60
Ch3- What header files must be included in the following program ``` int main () { double amount = 89.7; cout << showpoint << fixed; cout << setw(8) << amount << endl; return 0; } ```
iostream and iomanip
61
``` Ch3- Write C++ expressions for the following algebraic expressions a = 12x Z = 5x + 14y + 6K y = x^4 g = h + 12 / 4k c = a^2 / b^2 k^4 ```
``` a = 12 * x; z = 5 * x + 14 * y + 6 * k; y = pow(x, 4); g = (h + 12) / (4 * k); c = pow(a, 3) / (pow(b, 2) * pow(k, 4)); ```
62
Ch3- Assume a program has the following variable definitions: int units; float mass; double weight; and the following statement: weight = mass * units; Which automatic data type conversion will take place?
Units is prompted to a float, mass remains a float, and the result of mass * units is a double.
63
Ch3- Assume qty and salesreps are both integers. Use a type cast expression to rewrite the following statement so it will no longer perform integer division. unitsEach = qty / salesReps;
unitsEach = static_cast(qty) / salesRep;
64
Ch3- Rewrite the following variable definition so that the variable is a named constant. int rate;
const int RATE = 12;
65
``` Ch3- Write a multiple assignment statement that can be used instead of the following group of assignment statements: east = 1; west = 1; north = 1; south = 1; ```
east = west = north = south = 1;
66
Ch3 - Write a cout statement so the variable divSales is displayed in a field of 8 spaces, in fixed point notation, with a precision of 2 decimal places. The decimal point should always be displayed.
cout << setw(8) << fixed << showpoint | << setprecision(2) << divSales;
67
Ch3- Write a cout statement so the variable totalAge is displayed in a field of 12 spaces, in fixed point notation with a precision of decimal places.
cout << setw(12) << fixed | << setprecision(4) << totalAge;
68
Ch3 Write a cout statement so the variable population is displayed in a field of 12 spaces left-justified, with a precision of 8 decimals. The decimal point should always be displayed
cout << setw(12) << left << showpoint | << setprecision(8) << population;
69
Ch3- The _____ library function returns the cosine of an angle
cos
70
Ch3- The ____ library function returns the sine of an angle
sin
71
Ch3- The ____ library function returns the tangent of an angle
tan
72
Ch3- The ____ library function returns the exponential function of a number
exp
73
Ch3- The Library ____function returns the remainder of a floating-point division
fmod
74
The ___library ____the natural logarithm of a number
log
75
Ch4- Describe the difference between the if/else statement and a series of i f statements
n an if/elseif statement, the conditions are tested until one is found to be true. The conditionally executed statement(s) are executed and the program exits the if/elseif statement. In a series of if statements, all of the if statements execute and test their conditions because they are not connected.
76
Ch4- In an i f/ else if statement, what is the purpose of a trailing else?
The trailing else provides code that is executed when none of the conditions in the if/elseif statement are true.
77
Ch4- What is a flag and how does it work
A flag is a Boolean variable signaling that some condition exists in the program. When the flag is set to false it indicates the condition does not yet exist. When the flag is set to true it indicates that the condition does exist.
78
Ch4- Can an if statement test expression other than relational expressions? Explain
Yes. The if statement can test any value that yields a Boolean value (true or false) or a numeric value. When testing a numeric expression, a nonzero numeric value is considered true, and the value 0 is considered false.
79
Ch4- Briefly describe how the && operator works
It takes two expressions as operands and creates a single expression that is true only when both subexpressions are true.
80
Ch4- Briefly describe how the | | operator works
It takes two expressions as operands and creates a single expression that is true when either of the subexpressions are true.
81
Ch4- Why are the relational operators called relational?
Because they test for specific relationships between items. The relationships are greater-than, less-than, equal-to, greater-than or equal-to, less-than or equal-to, and not equal-to.
82
Ch4- Why do most programmers indent the conditionally executed statements in a decision structure?
It visually sets the conditionally-executed statements apart from the surrounding code. This is so you can easily identify the code that is conditionally-executed.
83
Ch4- An expression using the greater-than, less-than, greater than or equal to, less than or equal to, equal to or not equal to operator is called _____
Relational
84
Ch4- A relational expression is either ____ or ____
true, false
85
Ch4- The value of a relational expression is 0 if the expression is _____ or 1 if the expression is _____
false, true
86
Ch4- The If statement regards an expression with the value 0 as
false
87
Ch4- The if statement regards an expression with a nonzero value as
true
88
Ch4- For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of___
braces
89
Ch4- In an if /else statement, the if part executes its statement or block if the expression is _____ , and the else part executes its statement or block if the expression is ____
true, false
90
Ch4- The trailing else in an if/else if statement has a similar purpose as the ______ section of a switch statement
Default
91
Ch4- The if/else statement is actually a form of the ___ statement
nested
92
Ch4- If the subexpression on the left or the ____ logical operator is FALSE, the right subexpression is not checked.
&&
93
Ch4- If the subexpression on the left or the ____ logical operator is TRUE, the right subexpression is not checked
| |
94
Ch4- The ___ logical operator has higher precedence than the other logical operators
!
95
Ch4- The logical operators have ___ associativity.
left to right
96
Ch4- The ___ operator works best when testing a number to determine if it is within a range
&&
97
Ch-4 The ___ operator works best when testing a number to determine if it is outside a range
| |
98
Ch4- A variable with ____ scope is only visible when the program is executing in the block containing the variable's definition
block
99
Ch4- You use the ____ operator to determine whether one string object is greater than another string object.
>
100
Ch4- An expression using the conditional operator is called a(n) ____ expression
conditional
101
Ch4- The expression that is tested by a switch statement must have a(n) ___ value
integer
102
Ch4- The expression following a case statement must be a(n) _____ _____
integer constant
103
Ch4- A program will "fall through" a case section if it is missing the ____ statement
break