Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Contrast Template - Computer Programming - Exam, Exams of Computer Engineering and Programming

Main points of this past exam are: Contrast Template, Overloaded Functions, Function Prototype, Floating Point Numbers, Function Parameters, Particular Attention, Computer Memory, Floating Point Array, Bubble Sort Algorithm, Positive Integer Number

Typology: Exams

2012/2013

Uploaded on 03/28/2013

duraid
duraid 🇮🇳

4.3

(3)

75 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cork Institute of Technology
Page 1 of 7
Bachelor of Science (Honours) in Software Development and Computer
Networking – Stage 1
(NFQ Level 8)
Summer 2006
Computer Programming
(Time: 3 Hours)
Answer Q1 (40 marks) and
ONE question from Section B (30 marks) and
ONE question from Section C (30 marks).
(Total of THREE questions.)
Please read instructions carefully.
Examiners: Dr. J. Buckley
Dr. A. Kinsella
Ms. C. McGuane
Section A
1. [40 marks]
Answer all parts.
a) Compare and contrast template and overloaded functions. [4 marks]
b) Write the syntax of [3 marks]
(i) switch statement
(ii) a function prototype
(iii) a while loop
c) What is a
struct? [4 marks]
Write code to declare a struct called Time that holds hours, minutes, and seconds that
represent time.
Write a function that receives an instance of Time and returns the number of seconds that
have passed since midnight.
d) What is an array? [3 marks]
Write code to declare an array called numbers that holds 20 floating point numbers and
initialise each element to zero.
Write code to store 11.11 and 22.22 in the second and fifth locations respectively in
numbers.
e) With respect to function parameters, explain the terms “pass by value” [3 marks]
and “pass by reference”, paying particular attention to computer memory.
pf3
pf4
pf5

Partial preview of the text

Download Contrast Template - Computer Programming - Exam and more Exams Computer Engineering and Programming in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Science (Honours) in Software Development and Computer

Networking – Stage 1

(NFQ Level 8)

Summer 2006

Computer Programming

(Time: 3 Hours)

Answer Q1 (40 marks) and ONE question from Section B (30 marks) and ONE question from Section C (30 marks). (Total of THREE questions.) Please read instructions carefully.

Examiners: Dr. J. Buckley Dr. A. Kinsella Ms. C. McGuane

Section A

  1. [40 marks] Answer all parts. a) Compare and contrast template and overloaded functions. [4 marks] b) Write the syntax of [3 marks] (i) (^) switch statement (ii) a function prototype (iii) a while loop c) What is a struct? [4 marks] Write code to declare a struct called Time that holds hours, minutes, and seconds that represent time. Write a function that receives an instance of Time and returns the number of seconds that have passed since midnight. d) What is an array? [3 marks] Write code to declare an array called numbers that holds 20 floating point numbers and initialise each element to zero. Write code to store 11.11 and 22.22 in the second and fifth locations respectively in numbers. e) With respect to function parameters, explain the terms “pass by value” [3 marks] and “pass by reference”, paying particular attention to computer memory.

f) Write a function that receives a floating point array, and the number of numbers [8 marks] in the array. The function should sort the numbers in the array in decreasing order using the Bubble Sort algorithm.

The function’s prototype is void Sort ( float x[], int size );

g) Demonstrate how the function operates on the following array: [4 marks] 6 2 8 9

h) Suggest a name for the following function that represents its purpose. [3 marks] Demonstrate the workings of the function for the function calls What(10.1234) and What(11.768). float What ( float x ) { return int( x * 100 + 0.5 ) / 100; }

i) Suggest a name for the following function that represents its purpose. [4 marks] Demonstrate the workings of the function for the function calls What(12) and What(7).

int What( int n ) { int p = 0; int x = 0; while( n > 0 ) { x += (pow(10,p) * (n%2)); n /= 2; p++; } return x; }

Section B

  1. [30 marks]

Answer both parts.

a. [15 marks]

Design and write a function that receives a positive integer number and returns the reverse of the integer number. If your function receives 6548 it should return 8456. Write a driver program to demonstrate usage of this function.

b. [15 marks] CIT plans a new competition in the next academic year called Strictly Come Programming. Undergraduate programmers will compete against each other and will be assessed by five judges. Each judge can award points between 0 and 10. The highest and lowest scores are discounted. For example, if the judges’ scores for a contestant are 8 2 7 7.5 9 the highest, 9, and the lowest, 2, are ignored giving a total score of 8 + 7 + 7.5 = 22.5.

The contestants’ names and their five scores are saved in a file. For example input file might be Mickey Mouse 5 6.5 7 9 6. Minnie Mouse 9 9 9 8 9 Daisy Duck 6 7 6 5 8

You have been asked to write a program to process this data. The program should

  1. ask for and read the name of the file that contains the competition results
  2. read the results from the file
  3. calculate the total score excluding highest and lowest points
  4. add their names and total scores to an existing file called results.txt in a neat, tabular format.

For the above input file, the output file would be Mickey Mouse 20 Minnie Mouse 27 Daisy Duck 19

  1. [30 marks]

Answer both parts. a. [15 marks] Write a function that merges two files, each of which consists of numbers in ascending (increasing) order with duplicates allowed, into a third file sorted in ascending order. For example if the two files are numbers1.dat 1 3 5 7 9 10 numbers2.dat 2 2 4 6 8 9 The merged file would be 1 2 2 3 4 5 6 7 8 9 9 10 The function's prototype is void Merge(ifstream & in1, ifstream & in2, ofstream & output);

b. [15 marks] Write a program to read student data from a user-specified file. Each row of the file comprises a student's surname, first name, the total mark gained from assignments, the mark for Term 1 exam, the mark for Term 2 exam, and the mark for the summer exam. A sample file might be Mouse Mickey 80 55 65 50 Duck Donald 95 70 80 65 Duck Daffy 60 40 35 45 The assignments are worth 30% of the final grade, the exams are worth 20% of the final grade, and the summer exam is worth 50% of the final grade. Write a C++ program to read the details of each student from a file and calculates the student's final grade. The grade is calculated as assignments0.30 + exam10.10 + exam20.10 + summerExam0. The output should appear in an output file called "Summary.txt" in neat table format as follows Mickey Mouse 80 55 65 50 61. Donald Donald 95 70 80 65 76. Daffy Duck 60 40 35 45 48. Your program should ensure that all files have opened correctly. There is no maximum number of students given so you cannot use arrays.

  1. [30 marks]

A file booklist.txt contains records of books in a school library. Each record contains ƒ a unique ISBN number, which may include non-numeric characters ƒ the surname and first name of the author ƒ the number of copies the library owns ƒ the title of the book (which may contain several words) The struct for each record is struct Book { int ISBN; string surname, firstname; int number; string title; }; The library can maintain a catalogue of up to 10000 books. Write a program that uses Book to read the student data from booklist.txt into a suitable array and allows a user to perform the following, until s/he wishes to quit, ƒ ask the user for an ISBN number and remove that book from the list i.e. delete the record, if such a book is in the library ƒ ask the user for an ISBN number and allow the user to modify the number of copies of that book, if such a book is in the library ƒ to add a new book to the book list, taking into account the maximum number of book records that can be held in the catalogue ƒ allow the user to quit the program, automatically making an update of the records to booklist.txt Avoid repeated code by using functions.