Test2Key
Home ] Up ]

 

CSIS 250 Fall 2000 T2

Your Name

 

Your Secret Name

 

 


Assume the following definitions for the questions that follow.

int const MAX_LEN = 10;

int const MAX_COUNT = 10;

int const TEST_COUNT = 5;

 

int masterKey = 1;

 

const char *testNames[] =

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

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

 

const int MAX_NAMES = sizeof(testNames)/sizeof(testNames[0]);

 

const char *testPhones[] =

  {"111-1111", "222-2222", "333-3333",

   "444-4444"};

 

const int MAX_PHONES =

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

 

const char *testGroups[] =

  {"Group1", "Group2", "Group3", "Group4"};

 

const int MAX_GROUPS = sizeof(testGroups)/sizeof(testGroups[0]);

 

 


struct CPhoneEntry

  {

  char name[MAX_LEN+1];

  char phone[14+1];

  char group[10+1];

  int key;

  CPhoneEntry *next;

  };

 

 

class CPhoneBook

  {

  private:

    CPhoneEntry *first;

    CPhoneEntry *last;

    int count;

    CPhoneEntry * addressOfEntryAt(int pos);

  public:

    CPhoneBook(void);

    bool insertAtEnd(char name[], char phone[],

      char group[], int key);

    void display(void);

    void deleteAll(void);

    ~CPhoneBook(void);

    CPhoneBook(char ch);

    void sortByName(void);

    bool isSortedByName(void);

    void displayReverse(void);

    void displayReverse2(void);

    friend ostream & operator << (ostream &os,

      const CPhoneBook &list);

  };

 


1.  Identify the purpose of the following statement.

  CPhoneEntry *p;

  

a)            Create one pointer variable and one object variable

b)            Create two pointer variables

c)            Create two object variables

d)            Create one pointer variable

e)            None of the above

2.  Identify the missing statement in the following function.

CPhoneEntry * CPhoneBook::addressOfEntryAt(int pos)

  {

  if (count <= 0)

      return NULL;

  if (pos < 0)

      return NULL;

  if (pos >= count)

      return NULL;

 

  CPhoneEntry *p;

  p = first;

 

  ...

    p = p->next;

 

  return p;

  }

 

a)                 for (int steps=0; steps<=pos; steps++)

b)                 for (int steps=1; steps<=pos; steps++)

c)                 for (int steps=1; steps<pos; steps++)

d)                 for (int steps=0; steps<=pos; ++steps)

e)                 None of the above

3.  Identify the purpose of the following statement.

   n = rand()%(MAX_COUNT+1);

 

a)          Assigns a random value from 0 to 10

b)          Assigns a random value from 1 to 10

c)          Assigns a random value from 1 to 11

d)          Assigns a random value from 0 to 11

e)          None of the above

4.  Identify the missing statement in the following function.

bool CPhoneBook::isSortedByName(void)

  {

  CPhoneEntry *p, *q;

 

  if (first == last)

      return true;

 

  p = first;

  q = p->next;

  while (q != NULL)

    {

    ...

        return false;

    p = q;

    q = q->next;

    }

 

  return true;

  }

 

a)          if ((strcmp(p->name, q->name)>=0))

b)          if ((strcmp(p->name, q->name)<=0))

c)          if ((strcmp(p->name, q->name)>0))

d)          if ((strcmp(p->name, q->name)==0))

e)          None of the above

5.  Identify the statement to insert a phone entry with values {name=John, phone=231-7000, group=friend, key=1} in the myBook object of type CPhoneBook.

 

a)           myBook.insertAtEnd("231-7000", "John", "friend", 1);

b)          myBook.insertAtEnd("John", "friend", "231-7000", 1);

c)          myBook.insertAtEnd("friend", "John", "231-7000", 1);

d)          myBook.insertAtEnd("John", "231-7000", "friend", 1);

e)          none of the above

 

6.  Identify the missing statement in the following function.

CPhoneBook::CPhoneBook(void)

  {

  cout << "constructor called\n";

  ...

  first = NULL;

  last = NULL;

  }

 

a)          n = 0;

b)          n = 1;

c)          n = 2;

d)          n = 3;

e)          none of the above

7.  Identify the statement to display the object b3 of type CPhoneBook.

a)          b3.display;

b)          b3.display();

c)          display(b3);

