test3Key*
Home ] Up ]

 

CSIS 250 M2000 T2

Assume the following definitions for the questions that follow.

 

const int MIN_DIM    = 1;

const int MAX_DIM    = 19;

const int TEST_COUNT = 5;

 

class CRectangle

  {

  private:

    int length;

    int width;

  public:

    CRectangle(int len=1, int wid=1);      

    int perimeter(void) const;             

    int area(void) const;                  

    void setDimension(int len, int wid);   

    void setLength(int len);               

    void setWidth(int wid);                

    int getLength(void) const;             

    int getWidth(void) const;              

    void getDimension(int &len, int &wid) const;

    void display(void) const;

    int & badSet(void);

    CRectangle(char ch);

    ~CRectangle(void);

    friend bool isSquare(const CRectangle &rect);

  };

1.            Identify the purpose of the word const in the following statement.

a)     Function can only modify the non-constant data members

b)     Function can only modify the local variables

c)     Function cannot modify the data members

d)     Function can modify the data members

e)     None of the above

       

    int perimeter(void) const;

2.            Identify the purpose of the word void in the following statement.

a)     Function does not take any argument when called

b)     Function returns the dimensions of a triangle

c)     Function does not return a value

d)     Function requires two arguments when called

e)     None of the above

 

    void setDimension(int len, int wid);

3.            Identify the purpose of the word “friend” in the following statement.

a)     Function does not take any argument when called

b)     Function has access to the private members of the class

c)     Function does not return a value

d)     It is a call by value

e)     None of the above

 

    friend bool isSquare(const CRectangle &rect);

4.            Identify the missing statement in the following function.

a)     if ((length >= MIN_DIM) && (length <= MAX_DIM))

b)     if ((len >= MIN_DIM) && (len <= MAX_DIM))

c)     if ((len != MIN_DIM) && (len != MAX_DIM))

d)     if ((len >= MIN_DIM) || (len <= MAX_DIM))

e)     None of the above

 

void CRectangle::setDimension(int len, int wid)

  {

  ...

  if ((len >= MIN_DIM) && (len <= MAX_DIM))

      length = len;

    else

      length = 1;

  if ((wid >= MIN_DIM) && (wid <= MAX_DIM))

      width = wid;

    else

      width = 1;

  }

5.            Identify the purpose of the following statement.

a)     Puts a random value from 0 to MAX_DIM in x

b)     Puts a random value from 0 to MAX_DIM-1 in x

c)     Puts a random value from 1 to MAX_DIM in x

d)     Puts a random value from 0 to MAX_DIM+1 in x

e)     None of the above

 

    x = rand()%(MAX_DIM + 1);

6.            Identify the missing statement in the following function.

a)     len = length;

b)     length = MAX_DIM;

c)     length = len;

d)     length = 0;

e)     None of the above

 

void CRectangle::setLength(int len)

  {

  if ((len >= MIN_DIM) && (len <= MAX_DIM))

      ...

      length = len;

    else

      length = 1;

  }

7.            Identify the correct statement to set the length of a rectangle rect1 to 5.

a)     length.rect1 = 5;

b)     rect1.setLength(5);

c)     rect1.length = 5;

d)     setLength(rect1) = 5;

e)     None of the above

8.            Identify the missing statement in the following function.

a)     return length;

b)     return width;

c)     width = wid;;

d)     wid = width;

e)     None of the above

 

int CRectangle::getWidth(void) const

  {

  ...

  return width;

  }

9.            Identify the missing statement in the following function.

a)     return length;

b)     return width;

c)     width = wid;;

d)     wid = width;

e)     None of the above

 

void CRectangle::getDimension(int &len, int &wid) const

  {

  ...

  len = length;

  wid = width;

  }

10.      Identify the missing statement in the following function.

a)     return (length == width);

b)     return length == width;

c)     return (rect.length != rect.width);

d)     return (rect.length == rect.width);

e)     None of the above

 

bool isSquare(const CRectangle &rect)

  {

  ...

  return (rect.length == rect.width);

  }

11.      Identify the purpose of the following statement.

a)     Create an object r1 with length 4 and width 5

