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...

c++ exam


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 this examination from nor will I give it to another person. Signature: ____________________ · 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. b. 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 { public: AType( ); void f(int a); private: 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 { public: SomeClass( ); SomeClass (int x, int y); void func( ); private: 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 voiddoThis(inta,int&b) { inttemp; 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?="" a.="" no="" b.="" 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 18-19. Given linked list listdata 25 30 45 60 80 90 ptr1 ptr2 18. Give the value of expression ptr1->next->next->data 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="" void="" func(int="" i)="" {="" if="" (i="">< 7)="" {="">< i=""><' ';="" func(i+1);="" cout="">< i="">< ' '; } } which one will be produced when func(4) is called? a. 5 6 7 8 b. 4 5 6 6 5 4 c. 4 5 6 7 7 6 5 4 d. 5 6 7 8 8 7 6 5 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 double*ptr1; double*ptr2; 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). 1. (12 points) write a recursive void function with one parameter (positive integer) and the function shall write its argument to the screen backward. for example '="" ';="" }="" }="" which="" one="" will="" be="" produced="" when="" func(4)="" is="" called?="" a.="" 5="" 6="" 7="" 8="" b.="" 4="" 5="" 6="" 6="" 5="" 4="" c.="" 4="" 5="" 6="" 7="" 7="" 6="" 5="" 4="" d.="" 5="" 6="" 7="" 8="" 8="" 7="" 6="" 5="" 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="" double*="" ptr1;="" double*="" ptr2;="" 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).="" 1.="" (12="" points)="" write="" a="" recursive="" void="" function="" with="" one="" parameter="" (positive="" integer)="" and="" the="" function="" shall="" write="" its="" argument="" to="" the="" screen="" backward.="" for="">
May 12, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here