Question

In: Computer Science

INSTRUCTIONS: 1. The Assignment contains 3 questions (20 MARKS Each) with a total of 60 MARKS...

INSTRUCTIONS:
1. The Assignment contains 3 questions (20 MARKS Each) with a total of 60 MARKS
2. All questions must be answered electronically (No hand-written submissions)
3. Draw all the required diagrams using a drawing software application/tool e.g. Microsoft
Visio. (No snapshots/screengrabs will be accepted). You can use one of the CASE tools
you use in OOSAD if you wish.
4. Submit a Portable Document Format (PDF) as your final submission. No other file

QUESTION ONE
1. Briefly describe the 3 main operations that can be performed on a stack data structure.
[3 Marks]
2. Which container would best be used in each of the following situations? [4 Marks]
a. You have several phone messages coming in and want to handle them in the order
they were received.
b. You have a phone bill arriving each month and want to be able to look up any
month's bill.
c. You are planning a road trip and have listed several stops along the way but want
to be able to add a new one partway through.
d. You are having a conversation and keep going off on new topics. You want to
keep track of the conversation so that once you finish one topic, you can return to
the previous one—and then when that is done, the one before that, etc.
3. State three applications of the stack data structure [3 Marks]
4. Write a program that uses a queue or stack or both data structures to keep track of the
order of people who arrive to meet with you. You should repeatedly ask for a name, or, if
the user types next, you should print the name of the next person who should be met. An
example of a run of this might be as follows:
format will be accepted.
6. There will be no extension on the due date.
7. The assignment covers data structures and the C++ Standard Template Library (STL)
based on the recommended book (Malik, 2018)
8. This assignment will contribute 10 percent towards the final Continuous Assessment test

QUESTION TWO
1. Write a function called printVector that takes in a vector of integers called v, as a
parameter and then uses an iterator named iter, to print out each element, one per line.
[5 Marks]
2. Suppose you want to read in a bunch of peoples' names and salaries and then print a list
of the people from lowest to highest salary. To read in the information, imagine that you
just prompt users to enter their name and salary on the console repeatedly. Because
people won't have a negative salary, ask the user to indicate that he or she is done by
entering a sentinel value, such as a negative value for the salary.
Write a program that uses a vector from the Standard Template Library (STL) and
Templated sort function found in the Algorithm library to sort the data as pairs. Below is
the sample run of your program:

Enter a person's name and salary

(One name and then one salary per line. )

Enter a negative salary to stop.

Messi 500

Mane 200

Ronaldo 400

Neymar 300

Pogba 100

Mbesuma -2

100 pogba

200 Mane

300 Neymar

400 Ronaldo

500 Messi

QUESTION THREE
1. Suppose that stack is an object of type stackType<double>, the value of stack.top is 8,
and dec is a variable of type double. [4 Marks]
a. How many elements are in stack?
b. What is the index of the top element of stack?
c. Write the statement that assigns the top element of stack to dec.
d. Write the statement that removes the top element of stack.
2. What is a node in a binary tree that has no left and right children called? [1 Mark]

  

3. Use the binary tree shown below to answer the questions that follow: [5 Marks]
a. Find LA, the node in the left subtree of A.
b. Find LH, the node in the left subtree of H.
c. Find the height of the tree with root B.
d. List the nodes with exactly one child.
e. List the nodes of this binary tree in a preorder sequence.
4. The following lists the nodes in a binary tree in two different orders:
Preorder: A B C D E F G H I J K L M
Inorder: C E D F B A H J I K G M L
Draw the binary tree. [10 Marks]
References
Malik, D. S., 2018. C++ Programming: Program Design Including Data Structures. 8th ed. Boston:
Cengage Learning.

Solutions

Expert Solution

Question one:

1. i. PUSH--when we want to add an element in the stack we use the push operation to insert and element in the stack.

ii.POP - we want to delete the element that is on the top of the stack , than we use the POP function

iii.isEMPTY - we use this operation to see whether the stack is empty or not.

2.

a. You have several phone messages coming in and want to handle them in the order they were received.--we can use the queue data structure here as it stores the item based on their arrivale time and displays the item that was first arrived.

b. You have a phone bill arriving each month and want to be able to look up any month's bill.-- we can use the array here as we can easily see any item in the array using the index reference.

c. You are planning a road trip and have listed several stops along the way but want to be able to add a new one partway through.-- we can use array data structure because it allows the easy insertion and deletion of element at any index


Related Solutions

