Вы находитесь на странице: 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
Date of Exam

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

No. of Pages
No. of Questions = 5

Please follow all the Instructions to Candidates given on the cover page of the answer book.
All parts of a question should be answered consecutively. Each answer should start from a fresh page.
Assumptions made if any, should be stated clearly at the beginning of your answer.

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
already exist.
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)
36x1 struct array with fields:
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.

TA ZC164 (EC-3 Regular)

Second Semester 2013-2014

Page 1 of 2

TA ZC164 (EC-3 Regular)

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


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.

Arithmetic Mean

i 1 i

rms average


n i 1

harmonic mean

1 1 1
x1 x2 x3

geometric mean n x1 x2 x3 ...xn


TA ZC164 (EC-3 Regular)

Second Semester 2013-2014

Page 2 of 2