b)     Set the dimensions of an existing r1 to 4 and 5

c)     Create an object r1 with width 4 and length 5

d)     Release the memory taken by r1

e)     None of the above

 

    CRectangle r1;

12.      Identify the purpose of the following statement.

a)     Display the address of object pointed to by p

b)     Display the object pointed by p

c)     Delete the object pointed to by p

d)     Delete an array of objects pointed to by p

e)     None of the above

 

    delete []p;

13.      Identify the purpose of the following statement.

a)     Display the address of object pointed to by p

b)     Display the object pointed by p

c)     Delete the object pointed to by p

d)     Delete an array of objects pointed to by p

e)     None of the above

 

    delete p;


Assume the following definitions for the questions that follow.

 

int const MAX_VALUE  = 10;

int const TEST_COUNT = 40;

 

 

class CMoney

  {

  private:

    int dollars;

    int cents;

  public:

    CMoney(int dollars=0, int cents=0);

    CMoney(char ch);

    CMoney(const char *p);

    CMoney(double amount);

    ~CMoney(void);

    void display(void) const;

 

    CMoney operator + (const CMoney &amount) const;

    CMoney operator * (const CMoney &amount) const;

    bool operator == (const CMoney &amount) const;

    bool operator != (const CMoney &amount) const;

    CMoney operator - (void) const;

    CMoney operator + (void) const;

    CMoney operator - (const CMoney &amount) const;

 

    operator double(void) const;

 

  friend ostream &operator << (ostream &out,

      const CMoney &amount);

  friend istream &operator >> (istream &inp,

      CMoney &amount);

 

  CMoney & operator ++(void);

  CMoney & operator ++(int );

  };

14.      Identify the purpose of the following statement.

a)     Create one pointer variable and one object variable

b)     Create two pointer variables

c)     Create two object variables

d)     Create no pointer variable

e)     None of the above

 

    CMoney * m1, m2;

15.      Identify the purpose of the word “this”  in the following statement.

a)     Points to the object amount

b)     Points to the object in operation

c)     Points to a global object amount

d)     Points to the object amount1

e)     None of the above

 

this->dollars = dollars;

16.      Identify the missing statement in the following function.

a)     y = temp;

b)     temp = y;

c)     x = temp;

d)     temp = x;

e)     None of the above

 

    void swap (int &x, int &y)

      {

      int temp;

      temp = x;

      x = y;

      ...

      y = temp;

      }

17.      Identify the purpose of the following member definition.

a)     postincrement

b)     preincrement

c)     postdecrement

d)     predecrement

e)     None of the above

 

CMoney & CMoney::operator ++(int)

  {

  cents++;

  return *this;

  }

18.      Identify the missing statement in the following function.

a)     CMoney tAmount(atoi(p));

b)     CMoney tAmount(p);

c)     CMoney tAmount(atod(p));

d)     CMoney tAmount(atof(p));

e)     None of the above

 

CMoney::CMoney(const char *p)

  {

  if (strlen(p) == 0)

      dollars = cents = 0;

    else

      {

      ...CMoney tAmount(atof(p));

     

      this->dollars = tAmount.dollars;

      this->cents   = tAmount.cents;

      }

  }

19.      Identify the value of testCount after the execution of the following program segment.

a)     16

b)     5

c)     6

d)     4

e)     None of the above

 

  char *testValues [] = {"11.11", "+11.11",

     "-11.11", "22.22"};

  int testCount =

     sizeof(testValues)/sizeof(testValues[0]);

20.      Identify the value of testCount after the execution of the following program segment.

a)     165

b)       5

c)     6

d)     4

e)     None of the above

 

  char *testValues [] = {"11.11", "+11.11",

    "-11.11", "22.22"};

  int testCount = sizeof(testValues);

21.      Identify the value of testCount after the execution of the following program segment.

a)     165

b)     5

c)     6

d)     4

e)     None of the above

 

  char *testValues [] = {"11.11", "+11.11",

    "-11.11", "22.22"};

  int testCount =

    sizeof(testValues)/sizeof(testValues[2]);

22.      Identify the missing statement in the followinf member definition.

