CH 08 Q U I Z
Which line runs a.out getting its input from in.txt and sending its output to the file out.txt, and its errors to the file err.txt?
./a.out < in.txt > out.txt 2> err.txt
Which line runs a.out getting its input from in.txt and appending its output to the file out.txt?
./a.out > in.txt >> out.txt
Which line runs a.out getting its input from in.txt and sending its output to the new file out.txt?
./a.out > out.txt < in.txt
Which line runs the dd program and sends its errors to file named z.data?
./dd 2> z.data
Which line runs the dmm program and adds its output to a file named x.data?
./dmm >> x.data
Which line runs the dom program and sends both output and errors to file named v.data?
./dom > v.data 2>&1
Which line runs the dwk program and gets its input from a file named y.data?
./dwk < y.data
Which line runs the prt program and stores its output in a new file named x.data?
./prt > x.data
A process filter does something to the characters it encounters A process filter learns something about the stream by examining characters
True False
A state filter learns something about the stream by examining characters A state filter does something to the characters it encounters
True False
Counting the number of words in input by counting word transitions is an example of a state filter Counting the number of words in input by counting word transitions is an example of a process filter.
True False
The expression cin.get(ch) returns a reference to the input stream The expression cin.get(ch) returns the next character from input
True False
When using cin >> ch; to read a character, leading whitespace is skipped. When using cin >> ch; to read a character, leading whitespace is not skipped.
True False
When using the get() member function to read a character, leading whitespace is not skipped When using the get() member function to read a character, leading whitespace is skipped.
True False
You can test if an I/O operation succeeded by explicitly calling the stream's fail() member function To test if an I/O operation succeeded you must explicitly call the stream's fail() member function
True False
Calling cout.put(65) prints the character 'A' on output Calling cout.put(65) prints the number 65 on output Calling cout.put(65) is illegal. Your code will not compile. Calling cout.put(65.35) is illegal. Your code will not compile
True False False False
Append output to a file named z Discard both output and errors Write output to a new file named z Read the input from the file named z Write errors to a new file named z Send the output to the input of the program named z
X rm x > /dev/null/2>&1 X cat < z cat x 2>z date | z
Indefinite limit loop that reduces its input Indefinite limit loop that uses successive approximations Counter-controlled symmetric loop for producing a sequence of data Indefinite data loop that uses raw input Counter-controlled asymmetric loop for processing characters Iterator loop that may change its container Iterator loop that cannot change its container Counter-controlled loop for processing substrings Indefinite data loop that uses formatted input
while (n!=0) {n/=2;} while(abs(g1-g2) >= EPSILON) {...} for (int i = 12; i <= 19; i ++) {...} while(cin.get(ch)) {...} for (size_t i = 0, len = s.size(); i < len; i++) {...} for(auto&e : col) {...} for(auto e: col) {...} for(size_t i=4, slen =4; len = s.size(); i <len; i++) {...} while(cin >> n)
Assume the user types "brown cow" when this code runs. What is stored in ch2? char ch1; auto ch2 = cin.get(ch1);
cin
Complete the following code in the echo filter program. char ch; while (______________) cout.put(ch);
cin.get(ch)
Assume you have a char variable named ch. How do you read one character from input?
cin.get(ch);
Assume you have a char variable named ch. How do you look ahead before reading a character? 2 Q U E S T I O N S
cin.get(ch); cin.unget(ch); cin.putback(ch); cin.seek(ch); cin.peek(ch); -- > None of these
Assume you have a char variable named ch. How do you look ahead before reading a character?
cin.peek();
Assume you have a char variable named ch. How do you "unread" a character already read?
cin.putback(ch);
Which of these are not process filters?
compress input by turning off echo when reading blank spaces print one sentence per line counting word transitions
Complete the following code in the echo filter program. char ch; while (cin.get(ch)) _______________;
cout.put(ch)
Assume you have a char variable named ch. How do you write one character to output?
cout.put(ch);
The input stream member function for reading a character at a time is named:
get()
Has a single char& parameter Returns the last character read to the input stream Examines, but does not read the next character in an input stream Replaces the last character read with any character Called implicitly when an input statement is used as a test condition. A predicate function Converts its value argument to a character and sends it to output.
get() unget() peek() putback() fail() isalpha() put()
The expression cin.get(ch) does which of these?
reads the next character in input and stores it in ch returns a reference to cin that can be tested
Complete the following code in the lower filter program. char ch; while (cin.get(ch)) cout.put(____________);
tolower(ch)
Complete the following code in the upper filter program. char ch; while (cin.get(ch)) cout.put(____________);
toupper(ch)
Which of these are not state filters?
translating data from one form to another search for a particular value in a stream copy a file
Calling cout.put("A") is illegal. Your code will not compile.
True
Calling cout.put(c) converts its argument, c, to a character.
True
When a stream is converted to a Boolean condition, its fail() member function is implicitly called
True
When using the get() member function, a stream will fail only if there are no characters left in the input stream.
True
Assume the user types "brown cow" when this code runs. What type is ch2? char ch1; auto ch2 = cin.get(ch1);
istream&
Assume the user types "brown cow" when this code runs. What prints? char c; cout << cin.get(c) << endl;
Does not compile
Assume the user types "brown cow" when this code runs. What prints? char c; cout.put(cin.get(c));
Does not compile
Assume the user types "brown cow" when this code runs. What prints? int n; if (cin >> n) cout << "X\n"; else cout << "Y\n";
Y
Programs that process streams of characters are called text ______________.
filters