Вы находитесь на странице: 1из 2

# Birla Institute of Technology & Science, Pilani

## Work-Integrated Learning Programmes Division

Second Semester 2013-2014
Comprehensive Examination
(EC-3 Regular)
Course No.
Course Title
Nature of Exam
Weightage
Duration
Date of Exam
Note:
1.
2.
3.

: TA ZC164
: COMPUTER PROGRAMMING
: Open Book
: 50%
: 3 Hours
: 06/04/2014 (FN)

No. of Pages
=2
No. of Questions = 5

All parts of a question should be answered consecutively. Each answer should start from a fresh page.

Q.1. Write a function which reads real values from a user-specified input file and rounds them
to the nearest integer and then writes them into a user specified output file. Your function
should ensure that specified input file already exist, and the specified output file NOT
[10]
Q.2. The function dir returns the content of a specified directory. The dir command returns a
structure array with four fields as shown below.
>> d = dir(chap7)
d=
36x1 struct array with fields:
name
date
bytes
isdir
The field name contains the names of each file, date contains the last modification date
for the file, bytes contain the size of the file in bytes and isdir is 0 for conventional files
and 1 for directories.
(a)Write a function that accepts a directory name and returns the total size of all the files
(only files) in the directory.
(b)Write a recursive function that finds the size of the current directory by summing up
the size of all files that the directory and recursively summing up the total files in
each subdirectory contains. (Hint: identify the base case and recursion properly)
[4 + 8 = 12]
Q.3. Write a function that accepts any number of numeric input parameters and sums up all the
individual elements in the arguments. There is no limit on the number of input parameters.
Also, the input arguments can be of arrays of any dimensions. Your program should be as
generic as possible. For example, if your function is called with four arguments a,b,c and
d whose values are as follows:
a= [ 1 2], b = [1 2; 2 3; 4 5], c= 10 and d = [ 4 5], then the output should be 39 which is
the sum of individual elements.
[10]

Page 1 of 2

## Second Semester 2013-2014

Page 2

Q.4. Write a MATLAB function firstCaps which takes a string as input and capitalizes the
first character of each word and forces the remaining characters to be lower case. For
example, the function call
firstCaps(HELLO DANIEL HOW ARE U) should return
Hello Daniel How Are You
The function call
firstCaps(hello DANIEL HOW are you) should also return
Hello Daniel How Are You

[8]

Q.5. Write a function mystats(myArray) that calculates the arithmetic mean (average),
rms average, geometric mean and harmonic mean for a set of n positive numbers given in
myArray. The function returns arithmetic mean (average), rms average, geometric mean
and harmonic mean as output parameters.
The definitions of means are given as follows.
[10]

Arithmetic Mean

n
i 1 i

rms average

1
xi2

n i 1

harmonic mean

n
1 1 1
1
...
x1 x2 x3
xn

**********

Page 2 of 2