Answer BOTH questions from Section A and ONE question from Section B.

Similar documents
Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 2

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Do not turn over until you are told to do so by the Invigilator.

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Overview of Sorting Algorithms

Computer Engineering 1 (1E3)

UNIVERSITY OF EAST ANGLIA School of Computing Sciences May/June UG Examination EMBEDDED SYSTEMS CMPE3D02. Time allowed: 3 hours

Module Contact: Dr Graeme Richards, CMP. Copyright of the University of East Anglia Version 1

Module Contact: Dr Dan Smith, CMP Copyright of the University of East Anglia Version 1

Quicksort. The divide-and-conquer strategy is used in quicksort. Below the recursion step is described:

Lecture Notes on Quicksort

COMP 102: Test August, 2017

Module Contact: Dr Tony Bagnall, CMP Copyright of the University of East Anglia Version 1

ECE 2400 Computer Systems Programming Fall 2018 Topic 2: C Recursion

COS 126 General Computer Science Spring Written Exam 1

Pointers and scanf() Steven R. Bagley

Quicksort. Repeat the process recursively for the left- and rightsub-blocks.

! Search: find a given item in a list, return the. ! Sort: rearrange the items in a list into some. ! list could be: array, linked list, string, etc.

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

Module Contact: Dr Rudy Lapeer, CMP Copyright of the University of East Anglia Version 1

Lecture Notes on Quicksort

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

CS 310 Advanced Data Structures and Algorithms

Module Contact: Dr R J Lapeer, CMP Copyright of the University of East Anglia Version 1

Exam I Principles of Imperative Computation, Summer 2011 William Lovas. May 27, 2011

Copyright of the University of East Anglia Version 1

C0MP1921/2011/2091 SAMPLE Final Exam Data Structures and Algorithms/Data Organisation/Computing 2

COMP 102: Test August, 2017

University of Palestine. Mid Exam Total Grade: 100

Sorting and Searching Algorithms

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Do not turn over until you are told to do so by the invigilator. Module Contact: Dr. Beatriz de la Iglesia (CMP)

Introduction. Sorting. Table of Contents

CS 1301 Exam 1 Spring 2014

Cosc 241 Programming and Problem Solving Lecture 17 (30/4/18) Quicksort

Binary Trees. Quicksort. SorKng process with quicksort. University of Massachuse5s Amherst ECE 242 Data Structures and Algorithms Lecture 18

CS Sorting Terms & Definitions. Comparing Sorting Algorithms. Bubble Sort. Bubble Sort: Graphical Trace

VARIABLE, OPERATOR AND EXPRESSION [SET 1]

Module Contact: Dr Beatriz de la Iglesia, CMP Copyright of the University of East Anglia Version 1

Announcements. Topics: To Do:

McGill University School of Computer Science COMP-202A Introduction to Computing 1

1 Short Answer (15 Points Each)

Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department

Copyright of the University of East Anglia Version 2

BEng (Hons) Electronic Engineering. BEng (Hons) Telecommunications. Examinations for / Semester 2

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

CS 1301 Exam 1 Spring 2014

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Fundamentals of Python: First Programs. Chapter 4: Strings (Indexing, Slicing, and Methods)

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Sorting. Task Description. Selection Sort. Should we worry about speed?

1. What does the following code fragment write to the monitor?

COMP1511 focuses on writing programs. Effciency is also important. Often need to consider:

CS 33. Introduction to C. Part 4. CS33 Intro to Computer Systems IV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CE151-4-AU UNIVERSITY OF ESSEX. Sample Examination Questions 2011 INTRODUCTION TO PROGRAMMING

Homework Assignment #3. 1 (5 pts) Demonstrate how mergesort works when sorting the following list of numbers:

Lecture Notes 14 More sorting CSS Data Structures and Object-Oriented Programming Professor Clark F. Olson

Sorting. Lecture10: Sorting II. Sorting Algorithms. Performance of Sorting Algorithms

NATIONAL UNIVERSITY OF SINGAPORE

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Functions. Arash Rafiey. September 26, 2017

Algorithm for siftdown(int currentposition) while true (infinite loop) do if the currentposition has NO children then return

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort

Introduction. Sorting. Definitions and Terminology: Program efficiency. Sorting Algorithm Analysis. 13. Sorting. 13. Sorting.

ECE 2400 Computer Systems Programming Fall 2018 Topic 1: Introduction to C

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

CIS March 1, 2018

Introduction to Programming SAMPLE. Examination Paper. Time: 3 hours

DATA STRUCTURES AND ALGORITHMS

Sorting. Order in the court! sorting 1

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

CSE 2123 Sorting. Jeremy Morris

