Sie sind auf Seite 1von 13

THE UNIVERSITY OF THE WEST INDIES

EXAMINATIONS OF

May

2015

Code and Name of Course: COMP1105 - COMPUTER PROGRAMMING 1


Date and Time:

Duration: 3 hours

INSTRUCTIONS TO CANDIDATES: This paper has 9 pages and 4 questions


All Questions are Compulsory
Marking Code:
Tests acceptable and basic knowledge of the material = 31.5
Tests applied skills and critical and analytical thinking = 21.5
Tests excellent skills and breadth of knowledge = 7
Question 1 [15 marks] (8 marks + 5 marks + 2 marks)
You are being interviewed as a contract programmer for the Faculty of Science and Technology.
Your responsibility is to create simple, suitable, and secure games for students enrolled in
summer school to play in labs as a means of relaxation in the intense six week schedule of
summer school, in the down periods between classes and lab sessions.
Note: Read the entire question before you begin.
The interviewers ask you to write pseudocode (in 45 minutes) for a simple guessing game. Write
your solution all in one program. All of the necessary preamble and concluding logic for an
algorithm is expected.
[2 marks]
a. In this game you have to start by printing a grid with a title as follows:
THE GRID OF GUESSES
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
Page 1 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

____________________
|
|
|
|
|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Call a function (sub-program) with at least one loop in it to print the layout of the grid.
[3 marks]
b. Then print the following message:
Welcome to the guessing game. You have 25 tries to guess the number that I am
thinking of between 1 and 30. Each time you make an incorrect guess, we will
show it to you in the GRID OF GUESSES. You may keep guessing until you are
successful or until you have filled the grid.
The algorithm must then generate the number between 1 and 30 and not reveal it to the
user, ask the user to guess the number and then read the guess.
[2 marks]
c. The algorithm must check the guess against the generated number and if they are the
same it must print a message to the screen saying Congrats, you have won!, and then
stop the game.
[2 marks]
d. If the guess is not correct, the algorithm must perform two tasks:
Print to the screen the incorrect guess in the grid in the next available spot.
Check to see if the guess is greater or less than the random number and indicate this
to the user.
[2 marks]
For example, if the random number is 17 and the player guesses 10, the following would be
printed to the screen:
THE GRID OF GUESSES
10
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
Your number is too small. Try again
If the player then guesses 20, the following would be printed to the screen:
THE GRID OF GUESSES
10
|20
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
Page 2 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

