You are on page 1of 47

[FINAL] Final Exam Reviewer (APPLICATIONS)

Due Apr 7 at 11:59pm Points 110 Questions 22


Available Apr 5 at 12am - Apr 7 at 11:59pm 3 days Time Limit 60 Minutes

Instructions
Hi!

Use this as a reviewer for the final exam. Scores here will not be recorded. We will
limit taking this for ONE ATTEMPT only in order to avoid question farming. There is no
guarantee that questions here will appear exactly in the Final Exam.

We hope you put this in good use.

For your reference.

Attempt History
Attempt Time Score
LATEST Attempt 1 43 minutes 87.23 out of 110

 Correct answers are hidden.

Submitted Apr 7 at 11:32pm

Question 1 5 / 5 pts

Determine if the following is linear or non-linear list. Write A for


LINEAR LIST and B for NON-LINEAR LIST.

B heap

A array

A stack
A queue

B graph

A linked list

Answer 1:

Answer 2:

Answer 3:

Answer 4:

Answer 5:

Answer 6:

Partial Question 2 4.5 / 5 pts

Given the Class Definition below, answer succeeding


questions:
Shelf -- Name of the ADT

string -- Data type of the contents that can be handled by

the ADT

T -- (T/F) The class definition includes a

constructor.

T -- (T/F) The class definition includes a destructor.

10 -- Total number of operations that the ADT

6 -- Total number of operations that has a returning

value.

4 -- Total number of operations without any

returning value.

int -- Data type of the value returned by the operation

Count_Space()

bool -- Data type of the value returned by the operation

Shelf_Full()
int -- Data type of the value returned by the operation

Find_Book()

10000 -- Total number of books that can be stored in

variable book.

public -- Access modifier of the operations.

private -- Access modifier of the data.

string -- Data type of the parameter expected by the

operation Remove_Book()

int -- Data type of the parameter expected by the

operation View_Book()

F -- (T/F) The ADT makes use of a linear list.

F -- (T/F) The operation Shelf_Empty() expects a

parameter.

F -- (T/F) Values of data row and col will be assigned

in the destructor.

Load_Book -- The function that will be responsible for

initializing the contents of the variable book.

F -- (T/F) The ADT is dynamic.

Answer 1:

Shelf

Answer 2:

string
Answer 3:

Answer 4:

Answer 5:

10

Answer 6:

Answer 7:

Answer 8:

int

Answer 9:

bool

Answer 10:

int

Answer 11:

10000

Answer 12:

public

Answer 13:

private

Answer 14:

string

Answer 15:

int
Answer 16:

Answer 17:

Answer 18:

Answer 19:

Load_Book

Answer 20:

Question 3 5 / 5 pts

Fill in all blanks in the program below:

#include <iostream>
#include <cstdlib>

using namespace std ;

int main()
{

float *p1, *p2 ;

p1 = new float();
p2 = new float();
*p1 = 1.5;
* p2 = 3.2;

cout << "Value of p1 : " << *p1 << endl;

cout << "Value of p2 : " << *p2 << endl;


cout << endl << "Results ... " << endl;
cout << "Sum : " << *p1 + *p2 << endl;

cout << "Difference : " << *p1 - *p2 << endl;

cout << "Product : " << *p1 * *p2 <<

endl;
cout << "Quotient : " << *p1 / *p2 <<

endl;

system("pause");
}

Answer 1:

std

Answer 2:

Answer 3:

Answer 4:

*p1

Answer 5:

Answer 6:

*p2

Answer 7:

Answer 8:

<<

Answer 9:
cout

Answer 10:

Partial
Question 4 4.5 / 5 pts

Consider the program below and answer succeeding questions:

2 -- How many pointer variables are there?

42 -- What is the initial value of *p2?

T -- (T/F) It is required to invoke the new operator

if you intend to assign a value to be pointed to by a pointer.

T -- (T/F) p2 = p1 is an example of dereferencing.

T -- (T/F) The value of pointed to by p1 will be

changed when *p2 = 53 is executed.


T -- (T/F) The output of displaying p1 and *p1 is

the same.

delete -- The command that destroy the connection

between the pointer and the value it is pointing.

F -- (T/F) Invoking a new operator for p1 will not

change anything.

F -- (T/F) The data type that p1 and p2 can point is

float.

F -- (T/F) Once a pointer is assigned to point to a

value, it can no longer be re-assigned to other values.

Answer 1:

Answer 2:

42

Answer 3:

Answer 4:

Answer 5:

Answer 6:

Answer 7:

delete

