



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: Function Prototype, Function Call, Function Definition, Array, Numerator, Partial Marks, Decimal Number, Maximum Salary, Integer Number, Positive Number
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!
Answer Q1 (40 marks) and ONE question from Section B (30 marks) and ONE question from Section C (30 marks). Please read instructions carefully.
Examiners: Dr. J. Buckley Mr. A. Kinsella Ms. C. McGuane
i) Function prototype ii) Function call iii) Function definition
b) With respect to C++, what is a stream? [4 marks]
c) What is an array? [4 marks] Write code to declare an array of 100 integers called Numbers. Write code to assign the first and last elements of the array the values 10 and 30 respectively.
d) What is a struct? [8 marks]
Write code to define a struct called Fraction that holds a numerator and a denominator. Write a function that reads an instance of Fraction in the form x/y. The function should be able to read the fraction from both the keyboard and a file.
e) With regard to functions explain the terms pass by value and pass by reference. [4 marks]
f) Arrays are automatically passed by reference – why? [4 marks]
g) Given the following declarations [5 marks]
int a = 5, b = 3, c = 2, d = 10; float x = 0.5f; Evaluate each of these expressions in accordance with the rules of precedence of C++ (1) a * b / c (2) a * ( b / c ) (3) a * ( b / c * x ) (4) a + b * c / d (5) a + b / ( c / d )
h) What is the output of the following program? [5 marks] Show all your workings clearly for partial marks. #include
int x = 0; void main() { int y = 3; cout << x << setw(3) << y << endl; cout << x++ << setw(3) << --y << endl; if ( x = y ) cout << “The two variables are equal. “ << endl; else cout << “The two variables are different. “ << endl; y = x++ ; cout << x << setw(3) << y << endl; }
b) [15 marks]
Write a C++ program to open a connection to two files – "input.txt" for reading data and "output.txt" for writing data. Ensure that both files have opened properly.
The program must make a copy of "input.dat" to "output.dat" making the following changes:
a) [8 marks] A phone number consists of an international code, a local code, and the phone number itself. For example the CIT phone number is 353 with 021 and 4326100. Write a structure for a phone number called PhoneNumber. Write a function that reads an instance of PhoneNumber in the form XXX-XXX-XXXXXXX. The function should be able to read phone numbers from file or from the keyboard. Write a function that writes an instance of PhoneNumber in the form XXX-XXX-XXXXXXX. The function should be able to write phone numbers to a file or to the screen.
b) [11 marks] Records of customers of a particular bank consist of the bank account number (a 5 digit number), customer's name (first name and surname), phone number, current balance (with € ; negative if an overdraft) and overdraft limit. Examples might be 24680 Mickey Mouse 353-21-4123456 €1253.22 €100. 12569 Minnie Mouse 353-21-4123456 -€50.00 €100.
Write a structure for a bank customer called BankCustomer. Write a function that reads an instance of BankCustomer. The function should be able to read a bank customer's details from a file or from the keyboard. Write a function that writes an instance of BankCustomer in suitable format. The function should be able to write a bank customer's details to a file or to the screen. You should use the functions from (a). The ASCII code for € is 238.
Write a program that simulates a game of cards. The game
Sample output: K♥ 4 ♣ Player 1 total = 17 Q♦ 2 ♠ Player 2 total = 14 Player 1 wins!
The ASCII code for ♥ is 259, for ♦ is 260, for ♣ is 261, and for ♠ is 262. The values for the Picture Cards are as follows: Ace is 1, Jack is 11, Queen is 12, and King is 13.