Intro to Computing
Final, Summer 2014
Date: 4thAugust, 2014 Marks: 75 Time: 180 minutes.
1. [15 marks]
Write a function getplural that receives a noun from main and convert into plurals on the basis
of these rules:
a. If noun ends in” y„ remove” y„ and add „ies.„
b. If noun ends in „s„, ” ch„, or ” sh„ and ” es.„
c. In all other case, just add ” s.„
The main will call the function and will display the plural of the noun.
Output:
Enter a noun: student
The plural of student is students
Note:
1. Built in strings and string functions are not allowed.
2. The size of the string will be such that nouns of maximum length can be input.
2. [15 marks]
An image can be represented by a 2D array of integers, where each integer represents the
colour of a particular row and column in that image. One way to blur an image is that for each
element at a particular row or column, we calculate the average of all its neighbours (including
itself), and then replace the original value with this average. For example, in the image below, 2
should be replaced by the average of 2,2,3,4,2,4,8,8, and 9 i.e. 5. The number of neighbours are
clear from example given below.
2 2 3 1 2 3
4 2 4 4 5 6
8 8 9 7 8 9
Write a program which blurs an image. The main creates a 2D integer array. Your program
should be changeable for image resolution (number of rows and columns) i.e. generic program.
Then the user should be asked to enter the image data from the console as well. After that, it
should call a function called blur which takes the image as input and returns a blurred image.
3. [15 marks]
Write a program (main) in C++ to count and display the number of lines not starting with string
“The” present in a text file "STORY.TXT".
Example:
If the file "STORY.TXT" contains the following lines,
The rose is red.
A girl is playing there.
There is a playground.
An aeroplane is in the sky.
Numbers are not allowed in the password.
Department of Computer Science
National University of Computer & Emerging Sciences, Lahore Page 1 of 3
Final, Summer 2014
Date: 4thAugust, 2014 Marks: 75 Time: 180 minutes.
1. [15 marks]
Write a function getplural that receives a noun from main and convert into plurals on the basis
of these rules:
a. If noun ends in” y„ remove” y„ and add „ies.„
b. If noun ends in „s„, ” ch„, or ” sh„ and ” es.„
c. In all other case, just add ” s.„
The main will call the function and will display the plural of the noun.
Output:
Enter a noun: student
The plural of student is students
Note:
1. Built in strings and string functions are not allowed.
2. The size of the string will be such that nouns of maximum length can be input.
2. [15 marks]
An image can be represented by a 2D array of integers, where each integer represents the
colour of a particular row and column in that image. One way to blur an image is that for each
element at a particular row or column, we calculate the average of all its neighbours (including
itself), and then replace the original value with this average. For example, in the image below, 2
should be replaced by the average of 2,2,3,4,2,4,8,8, and 9 i.e. 5. The number of neighbours are
clear from example given below.
2 2 3 1 2 3
4 2 4 4 5 6
8 8 9 7 8 9
Write a program which blurs an image. The main creates a 2D integer array. Your program
should be changeable for image resolution (number of rows and columns) i.e. generic program.
Then the user should be asked to enter the image data from the console as well. After that, it
should call a function called blur which takes the image as input and returns a blurred image.
3. [15 marks]
Write a program (main) in C++ to count and display the number of lines not starting with string
“The” present in a text file "STORY.TXT".
Example:
If the file "STORY.TXT" contains the following lines,
The rose is red.
A girl is playing there.
There is a playground.
An aeroplane is in the sky.
Numbers are not allowed in the password.
Department of Computer Science
National University of Computer & Emerging Sciences, Lahore Page 1 of 3