write the output of the code below.
#include <iostream>
using namespace std;
int& f(int &i )
{
i += 10;
return i ;
}
int main()
{
int k = 0;
int& m = f(k);
cout << k << "#";
f(m)++;
cout << k << endl;
return 0;
}
(2分)
write the output of the code below.
#include <iostream>
using namespace std;
class counter{
private:
int value;
public:
counter():value(0) {}
counter& operator++();
int operator++(int);
void reset()
{
value = 0;
}
operator int() const
{
return value;
}
};
counter& counter::operator++()
{
if (3 == value)
value = 0;
else
value += 1;
return *this;
}
int counter::operator++(int)
{
int t = value;
if (3 == value)
value = 0;
else
value += 1;
return t;
}
int main()
{
counter a;
while (++a)
cout << "***\n";
cout << a << endl;
while (a++)
cout << "***\n";
cout << a << endl;
return 0;
}
One for each line:
(1分)
(1分)
(1分)
(1分)
(1分)
write the output of the code below.
#include <iostream>
using namespace std;
class Sample{
friend long fun(Sample s);
public:
Sample(long a)
{
x = a;
}
private:
long x;
};
long fun(Sample s)
{
if (s.x < 2) return 1;
return s.x * fun(Sample(s.x-1));
}
int main()
{
int sum = 0;
for(int i=0;i<6;i++)
{
sum += fun(Sample(i));
}
cout << sum;
return 0;
}
(1分)