



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!




Answer Question 1 and THREE others Examiners:^ Prof. G. Hurley Dr. S. Foley Mr. D. O’Donovan
[6 %] (b) Write a program to prompt the user to enter a value, t (^) final , in seconds between 0 and 15
t v t e^ τ τ
, write the resulting values
between 0 and t (^) final at 10 m s intervals to (i) on-screen and (ii) a file called “results.dat”, at increments of 0.01secs, in the following fashion:
etc.
Hint: The C command double exp( double x ); generates the e x function [12 %]
(c) Show the modifications necessary to the program in (b) such that the user may enter the terminating voltage at which the program is required to stop. [7 %]
(b) Describe two possible uses of the return type of a function. [2 %]
(c) Write a function which calculates how many characters are uppercase within the string supplied as a parameter to the function called ‘UpperCaseCount’. The number of uppercase characters should be returned as the result of the function. [10 %]
(d) Write a function to reverse the contents of a string supplied as an argument. [8 %]
ch is a character) i. x is a number between 4 and 16 ii. x is any number other than 6 or 10. iii. ch is an uppercase character vi. x is a positive even number divisible by 12 v. x is an odd number between 3 and 9. [10 %]
(b) i. The code segment in Figure 5-1 does not operate as expected – explain why. [3 %] ii. How would you correct this situation? [3 %] #include <stdio.h> void main() { float count; count = 0.0; while (count != 3.4) { printf(“\n%f",count); count+=0.2; } } Figure 5-
(c) A student grade is derived from its mark as follows:
Mark Student Grade 100 - 80 A 79 - 60 B 59 - 40 C 39 - 0 F
Write a C function which will return the appropriate student grade representing the mark supplied as an argument. [9 %]
(b) i. Rewrite the for loop in Figure 6-1 with (i) a while loop and (ii) a do-while loop.
for (x = 1;x<=20;x++) { printf (“x is %d\n”, x); printf (“x squared is %d\n”, x*x); } Figure 6-1 [6 %]
ii. Explain the difference between pre-test and post-test while loops. [3 %]
(c) Rewrite the nested if statements in code segment 6-2 with a single switch statement. if ((number == 5) || (number == 7)) printf (“Clause One\n”); else if ((number > 0) && (number < 4)) printf (“Clause Two\n”); else if (number==0) printf (“Clause Three\n”); else if ((number==6) ||(number > 7)&&(number <= 10)) { printf (“Clause ”); printf (“Four\n”); } else if (x==4) printf (“Clause Five\n”); Figure 6-2 [8 %]