Ghostrogue - Programming Fundamentals I
Ghostrogue - Programming Fundamentals I
CH 1 CH 1 (cont) CH 1 (cont)
The basic commands that a computer T To develop a program to solve a T ____ represent information with a Digital
performs are input (get data), output problem, you start by analyzing sequence of 0s and 1s. Signals
(display result), storage, and performance the problem.
A sequence of eight bits is called byte
of arithmetic and logical operations.
C++ programs have always been F a ____.
Main memory is directly connected to the T portable from one compiler to
The digit 0 or 1 is called a binary bit
CPU. another.
digit, or ____.
When the computer is turned off, everything F Several categories of computers mainframe,
The term GB refers to ___ gigabyte
in secondary memory is lost. exist, such as ____. midsize,
____ consists of 65,536 Unicode
and micro
The devices that feed data and programs F characters.
into computers are called output devices. The basic commands that a input,
A program called a(n) ____ compiler
computer performs are ____, output,
Information stored in main memory must be T translates instructions written in
transferred to some other device for and performance of arithmetic storage
high-level languages into machine
permanent storage. and logical operations.
code.
Main memory is called ____. random
The device that stores information F A program called a(n) ____ linker
access
permanently (unless the device becomes combines the object program with
unusable or you change the information by memoryq
the programs from libraries.
rewriting it) is called primary storage. The ____ is the brain of the CPU
A program that loads an loader
The command that does the linking on F computer and the single most
executable program into main
expensive piece of hardware in
Visual C++ 2012 Express and Visual memory is called a(n) ____.
your personal computer.
Studio 2012 is Make or Remake.
A step-by-step problem-solving algorithim
Main memory is an ordered memory
When you compile your program, the F process in which a solution is
compiler identifies the logic errors and sequence of items, called ____. cells
arrived at in a finite amount of time
suggests how to correct them. The devices that feed data and input
is called a(n) ____.
programs into computers are
Dividing a problem into smaller structured
called ____ devices.
subproblems is called ____
The devices that the computer output design.
uses to display results are called
A(n) ____ consists of data and the object
____ devices.
operations on those data.
____ programs perform a Application
specific task.
The programming language C++ evolved C A comma is also called a F The expression static_cast(6.9) + 13
from ____. statement terminator. static_cast(7.9) evaluates to ____.
Suppose that alpha and beta are int alpha = The extraction operator >> skips only all F Suppose that x is an int variable and y x=
variables and alpha = 5 and beta = 50 leading blanks when searching for the next is a double variable and the input is: 10, y
10. After the statement alpha *= beta; data in the input stream. 10 20.7 Choose the values after the =
executes, ____. following statement executes: cin >> x 20.7
When reading data into a char variable, T
>> y;.
Suppose that sum and num are int sum = after skipping any leading whitespace
variables and sum = 5 and num = 15 characters, the extraction operator >> finds Suppose that x and y are int variables. cin
10. After the statement sum += num and stores only the next character; reading Which of the following is a valid input >> x
executes, ____. stops after a single character. statement? >> y;
Insertion Point 1 alpha = Entering a char value into an int variable T Suppose that x is an int variable, y is a x=
beta; causes serious errors, called input failure. double variable and ch is a char 15,
beta = If input failure occurs in a C++ program, the F variable and the input is: 15A 73.2 ch =
beta + program terminates immediately and Choose the values after the following 'A', y
1; displays an error message. statement executes: cin >> x >> ch >> =
y; 73.2
In an output statement, each occurrence of F
CH 3 Suppose that x is an int variable, ch is B ch
endl advances the cursor to the end of the
current line on an output device. a char variable, and the input is: 276. = '2',
It is a good idea to redefine cin and cout in F
x=
your programs You can use the function getline to read a T
76
In the statement cin >> x; , x can be a F string containing blanks
Suppose that alpha is an int variable alpha
variable or an expression
and ch is a char variable and the input = 17,
The following statements will result in input F
is: 17A What are the values after the ch =
failure if the input values are not on a
following statements execute? cin » 'A'
separate line. (Assume that x and y are int
alpha; cin » ch;
variables.) cin >> x; cin >> y;
Suppose that x is an int variable, y x = 15, Y Suppose that ch1 and ch2 are char ch1 = Suppose that alpha, beta, and 300
is a double variable, z is an int = 76 . 3 , variables, alpha is an int variable, and 'A', gamma are int variables and the
variable, and the input is: 15 76.3 z = 14 the input is: A 18 What are the values ch2 = input is: 100 110 120 200 210 220
14 Choose the values after the after the following statement ," 300 310 320 What is the value of
following statement executes: cin executes? cin.get(ch1); cin.get(ch2); alpha gamma after the following
>> x >> y >> z; cin >> alpha; = 18 statements execute? cin >> alpha;
cin.ignore(100, '\n'); cin >> beta;
Suppose that ch1, ch2, and ch3 'C' Suppose that ch1, ch2, and ch3 are 'B'
cin.ignore(100,'\n'); cin >> gamma;
are variables of the type char and variables of the type char and the
the input is: A B C Choose the input is: A B C What is the value of Suppose that ch1 and ch2 are char W
value of ch3 after the following ch3 after the following statements variables and the input is: WXYZ
statement executes: cin >> ch1 >> execute? cin.get(ch1); cin.get(ch2); What is the value of ch2 after the
ch2 >> ch3; cin.get(ch3); following statements execute?
cin.get(ch1); cin.putback(ch1); cin
Suppose that x and y are int x = 28, Y When you want to process only partial ignore
>> ch2;
variables, z is a double variable, = 32, z = data, you can use the stream function
and the input is: 28 32.6 12 0.6 ____ to discard a portion of the inp Suppose that ch1 and ch2 are char X
variables and the input is: WXYZ
Suppose that x and y are int This
What is the value of ch2 after the
variables, ch is a char variable, statement
following statements execute? cin
and the input is: 4 2 A 12 Choose results in
>> ch1; ch2 = cin.peek(); cin >> ch2;
the values of x, y, and ch after the input
following statement executes: cin failure In C++, the dot is an operator called member
>> x >> ch >> y; the ____ operator. access
CH 3 (cont) CH 3 (cont)
Suppose that x = 25.67, y = 25.67 356.88 Consider the following program inFile.op
356.876, and z = 7623.9674. 7623.97 segment. ifstream inFile; //Line 1 int en("prog‐
What is the output of the x, y; //Line 2 ... //Line 3 inFile >> x data.dat"
following statements? cout << >> y; //Line 4 Which of the following );
fixed << showpoint; cout << statements at Line 3 can be used to
setprecision(2); cout << x << ' ' open the file progdata.dat and input
<< y << ' ' << z << endl; data from this file into x and y at
Line 4?
x = 55.68, y = 476.859, and z = 55.680
23.8216. statements? cout << 476.860 Suppose that outFile is an ofstream outFile.o
fixed << showpoint; cout << 23.82 variable and output is to be stored in pen("out‐
setprecision(3); cout << x << ' ' the file outputData.out. Which of the putData.
<< y << ' ' << setprecision(2) following statements opens the file out");
<< z << endl; outputData.out and associates
outFile to the output file?
Suppose that x = 1565.683, y 1565.683
= 85.78, and z = 123.982. 85.7800
What is the output of the 123.98
following statements? cout <<
fixed << showpoint; cout <<
setprecision(3) << x << ' '; cout
<< setprecision(4) << y << ' '
<< setprecision(2) << z <<
endl;