


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Instructions: Examiner: Ms Gemma O’Callaghan Answer questions 1 and any two others. Mr. James Greenslade Question 1 is compulsory. Mr. John Walsh
Question 1: (50 marks)
(a) What is the output from the following program? #include
int function1(double &number, int rep);
int main() { double num1, num2; int num3;
num1 = 4.0; num3 = 2;
cout<<"function1: "<<function1(num1,num3)<<endl; cout<<"num1 :"<<num1<<endl; num2 = 11.0; cout<<"function1 again: "<<function1(num2,5)<<endl; cout<<"num2: "<<num2<<endl;
return 0; }
int function1(double &number, int rep) { int count = 0; do { number = number +1.1;
rep--; count++; }while(rep > 0);
return count; } (6 marks)
(b) Create a class called SavingsAccount. Use a static class variable to hold the annualInterestRate for all account holders. Each object of the class contains the following data members, an account number and a savings balance which indicates the total amount that is currently in the account. Provide a method calculateMonthlyInterest() which will calculate the monthly interest by multiplying the savings balance by the annualInterestRate divided by 12.Provide a constructor method that allows an object of this class to be initialised when it is declared. (10 marks)
(c) Write a statement to declare a file pointer called output. Write a statement to open the file “Essay.txt” that is associated with the file pointer for reading. Write a statement to close the file pointer when you are finished with it. (6 marks)
(d) Write C++ code to read from the file “Essay.txt” that you opened above and count the number of vowels in the file. (6 marks)
(e) Write the C++ code to display the following pattern.
**
(6 marks)
(f) Write a C++ function that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the function should return 1367. (6 marks)
(g) Write a structure template for a student record consisting of their student number, their first name, their surname and also an array to hold the results of their six final exams. Write statements to input values from the keyboard for each member of the student record. (10 marks)
Hint:- Use C++ strings to hold the employee names. (8 marks)
Question 4: (25 marks) (a) Explain the differences between arrays and linked lists. (4 marks)
(b) Show how to define the structures used to be able to create a linked list of characters. (5 marks)
(c) Write the C++ code needed to create a linked list of characters that is made up of three nodes. head -> C -> + -> + -> NULL (10 marks)
(d) Write a function to add an element to the front of a linked list of characters. (6 marks)