|
|
|
|
|
____________________
|
|
|
|
|
____________________
Your number is too big. Try again
e. Your algorithm must also keep score. Use a counter that starts at 25 and for every
incorrect guess, decrement it. The more guesses the less points. The user must be
restricted to 25 guesses.
[2 marks]
Print your final score to the screen and to the file: myScores.txt.
[2 marks]
You do not have to use an array to hold the contents of the grid.
YOUR SOLUTION SHOULD INCLUDE DOCUMENTED PSEUDOCODE ONLY.
NO C-CODE IS REQUIRED.
SCHEME:
BEGIN ALGORITHM (MAIN PROGRAM) [ MARK]
DECLARE [ MARK]
integer iSecret
integer iGuess,
integer array pos
integer guesses
integer points
File pointer fp to point to counter.txt
Initialize [[ MARK]
Initialize pos to \s // can work because of ascii
Initialise guesses to 25
/*
a. In this game you have to start by printing a grid with a title as follows:
THE GRID OF GUESSES
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Call a function (sub-program) with at least one loop in it to print the layout of the grid.
*/

Call SubProgram PrintGrid [1/2 mark]


Page 3 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

print
Welcome to the guessing game. You have 25 tries to guess the number that I am
thinking of between 1 and 30. Each time you make an incorrect guess, we will show it to
you in the GRID OF GUESSES. You may keep guessing until you are successful or until
you have filled the grid.
// [1 mark]
/*
The algorithm must then generate the number between 1 and 30 and not reveal it to the
user, ask the user to guess the number and then read the guess.
*/
iSecret Generate a random number between 1 and 20 // [1/2 mark]
print "Guess the number (1 to 30) // [ mark for request and read]
read iGuess
/*the algorithm must check the guess against the generated number and if they are the
same it must print a message to the screen saying Congrats, you have won!, and then
stop the game.
*/
[1/2 mark]
[1/2 mark]
DO WHILE (iSecret NOT EQUAL iGuess) AND (guesses >= 0)
if iSecret EQUAL iGuess then // [ 1/2 mark]
print Congrats, you have won // [1/2 mark]
exit program // [1/2 mark]
endif
/*
10
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
Your number is too small. Try again
*/
if iSecret < iGuess || iSecret > iGuess then [ mark]
increment guesses [ mark]
pos [guesses] iGuess [ mark]
decrement points
// keep track of guesses and points [ mark]
print
pos [0] | pos[1]| pos[2]| pos[3]| pos[4]| //etc. for all positions [ mark]
____________________
pos [5] | pos[6]| pos[7]| pos[8]| pos[9]| //etc. for all positions
Page 4 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

____________________
|
|
|
|
|
____________________
|
|
|
|
|
____________________
|
|
|
|
|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
if iSecret < iGuess then [ MARK] // HANDLE THE SMALL
print Your number is too small. Try again
if iSecret > iGuess then [ MARK] //HANDLE THE LARGE
print Your number is too large. Try again
print "Guess the number (1 to 30) // [ mark for request and read]
read iGuess
End WHILE //(iSecret NOT EQUAL iGuess) AND (guesses < = 25) // while they have not
// guessed correctly [1/2 mark]
// and < 25 tries [1/2 mark]
open fp for writing [ MARK]
if fp EQUAL null [ MARK]
print error [ MARK]
exit program
print here are your points: points to fp [ MARK]
End Algorithm [1/2 MARK]
Begin Algorithm (SubProgram PrintGrid) // define function header [1/2 mark]
//use a loop correctly to do something in the grid pattern
For i = 1 to 5 DO // print the five rows [ mark]
For i = 1 to 5 DO [ MARK]
Print
| // print tab and pipe pattern five times
EndFOR
For i = 1 to 5 DO [ MARK]
Print _ _ _ _ _ // print underline pattern 5 times
EndFOR
EndFOR
End Algorithm (SubProgram PrintGrid)

Question 2: Multiple Choice [15 Marks - 1 mark each] (9 marks + 6 marks)


i.

Which of the following is not a valid C variable name?


a. int #number;
b. float 1rate;
c. int main;
d. all of the above

ii.

The format identifier %lf is also used for _____ data type?
a. char
b. int

[1 mark]

Page 5 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

c. float
d. double
[1 mark]
iii.

What is the output of this C code if the input is 6, 8 and 10?

1. #include <stdio.h>
2.
3. void main()
4. {
5.
int num1, num2, num3;
6.
7.
printf("Enter the values of num1, num2 and num3 ");
8.
scanf("%d %d %d", &num1, &num2, &num3);
9.
printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3);
10.
if (num1 > num2)
11.
{
12.
if (num1 > num3)
13.
{
14.
printf("num1 is the greatest among three \n");
15.
}
16.
else
17.
{
18.
printf("num3 is the greatest among three \n");
19.
}
20.
}
21.
else if (num2 > num3)
22.
printf("num2 is the greatest among three \n");
23.
else
24.
printf("num3 is the greatest among three \n");
25.
}
Figure 1
a. num1 = 6
b. num1 = 6

num2 = 8
num3 = 10 num3 is the greatest among three
num2 = 8 num3 = 10

num3 is the greatest among three


c. num1 = 6 num2 = 8 num3 = 10 num3 is the greatest among three
d. num1 = 10
num2 = 8
num3 = 6
num1 is the greatest among three

[1 mark]

