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

Fraction - Computer Programming - Exam, Exams of Computer Engineering and Programming

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

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
Bachelor of Science (Honours) in Software Development &
Computer Networking - Stage 1
(NFQ – Level 8)
Autumn 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).
Please read instructions carefully.
Examiners: Dr. J. Buckley
Mr. A. Kinsella
Ms. C. McGuane
Section A
1. [40 marks]
a) Define the following [6 marks]
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]
pf3
pf4
pf5

Partial preview of the text

Download Fraction - 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 &

Computer Networking - Stage 1

(NFQ – Level 8)

Autumn 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). Please read instructions carefully.

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

Section A

  1. [40 marks] a) Define the following [6 marks]

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 #include using namespace std;

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; }

  1. [30 marks] a) [15 marks] Write a function that receives a positive integer number and determines if it is a prime number or not. A prime number is a number that is divisible only by itself and 1. Write a driver program that reads a positive number from the user and uses the prime number function. Include data validation to ensure the number is positive.

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:

  • change all letters to uppercase
  • move onto a new line in "output.dat" when you find a fullstop ('.') character in "input.txt"
  • change all occurrences of ‘E’ or ‘e’ to “XX”

Section C

  1. [30 marks]

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.

  1. [30 marks]

Write a program that simulates a game of cards. The game

  • deals one card to player 1
  • deals one card to player 2
  • deals a second card to player 1
  • deals a second card to player 2
  • displays both hands to the screen with face totals
  • determines the winner - the player with the largest total value on their cards wins.

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.