1.) What does RAM stand for? 8 16 Final Examination COSC 501, Spring 2021 Name: _____________________ Student ID: ________________ By signing below, I pledge that I neither received the information of...

1.) What does RAM stand for?
Final Examination
COSC 501, Spring 2021
Name: _____________________
Student ID: ________________
By signing below, I pledge that I neither received the information of this examination from nor will I give it to another person.
XXXXXXXXXXSignature: ____________________
· You have 3 day to submit this examination.
· Write answers in this document, save and submit.
· Total points are 300.
· You should add comments to code, failing to do so will result in deducting grades
Good Luck!
Question 1: Multiple Choice (26 x 6 = 156 points).

1. Which one is true about stacks and queues?
a. stacks are last-in-first-out, while queues are first-in-first-out.
XXXXXXXXXXb. stacks are first-in-first-out and both of them could be accessed randomly.
c. stacks are last-in-first-out and queues could be accessed randomly.
d. queues are last-in-first-out, while stacks are first-in-first-out.
e. queues are first-in-first-out and stacks could be accessed randomly.
2. Given declaration
struct ListNode
double volume;
ListNode* next;
ListNode* headPtr;

Assume headPtr as the external pointer to the first node in a linked list with multiple nodes (at least 2), which statement deletes the second node?
a. headPtr = headPtr->next;
b. *headPtr = headPtr->next;
c. headPtr->next = headPtr->next->next;
d. headPtr->(*next) = headPtr->next->next;
e. none of the above
3-4. Consider class definition
class AType {
AType( );
void f(int a);
int n;
3. The following client code has one or more errors
ATypeob1, ob2;// Line 1
ob1.f(3);// Line 2
ob2.n = ob1.n;// Line 3
Identify line(s) with error(s):
a. Line 1b. Line 2c. Line 3d. Lines 1 and 2e. Lines 2 and 3
4. Which statement in a client program is valid? (ob1 and ob2 are class AType objects)
a. ob1 = ob2;b. cin << ob1.n;c. cout >> ob2.n;
d. if (ob1.n > 7) ob2.G(10); e. none of the above
5. Using declaration with C++ string type
string myname, yourname;
Which statement(s) is (are) not valid?
a. cout << myname;b. cin >> yourname;
c. if (myname != yourname) myname = yourname;
d. all of them are invalid.
e. none of them are invalid.
6. Which statement about structure data type is false?
a. members in the same structure must be of the same data type.
b. array could be member of structure.
c. structure could be passed to function as parameter.
d. member of structure could be another structure.
e. none of the above
7. If the program makes too many recursive function calls, it will incur
a. stack underflow
b. stack overflow
c. syntax error
d. a and b
e. a, b and c
8-10. Consider class declaration
class SomeClass {
SomeClass( );
SomeClass (int x, int y);
void func( );
int m;
int n;
8. Consider the code above and client code

SomeClass delta(5, 6);
After delta is created, what is the value of delta.m?
a. 0b. 5c. 6
d. unknown, but the declaration is valid.
e. the declaration is invalid.
9. Consider the code above and client code
SomeClass alpha, beta;
Which identifiers are names of class instances (objects)?
a. m and nb. alpha.m and beta.nc. SomeClass
d. alpha and betae. none of the above
10. Which one declares an array of 5 characters and initializes them to known values?
a. char array[5]={'a','b','c','d','e'};
b. char array[4]={'a','b','c','d','e'};
c. char array[5]={''};
d. char array[]={'a','b','d','e'};
e. b and d
f. a and c
g. none of the above
11. Consider function
a= a+ 100;
temp= b;
b= a + temp;
Suppose that function caller has integer variables x and y, whose values are 10 and 20, respectively. What are the values of x and y after returning from the following function call?
doThis (y, x);
a. x = 10 and y = 20b. x = 10 and y = 120c. x = 130 and y = 120
d. x= 130 and y = 20e. none of the above
12. Constructor has the same name as
a. classb. class instancec. programd. private member e. none of the above
13. Given function prototype
double fix (int&, double);
Which one is an appropriate function call? (x is of type int and y is of type double.)
a. return fix(10,y);
b. y = 3.0 * fix(x, 1.25);
c. if (fix (3, 1.5) >= 0.0) cout << "Done";
d. all of the above
14. Which one about call-by-reference is true?
a. actual parameter is never modified by execution of the called function.
b. formal parameter is never modified by execution of the called function.
c. actual parameter must be a variable.
d. actual parameter cannot have a Boolean value.
15. Can two different classes contain private members with the same name?
XXXXXXXXXXa. nob. yes, but only if the two classes have the same name.
c. yes, but only if the main program does not declare both classes at the same time.
d. yes, this is always allowed.
e. none of the above
16. Given code block
struct NodeType
int data;
NodeType* next;
NodeType* p;
NodeType* q;
p = new NodeType;
p->data = 12;
p->next = NULL;
q = new NodeType;
q->data = 5;
q->next = p;
Which expression has value 12?
a.q b.q->data c.q->next->data
d.q->next e.none of the above
17. If p1 is an integer pointer pointing to memory location 3002 (an integer takes up 4 bytes), then (p1+1) will evaluate to
a. 3003b. 3004 c. 3005 d. 3006 e. none of the above
XXXXXXXXXXGiven linked list
18. Give the value of expression
a. 30b. 45c. 60d. 80 e. 90
19. Which expression is false?
a. listdata -> next = = ptr1b. ptr1-> next->next->next = = ptr2
c. listdata-> next -> data = = *ptr1 d. ptr2->next->next = = NULL
20. To dereference a structure data field pointed by pointer, the appropriate operator is
a. &b. *c. ->d. <-e. none of them
21. Which one could describe the base case of a recursive algorithm?
a. f(x) = x + f(x-1);
b. if (x = = 100) x = x + y ;
c. all parameters are integers.
d. cout <<"error";
e. a and b above
22. Consider function
voidfunc(int i)
if (i < 7) {
cout<< i <<' ';
cout << i << ' ';
Which one will be produced when func(4) is called?
e. none of the above
23. Given declaration
int *myPtr;
Which one is a valid statement?
a. myPtr = new int[10] *;b. new myPtr = int[10];
c. new myPtr[10];d. myPtr = new int[10];
e. myPtr = new int&[10];
24. What is special about the last node in a single linked list?
a. its data member is empty.
b. its data member contains value 0.
c. its link member is empty.
d. its link member contains value NULL.
e. it has no link member.
25. Given declaration
Which one is a valid statement?
a.* ptr1 = & ptr2;
b.*ptr1 = * ptr2;
c.ptr1 = &ptr2;
d.ptr1 = 3.5;
e. none of the above
26. Dynamic variables have no names.
a. True
b. False
Question 2: Code block design and output evaluation (66 points).

XXXXXXXXXXpoints) Write a recursive void function with one parameter (positive integer) and the function shall write its argument to the screen backward. For example, if the argument is 1234, the function shall print out 4321.
XXXXXXXXXXpoints) This program creates a linked list with three names:
struct Node
string name;
Node *link;
typedef Node* NodePtr;
int main()
NodePtr listPtr, tempPtr;
listPtr = new Node;
listPtr->name = "Alex";
tempPtr = new Node;
tempPtr->name = "Tina";
listPtr->link = tempPtr;
tempPtr->link = new Node;
tempPtr = tempPtr->link;
tempPtr->name = "Bob";
tempPtr->link = NULL;
return 0;
Perform task: Insert name “Simpson” to the list after “Tina”.
XXXXXXXXXXpoints) Small class definition:
class Small
Small( );
void k( );
void h(int i);
int size;
Suppose that x and y are both Small objects. Write the word True or False to indicate whether the statements are legal or not:
a. x = y; // in client program__________
b. x.size = 4; // in function h XXXXXXXXXX__________
c. size = 4; // in function k XXXXXXXXXX__________
d. y.size = x.size; // in client program__________
e. x.k( ); // in client program__________
f. Small.h( 10 ); // in client program__________
XXXXXXXXXXpoints) Given code block
inti, j;
for (j = 0; j < 4; j++)
for (i = 1; i >= 0; i--)
table[i][j] = (3*j) + i - 1;
After execution, what are the contents in table array?
_____ _____ _____ _____
_____ _____ _____ _____
XXXXXXXXXXpoints) What is the result for func(73)?
void func(int n )
cout<< n % 5;
if (n > 5){
func(n / 4);
cout << n % 5;
} XXXXXXXXXXOutput : ____________________________________
Question 3: Write program (78 points).

