You are on page 1of 3

COMSATS Institute of Information Technology, Sahiwal

DEPARTMENT OF COMPUTER SCIENCE


Assignment # 04
(Submission Deadline: [In soft form] 8/12/2015, 11:59 PM [in hard form] 16/12/2015, 12:00 Noon)
Total Marks: 60
Instructor:

Arshad Farhad

Course:

ICP

Copied assignments will get zero for sure!


Q1. Write a function Power (base, exponent) that returns the value of
Base exponent
For example, Power (2, 3) = 2 * 2 * 2. Assume that exponent is a positive, nonzero integer and
that base is an integer. The function Power should use for or while to control the calculation. Do
not use any math library functions. Below figure demonstrate an example. You must print your
detail information at the end of program.
[10]

Q2. Suppose you are working as a C++ programmer in The Professional Hub organization. Your
role in this organization is to develop C++ based applications for special purpose use. You have
been asked by a customer to develop a CU online portal to facilitate students. You have been
provided the following functional requirements of the system, which includes;

There should be a faculty portal and a student portal.

Faculty portal are being used by the Lecturers of CU to enter student records. Lecturer A enters 3
subject marks in the faculty portal only. However, these marks can be seen by students in their
own portal along with their marks average.

Additionally, based on the above depiction, use your knowledge of functions to implement such a
system to satisfy customer requirements at any cost. Also, print your name, roll number at the end
of program and display on the screen.

[10]

Q3. Write a function named Validate that uses a parameter variable to accept an integer argument.
The function should ask the user to enter a number in the range of 1 through 100. The input should
be validated and stored in the parameter variable.
[10]
Q4. Write program for the following functions;
1.
2.
3.
4.
5.

Addition
Subtraction
Multiplication
Division [Should return double]
Modulus [Should return integer]

Functions should be called by value to perform the above functions and return the result into main
function. Also, display the result in main function. Do not display the result in the defined function.
Moreover, clearly states the Function prototype, Function calling & Function definition by using
comments. Moreover, repeat the program for pass by value.
[10]
Q5. The Student CD contains a partially written program named AreaRectangle.cpp. Your job is
to complete the program. When it is complete, the program will ask the user to enter the width and
length of a rectangle, and then display the rectangles area. The program calls the following
functions, which have not been written:
getLength This function should ask the user to enter the rectangle's length, and then return that
value as a double.
getWidth- This function should ask the user to enter the rectangle's width, and then return that
value as a double.
getArea This function should accept the rectangle's length and width as arguments, and return
the rectangle's area. The area is calculated by multiplying the length by the width.
displayData This function should accept the rectangle's length, width, and area as arguments,
and display them in an appropriate message on the screen.
[10]
Q6. Write a program for the following statements.

[10]

There are two arrays; a) Array of strings b) an integer array


Arrays of string should be provided by the user at the time of initialization. However, array of
integer should read data from a file. Moreover, in array of string there should be 10 rows and

columns should of your choice. While, integer array should be equal to the size of rows previously
used for string array.
Your job is to display the string and integer values stored in array in the following fashion. Also,
show the sum & average of integer array at the end.
e.g. String at row 1: Arshad has 1000 rupees.

String at row 10: Khan has 1020 rupees.


Summing all elements of array: ???
Average is: ???
Guidelines & Submission Rules:

Every student must print his/her information in each program: (Name, Reg.no, and Class)
The assignment should contains original outputs (in picture form). Hint: use snipping tool
to capture output image.
If a student failed to submit assignment via email within the time frame provided.
Therefore, his/her 10 marks will be deducted right away.
Email Subject: FA15-MCS-001

Good Luck

You might also like