Você está na página 1de 3

THE OPEN UNIVERSITY OF SRI LANKA

DIPLOMA IN TECHNOLOGY LEVEL 3


ACADEMIC YEAR 2012/2013
ASSIGNMENT # 02
MEK3170 C PROGRAMMING
INSTRUCTIONS
1. Answer all questions.
2. This assignment is based on course material presented in Book 1 and Book2.
3. Send your answer scripts under registered cover to the address given below or put it into
the assignment box available at the Research Laboratory (New Science and Technology
Building) of Mechanical Engineering Department on or before 15th of March 2013.

THE COURSE COORDINATOR MEK 3170


DEPARTMENT OF MECHANICAL ENGINEERING
THE OPEN UNIVERSITY OF SRI LANKA
P.O.BOX 21, NAWALA, NUGEGODA
4. Note that you need to submit the soft copy of your answer script (.cpp files) to the virtual
class. User name and password for the virtual class is provided to you through post.
5. No late submissions will be accepted.
6. Any type of copying is not allowed and if found a zero mark will be given.
7. Use only Borland C++ or Visual C++ compiler to compile your programs.
8. All your programs should have comments as applicable.
Q1.
Write a complete C/C++ program for the following tasks
i.
Create two arrays named intArray[] and squareArray[] with a user defined size.
ii.
The intArray[] should accept positive integer values from the user.
iii.
squareArray[] should have the square value of the corresponding element of the
intArray[]. Use pointer arithmetic and pointers to functions techniques in order to
write your program.
eg:- intArray[] = {3,4, 5}
squareArray[] = { 9,16,25}
iv. Display both the arrays.

Q2.
Write a complete C++ program introducing functions for each task listed below. You are
supposed to use arguments passed by value technique in order to write the program.
Page 1 of 3

i.
ii.
iii.
iv.

To input a sentence with more than 20 characters and less than 100 characters.
To replace each first letter character (given in lower case) of a word to upper case
in any given sentence and display the new sentence.
To count the number of characters in the string and display the count.
To find whether any word in the sentence occurs multiple times. If so display Yes
and if not No.

Q3.
Write a complete C/C++ program to implement a simple calculator with following menu and
execute different functions depending on the user selection. The calculator should perform
Addition( + ), Subtraction ( - ), Multiplication (*), Division (/ ) and find Modulus(%) of two
numbers.

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

-----------Menu--------Enter the numbers to perform the mathematical operations


Add the two numbers
Subtract the second number from the first number
Multiply the two numbers
Divide the first number from the second number
Find the remainder after the division
Check whether the numbers are even or odd
Check whether the numbers are prime numbers
Exit program

Use a pointer to call different functions depending on the option that the user has entered.
If the user selects Option no 2 or 3 or 4 or 5 or 6 without selecting Option no 1 the user
should be prompt with a message asking him/her to select Option no 1 first. The user
should always enter an integer value for the option selection, if not the user should be
prompt with another message asking for proper input for selection.
You may write your own assumptions you made when building the program considering
the functionalities that the program need to execute.
Q4.
Write a complete C++ program to calculate the volume of a cube, cylinder and a cuboid. Use
function overloading technique in order to write the program.
NOTE:- Formulas necessary to find the volume are as follows
Volume of a cube = s s s =s3
r r h r 2 h
Volume of a cylinder =
=
l b h lbh
Volume of a cuboid =
=
Where s Length of a side of the cube
r - Radius of the base of the cylinder
Page 2 of 3

h Height of the cylinder


l- Length of the cuboid
b Width of the cuboid

- 3.14519
Q5. Define a class in C++ to represent a bank account. Use constructors and destructors as
applicable. Include the following as data members
Name of the depositor
Account number
Type of account
Balance amount in the account
You are supposed to write member functions for the following tasks.
To deposit an amount
To withdraw an amount after checking the balance
To display name and the balance
You may use the following data given on TableQ5 for the program.

Name of the depositor

Account number

Type of account

Balance(Rs.)

Kamala
Raja
Nelum

1010890
2020980
3030089

Savings
Savings
Savings

150000.00
60000.00
140000.00

Table Q5
Bank Transactions that needs to program are
Kamala withdraws an amount of Rs.110000.00 from his account
Raja Deposits(Save money) Rs. 3000.00 on his account
Nelum Checks his account balance
Write a main program which can be used to test your program.
Note: You should use object oriented concepts to develop the program.
- END -

Page 3 of 3

Você também pode gostar