a)     tempAmount = double(this->cents)+ double(this->dollars)/100;

b)     tempAmount = double(this->dollars)/100+ double(this->cents);

c)     tempAmount = double(this->dollars)+ double(this->cents/100);

d)     tempAmount = double(this->dollars)+ double(this->cents)/100;

e)     None of the above

 

CMoney::operator double(void) const

  {

  double tempAmount;

  ...tempAmount = double(this->dollars)+ double(this->cents)/100;

 

  return tempAmount;

  }

23.      Identify the missing statement in the following member definition.

a)     tempAmount = *this - amount;

b)     tempAmount = *this + (-amount);

c)     tempAmount = this + (-amount);

d)     tempAmount = this - amount;

e)     None of the above

 

CMoney CMoney:: operator - (const CMoney &amount) const

  {

  CMoney tempAmount;

  ...tempAmount = *this + (-amount);

  return tempAmount;

  }

24.      Identify the missing statement in the following member definition.

a)     return *this;

b)     return this;

c)     return +this;

d)     return (+this);

e)     None of the above

 

CMoney CMoney::operator + (void) const

  {

  ...return *this;

  }

25.      Identify the missing statement in the following member definition.

a)     return (*this != amount);

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

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

d)     return (*this == amount);

e)     None of the above

 

bool CMoney::operator != (const CMoney &amount) const

  {

  ...return !(*this == amount);

 

  }

26.      Identify the missing statement in the following member definition.

a)     cents = int(amount/100);

b)     cents = int(amount)*100;

c)     cents = int(amount)/100;

d)     cents = int(amount*100);

e)     None of the above

 

CMoney::CMoney(double amount)

  {

  dollars = int(amount);

  amount = amount - dollars;

  if (amount > 0.0)

      amount = amount + 0.001;

    else

      amount = amount -0.001;

 

  ...cents = int(amount*100);

 

  }


Assume the following definitions for the questions that follow.

 

const int MIN_VALUE = 1;

const int MAX_VALUE = 20;

const int TEST_COUNT = 5;

 

class CRational

  {

  private:

    int den;

    int num;

  public:

    CRational (int den=1, int num=1);

    CRational (char ch);             

    void simplify(void);             

    CRational Add(CRational rat);    

    CRational Subtract(CRational rat);

    CRational Multiply(CRational rat);

    CRational Divide(CRational rat); 

    void display(void);              

    void displayValue(void);         

  };

 

int gcd(int x, int y);

27.      Identify the missing statement in the following member definition.

a)     *this.num = num;

b)     this.num = num;

c)     num = this->num;

d)     this->num = num;

e)     None of the above

 

CRational::CRational (int den, int num)

  {

  this->den = den;

  ...this->num = num;

  simplify();

  }

28.      Identify the missing statement in the following member definition.

a)     int gcfactor = gcd(this->num, this->den);

b)     int gcfactor = gcd(abs(this->num) this->den);

c)     int gcfactor = gcd(abs(this->num), this->den);

d)     gcfactor = gcd(abs(this->num), this->den);

e)     None of the above

 

void CRational::simplify(void)

  {

  if (this->den < 0)

      {

      this->den = -this->den;

      this->num = -this->num;

      }

 

  if (this->num != 0 && this->den != 0)

      {

      ...int gcfactor = gcd(abs(this->num), this->den);

      this->num = this->num / gcfactor;

      this->den = this->den / gcfactor;

     }

  }

29.      Identify the missing statement in the following member definition.

a)     tempAmount.den = this->den * rat.den;

b)     tempAmount.den = this->num * rat.num;

c)     tempAmount.den = this->den + rat.den;

d)     tempAmount.den = this->num + rat.num;

e)     None of the above

 

CRational CRational::Add(CRational rat)

  {

  CRational tempAmount;

  tempAmount.num = this->num * rat.den +

                   this->den * rat.num;

  ...tempAmount.den = this->den * rat.den;

 

  tempAmount.simplify();

  return tempAmount;

  }

30.      Identify the missing statement in the following member definition.

a)     tempAmount.den = this->den * rat.den;

b)     tempAmount.den = this->num * rat.num;

c)     tempAmount.den = this->den - rat.den;

