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
Q

Ch1- A variable must be ____ before it can be used in a program

A

defined

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

Ch1- The three primary activities of a program _____, ____, and _____.

A

input, processing, output

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

Ch1- _____ is information a program gather from the outside world

A

input

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

Ch1- _____ is information a program sends to the outside world

A

output

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

Ch1- A(n) ____ is a diagram that graphically illustrates the structure of a program

A

Hierarchy Chart

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

Ch2- How many operands does each of the following types of operators require?

A

1 unary
2 binary
3 Ternary

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

Ch2- How may the double variables temp, weight, and age be defined in one statement?

A

double temp, weight, age;

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

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?

A

int months = 2, days, years = 3;

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

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
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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q
Ch2- Is the following comment written using single-line or multi-line comment symbols?
*/ This program was written by M. A, Codewriter*/
A

Multi-single line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q
Ch2- Is the following comment written using single line or multi line comment symbols
// This program was written by M. A Codewriter
A

Single Line

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

include

Ch2- Modify the following program so it prints two blank lines between each line of text

using namespace std;
int main ()
{
cout &laquo_space;” Two mandolins like creatures in the”;
cout &laquo_space;“dark”;
cout &laquo_space;” Creating the agony of ecstasy.”;
cout &laquo_space;” - George Barker”;
return 0;
}

A
#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;
  }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

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

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

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

Ch2- Every complete statement ends with a(n) _____

A) Period
B) #symbol
C) semicolon
D) ending brace

A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q
Ch2- Which of the following statements is correct 
A) #include (iostream)
B) #include (iostream}
C) #include 
D) # include {iostream}
E) All of the above
A

C

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

Ch2- Every C++ Program must have a _____

A

function main

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

Ch2- Preprocessor directors begin with

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q
Ch2- The following data
          72
          'A'
          " Hello World"
          2.8712
are all examples of
A

Literals or constants

43
Q

Ch2- A group of statements such as the contents of a function, is enclosed in ____

A

Braces

44
Q
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;
A

B,C

45
Q

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
A) 12 
B) 4 
C) 2 
D) 6 
E) 1
46
Q
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

A) 3.287E6
B) -978.65E12
C) 7.65491E-3
D)-58710.23E-4

47
Q
Ch2- The negation operator is \_\_\_\_\_
A) unary 
B) binary 
C) ternary
D) none of the above
A

A

48
Q

Ch2- A(n) ______ is like a variable, but it’s value is read-only and cannot be changed during the program’s execution.

A

named constant

49
Q

Ch2- When do preprocessor directives execute ?

A

A

50
Q

Ch2- T/F

A variable must be defined before it can be used

A

True

51
Q

Ch2- T/F

Variable names may begin with a number

A

False

52
Q

Ch2- T/F

Variable names may be up to 31 characters long

A

True

53
Q

Ch2- A left brace in a C++ program should always be followed by a right brace later

A

True

54
Q

Ch2- You cannot initialize a named constant that is declared with the const modifier.

A

false

55
Q

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
A
int speed, time, distance;
speed = 20;
time = 10;
distance = speed * time;
cout << distance << endl;
56
Q

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
A
double force, area, pressure;
force = 172.5;
area = 27.5;
pressure = force / area;
cout << pressure << endl;
57
Q

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; 
{
A

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 &laquo_space;instead of

58
Q

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

A

in&raquo_space; age&raquo_space; pay&raquo_space; section;

59
Q

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

A) cin&raquo_space; description;

B) getline(cin, description);

60
Q

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;
}
A

iostream and iomanip

61
Q
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
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
Q

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?

A

Units is prompted to a float, mass remains a float, and the result of mass * units is a double.

63
Q

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;

A

unitsEach = static_cast(qty) / salesRep;

64
Q

Ch3- Rewrite the following variable definition so that the variable is a named constant.

int rate;

A

const int RATE = 12;

65
Q
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;
A

east = west = north = south = 1;

66
Q

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.

A

cout &laquo_space;setw(8) &laquo_space;fixed &laquo_space;showpoint

&laquo_space;setprecision(2) &laquo_space;divSales;

67
Q

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.

A

cout &laquo_space;setw(12) &laquo_space;fixed

&laquo_space;setprecision(4) &laquo_space;totalAge;

68
Q

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

A

cout &laquo_space;setw(12) &laquo_space;left &laquo_space;showpoint

&laquo_space;setprecision(8) &laquo_space;population;

69
Q

Ch3- The _____ library function returns the cosine of an angle

A

cos

70
Q

Ch3- The ____ library function returns the sine of an angle

A

sin

71
Q

Ch3- The ____ library function returns the tangent of an angle

A

tan

72
Q

Ch3- The ____ library function returns the exponential function of a number

A

exp

73
Q

Ch3- The Library ____function returns the remainder of a floating-point division

A

fmod

74
Q

The ___library ____the natural logarithm of a number

A

log

75
Q

Ch4- Describe the difference between the if/else statement and a series of i f statements

A

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
Q

Ch4- In an i f/ else if statement, what is the purpose of a trailing else?

A

The trailing else provides code that is executed when none of the conditions in the if/elseif statement are true.

77
Q

Ch4- What is a flag and how does it work

A

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
Q

Ch4- Can an if statement test expression other than relational expressions? Explain

A

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
Q

Ch4- Briefly describe how the && operator works

A

It takes two expressions as operands and creates a single expression that is true only when both subexpressions are true.

80
Q

Ch4- Briefly describe how the | | operator works

A

It takes two expressions as operands and creates a single expression that is true when either of the subexpressions are true.

81
Q

Ch4- Why are the relational operators called relational?

A

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
Q

Ch4- Why do most programmers indent the conditionally executed statements in a decision structure?

A

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
Q

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 _____

A

Relational

84
Q

Ch4- A relational expression is either ____ or ____

A

true, false

85
Q

Ch4- The value of a relational expression is 0 if the expression is _____ or 1 if the expression is _____

A

false, true

86
Q

Ch4- The If statement regards an expression with the value 0 as

A

false

87
Q

Ch4- The if statement regards an expression with a nonzero value as

A

true

88
Q

Ch4- For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of___

A

braces

89
Q

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 ____

A

true, false

90
Q

Ch4- The trailing else in an if/else if statement has a similar purpose as the ______ section of a switch statement

A

Default

91
Q

Ch4- The if/else statement is actually a form of the ___ statement

A

nested

92
Q

Ch4- If the subexpression on the left or the ____ logical operator is FALSE, the right subexpression is not checked.

A

&&

93
Q

Ch4- If the subexpression on the left or the ____ logical operator is TRUE, the right subexpression is not checked

A

|

94
Q

Ch4- The ___ logical operator has higher precedence than the other logical operators

A

!

95
Q

Ch4- The logical operators have ___ associativity.

A

left to right

96
Q

Ch4- The ___ operator works best when testing a number to determine if it is within a range

A

&&

97
Q

Ch-4 The ___ operator works best when testing a number to determine if it is outside a range

A

|

98
Q

Ch4- A variable with ____ scope is only visible when the program is executing in the block containing the variable’s definition

A

block

99
Q

Ch4- You use the ____ operator to determine whether one string object is greater than another string object.

A

>

100
Q

Ch4- An expression using the conditional operator is called a(n) ____ expression

A

conditional

101
Q

Ch4- The expression that is tested by a switch statement must have a(n) ___ value

A

integer

102
Q

Ch4- The expression following a case statement must be a(n) _____ _____

A

integer constant

103
Q

Ch4- A program will “fall through” a case section if it is missing the ____ statement

A

break