0% found this document useful (0 votes)
10 views

Section 8: Part A: Tutorial Problems For Practice

This document contains instructions for a programming assignment. It provides two parts - Part A with tutorial problems to practice algorithms and flowcharts, and Part B containing two programming assignment problems. For Part A, students are asked to write programs that calculate various mathematical functions. For Part B, students must write programs to calculate the area and volume of geometric shapes based on given parameters, and determine if rectangles overlap by comparing their coordinates. Solutions are to be submitted to the course Moodle page by 12:45 hrs.

Uploaded by

Sohini Roy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Section 8: Part A: Tutorial Problems For Practice

This document contains instructions for a programming assignment. It provides two parts - Part A with tutorial problems to practice algorithms and flowcharts, and Part B containing two programming assignment problems. For Part A, students are asked to write programs that calculate various mathematical functions. For Part B, students must write programs to calculate the area and volume of geometric shapes based on given parameters, and determine if rectangles overlap by comparing their coordinates. Solutions are to be submitted to the course Moodle page by 12:45 hrs.

Uploaded by

Sohini Roy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Section 8

PDS Lab Lab-6 06.10.2016


 

Part‐A: Tutorial Problems for Practice 

Instructions:
 Draw flowchart and or algorithm depicting how to solve each problem in this part.
 Submit your work latest by today. Please clearly write your name, roll number and mobile
number on the front page of the sheets.
 Create a sub directory named as LabT6 under your home directory.
 Give the name of the programs as <R> <T>1.c, <R> <T>2.c, .. etc. for the tutorial problems
problem 1, 2….., respectively. Here <R> implies your Registration No.
 Store all the programs under this tutorial part in the directory LabT6

Determine what each of the following foomatic functions computes:

1. ------------------------------------------------------------

unsigned int foo1 ( unsigned int n )


{
unsigned int t = 0;

while (n > 0) {
if (n % 2 == 1) ++t;
n = n / 2;
}
return t;
}

2. ---------------------------------------------------------------

unsigned int foo2 ( unsigned int n )


{
unsigned int t = 0;

while (n > 0) {
if (n & 1) ++t;
n >>= 1;
}
return t;
}
3. -----------------------------------------------------------------

double foo3 ( double a , unsigned int n )


{
double s, t;

s = 0;
t = 1;
while (n > 0) {
s += t;
t *= a;
--n;
}
return s;
}

4. ---------------------------------------------------------

double foo4 ( float A[] , int n )


{
float s, t;

s = t = 0;
for (i=0; i<n; ++i) {
s += A[i];
t += A[i] * A[i];
}
return (t/n)-(s/n)*(s/n);
}

[Hint: First try to have the answer of your own and then verify your answer by writing
appropriate programs for each problems. If you need help, ask the TAs.]

 
Part‐B: Assignment Problems 

Instructions:
 Create a sub directory named as LabA6.
 Give the name of the programs as <R> <A2>1.c, <R> <A2>2.c, …, etc. for the tutorial
problems 1, 2….., respectively. Here <R> implies your Registration No.
 Store all the programs under this tutorial part in the directory LabA6.
 You should upload your programs to the Moodle course web page. Preferably in ZIP form
latest by 12:45 hrs. today only.

  

1. Write functions to compute the following.


a) The area of a circle whose diameter is supplied as an argument.
b) The volume of a 3-dimensional sphere whose surface area is given as an argument

For each of the above functions write a main program to read the input to the function
and print the output of the function for that input.

2. Two rectangles are said to overlap if there exists a common point lying inside or on the
boundary of both rectangles. Assume that all rectangles have edges parallel to the x and y
axes.

Fig 1 (a) Fig 1 (b)

Fig 1(a) shows a case where all pairs of rectangles overlap. In Fig 1(b). the shaded
rectangles do not overlap. Both figures contain 3 rectangles.
a) Write a C function overlap(x1, y1, x2, y2, a1, b1, a2, b2) that receives the diagonally
opposite corner points of two rectangles as arguments such that (x1, y1) and (x2, y2) are
the two diagonally opposite corner points of one rectangle, while (a1, b1) and (a2, b2) are
the two diagonally opposite corner points of the other rectangle. The function returns 1 if
the rectangles overlap, otherwise 0.

b) Write a main( ) program that reads the value of an integer N and then reads in the
diagonally opposite corner points of N rectangles. Assume N < 10. The coordinates are
stored in four arrays, X1[ ], Y1[ ], X2[ ], Y2[ ]. The coordinates (X1[k], Y1[k]) and
(X2[k], Y2[k]) represent the corner points of the kth rectangle. Your program must then
use the function overlap(…) to determine whether all pairs of rectangles overlap. If not,
then it must print the corner points of every distinct pair of rectangles which do not
overlap.

[Submit your solutions to Moodle course management system, latest by 12:45 hrs. toady.] 

You might also like