d)          b3->display();

e)          none of the above

8.  Identify the purpose of the following statement.

p = new CPhoneEntry;

 

a)          create a pointer and name it p

b)          create a new entry and let p point to it

c)          set new entry to p

d)          let p point to new CPhoneBok type object

e)          none of the above

9.  Identify the statement to display the phone field of an object of type CPhoneEntry pointed to by p.

a)          cout << p.phone;

b)          cout << (*p)->phone;

c)          cout << phone(*p);

d)          cout << p->phone;

e)          none of the above

10.  Identify the missing statement in the following function definition.

bool CPhoneBook::insertAtEnd(char name[], char phone[], char group[], int key)

  {

  CPhoneEntry *p;

 

  p = new CPhoneEntry;

  if (NULL == p)

      return false;

 

  strcpy(p->name, name);

  strcpy(p->phone, phone);

  strcpy(p->group, group);

  p->key = key;

  p->next = NULL;

 

  if (NULL == first)

      {

      first = p;

      last  = p;

      }

    else

      {

      ...

      last = p;

      }

 

  count++;

  return true;

  }

 

a)          p->next = last;

b)          first->next = p;

c)          p->next = first;

d)          last->next = p;

e)          none of the above

11.  Identify the missing statement in the following function definition.

void CPhoneBook::deleteAll(void)

  {

  while (first != NULL)

    {

    ...

    delete first;

    first = last;

    }

  count = 0;

  }

 

a)          first = last->next;

b)          next = first->last;

c)          last = next->first;

d)          last = first->next;

e)          none of the above

12.  Identify the missing statement in the following function.

CPhoneBook::~CPhoneBook(void)

  {

  cout << "destructor called\n";

  ...

  }

 

a)          count = 0;

b)          first = NULL;

c)          last = NULL;

d)          first = last = NULL;

e)          none of the above

13.  Identify the missing statement in the following function.

ostream & operator << (ostream &dan, const CPhoneBook &list)

  {

  CPhoneEntry *p;

 

  dan << "Phonebook[" << list.count << "]\n";

 

  p = list.first;

 

  while (p != NULL)

    {

    dan << p->name << ", ";

    dan << p->phone << ", ";

    dan << p->group << ", ";

    dan << p->key << endl;

    ...

    };

 

  return dan;

  }

 

a)          p->next = p;

b)          next->p = p;

c)          p->p = next;

d)          p = p->next;

e)          none of the above

14.  Identify the statement to swap the records of type CPhoneEntry pointed to by p and q.

a)          swap(*p, *q);

b)          swap(p*, q*);

c)          swap(e1, e2);

d)          swap(*e1, *e2);

e)          none of the above

15.  Identify the missing statement in the following function.

void CPhoneBook::displayReverse2(void)

  {

  for (int pos=count-1; pos>=0; pos--)

    {

    CPhoneEntry *p;  //better if put outside the loop

    ...

 

    cout << p->name << ", ";

    cout << p->phone << ", ";

    cout << p->group << ", ";

    cout << p->key << endl;

    }

 

  cout << endl;

  }

 

a)          p = first;

b)          p = last;

c)          p = p->next;

d)          p = pos;

e)          none of the above

16.  Identify the output given by the following program segment.

const char *testNames[] =

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

   "Sam", "Don", "Dan", "Tim"};

 

cout << sizeof(testNames);

 

a)          45

b)          33

c)          44

d)          34

e)          none of the above

17.  Identify the output given by the following program segment.

const char *testNames[] =

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

   "Sam", "Don", "Dan", "Tim"};

 

cout << sizeof(testNames[0]);

 

a)          45

b)          33

c)          44

d)          34

e)          none of the above


CSIS 250 Fall 2000 T2

Your Name

 

Your Secret Name

 

 

1.

a

b

c

d

e

2.

a

b

c

d

e

3.

a

b

c

d

e

4.

a

b

c

d

e

5.

a

b

c

d

e

6.

a

b

c

d

e

7.

a

b

c

d

e

8.

a

b

c

d

e

9.

a

b

c

d

e

10.

a

b

c

d

e

11.

a

b

c

d

e

12.

a

b

c

d

e

13.

a

b

c

d

e

14.

a

b

c

d

e

15.

a

b

c

d

e

16.

a

b

c

d

e

17.

a

b

c

d

e