Answer 8:
F

Answer 9:

Answer 10:

Partial
Question 5 3.5 / 5 pts

Given the program below, answer the succeeding questions:

emp -- What is the name of the struc?

employee -- What is the name of the pointer variable?

char -- What data type can the pointer variable points

to?

T -- (T/F) The variable employee in the main

program and in the function Output are the same.

T -- (T/F) The type of parameter passing used from

main program to function Output is by reference.


T -- (T/F) It is also possible to pass a struct into a

function by value.

4 -- How fields are there in emp?

T -- (T/F) The new operator is necessary to

provide memory allocations for employee.

T -- (T/F) The only function called in the main

program is Accept().

T -- (T/F) The program is capable of accepting

information of multiple employees.

Answer 1:

emp

Answer 2:

employee

Answer 3:

char

Answer 4:

Answer 5:

Answer 6:

Answer 7:

4
Answer 8:

Answer 9:

Answer 10:

Partial Question 6 3.5 / 5 pts

Consider the diagram, answer the succeeding questions:

3 -- What is the size of the stack?

T -- (T/F) The stack is static.

F -- (T/F) When 15 is pushed into the stack, the

value of is_Full() is FALSE.

1 -- Consider, the 2nd occurrence of the stack in

the diagram, what is the value of top?

F -- (T/F) There is a way to retrieve directly the

bottom of the stack.

T -- (T/F) A stack can accept duplicate inputs.

int -- What is the data type of the stack?


2 -- Consider, the 3rd occurrence of the stack in

the diagram, what is the value of top?

3 -- How many pops will you need to retrieve the

value 5 when the stack is full?

F -- (T/F) You can still add values to a stack even if

it is full.

Answer 1:

Answer 2:

Answer 3:

Answer 4:

Answer 5:

Answer 6:

Answer 7:

int

Answer 8:

Answer 9:

3
Answer 10:

Partial Question 7 3 / 5 pts

//This program check for balance parenthesis using parenthesis,


braces and square brackets.
//Note all [] in character array are changed to {} due to conflict in
Canvas.
#include <iostream>

#include < stack >

#include <string>
using namespace std;

int main()
{
int x=0;
char temp;
string input;

stack < char > iStack;

system("cls");
cout << "Enter a series of parentheses: ";
cin >> input;

for (int i = 0; i < input. length() ; i++)

{
if (input{i} == '(' || input{i} == '{' || input{i} == '[')

iStack. pop (input{i});

else if (input{i} == ')' || input{i} == '}' || input{i} == ']')


if (!iStack.empty())
{

temp = iStack. top ();

if (temp == '(' && input{i} == ')') iStack.pop();


else if (temp == '{' && input{i} == ' } ')

iStack.pop();
else if (temp == '[' && input{i} == ']') iStack.
pusg ();

else

x= 0 ;

}
else
x = -1;
else
{
cout << "Invalid Input!" << endl;
exit(0);
}
}

if (! iStack.empty{} )

x = -1;

if (x == 0 )

cout << "Balanced Parenthesis!" << endl;


else
cout << "Inbalanced Parenthesis!" << endl;
system("pause");
}

Answer 1:

stack

Answer 2:

char

Answer 3:

length()

Answer 4:

top
Answer 5:

Answer 6:

pusg

Answer 7:

Answer 8:

iStack.empty{}

Answer 9:

Question 8 5 / 5 pts

Consider the program below, answer succeeding questions:

F -- (T/F) The program makes use of a deque as

an STL stack implementation.

iStack -- What is the name of the stack?

int -- What is the data type of the values stored in

the stack?
T -- (T/F) The program makes use of a dynamic

stack.

4 -- What is the value of top after the 2nd iteration

of the push operation?

6 -- What is the value of top after the final

iteration?

F -- (T/F) The stack has a fixed size.

3 -- After pushing all the data into the stack, what

is the value of iStack,size()?

T -- (T/F) The stack will never become full.

F -- (T/F) The stack will never become empty.

Answer 1:

Answer 2:

iStack

Answer 3:

int

Answer 4:

Answer 5:

Answer 6:

6
Answer 7:

Answer 8:

Answer 9:

Answer 10:

Partial Question 9 4.5 / 5 pts

Consider the diagram below, and answer the succeeding


questions:

T -- (T/F) The queue is static.


int -- What is the data type of the queue?

Rear -- In the diagram, what is the name of the pointer

that points to the last element in the queue?

F -- (T/F) The pointer front moves every time you

add an element to the queue.

F -- (T/F) The operation of retrieving an item from