d)     tempAmount.den = this->num - rat.num;

e)     None of the above

 

CRational CRational::Subtract(CRational rat)

  {

  CRational tempAmount;

  tempAmount.num = this->num * rat.den –

                   this->den * rat.num;

  ...tempAmount.den = this->den * rat.den;

  tempAmount.simplify();

  return tempAmount;

  }

31.      Identify the missing statement in the following member definition.

a)     tempAmount.den = this->den * rat.num;

b)     tempAmount.den = this->num * rat.den;

c)     tempAmount.den = this->den - rat.num;

d)     tempAmount.den = this->num - rat.den;

e)     None of the above

 

CRational CRational::Multiply(CRational rat)

  {

  CRational tempAmount;

  tempAmount.num = this->num * rat.num;

  ...tempAmount.den = this->den * rat.den;

 

  tempAmount.simplify();

  return tempAmount;

  }

32.      Identify the missing statement in the following member definition.

a)     tempAmount.den = this->den * rat.den;

b)     tempAmount.den = this->num * rat.num;

c)     tempAmount.den = this->den - rat.den;

d)     tempAmount.den = this->num - rat.num;

e)     None of the above

 

CRational CRational::Divide(CRational rat)

  {

  CRational tempAmount;

  tempAmount.num = this->num * rat.den;

  ...tempAmount.den = this->den * rat.num;

  tempAmount.simplify();

  return tempAmount;

  }

33.      Identify the missing statement in the following member definition.

a)     if y > x

b)     if (y > x);

c)     if (y > x)

d)     if (y < x)

e)     None of the above

 

int gcd(int x, int y)

  {

  while (x != y)

    ...

if (y > x)

        y = y - x;

      else

        x = x - y;

  return x;

  }


Assume the following definitions for the questions that follow.

 

const int MIN_VALUE = 1;

const int MAX_VALUE = 20;

const int TEST_COUNT = 5;

 

class CRational

  {

  private:

    int den;

    int num;

  public:

    CRational (int den=1, int num=1);

    CRational (char ch);            

    void simplify(void);            

    CRational operator +(CRational rat);

    CRational operator -(CRational rat);

    CRational operator *(CRational rat);

    CRational operator /(CRational rat);

    void display(void);                

    void displayValue(void);           

    bool operator == (const CRational &rat) const;

    bool operator != (const CRational &rat) const;

    bool operator >= (const CRational &rat) const;

    bool operator <= (const CRational &rat) const;

    bool operator > (const CRational &rat) const;

    bool operator < (const CRational &rat) const;

   

    friend ostream &operator << (ostream &out,

       const CRational &rat);

    friend istream &operator >> (istream &inp,

       CRational &rat);

  };

 

int gcd(int x, int y);                 

 

 

 

 

34.      Identify the missing statement in the following member definition.

a)     return cin;

b)     return out;

c)     return this;

d)     return *this

e)     None of the above

 

ostream &operator << (ostream &out, const CRational &rat)

  {

  out << rat.num << " / " << rat.den << endl;

  if (0 == rat.den)

      out << "*** Error - denominator is zero\n";

 

  ...

  }

 

35.      Identify the missing statement in the following member definition.

a)     return (this == rat.num);

b)     return (*this == rat);

c)     return ((num * rat.den) == (den * rat.num));

d)     return ((this->num * rat.den) >= (this->den * rat.num));

e)     None of the above

 

 

bool CRational::operator == (const CRational &rat) const

  {

  ...

  }

 

36.      Identify the missing statement in the following member definition assuming that the operator == is defined for CRational.

a)     return (*this == rat);

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

c)     return (*this != rat);

d)     return !(this == rat);

e)     None of the above

 

 

bool CRational::operator != (const CRational &rat) const

  {

  ...

  }

 

37.      Identify the missing statement in the following member definition.

a)     return ((this->num * this->den) >= (rat.num * rat.den));

b)     return ((this->num + rat.den) >= (rat.num + this->den));

c)     return ((this->num - rat.den) >= (rat.num - this->den));

d)     return ((num * rat.den) >= (rat.num * den));

e)     None of the above

 

 

