



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 7
This page cannot be seen from the preview
Don't miss anything!
(NFQ Level 8)
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
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; }
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
For the above input file, the output file would be Mickey Mouse 20 Minnie Mouse 27 Daisy Duck 19
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.
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.