the queue is called enqueue.

T -- (T/F) The operation of adding an item from the

queue is called dequeue.

F -- (T/F) The only retrieval item in a queue is the

top.

9 -- What is the value of rear at the last occurrence

of the queue in the diagram?

T -- (T/F) The order in which the values are added

to the queue will also be the order that they will be retrieved.

T -- (T/F) The given queue may become full.

Answer 1:

Answer 2:

int

Answer 3:

Rear

Answer 4:
F

Answer 5:

Answer 6:

Answer 7:

Answer 8:

Answer 9:

Answer 10:

Question 10 5 / 5 pts

Consider Program E: True/False: Assigning of one queue to the other


is allowed.
True

False

Partial Question 11 3.5 / 5 pts

Consider the program below, answer succeeding questions:

3 -- How many data members are there in the

struct crew?
2 -- How many data members are there in the

struct guest?

GuestLine -- What is the name of the queue?

1 -- How many pointer variable are there?

Crew -- What is the name of the pointer variable?

int -- What is the data type of the pointer variable?

STL -- What type of queue adapter is used?

int -- What are the data types of the data members

in both structs?

T -- (T/F) The function front returns a value.

F -- (T/F) The function push deletes and discard

the memory allocation in the queue.

Answer 1:

Answer 2:

Answer 3:

GuestLine

Answer 4:

Answer 5:

Crew
Answer 6:

int

Answer 7:

STL

Answer 8:

int

Answer 9:

Answer 10:

Partial Question 12 2.5 / 5 pts

//Determines if a number is PRIME or NOT.


#include <iostream>
using namespace std;
int prime(int n, int i=1);
int main()
{
int num;
cout << "Enter a positive number: ";

cin >> num ;

if (prime(num)== num )

cout << " PRIME " << endl; //Answer must either

PRIME / NOT PRIME.


else

cout << " NOT PRIME " << endl; //Answer must either

PRIME / NOT PRIME.


system("pause");
}

int prime(int n, int i=1 )

if (i == n)

return( n );

else if (n % i == 0 )

return( i + prime(n, i+1 ));

else
return(0 + prime(n, i + 1));

Answer 1:

num

Answer 2:

num

Answer 3:

PRIME

Answer 4:

NOT PRIME

Answer 5:

i=1

Answer 6:

==

Answer 7:

n
Answer 8:

Answer 9:

Answer 10:

i+1

Partial Question 13 3.5 / 5 pts

Given the Expression Tree, answer the succeeding questions:

4 -- What is the degree of the tree?

T -- (T/F) node g is a terminal node.

3 -- How many ancestors do node b have?

4 -- How many ancestors do node e have?

4 -- What is the path length from root + to

node d?

7 -- How many terminal nodes are there?


F -- (T/F) In an expression tree, internal nodes

are represented by the variables in the expression.

T -- (T/F) In an expression tree, expressions

found in the higher level will be evaluated first.

T -- (T/F) All nodes are predecessors of the

root node.

5 -- What is the height of the tree?

Answer 1:

Answer 2:

Answer 3:

Answer 4:

Answer 5:

Answer 6:

Answer 7:

Answer 8:

Answer 9:
T

Answer 10:

Partial Question 14 4 / 5 pts

Consider the diagram below, answer succeeding questions:

char -- What is the data type of the value part of the

node?

1 -- How many pointer variables are needed for

each node?

T -- (T/F) In order to define each node in a binary

tree you will need a class.

T -- (T/F) All pointers pointing to NULL are leaf

nodes.

M -- To what data value is the root pointing?


F -- (T/F) If the left pointer of a node is NULL, it

means it has a child.

T -- (T/F) A node may have both of its pointers

NULL.

F -- (T/F) If I will be searching for the value P, I

need to traverse the entire tree.

F -- (T/F) If a new node is added to the binary

tree, the root will adjust and point to the new node.

T -- (T/F) The first value that will be added to the

binary tree will automatically become the root node.

Answer 1:

char

Answer 2:

Answer 3:

Answer 4:

Answer 5:

Answer 6:

Answer 7:

Answer 8:
F

Answer 9:

Answer 10:

Partial Question 15 3.5 / 5 pts

Given the BST below:

NOTE: Use ALL CAPS LEFT or RIGHT in your ANSWERS. Update


your BST in doing the operations below.

1. Node 12 will be inserted at LEFT of

17

2. Node 3 will be inserted at ,LEFT of

3. Node 40 will be inserted at RIGHT of

31
4. Node 60 will be inserted at RIGHT of

49