iv.

How many times will True be printed?


1.
2.
3.
4.
5.
6.
7.
8.

a.
b.
c.
d.

#include <stdio.h>
int main()
{
int i = 0;
while (i == 0);
printf("True\n");
printf("False\n");
}

Infinite times
1 time and then False
Never
It depends
Page 6 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

[1 mark]
1.

/* C program to check whether a given integer is odd or even*/

2.
3.

#include <stdio.h>

4.
5.

void main()

6.

7.

int ival, remainder;

8.
9.

printf("Enter an integer : ");

10.

scanf("%d", &ival);

11.

remainder = ____________________; // 1

12.

if (remainder == 0)

13.

printf("%d is an _________ integer\n", ival); // 2

14.

else

15.
16.

printf("%d is an _________ integer\n", ival); // 3


}

Figure 2

v.

The C-code in Figure 2 above will check whether a given integer is odd or even. What
should be entered in the blanks?
a.
b.
c.
d.

(1) ival / 2 (2) even (3) odd


(1) remainder % 2 (2) even (3) odd
(1) remainder % 2 (2) odd (3) even
(1) ival % 2 (2) even (3) odd
[1 mark]

vi.

The keyword used inside a loop to return to the beginning of the loop
a.Exit
c.Continue

b.Goto
d.Return
[1 mark]

vii.

What will be the output of the code below?


a.
dance (three spaces to the left of dance)
b. dance (followed by three spaces after dance)
c. dance
d. *dance
[1 mark]
#include <stdio.h>
int main()
{
char s[8] = "dance";
int i = 9;
printf("%*s", i, s);
}
Page 7 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

viii.

What will be the output value if you will compile and execute the following c code?

1. #define x 5+2
2. void main(){
a. int i;
b. i=x*x*x;
c. printf("%d",i);
3. }

[1 mark]
a.
b.
c.
d.
ix.

343
27
133
Compiler

User-defined data types can be derived using___________.


a. struct
b. enum
c. typedef
d. All of the mentioned
[1 mark]

x.

Which of the following is a unary operator?


a. &&
b. !

c. ? :
d. %c
[1 mark]

xi.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

What is the output of this C code?


#include <stdio.h>
int main()
{
foo();
foo();
}
void foo()
{
int i = 11;
printf("%d ", i);
static int j = 12;
j = j + 1;
printf("%d\n", j);
}

a. 11 12 11 12
b. 11 13 11 14
c. 11 12 11 13
d. Compile time error
[1 mark]
xii.

Which of these statements relates to modularization?


a. Application code is subdivided into separate subprograms, with each running a
specific function or subroutine.
Page 8 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

xiii.

b. Parts of code can be split up and worked on by multiple programmers, teams or


by an individual over time, with each part of code dedicated to doing on specific
task.
c. Subprograms are recyclable, and the programmer can simply call on an existing
module in a new program that he/she is working on, saving time and energy in
his/her work.
d. All of the above
[1 mark]
What will be the output of the program below?
#include<stdio.h>
int main()
{
int k=1;
printf("%d = = 1 is %s\n", k, k= =1?"TRUE":"FALSE");
return 0;
}

a.
b.
c.
d.

k = = 1 is TRUE
1 = = 1 is TRUE
1 = = 1 is FALSE
K = = 1 is FALSE
[1 mark]

xiv.

What does fp point to in the program below?

#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("trial", "r");
return 0;
}

a.
b.
c.
d.

The first character in the file


A pointer to the beginning of the file.
The name of the file.
The last character in the file.
[1 mark]

xv.

The sequential model of software development which has no feedback is known as the:
a. Spiral Model
b. Waterfall Model
c. Fountain Model
d. Iterative Model
[1 mark]

Question 3 [15 marks][7.5 marks+6.5 mark+1 mark]

Page 9 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

