The Following Pseudo Code Was Given in Your Exam. Complete The Pseudo Code in C++ Such That It Draws The Following Figure
The Following Pseudo Code Was Given in Your Exam. Complete The Pseudo Code in C++ Such That It Draws The Following Figure
Section-A
Assignment-2
Submission: Monday 6th April, 2015 till 1:30pm
Submission path: \\xeon\Spring 2015\Sidra Basharat\ITC\submissions\assign-2
Exercise 1:
The following pseudo code was given in your exam. Complete the pseudo code in c++
such that it draws the following figure:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10
.
11
.
12
.
13
.
14
.
15
.
16
.
17
.
18
.
19
.
20
.
21
.
22
.
23
.
24
.
25
.
26
.
27
.
Set size to 5
Set z to 1
Set i to 0
While i<=size
Begin
Set j=size
While j>i
Begin
Output
Set j to j-1
End
Output *
If i>0
Begin
Set k to 1
While k<=z
Begin
Output
Set k to k+1
End
Set z to z+2
Output *
End
Move to next line
Set i to i+1
End
For size=5
Exercise 2:
Modify the above code and draw this figure:
for size=5
Exercise 3:
The ancient Greeks classified numbers geometrically. For example, a number was called
triangular if that number of pebbles could be arranged in a symmetric triangle as
shown in the figure below. The first ten triangular numbers are 1, 3, 6, 10, 15, 21, 28, 36,
and 45. Write a program that takes as input a number N and prints whether it is
triangular or not.
Exercise 4:
Consider the sequence: 1, 1, 1, 2, 3, 4, 6, 9, 13, 19, 28, 41, 60, 88,
The function to generate this sequence is given as below:
f(1) = 1, f(2) = 1, f(3) = 1, and f(n) = f(n-1)+f(n-3).
Write code in C++ to generate the nth number in the sequence. (Hint: it is very similar to
the Fibonacci sequence).
Exercise 5:
You are given with a file which contains start and end time of call records. The format of
file is as follows:
The first line contains the number of calls, followed by n lines containing the start and
end time for the calls. The time is given as hour:min in 24 hour clock format. Write a C+
+ program that reads the start and end time of all n calls and compute the average
duration for those calls in minutes. For example consider the following data
5
12:50 13:20
18:30 18:40
8:10 8:30
15:20 15:40
23:10 0:50