5. Post Order Traversal: 5, 10, 8, 4, 6, 11, 17 // separate your answer

with a comma (,) and a space after it

6. Pre-Order Traversal: 11, 6, 4, 5, 8, 10, 19 // separate your answer

with a comma (,) and a space after it

Answer 1:

LEFT

Answer 2:

17

Answer 3:

,LEFT

Answer 4:

Answer 5:

RIGHT

Answer 6:

31

Answer 7:

RIGHT

Answer 8:

49

Answer 9:

5, 10, 8, 4, 6, 11, 17, 31, 49, 43, 19, 11


Answer 10:

11, 6, 4, 5, 8, 10, 19, 43, 31, 49, 17

Partial Question 16 4.23 / 5 pts

Consider the graph below, answer succeeding questions:

F -- (T/F) The graph is an undirected graph.

2 -- How many in-degree do Houston have?

T -- (T/F) The graph is an example of a weighted

graph.

Chicago -- Which of the following nodes has the highest

number of in-degrees?

T -- (T/F) All nodes have in-degrees.

160 -- How much is the cheapest cost from Austin to

Houston?

Dallas -- What node has the highest number of out-

degree?
F -- (T/F) There is no available path from Atlanta to

Dallas.

T -- (T/F) All nodes are reachable.

T -- (T/F) The graph does not have any loops.

360 -- How much is the cheapest route from Dallas to

Houston?

F -- (T/F) There is no available path from Denver to

Austin.

F -- (T/F) Denver is adjacent to Austin.

Answer 1:

Answer 2:

Answer 3:

Answer 4:

Chicago

Answer 5:

Answer 6:

160

Answer 7:

Dallas
Answer 8:

Answer 9:

Answer 10:

Answer 11:

360

Answer 12:

Answer 13:

Partial Question 17 4 / 5 pts

Given the constructor for the Class Graph, fill in all necessary
blanks.

