ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 2 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 02 May 2017 My Price 9.00

put of each of the following C++ statements

Do I have the right answers for these question? if not what did I miss and why?

Questions are in the attached pdf.

My Answers are:

Chapter 5-2. What is the output of each of the following C++ statements?

a. 18

b. 32

c. 25

d.    16

Chapter 5-4. Mark each of the following statements as valid or invalid. If a statement is invalid, explain why.

a. VALID

b. VALID

c. VALID

d. *list = B;

INVALID (*list is a dereferenced pointer to list which is a collection of nodes and you are trying to assign it to an actual node.)

e. VALID

f. B = A->link->info;

INVALID (B is of nodeType<Type> and A->link->info is of type int)

g. VALID

h. list = B->link->link;

INVALID List is collection of nodes and B->link-> is a pointer to a node.

i. B = B->link->link->link;

INVALID (Read access violation because B->link->link->link is NULL;

 

 

COSC 2336 Programming Fundamentals III Lab 5 - Exercisesi Figure 5-1 Linked List for Exercises 2 &amp; 4 Chapter 5-2.What is the output of each of the following C++ statements?
a.
b.
c.
d. cout
cout
cout
cout &lt;&lt;
&lt;&lt;
&lt;&lt;
&lt;&lt; list-&gt;info;
A-&gt;info;
B-&gt;link-&gt;info;
list-&gt;link-&gt;link-&gt;info Chapter 5-4. Mark each of the following statements as valid or invalid. If a statement is invalid, explain
why.
a.
b.
c.
d.
e.
f.
g.
h.
i. A = B;
list-&gt;link = A-&gt;link;
list-&gt;link-&gt;info = 45;
*list = B;
*A = *B;
B = A-&gt;link-&gt;info;
A-&gt;info = B-&gt;info;
list = B-&gt;link-&gt;link;
B = B-&gt;link-&gt;link-&gt;link; Professor R. Garrett COSC 2336 Programming Fundamentals III Page 1 COSC 2336 Programming Fundamentals III Chapter 5-14. What is the output of the following program segment?
list&lt;int&gt; intList;
ostream_iterator&lt;int&gt; screen(cout, &quot; &quot;);
list&lt;int&gt;::iterator listIt;
intList.push_back(5);
intList.push_front(23);
intList.push_front(45);
intList.pop_back();
intList.push_back(35);
intList.push_front(0);
intList.push_back(50);
intList.push_front(34);
copy(intList.begin(), intList.end(), screen);
cout &lt;&lt; endl;
listIt = intList.begin();
intList.insert(listIt,76);
++listIt;
++listIt;
intList.insert(listIt,38);
intList.pop_back();
++listIt;
++listIt;
intList.erase(listIt);
intList.push_front(2 * intList.back());
intList.push_back(3 * intList.front());
copy(intList.begin(), intList.end(), screen);
cout &lt;&lt; endl; Professor R. Garrett COSC 2336 Programming Fundamentals III Page 2 COSC 2336 Programming Fundamentals III Lab 5 - Programming Exercisesi
Chapter 5-6.
a. Add the following operation to the class orderedLinkedList:
void mergeLists(orderedLinkedList&lt;Type&gt; &amp;list1,
orderedLinkedList&lt;Type&gt; &amp;list2);
// This function creates a new list by merging the
// elements of list1 and list2.
// Postcondition: first points to the merged list; list1
// and list2 are empty
Example: Consider the following statements:
orderedLinkedList&lt;int&gt; newList;
orderedLinkedList&lt;int&gt; list1;
orderedLinkedList&lt;int&gt; list2;
Suppose list1 points to the list with the elements 2 6 7 and list2 points to the list with the
elements 3 5 8. The statement: newList.mergeLists(list1, list2); creates a new linked
list with the elements in the order 2 3 5 6 7 8 and the object newList points to this list. Also,
after the preceding statement executes, list1 and list2 are empty.
Implementation Notes: No additional memory is required when creating the merged list. The
correct solution should perform the following tasks:
1.
2.
3.
4.
5.
6.
7.
8. Create a pointer to the merged list (newList)
Compare the first element in list1 and list2
Insert the smaller of the 2 elements into the merged list through pointer manipulation.
Advance the “first” pointer of the list containing the smaller element.
a. The size of the list containing the smaller element is reduced by 1.
Repeat the process until one of the lists is empty.
The elements in the remaining list should then be added to the end of the merged list.
Don’t forget to update the “count” variable in each list after removing an element from
that list.
After the elements in both lists have been added to the merged list simply set the “first”
and “last” pointers in each list to NULL to indicate the lists are empty. This does not result
in a memory leak because the elements in each list were added to the merged list through
pointer manipulation. Professor R. Garrett COSC 2336 Programming Fundamentals III Page 3 COSC 2336 Programming Fundamentals III
Modify the file orderedLinkedList.h and add your changes at the end of the
orderedLinkedList class definition. The file linkedList.h required by the file
orderedLinkedList.h has been provided as well.
b. Write the definition of the function template mergeLists to implement the operation
mergeLists. Modify the class orderedLinkedList in the file orderedLinkedList.h
and add your function definition at the end of the file. Then use the test program lab5-6.cpp to test
your program. Use the input data (if any) shown in the output window on the following pages and
then compare your results with the expected results.
Expected Program Input and Output i
Exercises and Programming Exercises were extracted from the adopted course textbook, Data Structures Using
C++, Second Edition, D.S. Malik, 2010 Course Technology, Cengage Learning for the purpose of annotating each
exercise with Professor specific instructions (when necessary) that facilitate student completion. Professor R. Garrett COSC 2336 Programming Fundamentals III Page 4

Attachments:

Answers

(11)
Status NEW Posted 02 May 2017 04:05 AM My Price 9.00

-----------

Not Rated(0)