Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 8 Question 100 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 100
Topic #: 8
[All CPP Questions]

What happens when you attempt to compile and run the following code?

#include

#include

#include

#include

#include

#include

using namespace std;

class B { int val;

public:

B(int v=0):val(v){}

int getV() const {return val;}

operator int() const { return val; };};

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) {out<

int main () {

int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

fstream f("test.out", ios::trunc|ios::out);

list l(t, t+10);

for_each(l.begin(), l.end(), Out(f));

f.close();

f.open("test.out");

for( ; f.good() ; ) {

B i;

f>>i;

cout<

}

f.close();

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Louvenia
2 days ago
Ah, the joys of C++ programming. Where the syntax is like a maze, and the output is a riddle wrapped in an enigma. I wonder if the exam will have a bonus round for interpretive dance?
upvoted 0 times
...
Virgina
3 days ago
I'm going with E. The code looks like it's writing the contents of the list to the file, and then reading them back out. Should be a piece of cake! Now, if only the exam questions were this straightforward...
upvoted 0 times
...
Melissa
5 days ago
This is a tricky one! I'm leaning towards C, since the code is opening the file for reading after writing to it. But then again, the output suggests E might be the right answer. Decisions, decisions...
upvoted 0 times
...
Lucina
7 days ago
Hmm, I'm torn between B and E. The code seems to be opening the file for writing, and then reading from it. I'll go with B, just to be safe. Wouldn't want to end up with a compile error!
upvoted 0 times
...
Makeda
8 days ago
I'm not sure, but I think it might be D) compilation error.
upvoted 0 times
...
Eleonore
10 days ago
I agree with Amira, because the code is opening the file in trunc mode.
upvoted 0 times
...
Charlene
13 days ago
The code looks correct, so I'd say the correct answer is E. The program will display the sequence 1 2 3 4 5 6 7 8 9 10. Can't wait to see if I get this one right!
upvoted 0 times
...
Amira
14 days ago
I think the answer is B) file test.out will be truncated.
upvoted 0 times
...
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77