Exercise

1. What will be the output of the following program?
Note:Includes all required header files

using namespace std;
int main()
{
ofstream ofile;
ofile.open ("find.txt");
ofile << "letsfindcourse" << endl;
cout << "Data written to file" << endl;
ofile.close();
return 0;
}

A. Compile error
B. Runtime error
C. The program prints "letsfindcourse" in the file find.txt
D. none of the above

View Answer


2.What is the output of this program?
Note:Includes all required header files

using namespace std;
int main ()
{
char fine, course;
cout << "Enter a word: ";
fine = cin.get();
cin.sync();
course = cin.get();
cout << fine << endl;
cout << course << endl;
return 0;
}

A. course
b) fine
c) Returns fine 2 letter or number from the entered word
d) None of the mentioned

View Answer


3.What is the output of this program?
Note:Includes all required header files

using namespace std;
int main ()
{
ofstream outfile ("find.txt");
for (int i = 0; i < 70; i++)
{
outfile << i;
outfile.flush();
}
cout << "Done";
outfile.close();
return 0;
}

A. Done
B. Error
C. Runtime error
D. None of the mentioned

View Answer


4.What is the output of this program?
Note:Includes all required header files

using namespace std;
int main ()
{
int p = 1000;
double q = 3.14;
cout << p;
cout << endl;
cout << q << endl << p * q;
endl (cout);
return 0;
}

A. 1000 B. 3.14 C. 3140 D. All of the above

View Answer


5.Which of the following is true about the following program
Note:Includes all required header files

using namespace std;
int main ()
{
char i;
streambuf * p;
ofstream of ("find.txt");
pbuf = of.rdbuf();
do {
i = cin.get();
p -> sputc(i);
} while (i != '.');
of.close();
return 0;
}

A. insertion operator
B. $ symbol
C. dot operator
D. none of the mentioned

View Answer


6.What will be the output of this program?
Note:Includes all required header files

using namespace std;
int main ()
{
int p = 10;
double q = 1.14;
cout << p + q;
endl (cout);
return 0;
}

A. 10 B. 1.14 C. 11.14 D. All of the above

View Answer


7.What will be the output of this program?
Note:Includes all required header files

using namespace std;
int main ()
{
FILE *fp;
char x[1024];
fp = fopen("find.txt", "r"); // "ayushjain and prateek"
x[0] = getc(fp);
fseek(fp, 0, SEEK_END);
fseek(fp, -7L, SEEK_CUR);
fgets(x, 6, fp);
puts(x);
return 0;
}

A. ayushj B. yushja C. ayushja D. prate

View Answer


8.What is the output of this program?
Note:Includes all required header files

using namespace std;
int main ()
{
int l;
char * b;
ifstream i;
i.open ("find.txt", ios :: binary );
i.seekg (0, ios :: end);
l = i.tellg();
i.seekg (0, ios :: beg);
b = new char [l];
i.read (b, l);
i.close();
cout.write (b, l);
delete[] b;
return 0;
}

A. Error
B. find
C. This is find
D. Runtime error

View Answer



Discussion

* You must be logged in to add comment.