a. Examine the program shown in Figure 3 and list all of the syntax and logical errors that are
present by stating the line number, the error [1/2 mark] and indicating the correct syntax or
logic [1/2 mark]. The program is written to swap the values of num1 and num2 into the other
variable. So at the end of the program, the original value of num1 should be in num2 and the
original value of num2 will be in num1.
Mark and correct each highlighted issue to a max of 5 marks. There are 10 opportunities for
marks.
[5 marks]
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

#include <stdio.h>;
void swap(a, b);
{
temp = a;
a = b;
b = temp;
return();
}
int main();
{
num1 = 10, num2 = 20;
printf("Before swapping num1 = %d num2 = %d\n", num1, num2);
swap(int num1, int num2);
printf("After swapping num1 = %d num2 = %d \n", num1, num2);
return();
}

Figure 3
b. Explain the scope of the variables num1 and temp.
[2 marks]
Answer:
They have local scope[1 mark]. A variable that is declared inside a function definition is local. It
is created and destroyed every time the function is executed, and it cannot be accessed by any
code outside the function. [1 mark]
c. Using the code example briefly explain term call-by-value.
[1 mark]
The values of num1 and num2 are copied and passed to a and b. The value of num1 and
num2 do not change.
b. Write the C-program for a time converter that will request and accept the time in Bridgetown
and ask the user for a number representing a second city. The options for the second country
are 1- New York, 2- London (England), 3- Toronto, 4- Hong Kong, 5- Acapulco (Mexico), 6Detroit, and 7- St. George's (Grenada). You must use a switch statement to print the time in
Barbados and the time in the given city during the summer months. The summer time
conversion is as follows:
1234-

New York: Same as Bridgetown


London (England): +4 hours
Toronto: Same as Bridgetown
Hong Kong: +12 hours
Page 10 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