1. (21 points) Write a C++ program that creates an array with 30 random integers (between 1 and 100) and passes the array to function to print it out in reverse order using bubble sort.
2. (21 points) Jet Propulsion wants to write a program that takes an array (containing digitized representation for a night sky picture) and locates the stars on the picture. Each element in the array denotes the light amount at the corresponding portion of the image when the picture was taken. Light amount ranges from 0 to 20.
Sample Input:
A star is probably located in the area covered by array element a[i][j] in the case of
XXXXXXXXXXa[i][j] + sum of 4 surrounding light amounts) / 4.0 > 3.5,
where 4 surroundings are the 4 neighbors (North, South, East and West).
Ignore possible stars at the edge of the array, which means you do not need to check the boundary elements.
The output shall be a star map that contains asterisks at where stars present and blanks otherwise. With the given Sample Input, your Sample Output (star map) might look like:
Sample Output (not correct!!!):

Write a detect function in C++. The 2-D array shall be passed to detect, which generates a 2-D star map using the aforementioned condition. (Just implement detect function ONLY)
Please use the following declarations:
constint N_Row = 6;
constintN_Col = 8;
typedefchar MapType[N_Row][N_Col];
typedef int DataType[N_Row][N_Col];

voiddetect(DataType, MapType);

int main( )
DataType inTens;

