C++ 5 T/F questions need help! Syed needs help with C++ Programming as soon as p
ID: 3591266 • Letter: C
Question
C++ 5 T/F questions need help!
Syed needs help with C++ Programming as soon as possible. Syed wrote:
Can you help me solve these few T/F questions?
96. The following function call agrees with its prototype:
swap(&x, &y); // x and y are of ‘int’ type
void swap(int * p, int * q);
T__ F__
97. To create an output stream, you must declare a stream object to
be of class ‘ifstream’.
T__ F__
98. The following statement is syntactically illegal because of
using \ instead of for file-folder specifier:
ifstream inputFile("c:\demofile.txt");
T__ F__
99. The following code-segment of ‘main()’ is syntactically legal:
#include <iostream> #include <fstream> using namespace std;
int main()
{
ofstream outputFile("c:\demofile.txt");
if(outputFile.is_open())
outputFile << "Bach " << "Beethoven " <<"Mozart ";
outputFile.close();
}
T__ F__
100. The following code-segment of ‘main()’ is syntactically incorrect:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string name;
ifstream inputFile("c:\demofile.txt");
if(!inputFile)
{
cout << "File is not open ";
exit(EXIT_FAILURE);
}
while(inputFile >> name)
cout << name << endl;
}
T__ F__
Explanation / Answer
1)
swap(&x, &y); // x and y are of ‘int’ type
void swap(int * p, int * q);
Answer: True
2)
To create an output stream, you must declare a stream object to
be of class ‘ifstream’.
Reason:
you may or may not declare a stream object to
be of class ‘ifstream’.
Answer: False.
3)
using \ instead of for file-folder specifier:
ifstream inputFile("c:\demofile.txt");
Anser: True
4)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream outputFile("c:\demofile.txt");
if(outputFile.is_open())
outputFile << "Bach " << "Beethoven " <<"Mozart ";
outputFile.close();
}
Answer:True
5)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string name;
ifstream inputFile("c:\demofile.txt");
if(!inputFile)
{
cout << "File is not open ";
exit(EXIT_FAILURE);
}
while(inputFile >> name)
cout << name << endl;
}
Answer:True
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.