In: Computer Science
C++
19.Which of the following headers is required for reading from and writing to disk files?
#include <ifstream>
#include <fstream>
#include <iostream>
#include <ofstream>
20.Which of the following options is the correct way to call the open function on an ifstream object named ifstr?
ifstr.open("data.txt")
ifstr.open("data", ".txt")
ifstr.open("data.txt", "read")
ifstr.open()
24. What is wrong with the following function definition?
void erase_file(ifstream infile, ofstream outfile) { char ch; while (infile.get(ch)) { outfile << ch; } }
The ifstream and ofstream parameters must be reference parameters.
The function does not read an end of line character to terminate the while loop.
The output from the function does not display all of the characters in the file.
The ifstream and ofstream parameters must be pointers.
35.What is the output from the following code snippet?
int main() { for (int i = 100; i < 106; i = i + 2) { ostringstream oss; oss << "base-" << setw(3) << i; cout << oss.str() << endl; } }
base-100base102base104base106
base-
base-
base-
base
base-100
base-102
base-104
base-106
base-100
base-102
base-104
37.What is the problem with the following code snippet?
double* acc_ptr; *acc_ptr = 1000;
The acc_ptr variable is never initialized.
There is no problem.
The second statement assigns an integer to a pointer.
There is a compilation error.
51.What is the difference between a dynamically allocated array and an array variable?
The dynamically allocated array must be declared with the "dynamic" keyword.
The dynamically allocated array must have a fixed size when it is declared. The array variable can have a dynamic size, determined at run-time.
The dynamically allocated array cannot be declared with the "const" keyword.
The array variable must have a fixed size when it is declared. The dynamically allocated array can have a size determined at run-time.
19.Which of the following headers is required for reading from and writing to disk files?
#include <ifstream>
[correct]#include <fstream>
#include <iostream>
#include <ofstream>
20.Which of the following options is the correct way to call the open function on an ifstream object named ifstr?
ifstr.open("data.txt")
ifstr.open("data", ".txt")
[correct]ifstr.open("data.txt", "read")
ifstr.open()
24. What is wrong with the following function definition?
void erase_file(ifstream infile, ofstream outfile) { char ch; while (infile.get(ch)) { outfile << ch; } }
The ifstream and ofstream parameters must be reference parameters.
The function does not read an end of line character to terminate the while loop.
The output from the function does not display all of the characters in the file.
The ifstream and ofstream parameters must be pointers.
35. What is the output from the following code snippet?
int main() { for (int i = 100; i < 106; i = i + 2) { ostringstream oss; oss << "base-" << setw(3) << i; cout << oss.str() << endl; } }
Output-
base-100
base-102
base-104
37.What is the problem with the following code snippet?
double* acc_ptr; *acc_ptr = 1000;
The acc_ptr variable is never initialized.
[correct]There is no problem.
The second statement assigns an integer to a pointer.
There is a compilation error.
51.What is the difference between a dynamically allocated array and an array variable?
The dynamically allocated array must be declared with the "dynamic" keyword.
The dynamically allocated array must have a fixed size when it is declared. The array variable can have a dynamic size, determined at run-time.
The dynamically allocated array cannot be declared with the "const" keyword.
[correct]The array variable must have a fixed size when it is declared. The dynamically allocated array can have a size determined at run-time.