3. Capital Budgeting Assignment (15 marks) Instructions: The assignment is based on the case below. The...
3. Capital Budgeting Assignment Instructions: The assignment is based on the case below. The instructions relating to the assignment are at the end of the case. Dan and Susan are facing an important decision. After having discussed different financial scenarios, the two computer engineers felt it was time to finalize their cash flow projections and move to the next stage – decide which of two possible projects they should undertake. Both had a bachelor degree in engineering and had put...
ASSIGNMENT 3- 60 MARKS 1. (a) Briefly define interest rate and explain the types of interest...
ASSIGNMENT 3- 60 MARKS 1. (a) Briefly define interest rate and explain the types of interest rate. 10 Marks (b) Jim deposits $3,000 today into an account that pays 10% per year, and follows it up with three more deposits at the end of each of the next 3 years. Each subsequent deposit is $2,000 higher than the previous one. How much money will Jim have accumulated in his account by the end of 3 years? 10 Marks 2. (a)...
Assignment 3 BUS 151: Microeconomics Semester 402 Total Marks=20 Note: Answers should be written with appropriate...
Assignment 3 BUS 151: Microeconomics Semester 402 Total Marks=20 Note: Answers should be written with appropriate headings. You may also draw figures to answer your questions more clearly. Question 1: Explain with your example that how a country with absolute advantage in its production of two goods can gain from trade from another country which has no comparative advantage on the same goods. (6 marks) Chapter 3 Question 2: By explaining law of demand and law of supply show how...
PROBLEM 5: FOREIGN CURRENCY (20 MARKS TOTAL) Use the information here for answering questions 1 to...
PROBLEM 5: FOREIGN CURRENCY (20 MARKS TOTAL) Use the information here for answering questions 1 to 3 on this page. On 1 April 2020, Winton Ltd, an Australian entity, places an order for GBP £200,000 of inventory with Austen plc, a UK supplier. On the same date, Winton Ltd enters into a forward exchange contract with the bank to buy GBP £200,000, to be settled on 31 July 2020. The goods are shipped FOB London on 1 May 2020 and...
QUESTION 3 (14 marks) (Total 20 marks) A. Undeniably, profitability is the ultimate goal of companies...
QUESTION 3 (Total 20 marks) A. Undeniably, profitability is the ultimate goal of companies and readers of a company’s financial statements are very much interested in the reported profit figure. The profit figure is achieved by the preparation of the statement of profit or loss and the statement of financial position. If the foregoing is the 3 case, why then bother about the statement of cash flows? B. Globally, accounting standards are developed based on different methods. It is generally...
QUESTION 1 (10 Marks- 5 each)- This question contains two sub questions a and b. Describe...
QUESTION 1 (10 Marks- 5 each)- This question contains two sub questions a and b. Describe five requirements of the COBIT framework. Compare the followings in terms of capacity, expenses, processing power, size and users they support: Supercomputers Mainframe Computers Comparison Element Supercomputers Mainframe Computers
Use it and Excel to answer this question. It contains Assignment 1 marks for two past...
Use it and Excel to answer this question. It contains Assignment 1 marks for two past sections of this course Treat it as a random sample. Perform a hypothesis test to determine if the two sample means are equal. Use α = 0.10. Section A Section B 15 16 26 52 52 55 53 57.5 54 58 56.5 60 61 61 61.5 70 63 70 66 71 66 72 66.5 73 69 74.5 71 75 77 75.5 77 76 78...
Question 1 [1 mark each/Total 20 marks] Choose the correct answer 5) A relative price is...
Question 1 [1 mark each/Total 20 marks] Choose the correct answer 5) A relative price is the A) slope of the demand curve. B) difference between one money price and another. C) slope of the supply curve. D) ratio of one money price to another. 6) Wants, as opposed to demands, A) are the unlimited desires of the consumer. B) are the goods the consumer plans to acquire. C) are the goods the consumer has acquired. D) depend on the...
Compare and contrast the following: (4 marks each, total 20 marks) Scanning electron microscope and confocal...
Compare and contrast the following: (4 marks each, total 20 marks) Scanning electron microscope and confocal microscope Gated transport channels and carrier proteins – in membranes Tight junctions and desmosomes Substrate level phosphorylation and oxidative phosphorylation Non-cyclic and cyclic photophosphorylation Cell membranes are selective. Explain how the lipid bilayer determines permeability and selectivity of the membrane. Describe how microtubules help vesicles move. Differentiate the fate of proteins made at the rough endoplasmic reticulum compared to proteins made in the cystol....
INSTRUCTIONS: This question contains three (3) parts. Answer all parts of the questions. Clearly label your...
INSTRUCTIONS: This question contains three (3) parts. Answer all parts of the questions. Clearly label your response to each part using bold text. For example: Part a): Your response... (a) The weighted average cost of capital (WACC) can be calculated as where E is the market value of equity, D is the market value of debt, V = E + D, ke is the cost of equity, kd is the cost of debt and t is the tax rate. Briefly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT