Quiz 6 Questions For the next four questions, assume that you have the following
ID: 3726169 • Letter: Q
Question
Quiz 6 Questions
For the next four questions, assume that you have the following variable declaration, which is placed at the top of a source code file called quiz6.cpp, outside of any function definition:
1. What header file must be included to perform file I/O in a C++ program?
2. Assume that a input file stream named data has been opened properly and is connected to a text file full of integer values. Write code to properly count all of the integers in the file.
3. Assume that the input file stream named info has just been opened. Write code to determine whether or not the open was successful.
4. Write the declaration for pr, a constant pointer to a float.
5. Write the declaration for which, a pointer to a constant char.
6. Declare a constant object of the class Student. Assume that the default constructor for the class will supply suitable values for the data members (i.e., you don't need to supply any).
7. What is the storage class of this variable?
8. What is the scope of this variable?
9. If you wanted to use this variable in a different source code file that will be linked together with quiz6.cpp, what would you need to do?
10. If you wanted to make sure that any other source code file that will be linked together with quiz6.cpp can not use this variable, what would you need to do?
11. What does the keyword static do if placed in front of a local variable declaration?
12. Local variables and function parameters have what scope?
13. What kinds of identifiers in C++ have class scope?
14. When are static storage class variables created and initialized and when are they destroyed?
Explanation / Answer
Solution:
The first four questions are done as per Chegg guidelines, please repost others.
1)
What header file must be included to perform file I/O in a C++ program?
#include<fstream>
2)
Assume that an input file stream named data has been opened properly and is connected to a text file full of integer values. Write code to properly count all of the integers in the file.
3)
Assume that the input file stream named info has just been opened. Write code to determine whether or not the open was successful.
infile.open( myFileName.c_str() );
if (infile) break;
cout << "Invalid file. Please enter a valid input file name> " << flush; // If the file is invalid
}
or
ifstream theFile ("A2.txt");
if (theFile.is_open())
{
while ( getline (theFile, number) )
{
cout << number << ' ';
}
theFile.close();
}
else cout << "Unable to open file";
4)
Write the declaration for pr, a constant pointer to a float.
const float *pr;
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.