write the output of the code below.
#include<iostream>
using namespace std;
class INCREMENT
{
public:
INCREMENT( int v = 0, int i = 1 );
void addIncrement()
{
v += increment;
}
void print() const;
int get() const
{
return v;
}
private:
int v;
const int increment;
};
INCREMENT::INCREMENT( int v, int i ) : v( v ), increment( i )
{
}
void INCREMENT::print() const
{
cout << v << endl;
}
int main()
{
INCREMENT value( 1, 2);
value.print();
for ( int j = 1; j <= 2; j++ )
{
value.addIncrement();
value.print();
}
return 0;
}
One for each line:
line 1:(1分)
line 2:(1分)
line 3:(1分)
write the output of the code below.
#include<iostream>
using namespace std;
class TEST
{
int num;
public:
TEST( int num=0);
void increment( ) ;
~TEST( );
};
TEST::TEST(int num) : num(num)
{
cout << num << endl;
}
void TEST::increment()
{
num++;
}
TEST::~TEST( )
{
cout << num << endl;
}
int main( )
{
TEST array[2];
array[0].increment();
array[1].increment();
return 0;
}
One for each line:
line 1:(1分)
line 2:(1分)
line 3:(1分)
line 4:(1分)