bool CRational::operator >= (const CRational &rat) const

  {

  ...

  }

 

38.      Identify the missing statement in the following member definition assuming that the operator >= has been defined for CRational.

a)     return !(*this >= rat);

b)     return (*this >= rat);

c)     return (this == rat);

d)     return !(rat >= *this);

e)     None of the above

 

 

bool CRational::operator < (const CRational &rat) const

  {

  ...

  }

 

 

 


Assume the following definitions for the questions that follow.

const int MAX_LEN = 10;

const int MAX_SIZE = 10;

 

const char *testData[] =

  {"Bob", "Tom", "Ann", "Ron", "Ben",

   "Ken", "Rob", "Sam", "Don", "Dan"};

 

const int MAX_DATA = sizeof(testData)/sizeof(testData[0]);

 

struct NodeType

  {

  char name[MAX_LEN+1];

  NodeType *next;

  };

 

class CSLL

  {

  private:

    NodeType *head;

    int count;

  public:

    CSLL(void);

    CSLL(char ch);

    CSLL(int n);

    CSLL(const CSLL &list);

    ~CSLL(void);

    CSLL &operator = (const CSLL &list);

    void display(void) const;

    void displayDistinct(void) const;

    void displayPhysical(void) const;

    void insertAtHead(const char s[]);

    void insertAtTail(const char s[]);

    void removeAll(void);

    bool has(const char[]);

  };

 

39.      Identify the missing statement in the following member definition.

a)     n++;

b)     count--;

c)     n--;

d)     count++;

e)     None of the above

 

 

CSLL::CSLL(int n)

  {

  head = NULL;

  count = 0;

  while (n>0)

    {

    insertAtHead(testData[rand()%MAX_DATA]);

    ...

    }

  }

 

 

40.      Identify the missing statement in the following member definition.

a)     NULL = head;

b)     *head = NULL;

c)     head = NULL;

d)     head->next = NULL;

e)     None of the above

 

 

CSLL::CSLL(void)

  {

  ...

  count = 0;

  }

 

41.      Identify the missing statement in the following member definition.

a)     p->next = p;

b)     p = p.next;

c)     p = p->next;

d)     p = *p->next;

e)     None of the above

 

 

CSLL::CSLL(const CSLL &list)

  {

  count = 0;

  head = NULL;

 

  NodeType *p;

 

  p = list.head;

 

  while (p != NULL)

    {

    insertAtTail(p->name);

    ...

    }

  }

 

42.      Identify the missing statement in the following member definition.

a)     p->next = p;

b)     p = p.next;

c)     p = p->next;

d)     p = *p->next;

e)     None of the above

 

 

void CSLL::display(void) const

  {

  NodeType *ptr;

 

  cout << "List[" << count << "]: ";

 

  ptr = head;

  while (ptr != NULL)

    {

    cout << ptr->name << ' ';

    ...

    }

 

  cout << endl;

  }

 

43.      Identify the missing statement in the following member definition.

a)     p->next = p;

b)     p = p.next;

c)     p = p->next;

d)     p = *p->next;

e)     None of the above

 

 

bool CSLL::has(const char s[])

  {

  NodeType *p;

  p = head;

  while (p != NULL)

    {

    if (strcmp(p->name, s)==0)

        return true;

    ...

    }

 

  return false;

  }

 

 

 

44.      Identify the missing statement in the following member definition.

a)     p->next = p;

b)     p = p.next;

c)     p = p->next;

d)     p = *p->next;

e)     None of the above

 

 

CSLL &CSLL::operator = (const CSLL &list)

  {

  if (this->count > 0)

      removeAll();

 

  NodeType *p;

  p = list.head;

 

  while (p != NULL)

    {

    insertAtTail(p->name);

    p = p->next;

    }

 

  ...

  }

 

45.      Identify the missing statement in the following member definition.

a)     p->next = p;

b)     p = p.next;

c)     p = p->next;

d)     p = *p->next;

e)     None of the above

 

 

void CSLL::removeAll(void)

  {

  NodeType *p;

  while (head != NULL)

    {

    p = head;

    head = head->next;

    ...

    }

  count = 0;

  }