面向对象程序设计2022-2023秋冬习题集2
开始时间2022/12/09 24:44:00
结束时间2023/01/31 23:59:00
答题时长77715分钟
答卷类型标准答案
总分7

填空题得分:暂无总分:7
4-1

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分)


4-2

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分)