Graph::Graph(int x)
{

V= x ;

adj = new list <int> [ V ];

adj2 = new int* [ V ];

for (int i = 0; i < V; i++)

adj2[ i ] = new int[ V ];

for (int i = 0 ; i < V; i++)


for (int j = 0; j < V; j ++ )

adj2 [i] [j] = 0;

Answer 1:

Answer 2:

new

Answer 3:

Answer 4:

++

Answer 5:

[i]

Answer 6:

[j]

Partial Question 18 4 / 5 pts

Given the algorithm for Bubble Sort, answer succeeding


questions.
a -- What parameter will receive the array to be

sorted from the outside?

n -- What variable represents the size of the

array?

T -- (T/F) The comparison will start at the last

element of the array.

F -- (T/F) The value of last is determined by the

formula n-2.

T -- (T/F) The algorithms requires a loop within

a loop to sort.

T -- (T/F) The process of sorting will still

continue even if the list is sorted.

11 -- If the size of the array is 10, how many

times will the loop iterate?

T -- (T/F) In Bubble Sort, there is a guarantee

that after each pass a value is assigned to its proper location.


swap -- The predefined function that is responsible

for interchanging the values.

F -- (T/F) The number of pass is represented by

the variable j.

Answer 1:

Answer 2:

Answer 3:

Answer 4:

Answer 5:

Answer 6:

Answer 7:

11

Answer 8:

Answer 9:

swap

Answer 10:

F
Partial Question 19 3 / 5 pts

Consider the diagram below, answer succeeding questions:

70 -- What is the value of the pivot element?

F -- (T/F) In partitioning, all values less than the

pivot will go to the right.

T -- (T/F) In partitioning, all values less than the

pivot will go to the left.

T -- (T/F) The position of the pivot element in the

sorted list is fixed.

T -- (T/F) In combining, comparison of elements is

still necessary.

F -- (T/F) The chosen pivot element divides the list

equally.

T -- (T/F) The performance of the quick sort

depends on the chosen pivot element.

4 -- During the first partition process, how many

values is assigned to the left of the pivot element?


T -- (T/F) In quick sort, the process of partitioning

continues until the a single element is left in the list.

T -- (T/F) Recursion will be applied in the combine

step of quick sort.

Answer 1:

70

Answer 2:

Answer 3:

Answer 4:

Answer 5:

Answer 6:

Answer 7:

Answer 8:

Answer 9:

Answer 10:

T
Partial Question 20 4 / 5 pts

Given the code for Sequential Search, answer succeeding


questions:

loc -- What is the name of the variable that will store

the value that you are searching?

list -- What is the name of the array that stores the

values?

bool -- What is the data type of found?

F -- (T/F) The program makes use of a dynamic

array.

T -- (T/F) The program will compare the search

item to each of the element in the array.


T -- (T/F) The worst case in a sequential search is

when the item you are looking for is not found in the list.

true -- What will be the value of found when a search

is successful?

int -- What variable represents the output of the

output of the function?

-1 -- What is the output if a search is unsuccessful?

int -- What is the data type that will be returned by

the function?

Answer 1:

loc

Answer 2:

list

Answer 3:

bool

Answer 4:

Answer 5:

Answer 6:

Answer 7:

true

Answer 8:
int

Answer 9:

-1

Answer 10:

int

Partial Question 21 4.5 / 5 pts

Given the illustration below, answer the succeeding questions:

2.5 -- What is the value being pointed to by Head?

2.5 -- What is the value being pointed to by NodePtr?

7.9 -- What is the value being pointed to by NodePtr-

>Next?

NULL -- What is the value of NewNode-> next?

10.5 -- What is the value of NewNode->value?


F -- (T/F) The Head pointer will be used for

traversal.

T -- (T/F) A NewNode is necessary to be created

every time you want to add a new in a list.

T -- (T/F) In order to insert NewNode, the next

pointer of 12.6 must point to NewNode.

T -- (T/F) Another pointer called PrevNode is

necessary to do insertion.

F -- (T/F) The next pointer of the last node in the

linked list must have a value of 0.

Answer 1:

2.5

Answer 2:

2.5

Answer 3:

7.9

Answer 4:

NULL

Answer 5:

10.5

Answer 6:

Answer 7:

T
Answer 8:

Answer 9:

Answer 10:

Partial Question 22 3 / 5 pts

//This program demonstrates the operations on linked list using the list
STL.
#include <iostream>
#include <string>
#include <list>
using namespace std;
int menu();

struct Product
{
int code;
string name;
};

int main()
{
Product product;

list < string > products;

list <Product>::iterator iter;


int code, ch;
do
{
ch = menu();
system("cls");
if (ch == 1)
{
cout << " << Appending a Product >> " << endl << endl;
cout << "Product Code: ";
cin >> product.code;
cout << "Product Name: ";
cin.ignore();
getline(cin, product.name);

products.push_back( product.code );

}
else if (ch == 2)
{
cout << " << Inserting a Product >> " << endl << endl;
cout << "Product Code: ";
cin >> product.code;
cout << "Product Name: ";
cin.ignore();

getline(cin, product.name );

for (iter = products.begin(); iter != products.end(); iter++)


{

if ( products ->code > product.code)

{
products.insert(iter, 1, product);
break;
}
}
}
else if (ch == 3)
{

bool found = false ;

if ( products.empty() )

cout << "The list is empty!" << endl;


else
{
cout << " << Deleting a Product >> " << endl << endl;
cout << "Product Code: ";
cin >> code;

for (iter = products. begin() ; iter != products.end();

iter++)
{
product = *iter;
if (product.code == code)
{
products.erase(iter);
cout << "Product succesfully deleted!" << endl;
found = true;
break;
}
}

if (! products.empty() ) cout << "Product not found! " << endl;

}
}
else if (ch == 4)
{
if (products.empty())
cout << "The list is empty!" << endl;
else
{
cout << " << Traversing the Product List >> " << endl << endl;
for (iter = products.begin(); iter != products.end();
iter++ )

product = *iter ;

cout << "Product Code : " << product.code << endl;


cout << "Product Name : " << product.name << endl;
cout << "*****" << endl << endl;
}
}
}
else if (ch == 5)
{
cout << "Thank you for using the program!" << endl;
exit(0);
}
else
{
cout << "Invalid Input!" << endl << endl;
system("pause");
break;
}
cout << endl;
system("pause");
} while (ch >= 1 && ch <= 5);

int menu()
{
int ch;
system("cls");
cout << " << Product Linked List Demonstration >> " << endl << endl;
cout << "{1} Append a Product" << endl;
cout << "{2} Insert a Product" << endl;
cout << "{3} Delete a Product" << endl;
cout << "{4} Traverse the Product List" << endl;
cout << "{5} Quit the Program" << endl << endl;
cout << "Enter Choice: ";
cin >> ch;
return(ch);
}

Answer 1:

string

Answer 2:

product.code

Answer 3:

product.name

Answer 4:

products

Answer 5:

false

Answer 6:

products.empty()
Answer 7:

begin()

Answer 8:

products.empty()

Answer 9:

iter++

Answer 10:

*iter

You might also like