Chapter 8 Quiz ITE-6101-2013T(UGRD)
Computing Fundamentals
Question 1
pts
What is the output of the following program?
#include <iostream>
using namespace std;
class A {
public: int v;
A():v(1) {}
A(int i):v(i) {}
void operator<<(int a) { v+=a; }
};
int main(void) {
A i = 2;
i << 2;
cout << i.v << endl;
return 0;
}
1
The program will cause a compilation error.
2
4
Question 2
pts
What is the output of the following program?
, #include <iostream>
using namespace std;
class A {
public: int v;
A():v(1) {}
A(int i):v(i) {}
void operator<<(int a) { v>>=1; }
};
ostream& operator<<(ostream &o, A &a) {
return o<<a.v;
}
int main(void) {
A i = 2;
i << 2;
cout << i << endl;
return 0;
}
The program will cause a compilation error.
2
1
4
Question 3
pts
What is the output of the following program?
#include <iostream>
using namespace std;
class A {
public: int v;
A():v(1) {}
Computing Fundamentals
Question 1
pts
What is the output of the following program?
#include <iostream>
using namespace std;
class A {
public: int v;
A():v(1) {}
A(int i):v(i) {}
void operator<<(int a) { v+=a; }
};
int main(void) {
A i = 2;
i << 2;
cout << i.v << endl;
return 0;
}
1
The program will cause a compilation error.
2
4
Question 2
pts
What is the output of the following program?
, #include <iostream>
using namespace std;
class A {
public: int v;
A():v(1) {}
A(int i):v(i) {}
void operator<<(int a) { v>>=1; }
};
ostream& operator<<(ostream &o, A &a) {
return o<<a.v;
}
int main(void) {
A i = 2;
i << 2;
cout << i << endl;
return 0;
}
The program will cause a compilation error.
2
1
4
Question 3
pts
What is the output of the following program?
#include <iostream>
using namespace std;
class A {
public: int v;
A():v(1) {}