CS 139 Practice Midterm Questions #2

Module Contact: Dr Rudy Lapeer (CMP) Copyright of the University of East Anglia Version 1

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

Recursion. ! When the initial copy finishes executing, it returns to the part of the program that made the initial call to the function.

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

CSE373 Spring 2015: Final

Introduction to Computer Programming

APCS Semester #1 Final Exam Practice Problems

Lecture 7 Quicksort : Principles of Imperative Computation (Spring 2018) Frank Pfenning

? Answer:

QuickSort. CIS 15 : Spring 2007

Sorting. Order in the court! sorting 1

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

Complexity, General. Standard approach: count the number of primitive operations executed.

CSE 143. Two important problems. Searching and Sorting. Review: Linear Search. Review: Binary Search. Example. How Efficient Is Linear Search?

Transcription:

UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2013/14 INTRODUCTORY PROGRAMMING CMP-0005B Time allowed: 2 hours Answer BOTH questions from Section A and ONE question from Section B. All questions carry equal weight. Notes are not permitted in this examination. Do not turn over until you are told to do so by the Invigilator. CMP-0005B Module Contact: Dr Graeme Richards, CMP. Copyright of the University of East Anglia Version 1

Page 2 SECTION A 1. There is no requirement to test for input ranges or carry out other validation in the following parts of this question. Comments should only be included if they are required to add clarity to the code. (a) Write a C++ code fragment to ask the user how many numbers they wish to input. Then, allow them to input the numbers and output the sum of the numbers input. (b) Write a C++ code fragment to ask a user to enter their height in metres (m) and their weight in kilograms (kg) then output their body mass index (BMI). BMI = weight/height 2. The user should then be given the opportunity to enter another body weight and height (c) Write a C++ code fragment to allow a user to enter any number of positive integers. When a negative integer is entered the code should output all of the numbers that have been entered, but in reverse order. CMP-0005B Version 1

Page 3 2. (a) The C++ program below contains a number of syntax errors. Identify and describe each syntax error. Use line numbers to identify the errors. 1. int partition(int a[], left, right, pivotindex) 2. { 3. int pivot = a[pivotindex], temp=""; 4. repeat 5. { 6. whilst (a[left] < pivot) 7. left++; 8. whilst (a[right] > pivot) 9. right--; 10. if (left and right and a[left]!= a[right]) then 11. { 12. tmp = a[left]; a[left]= a[right]; a[right]=temp; 13. } 14. else 15. { 16. return right; 17. } 18. }while(left or right); 19. return right; 20. } 21. 22. void quicksort(int a[], left, right) 23. { 24. if (left <> right) 25. { 26. int pivot = (left or right) / 2; // middle 27. int pivotnew=partition(a,left,right,pivot); 28. quickstor(a, left, pivotnew - 1); 29. quickstor(a, pivotnew + 1, right); 30. } 31. (b) Write a C++ code fragment that generates a random number between 1 and 6 inclusive. It should then output a textual representation as output. E.g. if a 1 is generated the output should be one, if a 2 is generated the output should be two. CMP-0005B Version 1 TURN OVER

Page 4 (c) What is the output of the following main function after calling the function? int func(int a, int &b, int * c) { a = b; b = *c; *c = a; return a+b+*c; } void main() { int a=1, b=2, c=3; int* cpoint=&c; int result = func(a, b, cpoint); cout<<a<<" "<<b<<" "<<c<<" "<<result<<endl; } CMP-0005B Version 1

Page 5 SECTION B 3. (a) Write a function that asks a user for the number of hours they have worked and their hourly rate of pay and then returns these values. (b) Write another function that calculates total pay as hours hourly rate and returns this value. (c) Write another function that accepts hourly rate and hours worked as arguments and outputs these values along with total pay as calculated by the function in Question 3.b. (d) Write a main function that utilises the other functions in Question 3 to ask the user for their hours worked and hourly rate and outputs theses values together with the total pay. CMP-0005B Version 1 TURN OVER

Page 6 4. (a) Write a C++ class to represent a job carried out by a removal company. The class should include only four members, driver s name, customer s name, hours spent on job and hourly rate. The class should include a single constructor for all members and get and set methods for the driver s name. There should also be a method for calculating the total cost of a job (hours spent hourly rate) and a method to output all of a job s members and the total cost. [20 marks] (b) In a main function, create an instance of a new job by asking the user for the job information. (c) In the same main function create a vector capable of storing a set of jobs and add the job from Question 4b to it. [5 marks] (d) Assume that the vector in Question 4c includes many jobs. In the same main function add code to output the job details for each of the jobs in the vector. [5 marks] END OF PAPER CMP-0005B Version 1