Test2Key
Home ] Up ]

 

CSIS 250 S2000 T2

 

1.         Identify the output produced by the following program segment.

  char *test[]={"0", "1", "x", "2*x", "-2*x", "-x^3", "-4*x^4", "-x^5"};

  cout << sizeof(test)/sizeof(test[0]) << endl;

 

a)    6

b)    7

c)    8

d)    13

e)    None of the above

2.         Identify the output produced by the following program segment.

    char testString[80];

    int testExpo = 32;

    sprintf(testString, "%s^%d", "x", testExpo); break;

    cout << testString << endl;

 

a)    s^dx32

b)    x^32

c)    x^%d

d)    %s^%dx32

e)    None of the above

3.         Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//another constructor for CTerm with values

//////////////////////////////////////////////////////////////////////

CTerm::CTerm(const double &coef, const int &expo)

  {

  this->coef = coef;

  this->expo = expo;

  ...

  }

 

a)    prev = next = coef;

b)    prev = next = expo;

c)    prev = next = NULL;

d)    prev = next;

e)    None of the above

4.         Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//copy constructor for CTerm

//////////////////////////////////////////////////////////////////////

CTerm::CTerm(const CTerm &cn)

  {

  ...

  expo = cn.expo;

  prev = NULL;

  next = NULL;

  }

 

a)    this.coef = cn.coef;

b)    this->coef = coef;

c)    coef = cn.coef;

d)    coef = cn->coef;

e)    None of the above

5.         Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//constructor for CTerm when coef is given

//////////////////////////////////////////////////////////////////////

CTerm::CTerm(const int &coef)

  {

  this->coef = coef;

  ...

  prev = next = NULL;

  }

 

a)    this.coef = 0;

b)    this->coef = 0;

c)    this->expo = 0;

d)    expo = expo;

e)    None of the above

6.         Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//CTerm & CTerm::operator = (const CTerm &cn)

//////////////////////////////////////////////////////////////////////

CTerm & CTerm::operator = (const CTerm &cn)

  {

  coef = cn.coef;

  expo = cn.expo;

  ...

  }

 

a)    return;

b)    return coef;

c)    return *this;

d)    return 0;

e)    None of the above

7.         Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//member addition operator + overloaded for CTerm

//////////////////////////////////////////////////////////////////////

CTerm CTerm::operator + (const CTerm &cn) const

  {

  if (0 == coef)

      return cn;

 

  if (0 == cn.coef)

      return *this;

 

  CTerm temp;

   

  if (expo == cn.expo)

      {

      ...     // temp.coef = coef + cn.coef;

      temp.expo  = expo;

      if (0 == temp.coef)

          temp.expo = 0;

      }

    else

      cout << "Not compatible to add\n";

 

  return temp;

  }

 

a)    temp.coef = coef;

b)    temp.coef = cn.coef;

c)    temp.coef = coef + cn;

d)    temp.coef = *this + cn.coef;

e)    None of the above

8.         Identify the purpose of the following function?

//////////////////////////////////////////////////////////////////////

//member addition operator + overloaded for CTerm and double

//////////////////////////////////////////////////////////////////////

CTerm CTerm::operator + (const double &c) const

  {

  if (0 == coef)

      return c;

 

  if (0 == c)

      return *this;

 

  CTerm temp;

   

  if (expo == 0)

      {

      ...   // temp.coef = coef + c;

      if (0 == temp.coef)

          temp.expo = 0;

      }

    else

      cout << "Not compatible to add\n";

 

  return temp;

  }

 

a)    temp.coef = coef;

b)    temp.coef = cn.coef;

c)    temp.coef = coef + cn;

d)    temp.coef = *this + cn.coef;

e)    None of the above

9.         Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//friend addition operator + overloaded for double and CTerm

//////////////////////////////////////////////////////////////////////

CTerm operator + (const double &c, const CTerm & cn)

  {

  CTerm temp(cn);

  if (cn.expo != 0)

      {

      cout << "Not compatible to add\n";

      return temp;

      }

 

  ...

  return temp;

  }

 

a)    temp.coef = coef;

b)    temp.coef = cn.coef;

c)    temp.coef = coef + cn;

d)    temp.coef = temp.coef + c;

e)    None of the above

10.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//member multiplication operator * overloaded for CTerm

//////////////////////////////////////////////////////////////////////

CTerm CTerm::operator * (const CTerm &cn) const

  {

  if (0 == coef)

      return coef;

    else if (0 == cn.coef)

      ...

 

  CTerm tempNode;

 

  tempNode.coef = coef * cn.coef;

  tempNode.expo  = expo + cn.expo;

 

  return tempNode;

  }

 

a)    return this;;

b)    return cn.coef;

c)    return *this;

d)    return coef;

e)    None of the above

11.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//member multiplication operator * overloaded for CTerm and double

//////////////////////////////////////////////////////////////////////