detect( ______ , ______ );

void detect (DataTypeA, MapTypeM)
3. (18 points) Write a structure StuRecType for student information using nested structures, NameType, DateType and PersonInfoType:
(You have to define NameType, DateType and PersonInfoType before using them.)

Name (3 fields XXXXXXXXXXNameType
Last (string)
First (string)
Middle (char)
Date of Birth (3 fields) ---- DateType
Month (integer)
Day (integer)
Year (integer)
Personal Information (3 fields XXXXXXXXXXPersonInfoType
Gender (char)
Height (double)
Weight (double)
Student Information:
Social Security Number (string)
Student Name
Student DOB
Advisor’s Name
High School GPA (double)
Student Personal Information
4. (18 points) Design a class.
a. Give C++ class definition for the following abstract data type. Select suitable data representations and public interfaces for the operations (function members). (Do not implement the function members)
Mortgage Account (at most one transaction is performed in a month.)
Each instance of the variable rate Mortgage Account keeps track of customer’s balance and calculate the monthly payment on a home mortgage.
Operations (function members):
Create mortgage account.
(The default mortgage amount is $200,000 for an account. If the amount of mortgage amount is larger or smaller, then you have to pass the mortgage amount for the account.)
SetInterestRate for the date. (date and changed interest rate should be passed by
XXXXXXXXXXa parameter)
CalcMonthlyPayment with the due date. (date and monthly payment should be
XXXXXXXXXXpassed by a parameter)
Display the remaining principle, its interest rate, the number of remaining
payments, the number of years of the loan.
ReceivePayment with the date.

classMortgageAccountClass {
intnopayments;// the number of remaining payments
intyears;// term in years
b. Write client declaration statements for two mortgage account class objects (instances), one for Sam (loan amount is $200,000) and one for Mark (loan amount is $350,000) based on a.
May 12, 2021

Submit New Assignment

Copy and Paste Your Assignment Here