5- Acapulco: -2 hours
If any other city is given as input the program should print a suitable message.
[7 marks]
#include <stdio.h>
main( )
{
int city;
int hours, minutes;
char mode[3];

// 1 mark for variables used in program

// 1 mark for prompting and scanning variables correctly


printf(Please enter the time in Barbados in the format 12:00);
scanf(%d:%d, &hours, &minutes);
printf(Is it AM or PM?); // 1 mark for some accommodation for AM/PM
scanf(%s, mode);
// 1 mark to request and read
printf(Please enter the number indicating the second city);
printf( 1- New York, 2- London (England), 3- Toronto, 4- Hong Kong);
printf( 5- Acapulco (Mexico));
scanf(%d, &city);
switch( city )
{ // No change and a reasonable default 1 mark
// hours+4 , +12, 2 1 mark
case 1:
case 3:
case 2:
case 4:
case 5:
default

printf(No change in time);


hours += 4;
hours += 12;
hours -= 2;
: printf(ERROR: Your second city is not known);

}
// 1 mark for accommodating for 12 hrs or 24 hrs (if military time used)
if ((hours > 12) && (strcmp(mode, AM))
{hours = 12 hours;
strcpy(PM, mode);}
else if ((hours > 12) && (strcmp(mode, PM))
{hours = 12 hours;
strcpy(AM, mode);}
else if ((hours < 0) && (strcmp(mode, PM))
{hours = 12 + hours;
strcpy(AM, mode);}
else if ((hours > 12) && (strcmp(mode, AM))
{hours = 12 + hours;
strcpy(PM, mode);}
printf(Second city time is %d:%d %s, hours, minutes, mode);
} // end program

Question 4 [15 marks][7 marks+4 marks+4marks]


a. Write a function called swapIt that accepts two character arrays (string1 and string2 are arrays
filled with characters and string2 is the same size as string1), an integer value for the size of the
arrays (arraysize), and swaps the contents of the strings i.e. contents of two strings are
interchanged.
For example, if the declarations and initializations are as follows
char string1 [] = School;
Page 11 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

and
char string2 [] = Pastel;

then
string2 will become School
and
string1 will become Pastel

[5 marks]
void swapit(char string1[], charstring2[], int arraysize) // 1 mark
{
const int mysize = arraysize; // 1 mark declarations
char temparray [mysize];
for (int i = 0; i < arraysize; i++) // 1 mark loop to temporarily store
temparray [i] = string1[i];
for (i = 0; i < arraysize; i++) // 1 mark loop 2 to copy one to another
string1 [i] = string2[i];
for (i = 0; i < arraysize; i++) // 1 mark loop 3 copy out of temporary storage
string2 [i] = temparray[i];
return;
}
b. A certain computer stores floating point numbers using a 10-bit mantissa, a 5-bit exponent (in
excess 2 n-1 notation) and 1 bit for the sign. Show how the number 20.375 would be stored in a
16-bit word. (Assume the exponent is represented in Sign and Magnitude form). What is the
error in the representation?

0
1
sign

0 0
mantissa

[5 marks]
0 1 0 1
exponent

Sign bit [ 1 mark]


Convert whole part to binary [1/2 mark]
Convert fraction to binary [1/2 mark]
Result: 10100.01100
Exponent is 5 [1 mark]
In excess 2 n-1 notation with 5 bits => 5 + 2 5-1 [1 mark]
Convert to binary 10101 [1 mark]
c. The basic outline of a C program is shown below:
#include <stdio,h>
int main()
{
FILE *fpt1, *fpt2;
int num_t;
int num_line;
if ((fpt1 = fopen(mockingbird.txt, r) == NULL) ||
(fpt2 = fopen(counter.txt, r) == NULL))
{ printf(Cant open the files\!\n);
exit(1);
}
//...
Page 12 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

//Point A
//(i)
num_t = 0;
//[1/2 mark]
num_line = 0;
//[1/2 mark]
while (!feof(fpt1))
//[1/2 mark]
{
fscanf( fpt1, %c%, &mychar);
//[1/2 mark]
if (mychar == t)
//[1/2 mark]
num_t++;
//[1/2 mark]
//[1/2 mark]
if ((mychar == .)||(mychar == !)|| (mychar == ?))
num_line++;
//[1/2 mark]
}

//(ii)
fprintf(fptr2, %d, %d, num_t, num_line);//[1 mark]
//...
fclose(fpt1);
fclose(fpt2);
return 0;
}

Assume that mockingbird.txt has a format similar to the following:


When he was nearly thirteen, my brother Jem got his arm badly broken at
the elbow. When it healed, and Jem's fears of never being able to play
football were assuaged, he was seldom self-conscious about his injury.
His left arm was somewhat shorter than his right; when he stood or
walked, the back of his hand was at right angles to his body, his thumb
parallel to his thigh. He couldn't have cared less, so long as he could
pass and punt. When enough years had gone by to enable us to look back
on them, we sometimes discussed the events leading to his accident. I
maintain that the Ewells started it all, but Jem, who was four years my
senior, said it started long before that.

Write the code that will be inserted at Point A, by declaring any additional variables that
you need and writing code to do the following:
i.
Read in the contents of mockingbird.txt character by character and count all
of the occurrences of the letter t and the number of sentences in the file.
Remember that sentences end with full-stops, question marks and exclamation
marks.
[4 marks]
ii.

Output the number of the occurrences of the letter t and the number of
sentences in the story to the file counter.txt.
[1 mark]
END OF EXAM

Page 13 PLEASE TURN OVER

The University of the West Indies


Course code: COMP1105
May 2015
__________________________________________________________________________________________________
DO NOT WRITE OR TYPE ON THE BACK OF THIS SHEET: USE ONE SIDE ONLY
INSTRUCTIONS: Each page must be signed by the FIRST AND SECOND EXAMINERS. Completed forms should be
handed to the Assistant Registrar (Examinations).
.. ........... ...................................
First Examiner
Date: 2015/04/.

............................................
Second Examiner
Date: 2015/04/....

Das könnte Ihnen auch gefallen