CTerm CTerm :: operator * (const double &c) const

  {

  if (0 == coef)

      return coef;

    else if (0 == c)

      ...

 

  CTerm tempNode;

 

  tempNode.coef = coef * c;

  tempNode.expo  = expo;

 

  return tempNode;

  }

 

a)    return c;

b)    return c.coef;

c)    return *this;

d)    return coef;

e)    None of the above

12.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//friend multiplication operator * overloaded for double and CTerm

//////////////////////////////////////////////////////////////////////

CTerm operator * (const double &c, const CTerm & cn)

  {

  ...

  temp.coef=temp.coef*c;

  return temp;

  }

 

a)    CTerm temp(cn);

b)    CTerm temp;

c)    CTerm temp(‘r’);

d)    CTerm temp(‘u’);

e)    None of the above

13.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//member division operator / overloaded for CTerm and double

//////////////////////////////////////////////////////////////////////

CTerm CTerm::operator / (const double &c) const

  {

  if (0 == coef)

      return coef;

 

  if (0 == c)

      {

      cout << "Division by zero\n";

      return c;

      }

 

  CTerm temp;

  ...

  temp.coef=temp.coef/c;

  return temp;

  }

 

a)    temp = this;

b)    temp = *this;

c)    temp = c;

d)    temp = coef;

e)    None of the above

14.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//friend division operator / overloaded for double and CTerm

//////////////////////////////////////////////////////////////////////

CTerm operator / (const double &c, const CTerm & cn)

  {

  CTerm temp;

 

  if (0 == c)

      return temp;

 

  if (cn.expo != 0)

      {

      cout << " / not possible will result in -ve expo\n";

      return temp;

      }

 

  if (0 == cn.coef)

      {

      cout << "Division by zero\n";

      return temp;

      }

 

  ...

  temp.coef=c/temp.coef;

  return temp;

  }

 

a)    temp = this;

b)    temp = cn;

c)    temp = c;

d)    temp = coef;

e)    None of the above

15.    Identify the missing statement in the following function?

///////////////////////////////////////////////////////////////////////

//member equal operator == overloaded for CTerm

//////////////////////////////////////////////////////////////////////

bool CTerm::operator == (const CTerm &cn) const

  {

  ...

  }

 

a)    return ((expo == cn.expo) || (coef == cn.coef));

b)    return ((expo != cn.expo) && (coef != cn.coef));

c)    return ((expo != cn.expo) || (coef != cn.coef));

d)    return ((expo == cn.expo) && (coef == cn.coef));

e)    None of the above

16.    Identify the missing statement in the following function?

///////////////////////////////////////////////////////////////////////

//member equal operator == overloaded for CTerm and double

//////////////////////////////////////////////////////////////////////

bool CTerm::operator == (const double &c) const

  {

  ...

  }

 

a)    return ((expo == cn.expo) || (coef == cn.coef));

b)    return ((expo != cn.expo) && (coef != cn.coef));

c)    return ((expo != cn.expo) || (coef != cn.coef));

d)    return ((0 == expo) && (coef == c));

e)    None of the above

17.    Identify the missing statement in the following function?

///////////////////////////////////////////////////////////////////////

//friend equal operator == overloaded for double and CTerm

//////////////////////////////////////////////////////////////////////

bool operator == (const double &c, const CTerm & cn)

  {

  ...

  }

 

a)    return (c == cn);

b)    return (c != cn);

c)    return (cn == c);

d)    return ((expo == cn.expo) && (coef == cn.coef));

e)    None of the above

18.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//member equal operator != overloaded for CTerm

//////////////////////////////////////////////////////////////////////

bool CTerm::operator != (const CTerm &cn) const

  {

  ...

  }

 

a)    return !(c == cn);

b)    return (c != cn);

c)    return !(cn == c);

d)    return !(*this == cn);

e)    None of the above

19.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//member equal operator != overloaded for CTerm and double

//////////////////////////////////////////////////////////////////////

bool CTerm::operator != (const double &c) const

  {

  ...

  }

 

a)    return !(c == cn);

b)    return !(*this == c);

c)    return (c != cn);

d)    return !(cn == c);

e)    None of the above

20.    Identify the missing statement in the following function?

///////////////////////////////////////////////////////////////////////

//friend not equal operator != overloaded for double and CTerm

//////////////////////////////////////////////////////////////////////

bool operator != (const double &c, const CTerm & cn)

  {

  ...

  }

 

a)    return !(c != cn);

b)    return !(*this == c);

c)    return (c != cn);

d)    return !(cn == c);

e)    None of the above

21.    Identify the missing statement in the following function?

//////////////////////////////////////////////////////////////////////

//OperatorUnaryMinus

//////////////////////////////////////////////////////////////////////

CTerm CTerm::operator -() const

  {

  CTerm tempNode = *this;

  ...

  return tempNode;

  }

 

a)    coef = -coef;

b)    tempNode = -tempNode;

c)    tempNode.coef = -tempNode.coef;

d)    this->coef = -this->coef;

e)    None of the above