Vous êtes sur la page 1sur 70

yes

Foundation Program based


Case Studies

“I never teach my pupils; I only attempt to provide the conditions in which they can learn.”
~ Albert Einstein
FP Case Studies

Sl. No. Topic FP mapping Focus Area Page No.

Introduction to computer System software (Compilers ,


1 Translators case study 4
systems assemblers)
Customer Service Management
2 Operating Systems Disk Scheduling 10
System for Cottage

3 Round Robin- Process Scheduling Operating Systems Process Scheduling 13

Process Synchronization using


4 Tutor Synchronization Case Study Operating Systems 17
Semaphore

Generate Binary form of a Decimal Problem Solving


5 Stack 20
Number Techniques
Basic Data structures like array,
Problem Solving
6 Graph Traversal queues and advanced data 22
Techniques
structures like graphs
Application of STACK and QUEUE Problem Solving Problem solving techniques /
7 28
collectively Techniques Algorithms

Real time Application of Stack and Problem Solving


8 Stack and Queue Application 33
Queue Techniques

Declaring Variables, Function


9 3 Idiots Programming & Testing 35
Calls and Stack

10 Loop Unrolling Programming & Testing Code Tuning and Optimization 41

Programming Development
C Project Resource Organization Programming and
11 tools and Code, Object, Exe, 43
and Make Tool(UNIX) Testing
Header files organization
Blast or Escape from Balloons Objects Oriented Objects, Classes, Fields and
12 48
Game Object World Concepts Methods
Data Base Design for Students
13 Enrollment in Various Course at RDBMS Database Design – ER Modeling 53
Software Training Center

14 Income Tax Returns Processing RDBMS Database Design – ER Modeling 59

15 University Examination System RDBMS Database Design - Normalization 63

1
FP Case Studies

1) These are not actual case studies or projects but developed scenarios

2) These are developed by faculty members as part of Foundation


Program / Inspire contests.

3) Infosys is not responsible for any IP violation

4) All these case studies will be used only for learning purposes.

2
FP Case Studies

Case Study -1
Faculty Name Parkavi A
College Name MSRIT, Bangalore
Infosys DC Karnataka DCs

Name of the Case Study Translators case study


FP Course Linkage Introduction to computer systems
Focus Area System software (Compilers, Assemblers)
Complexity Medium

Problem Statement

Compiler has many phases. The phases perform the following operations: Phase1 divides the
program into tokens. Phase 2 finds out the syntax errors. Phase3 checks the semantic of the
program. Phase 4 generates three address code.Phase5 optimizes the code and phase6
generates the assembly language code.

Questions

1. What is the operation of compiler in first phase?

Identify the tokens used in the following code:


void main()
{
int a, b=7, c=2;
a=b + c;
}

2. What will be the operation of compiler in phase2?

Identify the errors in the following code


void main()
{
int a,b=,c=2

3
FP Case Studies

a=b +
}

3. What will happen during phase 3 of compiler?

Check for semantic over the given code and identify the errors.

void main()
{
int a=1, c;
char g[60];
c=a + g;
}

4. How will the intermediate code generation works? Do the three address code generation for
the given expression.

a=(b + c)*(b + c);

5. Why do we need code optimization? Optimize the given expression.

a=(b + c) * (b + c);

6. What will be done during phase 6 of compiler? Do code generation for the given expression.

a=b + c;

Solutions

1. Phase 1: Lexical analysis – Lexical analyzer will take the complete input program and
divide the program in to small tokens.

Token token type

void keyword

4
FP Case Studies

main keyword

( special symbol

) Special symbol

{ special symbol

Int keyword

a identifier

, separator

b identifier

= assignment operator

7 integer constant
, separator

c identifier

; terminator

a identifier

= assignment operator

b identifier

+ arithmetic operator

c identifier

; separator

} special symbol

2. Phase 2: Syntax analysis: Syntax analyzer will check for the syntax of the statements
used in the given program against the grammar of the programming language.

void main()

int a, b=, c=2 //  b= integer constant is missing

5
FP Case Studies

//c=2 terminator ; is missing

a= b + // b+ operand is missing for binary operator

// terminator also missing

3. Phase 3:Semantic analysis : Semantic analyzer will check for the meaning of the usages
of the variables or identifiers in the programming statements.

void main()

int a= 1, c;

char g[60];

c=a + g; //g is a string it can‟t be added with integer operand a, semantic

//error

4. Phase 4: Three address code generation : The intermediate code generation to convert the
statement involving more than one arithmetic operation can be divided to have one
operation in a single step so it can be represented in assembly language statement and
executed by CPU single operation at a time.

Input:

a=(b + c) * (b + c);

Output:

t1:=b + c;

t2:=b + c;

t3:=t1 * t2;

a:=t3;

6
FP Case Studies

5. Phase 5: Code optimization

The redundant codes can be eliminated to avoid the repeated task in CPU. In the given
problem b+c once calculated can be used again.

Input:

a= (b +c ) * (b + c);

Without optimization:

t1:=b + c;

t2:=b + c;

t3:=t1 * t2;

a:=t3;

Output:

t1:=b + c;

t2:=t1 * t1;

a:=t2;

6. Phase 6: Code generation: The three address code is the input for the code generation
phase and the output is the assembly language code.

Input

a=b + c;

Output:

LDA b

ADD c

STA a

7
FP Case Studies

Learning Outcomes

 Knowing the operations of compiler phases


 Usage of compiler operations
 Analyzing the compiler operations
 Knowing about assembler
 Knowing the instructions of assembler
 Using the instructions of assembler

8
FP Case Studies

Case Study -2
Faculty Name Malarvizhi R
College Name Kamaraj College of Engineering & Technology
Infosys DC Chennai

Name of the Case Customer Service Management System


Study for Cottage
FP Course Linkage Operating System
Focus Area Disk Scheduling
Complexity Simple

Problem Statement

There is a cottage with 40 rooms where customers can avail the facility of lodging for rent. The
layout of the cottage is shown in Figure 1. In such a cottage, there is a customer service
management system (CSMS) which offers various housekeeping services to its customers
through service boys. The customer can submit his/her request through phone call to this
customer service management system and the requests are recorded in the log book on time
basis as <Room Number, Service/s requested and requesting time>. The requests are accepted
everyday within 8 „O clock morning. The service boy who is appointed for that day will report
to the CSMS and will start to serve the recorded requests by visiting customer‟s room one by
one and he has to complete all the requests within 5 „O clock evening. The following data
show the room numbers of customers in which order they have submitted their requests.

9, 18, 3, 12, 1, 14, 35, 22


2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4
1 2 3 4 5 6 7 8 9 1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0 C 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
3
8 9 0

S
M
S
VERANDAH VERANDAH

Figure 1

9
FP Case Studies

Questions
1.

2. What are the different strategies that can be followed by the service boy to serve
customers‟ requests? If the CSMS does not specify any order in servicing the requests
then, what strategy can be followed by the service boy to complete his work with
minimum physical effort?

3. Assume that today service boy has to start his service from room number 11 and he wants
to move towards 12, 13, 14…. How he will rearrange the requests to reduce his physical
work? Show the scenario of servicing with simple sketch.

Solutions

1. (i) Customers can be served in the order they have requested but the decision is not
wise. (FCFS disk scheduling)

(ii) The service boy can rearrange the submitted requests in ascending order then starting
the service from first (least) number in the rearranged list. Again the decision is not wise
because service boy is always reporting to CSMS which is at the mid of rooms 20 and 21.
Hence, unnecessary roaming and physical work can be avoided if the rearrangement is
done considering the boy‟s current position.

(iii) Considering the boy‟s current position, he can choose the left or right direction for
his move and rearrangement of the orders can be done correspondingly. For an example,
if the boy wants to move towards 21, 22... then he can rearrange the requests in such a
way that rooms having shortest distance from his current position in this direction. (SSTF
Scheduling)

Room number sequence is: 12 14 18 22 35 9 3 1

10
FP Case Studies

Learning Outcomes

1. Student is able to realize the internal working of disk scheduling process.

2. The problem or demerit in FCFS scheduling is understood clearly

3. The student is able to do shortest seek time first disk traversal.

11
FP Case Studies

Case Study -3
Faculty Name H Harshavardhan
College Name Srinivas Institute of Technology,
Mangalore
Infosys DC Karnataka DCs

Name of the Case Study Round Robin- Process Scheduling.


Course Linkage Operating System Concepts
Focus Area Process Scheduling
Complexity Medium

Problem Statement

Presume that there are 6 people positioning in a queue. This queue is preserved for effortlessly
issuing of tickets for a unique event. As per the standardization of superior authority, more than 2
tickets should not be issued to a person at a time. In this line of people the first person needs 5
tickets and fifth person needs 7 tickets and the rest just need only one ticket for the event. How
this can be achieved by issuing any number of tickets appealed by all who are in the queue?
Which perception of Operating System can be correlated with this?

Questions

1. Suggest the manner in which the tickets are issued to the people?

2. Who is supposed to involve in multiple wait in line process and how many times?

Postulation:

It is one of the oldest, simplest, and fairest and most widely used scheduling algorithms,
designed especially for time-sharing systems. A small unit of time, called time slices or
quantum is defined. All runnable processes are kept in a circular queue. The CPU scheduler
goes around this queue, allocating the CPU to each process for a time interval of one quantum.
New processes are added to the tail of the queue. The CPU scheduler picks the first process from
the queue, sets a timer to interrupt after one quantum, and dispatches the process.

12
FP Case Studies

If the process is still running at the end of the quantum, the CPU is preempted and the process is
added to the tail of the queue. If the process finishes before the end of the quantum, the process
itself releases the CPU voluntarily. In either case, the CPU scheduler assigns the CPU to the next
process in the ready queue. Every time a process is granted the CPU, a context switch occurs,
which adds overhead to the process execution time.

Case in point:

Process Burst Time

P1 53

P2 17

P3 68

P4 24

Gantt chart:

P P P P P P P P P P
1 2 3 4 1 3 4 1 3 3

0 20 37 57 77 97 117 121 134 154 162

13
FP Case Studies

Solutions

ROUND I

No of tickets issued No of Additional tickets required

2 3

1 0

1 0

1 0

2 5

1 0

ROUND II

No. of tickets issued No. of additional tickets required

2 1

2 3

ROUND III

No. of tickets issued No. of additional tickets required

1 1

2 1

14
FP Case Studies

ROUND IV

No. of tickets issued No. of additional tickets required

1 0

From above course of action the first person has to approach three times and the fifth person four
times to acquire required quantity of tickets.

This is similar to Round Robin scheduling in Operating system concepts, where each job is given
one chance in one turn and the process is continued for all job in circular queue fashion.

Learning Outcomes

At the end of the session students will be able to.

1. Know the basic concepts of process Scheduling.


2. Able to explain RR scheduling algorithm for scheduling tasks.
3. Develop skills to fabricate distinctive analogies for RR scheduling algorithm.

15
FP Case Studies

Case Study -4
Faculty Name Dr Jaba Sheela L
College Name Panimalar Engineering College
Infosys DC Chennai

Name of the Case Study Tutor Synchronization Case Study


FP Course Linkage Operating System Concepts
Focus Area Process Synchronization using Semaphore
Complexity Medium

Problem Statement

The MCA department of Panimalar Engineering College conducts courses prescribed by the
Anna University, Chennai. Mathematical Foundation of Computer Science is a course that most
students find intricate to score. The faculty assigned for the course Ms.Joshi proposed to lend a
helping hand to the students who need extra coaching in the subject by clearing their doubts in
the tutorial hour. There are 14 such students. Ms.Joshi pays individual attention to each student
hence only one student can clear the doubts at a particular time and the remaining students have
to wait for their turn. When there are no students, Ms.Joshi does her other work like correcting
papers or reading some books.

Questions

Design a solution to synchronize the interaction between the students and the faculty.

Solutions

/* variable declaration */

Semaphore q_mutex = new Semaphore("q_mutex", 1);

16
FP Case Studies

Semaphore q_avail = new Semaphore("q_avail", 0);

Semaphore ans_avail = new Semaphore("ans_avail", 0);

/* Procedures for student */

void Askdoubts() {

q_mutex.P();

void GetClarified() {

q_avail.V();

ans_avail.P();

q_mutex.V();

void Student() {

while (true) {

Askdoubts(); // Ask doubts to the faculty

GetClarified(); // Obtain the answer form the faculty

/* Procedures for Faculty */

void Cleardoubts() {

q_avail.P();

void ClearDone() {

ans_avail.V();

17
FP Case Studies

void Faculty() {

while (true) {

Cleardoubts();

// give an answer

ClearDone();

/* Main procedure for the Problem */

void MFCTutoring() {

CreateThread("Ms.Joshi",Faculty);

CreateThread("Akash",Student);

CreateThread("Ritesh",Student);

CreateThread("Vinisha",Student);

Learning Outcomes

1. Gives insight into the process synchronization concept in Operating Systems.


2. It signifies a two process solution wherein the faculty is recognized as one process and
the student as the other process.
3. The same situation can be extended to multi-process solution with many faculty and
students.

18
FP Case Studies

Case Study -5
Faculty Name Ram Mohan
College Name MLR Institute of Technology
Infosys DC Karnataka DCs

Name of the Case Study Generate Binary form of a Decimal


Number
FP Course Linkage Problem solving techniques
Focus Area Stack
Complexity Medium

Problem Statement

Write a program to generate Binary representation of a given Decimal number.

2 13 Reminder

2 6 1

2 3 0

1 1

19
FP Case Studies

Solutions

To implement this, follow the steps given below.

1. Read a number
2. Iteration (while number is greater than zero)
1. Find out the remainder after dividing the number by 2
2. Print the remainder
3. Divide the number by 2
3. End the iteration

Questions: If the input to the program is 13 the program will print 1011

When we print the reminders we will get 1011 but the correct answer is 1101.

Here is the need for a stack. We need to collect reminders in a stack so that the correct result is
finally popped out. In this example the correct result is 1101 which can be popped at the end
from Stack.

Learning Outcomes

Learners can analyze the need for a proper data structure based on the application.
Creation of Stack using Arrays.
Perform Push operation when reminders are generated.
Pop the result which is the binary form of given Decimal number.

20
FP Case Studies

Case Study -6
Faculty Name Amit Sharma
College Name Ambala College of Engineering and Applied Research
Infosys DC Chandigarh DC

Name of the Case Study Graph Traversal


FP Course Linkage Problem Solving Techniques
Focus Area Basic Data structures like array, queues
and advanced data structures like graphs
Complexity Complex
Problem Statement

Let‟s assume that we are interested in airline route between seven cities: Delhi, Mumbai, Jaipur,
Pune, Bangalore, Ahmedabad and Goa. Our favorite airline (Spicejet) flies the following routes:

Ahmedabad to Goa
Ahmedabad to Pune
Bangalore to Jaipur
Bangalore to Pune
Delhi to Jaipur
Delhi to Mumbai
Goa to Ahmedabad
Jaipur to Ahmedabad
Jaipur to Delhi
Jaipur to Goa
Mumbai to Pune
Pune to Bangalore
Pune to Mumbai

21
FP Case Studies

Questions

1. Which structure will be used to represent physical relationship between these airline
routes?
2. Which data structure will be used to represent the structure (defined in Q.1) for solving
the problem?
3. Design a strategy to find the route (direct or indirect) from one city to another city.
4. Is there any route from Delhi to Goa? (Answer this by analyzing the graph).
5. Apply the strategy discussed in Q.3 to find the route from Delhi to Goa.

Solution

1. Graph:

Jaipu
r Bangalo
re
Del
hi Ahmedaba
d
Pun
Go e
a
Mumb
ai

22
FP Case Studies

1. Two dimensional array known as Adjacency Matrix. If there is a direct route between
two cities then store 1 at their intersection point in 2D array otherwise store 0. We can
store distance or fare between cities instead of 0 or 1 (if provided).

Cities Pune Delhi Goa Jaipur Ahmedabad Mumbai Bangalore


Pune 0 0 0 0 0 1 1
Delhi 0 0 0 1 0 1 0
Goa 0 0 0 0 1 0 0
Jaipur 0 1 1 0 1 0 0
Ahmedabad 1 0 1 0 0 0 0
Mumbai 1 0 0 0 0 0 0
Bangalore 1 0 0 1 0 0 0

Adjacency Matrix Representation

Adjacency List representation

Jaipur Mumbai
Delhi
Ahmedabad Delhi Goa
Jaipur

Goa Ahmedabad

Ahmedabad Goa Pune

Pune
Mumbai

Pune Bangalore Mumbai

Bangalore Jaipur Pune

23
FP Case Studies

2. The strategy we will use is first to take our starting city and see if we can reach our
destination directly. If we can‟t, we will take each of the places we can reach directly
and see if we can reach our destination directly from any one of them (i.e. in one stop).
If we can‟t, we repeat the process to see if we can reach our destination from any of the
next level of cities (i.e. in two stop). The process continues until we find our destination
or determine that we can‟t get there from here.

We will begin by looking at each city we can reach directly from the originating city. If
we find our destination, the search is over. Otherwise, we need to remember all the cities
(alternate route) we can reach in one stop so that we can fan out from them if we don‟t
find our destination at the one-stop level. We kept track of alternate routes by using a
queue. Each city adjacent to the originating city is placed in a queue say ALTER.
Remember that we have to place the originating city of all the adjacent cities in a queue
say ORIG. This will help us in determining the route in the end. Example if B, C, D are
adjacent to A, then B, C, D will be placed in ALTER and A, A, A will be placed in
ORIG.

Naturally, we need to keep track of the adjacent to a city, and we need to guarantee that
no city is processed more than once otherwise it becomes an infinite process. This can be
solved by using a STATUS field corresponding to each city. If STATUS=0 then the city
is not selected, When selected, STATUS change to 1 and place it in the ALTER. When
processed (to check for adjacent) its STATUS change to 2. Now if a city have its
STATUS=2 then it will not be selected. When the destination reached, just back track the
ALTER and ORIG to find the route between the source city and destination city.

3. Three possible routes.


Delhi->Mumbai->Pune->Bangalore->Jaipur->Ahmedabad->Goa.
Delhi->Mumbai->Pune->Bangalore->Jaipur->Goa.
Delhi->Jaipur->Goa.

4. Assumptions:-
ALTER: a queue use to store the adjacent city ready to be processed.
ORIG: a queue use to store the originating city of all ALTER cities.
FRONT: use to store the front index of queue from where cities removed.
REAR: use to store the rear index of queue from where cities inserted.
CURRENT: use to store the current processing city.
STATUS: an array that is use to store the status (0, 1, 2) of cities.

Here are the steps to find the route between DELHI and GOA.

24
FP Case Studies

1. CURRENT = NULL FRONT = 1 REAR = 1


ALTER: Delhi
ORIG: NULL
STATUS:

Pune Delhi Goa Jaipur Ahmedabad Mumbai Bangalore


0 1 0 0 0 0 0

2. CURRENT = Delhi FRONT = 2 REAR = 3


ALTER: Delhi, Mumbai, Jaipur
ORIG: NULL, Delhi, Delhi
STATUS:

Pune Delhi Goa Jaipur Ahmedabad Mumbai Bangalore


0 2 0 1 0 1 0
3. CURRENT = Mumbai FRONT = 3 REAR = 4
ALTER: Delhi, Mumbai, Jaipur, Pune
ORIG: NULL, Delhi, Delhi, Mumbai
STATUS:

Pune Delhi Goa Jaipur Ahmedabad Mumbai Bangalore


1 2 0 1 0 2 0

4. CURRENT = Jaipur FRONT = 4 REAR = 5


ALTER: Delhi, Mumbai, Jaipur, Pune, GOA
ORIG: NULL, Delhi, Delhi, Mumbai, Jaipur
STATUS:

Pune Delhi Goa Jaipur Ahmedabad Mumbai Bangalore


1 2 1 2 0 2 0

Destination city GOA reached.

25
FP Case Studies

5. ALTER: Delhi, Mumbai, Jaipur, Pune, GOA


ORIG: NULL, Delhi, Delhi, Mumbai, Jaipur.

To find the route, check the last city entered in ALTER and finds its originating city
in ORIG. Originating city of GOA is JAIPUR. Now find the position of JAIPUR in
ALTER and check for its corresponding originating city in ORIG. Originating city of
JAIPUR is DELHI. Repeat this process until you find the originating city NULL.
Hence the route with smallest number of stoppage is:-
DELHI->JAIPUR->GOA.

Learning Outcomes

1. Students will be able to understand different data structures like arrays, queues and
graphs and their usage in practical application.
2. Students will be able to learn how to apply the strategy or algorithm on real world of data
to solve the problem.
3. Student will learn how to represent the graph like structure during implementation.
4. Implementation of Breadth First Search.

26
FP Case Studies

Case Study -7
Faculty Name Awadhesh Kumar Srivastava
College Name Krishna Institute of Engineering and
Technology, Ghaziabad
Infosys DC Chandigarh

Name of the Case Study Application of STACK and QUEUE


collectively
FP Course Linkage Problem solving techniques
Focus Area Problem solving techniques / Algorithms
Complexity Medium

Problem Statement

Consider a company ABC as multilevel marketing company. It allows its member to make
maximum FIVE sub-members under him/her. Company has created its distributers in various
cities. Now any person can become member of the company under the distributer of his/her city,
and further can make sub-member under him/her. On making sub-member Y under a member X,
X and its ancestors (up to level THREE including level of X) get some remuneration from the
company on a particular proportion of what Y paid to company to become a member.

Company created a BST city (Binary Search Tree) to store various cities. Every node in this BST
contains city name, pointer “left” to left child node, pointer “right” to right child node and a
pointer MPTR to member-tree, which is made for members in that city in proper hierarchy.
Every node in member tree contains pointers to all its children nodes, and the various member
data (like Name, ID, No_of_submember etc).

27
FP Case Studies

ROOT of city

Delhi

Bombay Surat

Pointer to member-tree

Baroda Culcutta Trivendram

level 1 level 2 level3

Pointer to member-tree
m3
m1
m4
distributer m2

m6 m5

Questions

Write down an algorithm which gives all the Nth level members in all the cities.

28
FP Case Studies

Solutions

We have to traverse complete city-tree, and for every city we have to traverse member-tree at
level N.

We can traverse city-tree by inorder, preorder or post order. But we have chosen inorder because
inorder traversal of BST gives sorted order data. Since city-tree is BST, inorder traversal gives us
chronological order of city name. Inorder traversal can be done by recursive and non-recursive
algorithm; we would go with non-recursive algorithm. We would traverse member-tree level by
level and display the members who are at level N, and after displaying those members there is no
need to traverse the rest of the same member-tree. To do so, we write a procedure
Traverse_Inorder () which traverses city-tree in inorder and another procedure Travel_Level_N()
to traverse member tree level by level. In Traverse_Inorder () as processing of node we display
corresponding member-tree at level N.

Procedure Traverse_Inorder (root of city)

Step 0: Create STACK

Step 1: SET pointer CPTR to root of city

Step 2: Repeat Step 3 to Step 5 //endless loop

Step 3: Repeat Step 3.1 to Step 3.3 IF CPTR != NULL

Step 3.1: Traverse_Level_N(CPTR->MPTR,N)

Step 3.2: PUSH(CPTR)

Step 3.3: CPTR=CPTR->left

Step 4: CPTR=POP()

Step 5: IF CPTR != NULL

then CPTR=CPTR->right

else GOTO Step 6

Step 6: DESTROY STACK

29
FP Case Studies

Step 7: EXIT

Procedure Traverse_Level_N(ROOT, N)

Step 0: Create QUEUE

Step 1: Set Pointer MPTR = ROOT, Pointer SEP = dummy node, FLAG=0 and level=1

Step 2: ENQUEUE (MPTR) and ENQUEUE (SEP)

Step 3: Repeat Step 4 to Step 8 IF (MPTR = DEQUEUE()) != NULL

Step 4: ENQUEUE all the children node of MPTR

Step 5: SEP = VAL_FRONT() //Peek the value at the FRONT of the QUEUE

Step 6: IF SEP == dummy node

then level=level+1

ENQUEUE(SEP)

DEQUEUE() // Remove dummy node from the QUEUE

Step 7: IF level == N

then Repeat Step 7.1 to Step 7.3 IF VAL_FRONT() != dummy node

Step 7.1: MPTR = DEQUEUE()

Step 7.2: Print MPTR->name

Step 7.3: Set FLAG=1

Step 8: IF FLAG == 1 GOTO Step 9

Step 9: Destroy QUEUE

Step 10: EXIT

STACK and QUEUE used in the above algorithms are containing the address of the node, and
not the node itself. PUSH(), POP() and ENQUEUE(), DEQUEUE() are normal operation of
STACK and QUEUE respectively of complexity constant i.e. O(1). Both return NULL if empty
on POP() or DEQUEUE(). CREATE and DESTROY are self-explaining statements.

30
FP Case Studies

Complexity:

1. Procedure Traverse_Inorder() traverses the tree in inorder fashion so that city name will
be encountered chronologically , complexity of this algorithm is also linear (number of
node in the tree) i.e. O(m)

2. Procedure Traverse_Level_N() traverses the tree level by level till it gets to the desired
level. In worst case (when we have to traverse last level) complexity of this algorithm is
order of number of node in tree i.e. O(n).

3. So overall worst case complexity of this algorithm is O(∑ ( )) where ni is number of


members in the ith city and total number of cities are m.

Learning Outcomes

1. Algorithm writing
2. Better understanding of STACK and QUEUE by its combined application.
3. Time Complexity calculation
4. Out of box thinking

31
FP Case Studies

Case Study -8
Faculty Name Rammohan Rao
College Name MLR Institute of Technology
Infosys DC Hyderabad DC

Name of the Case Study Real time Application of Stack and Queue
FP Course Linkage Problem Solving Techniques
Focus Area Stack and Queue Application
Complexity Simple

Problem Statement

Consider a Printer connected to a computer. Let the printer be shared across the LAN.
Identify the various data structures that are used in printer.

Questions

1. How Printer handles multiple requests from different computers in the network?
2. How printer takes papers from the paper tray?

Solutions

Printer is a very good example to show the application of various data structures like queue and
stack.

1. Print Spooler is a program which maintains a print queue. Here a queue is used to
store various requests from various computers and are processed in FIFO order.
2. If we carefully observe how the paper is taken by printer from the tray. Printer
follows
LIFO to taken papers from the tray.

32
FP Case Studies

Learning Outcomes

Learners can analyze the need for a proper data structure based on the application.
Printer is a real time example so they can relate things to real time objects and can better
understand the application of a particular data structure.

33
FP Case Studies

Case Study-9
Faculty Name Sudhir Shenai
College Name Karunya University
Infosys DC Karnataka DCs

Name of the Case Study 3 Idiots


FP Course Linkage Programming & Testing
Focus Area Declaring Variables, Function Calls and Stack
Complexity Complex

Problem Statement

[Note: The case study depicts the training experience of 3 fresh recruits from a popular
Engineering College into a reputed IT firm. Here the names are changed to avert the privacy
issue and chosen to be familiar to the audience, and to add a little flavor of humor as well.]

Karunya University is gearing up for the campus recruitment. Its September last week. Its raining
man!!! Not just monsoon rain, placement offers too. Infy was the first company to hand pick the
best of the talents. To the surprise of “Professor Virus”, the placement officer, the 3 Idiots - Amir
Khan, Madhavan, Sharman Joshi topped the selection list. The Professor deemed them as 3
idiots, for they raise critical contradictory questions in the class, rather than accepting professor‟s
straight forward answer. Now, will the 3 idiots be the treasure to E&R team of Infy or the
Trouble? Lets, wait and watch the post recruitment scene in mysore DC. It‟s Tough Time for the
Technical Evangelist. God Bless Him!!

TE(Technical Evangelist): Pals, Have you all completed the assignment on Function Calls and
Stack.

Amir Khan: Sir, I have executed the following program.

#include <stdio.h>

void fnTest( );

int main( int argc, char **argv)

34
FP Case Studies

fnTest( );

int iValue1=100, iValue2=200;

printf(“\n The values of the variables iValue1 and iValue2 are:\n”);

printf(“iValue1=%d ivalue2=%d\n\n”,iValue1,iValue2);

void fnTest( )

int iNum1=100, iNum2=200;

printf(“\n The values of the variables iNum1 and iNum2 are:\n”);

printf(“iNum1=%d iNum2=%d\n\n”,iNum1,iNum2);

TE : You would have got a compile error, rite. (Smiling with a sense of proud)

Amir Khan: Exactly, TurboC3 throws Error Test.C Line No 6: Declaration not allowed here, but

What may be the reason?

TE : Don‟t you know „C‟ doesn‟t allow any executable statement before any declarations

inside a function. You should have listened to my class on functions. But you guys

are never attentive in my class. That‟s evident from your silly doubts.

Amir Khan: Sir, But why executable statement should not precede declaration inside a function.

TE : Uuuushhhhh … (with irritation). Well, I‟ll explain with an example. Consider the
code

below:

int main( int argc, char **argv)

35
FP Case Studies

iValue1=iValue2 * 2;

int iValue1=100, iValue2=200;

printf(“\n The values of the variables iValue1 and iValue2 are:\n”);

printf(“iValue1=%d ivalue2=%d\n\n”,iValue1,iValue2);

Since, C execution is sequential, the variables iValue1 and iValue2 values are not known priori
until the declaration statements are executed. To overcome this limitation, C mandates
declaration to precede executable statements and it is checked at the compilation stage itself.
Hence, the compile errors on compiling the above function.

Amir Khan: Sir, but ….

TE : [with high irritation] what but? ….. Can‟t u understand this simple stuff?

Amir Khan: Sir, I understand and agree with your explanation. But in my main function, I called

the function fnTest( ), before the declaration of variables iValue1 and iValue2.The

point here is, fnTest( ) doesn‟t use any of the variables declared in the main( ). In that

case the “function calling” before the declaration should not have any problem.

Because,the called and calling functions are sharing nothing . But, why the compiler

throws error. Kindly, reason out …

TE: [perplexed] Usssssshhhhh…. Time up! We‟ll discuss the problem in the next class.

Students: [giggling and appreciating Khan‟s shrewdness]

Omi Vaidhya: Sir, What Amir has shown is not your assignment on function call and Stack, He

has shown his own program. But I have completed your assignment, Sir. I got the
expected the answer.

TE: Good ! Very Good ! you earn the full credit , Keep it up.

36
FP Case Studies

Questions
If you are Khan‟s ardent fan,

1) Analyze and list various reasons for the error thrown by the Amir‟s program. [Error
Test. C Line No 6: Declaration not allowed here:]
2) Execute the same program in various compilers and compare and comprehend

The Class can be divided into 2 groups. One can discuss the first question and the other can
experiment the second. Finally both groups can enter in deliberations to share, analyze and
evaluate their findings.

Solutions

1) There are various reasons for the error, already one reason is discussed in the problem
statement as the answer of Technical Evangelist. The second reason is discussed in detail
below. The discussion can be continued to even Malloc allocation. The question is an
open ended problem; hence scope for discussion and various answers and opinions are
possible
2) The different compilers give different output. TurboC throws the error as mentioned, but
not all the compilers. Some compilers compile the program without any error. Here, the
reason is not all the compilers adheres to the same standard of C. There are various
standards of C exist, K&R C, C89, C90, C99, C1X the latest expected to be released.
Even if compilers adheres the same standard, there is a slight deviation to 100%
complaint, hence the code that passes in one compiler may not run the same in other.

Explanation of solution1:

The Diagram below elicits the stack view of the program under execution. The green block
indicates the scope of main() in the stack (space used by main in the stack). The yellow block
indicates the scope of fnTest(). When the fnTest() returns, the yellow block turned into ash color
to indicate that the block is no longer accessible to fnTest(). Now the next line to be executed in
the main() is declaration statement of variables iValue1 and iValue2. If it has to be successfully
executed, it should allocate stack space for variables iValue1 and iValue2, but that is not
possible. Because the stack space cannot be allocated inside the green block but should be over
the green block, which means violation of scope of the main( ). It is because of this reason,
compiler checks the condition and throws error, whenever a “function call statement” appears

37
FP Case Studies

before the declaration statement, inside a function. Thus C mandates the rule “Function call
statement should not precede declaration statement”.

Stack View of the Program


under Execution

I
iNum1=100 iNum1=100 N
iNum2=200 iNum2=200 V Inaccessible
A none
L to main( )
I
fnTest() fnTest() D none

int argc int argc int argc


char **argv char **argv char **argv

main() main() main()


int argc
char When the
**argv The first line to declaration line in
be executed Stack space view the main() is to be
inside the main( of the program, executed, the main
main( ) ) is function call when the cannot allocate the
to fnTest( ). The function fnTest( ) stack space for
When the main( ) is
yellow block returns to main( variables ivalue1
called for the first
shows the stack ). The ash color and ivalue2, as it
time, only formal
space occupied block indicates has to allocate it
parameters are
by the fnTest( ) that block is beyond the green
allocated space in
under execution invalidated and block, which is
the stack. The
green block no more usable beyond the scope
indicates the scope by fnTest() of main()
of main()

38
FP Case Studies

Learning Outcomes

1) Appraise the key reasons behind the rule “Executable statements should not precede the
Declaration of variables inside a function“ followed by C
2) Apply the knowledge of function call and stack to analyze declaration of variables.
3) Evaluate the impact of different Compiler Compliance on declaration of variables.

39
FP Case Studies

Case Study -10


Faculty Name Rammohan Rao
College Name MLR Institute of Technology
Infosys DC Hyderabad DC

Name of the Case Study Loop Unrolling


FP Course Linkage Programming and Testing
Focus Area Code Tuning and Optimization
Complexity Medium

Problem Statement

Can we fine tune the following program to reduce execution time of the program?

// sample code

for (i=0; i<1000; i++)

eval( i );

Loop Unrolling: It‟s one of the code tuning technique used to reduce the execution time of a
program by transforming loops.

Solutions

for (i=0; i<1000; )

eval(i);
eval(i+1);
eval(i+2);
eval(i+3);
eval(i+4);

40
FP Case Studies

i=i+5;
}

No. of condition checking will be reduced which will affect the execution time of program.

Questions

1. How do I know that the program after unrolling will take less execution time?
Answer: We recommend a free IDE called Eclipse Ganymede

2. Which shows elapsed time for every program after execution.

Answer: The above example was tested in Eclipse Ganymede

Learning Outcomes

Learners can practically feel the difference in execution times before and after unrolling.
Students will understand the importance of writing better programs.

41
FP Case Studies

Case Study -11


Faculty Name Anil Kumar Rangisetti
College Name GMR Institute of Technology
Infosys DC Hyderabad DC

Name of the Case Study C Project Resource Organization and Make


Tool(UNIX)
FP Course Linkage Programming and Testing
Focus Area Programming Development tools and Code,
Object, Exe, Header files organization.
Complexity Complex

Problem Statement

Develop a simple calculator which performs addition, subtraction and


multiplication operations on integers .

Questions

1) How to separate source code, object code, executable code and Header files code in
development environment?
2) How to minimize unnecessary compilation time?
3) How to clean up your Project?
4) How to take backup of your source, object, exe files?

Solutions

Question 1: Answer

1.Create Main Project Folder e.g:Calculator and under this folder create three more folders with
following names.
$mkdir SRC $mkdir INC $mkdir OBJ(Give these three commands under Calculator).
a.SRC- Maintains entire source code files.(e.g. calc.c,add.c,sub,c,mul.c)
b.INC- Maintains all the include/header files required for project.(e.g calcdefs.h)
c.OBJ-Maintains all the object code files.(e.g calc.o,add.o,sub.o,mul.o)

Note:Exe File will be created and Placed in Main Project Folder(e.g.Calculator)

42
FP Case Studies

Question 2 : Answer
To avoid Unnecessary Compilation we are taking help of Make tool.

1.Create a Makefile which gives various rules for project compilation process.Place it in Main
Project Folder(calculator)
Command is: vi Makefile

Ultimate Target file exe is placed in the first rule which lists all its dependent object files.
Make utility will scan from top to bottom and it compiles necessary source files by checking
last modification time stamps of each dependent files.

As Compilation depends on Timestamps It avoid unnecessary compilation for all source files.
Calculator Project Make file Source CODE.

Makefile:rules of the following form


Target:dependency list
<tab>Command_list
Before start command <tab> space is necessary
Note:SRC is a userdefined macro for giving the path for source code files:eg “src” is the path
of src code of c files.
OBJ is userdefined macro for giving the path for object code files:eg “obj” is the path of
object code of c files.

FileName:1.Makefile

vi Makefile and type following code:

SRC=src
OBJ=obj
INC=inc
calc.exe:$(OBJ)/calc.o $(OBJ)/add.o $(OBJ)/sub.o $(OBJ)/mul.o gcc -o calc.exe
$(OBJ)/calc.o $(OBJ)/add.o $(OBJ)/sub.o
$(OBJ)/mul.o
$(OBJ)/add.o:$(SRC)/add.c

gcc -c $(SRC)/add.c mv add.o


$(OBJ)/
$(OBJ)/sub.o:$(SRC)/sub.c gcc -c
$(SRC)/sub.c mv sub.o
$(OBJ)/
$(OBJ)/mul.o:$(SRC)/mul.c
gcc -c $(SRC)/mul.c mv
mul.o $(OBJ)/
$(OBJ)/calc.o:$(SRC)/calc.c $(SRC)/add.c $(SRC)/sub.c $(SRC)/mul.c
$(INC)/calcdefs.h
gcc -c $(SRC)/calc.c
mv calc.o $(OBJ)/
clean:

43
FP Case Studies

rm $(OBJ)/*.o rm
calc.exe
tar:
tar -cvf obj.tar $(OBJ)/*.o tar -cvf
src.tar $(SRC)/*.c tar -cvf exes.tar *.exe

Question 3: Answer.)

Makefile Supports clean rule for deleting unnecessary files after completion of project
execution. If you want to clean up project give following command
$make clean
Question 4: Answer.)

To Take backup of object files,exe files and source code we can give the following command.
$make tar
it create obj.tar src.tar exes.tar in the calculator project folder.
we can use them by extracting the contents with the help of tar command.

Makefile Supports tar rule for archiving important files.

Example Source Code Files:

vi Calc.c

#include<stdio.h>
#include"../inc/calcdefs.h"

int main()
{
int first,second,result;
int choice;

printf("Enter First Number,Second Number");


scanf("%d%d",&first,&second);

printf("Enter Choice 1.Add 2.Sub 3.Mul");


scanf("%d",&choice);

switch(choice)
{
case ADD: result=add(first,second);
printf("Result :%d",result); break;
case SUB:
result=sub(first,second);
printf("Result of 1SUBTRACT,,, :%d",result);
break;

44
FP Case Studies

case MUL: result=mul(first,second);


printf("Result :%d",result); break;
}

return 1;
}
vi Add.c:
int add(int a,int b)
{
return a + b;

}
vi Sub.c:
int sub(int a,int b)
{
return a - b;
}

vi Mul.c:
int mul(int a,int b)
{
return a * b;
}
vi calcdefs.h:
#define ADD 1
#define SUB 2
#define MUL 3

OUTPUT VERIFICATION:

1) Goto Calculator Project Folder:


2) Give makecommand. It creates calc.exein calculator folder. We can run it by typing just
calc.exe
3) To take back up of Project files we can give maketar command
4) To clean up the project give makeclean command

OBSERVATIONS:

1) First give command Makein folder calculator.It will compile all the source files and
creates calc.exe as output.It places all object code files in obj folder and exein Main
Project Folder.
2) If you give Second time Make command Immediately after first Make then it showsall files
are up to date.(Because No file is changed,it avoids Unnecessary compilation).
3) Change calc.c file and then give command Make.
4) Then it recompilesonly calc.c and creates new calc.exe
5) Change add.c file and then give command Make.(It may effect the calc.c )
6) As calc.c depends on add.c ,It recompilesonly add.c ,calc.c and creates new calc.exe.

45
FP Case Studies

7) After execution of calc project by giving command calc.exe .Give Make Clean command.
Then it deletes all object files in obj folder.It also deletes calc.exe file.
8) Give Maketar command to get the backup of sourse,obj,exe files in three different tar
files.(Obj.tar,Src.tar,Exe.tar)(This command should be given before giving command make
clean).

Learning Outcomes

1) Students are able to learn How to divide the source code files,header files ,Object files
and Executable of a project .
2) They are able to learn how to create Makefile and Use it for efficient compilation of
project.
3) They are able to learn How to clean up the Unnecessary files after project execution.
4) They are able to learn How to take backup of the required files of a project.

46
FP Case Studies

Case Study -12


Faculty Name Anil Kumar Rangisetti
College Name GMR Institute of
Technology
Infosys DC Hyderabad DC

Name of the Case Study Blast or Escape from Balloons Game


Object World
FP Course Linkage Objects Oriented Concepts
Focus Area Objects, Classes, Fields and Methods.
Complexity Medium

Problem Statement

Blast or Escape from Balloons Game Object World is a Gaming world. We can enter into
this world as a Player and we can enjoy the game by blasting of balloons and getting high
scores with the help of various weapons provided in world.

Game Rules:
1) Balloons are flying in a random way.(move up/down/left/right).Balloons may throw
bombs on to the player.Ballons size varies randomly.
2) Player starts with MaxLives=3 and he can move left/right only. During game, the player
can get various weapons and he has to hold weapon first and then he can fire at balloons.
3) Every time player blasts balloon his score get incremented according to balloon size.
4) Player loose his lives one by one. and score get decremented by 10.on following
conditions. Condition1:If he fails to fire Minimum number of balloons in specified
amount of time. Condition2:If he hit by bombs from balloons.
5) If he loses all lives or he blasts all balloons then Game will be over and Player will be
awarded.

Questions

1) Develop this Game according to rules in any OOP language.


2) Identify the Objects involved in Game world.
3) Identify the various Classes can be created to represent objects of the Gaming World.
4) Describe the Classes with required fields and Methods.

47
FP Case Studies

Solutions

Identified Objects: 1. Balloons of different sizes


2. Player
3. Weapons with bullets.
4.Bombs
Identified Classes: 1 .Balloon 2.Player 3.Weapon 4.Bomb
Describe Classes with required Fields and Methods:
Identified Fields of Balloons:
• Radius,color,xposition,yposition,status(Blasted,Flying) .

Identified Fields of Player:


• Name,Lives,Score,Position,status

Identified Fields of Weapon:


• Numberofbullets,firingSpeed,Status(free or busy )
Identified Fields of Bomb:
• TimetoBlast,radius,(we can add required fields)

Identified Methods for Balloons:


• moveLeft,moveRight,flyUp,getDown,throwBomb,blast

Identified Methods for Player:



incrementScore,decrementScore,incrementLive,decrementLive,moveLeft,mov
eRight, getScore,fireWeapon,holdWeapon.

Identified Methods for Weapon:

• fire,hold

Identified Methods for Bomb:


• throwBomb

In C++ We can define the Identified classes in following way.


We can add required Get,Set Methods for required Fields.
Player:

class Weapon;
class Player{

char name[20];

48
FP Case Studies

int lives;
int score;
int position;
int status;

public:

player(int n);
player();

int getscore();
void setName(char n[]);
char* getName();

int getScore();
void incrementScore(int value);
void decrementScore(int value);

void incrementLive(int value);


void decremenLlive(int value);

void moveLeft(int value);


void moveRight(int value);
int getCurrentPosition();

void holdWeapon(Weapon w);


void fireWeapon(Weapon w);

void setStatus();
int getStatus();

};
class Bomb;
Balloon:
class Balloon{

int radius;
int xPosition,yPosition;
int state; int
color; Bomb
b; public:

void moveLeft(int x,int y);


void moveRight(int x,int y);
void flyUp(int x,int y);
void getDown(int x,int y);

int getXCurrentPosition();
int getYCurrentPosition();

49
FP Case Studies

void setState(int s);


int getState();

void throwBomb(Bomb B1);


void blast();

void setRadius(int r);


int getRadius();

void setColor(int c);


int getColor();
};

Weapon:
class Weapon{

int numberOfBullets;
int firingSpeed;
int status;
public: Weapon(int
n);
Weapon();

void setSpeed(int s);


int getSpeed();

int fire();
int hold();

void setStatus(int s);


int getStatus();

int updateBullets(int n);


int getBulletNumber();

};

Class Bomb
{
int radius;
int timeToBlast;

int setRadius(int r);


int getRadius();

50
FP Case Studies

int setTimer(int timeToBlast);


int getTime();
};

In C++ Objects are created as follows.


To create Player Object: Player p1;
Balloon Object:Balloon B1;
Weapon Object:Weapon W1;
Bomb Object: Bomb b1;

The Game Can Developed By Making Necessary Interactions among these


objects(Player,Balloon,Weapon) with Proper flow control.

Learning Outcomes

1. Students are able to learn about objects, classes, fields and method.
2. They can identify object, classes, fields and methods from the Given scenario.
3. Student are able to learn How to define classes with required fields, methods and get, set
methods.

51
FP Case Studies

Case Study -13


Faculty Name Anil Kumar Rangisetti
College Name GMR Institute of Technology
Infosys DC Hyderabad DC

Name of the Case Study Data Base Design for Students Enrollment in
Various
Course at Software Training Center
FP Course Linkage RDBMS
Focus Area Database Design – ER Modeling
Complexity Complex

Problem Statement

In A Software Training Company , It needs to maintain following details


1. Registered Students Details.
2. Courses Offered.
3. Students and their enrolled courses.
4. Registered Faculty Details.
5. Each student enrollment details like(Fee paid,Join date,Course Completion Date)
needs to be recorded.
6. Faculty and their handled courses during various durations.

Constraints:
• One student can join in many courses .e.g A student can join in both c and cpp courses.
• A course should be taught by only one faculty during particular duration(start date ,end
date)
• A faculty can teach many courses.
• Few students may get discount on a course fee.

52
FP Case Studies

Questions

Develop Database with any Relation DBMS to meet business requirements.

Solutions

Conceptual Database Design Deals with modeling concepts as entities, relationships,


attributes. Its final output is ER diagram.

Identified Entity Sets: 1 .Student 2.Course 3.Faculty

Identified Relation Ship Sets: 1. Enroll 2. Teach

Describe entity sets with attributes:

Student: Sid,Sname,City,Pin,Phno,EmaiIId.
Course: Cid,Cname,Credits.
Faculty: Fid,FName, City,Pin,Phno,EmaiIId

Describe Relation ship sets with required attributes:

Enroll:JDate,EDate,Fees
Fees is associated enrollment as Same course can be offered at different fees for different
student.
Teach:SDate,EDate

53
FP Case Studies

54
FP Case Studies

Logical Database Design: We take ER diagram as a Input and translate the entity
sets and relationship sets into tables.

Translate the entity sets into tables.

Create table STUDENT(


SID Number(5),
SNAME Varchar2(20),
PHNO Number(10),
emailed Varchar2(20),
City varchar2(15),
PIN Number(6),
Constraint studpk primary key(sid));

Create table FACULTY(


FID Number(5),
FNAME Varchar2(20),
PHNO Number(10),
EMAILID Varchar2(20),
CITY varchar2(15),
PIN Number(6),
Constraint facultypk primary key(sid));

Create table COURSE(


CID Number(3),
CNAME Varchar2(20),
CREDITS Number(6),
Constraint coursepk primary key(sid));

Translate the relationship sets into tables.

Create table ENROLL(


SID Number(5),
CID Number(3),
JDate Date,
EDate Date,
Fees Number(8,2),
Constraint enrollpk primary key(SID,CID,JDate,EDate),
Constraint enrollfk1 foreign key(SID) references
STUDENT(SID), Constraint enrollfk2 foreign key(CID)
references COURSE(CID));

Create table TEACH(


FID Number(5),
CID Number(3),
SDate Date,

55
FP Case Studies

EDate Date,
Fees Number(8,2),
Constraint teachpk primary key(CID,JDate,EDate),
Constraint teachfk1 foreign key(CID) references
COURSE(CID), Constraint teachfk2 foreign key(FID)
references FACULTY(FID));
Sample Inputs and Verification of Constraints:
STUDENT

SID SNAME CITY PIN PHNO EMAILID


1000 Rama Vizag 532127 9898989898 rama@gmail.com
1001 Laxman Vijayawada 532128 9898989899 laxman@gmail.com
1002 Hanuman Hyderabad 532129 9898989890 Rama123@gmail.com

FACULTY
FID FNAME CITY PIN PHNO EMAILID
9000 Anil Vizag 532127 9898989891 Anil.eluru@gmail.com
9001 krishna Vijayawada 532128 9898989892 laxmanna@gmail.com
9002 Srinivas Hyderabad 532129 9898989893 Ramana123@gmail.com

COURSE
CID CNAME CREDITS
100 C 10
101 CPP 15
102 JAVA 20

Enroll Relatioship:One Student can join in many courses.(eg:SID:1000)


Course Fees can be varied from student to student.(CID:101)
SID CID JDATE EDATE FEES
1000 100 1-jan-2011 31-jan-2011 1000
1001 101 1-mar-2011 30-mar- 2000
2011
1003 101 1-feb-2011 28-feb-2011 3000
1000 103 1-apr-2011 31-apr-2011 3000

TEACH Relationship:One Faculty can teach many courses.(eg:FID:9000) Same


Course can be taught by Many Faculty On Different Durations.(CID:101)
Same Course can not be taught by more than one faculty on same durations.(because the
primary key is (CID,JDATE,EDATE)
FID CID JDATE EDATE
9000 100 1-jan-2011 31-jan-2011
9001 101 1-mar-2011 30-mar- *If Same Course can be taught by
2011 more than one faculty on same
9003 101 1-feb-2011 28-feb-2011 durations then we need to include
9000 103 1-apr-2011 31-apr-2011 FID also in primary key.

56
FP Case Studies

Learning Outcomes

1. Students will able to understand Conceptual Database Design with ER diagram.


2. They will able to Convert Given ER diagram to Tables according to given constraints.
3. They will able to Test the given constraints on developed database.

57
FP Case Studies

Case Study -14


Faculty Name Shenbagaraj R
College Name Mepco Schlenk Engineering College
Infosys DC Chennai

Name of the Case Income Tax Returns Processing


Study
FP Course Linkage RDBMS
Focus Area Database Design – ER Modeling
Complexity Complex

Problem Statement

Income tax returns processing is a web application which provides the online filing of tax details
of either individuals or firms and hence it will calculate and provide the returns statement. It is
very useful for the income tax payers to easily file their tax details and obtain their returns
statement.

There are four kind of users of this system namely General Audience, Chief Information Officer
(CIO), Audit specialist and Report Specialist. All the users have their own login.

 General audience may be an individual or representatives of a firm. They will create the
account in the system and they login in to their account to file the various necessary
income details and the various modes of expenses that will provide the deduction in the
tax amount. They also require giving the details of already paid tax amount with the
chalan details. The system will calculate the total tax payable and the amount of returns
and generate the returns statement.
 The CIO has the full authority to approve the account details of the users and approve
rules for calculating tax. He is having the authority to grant permission for Audit
Specialist to view the details and Report Specialist to generate various types of reports.
 Audit Specialist can audit the details of the taxpayer by using their id.
 Report Specialist can generate various kinds of reports needed from the details provided
by the CIO.

58
FP Case Studies

The product‟s main function is to calculate the tax returns for an individual or firm. The tax
payer has to create the account with the required information. Then, with this account he can
login and provide the information asked about the income details and the various expense details
for the deductions in tax amount according to the rules and norms specified by the Government.
By considering the details, the tax amount for the payer has been calculated. Then the tax payer
has to specify the details of the tax amount paid earlier with the details of chalan number etc.
Finally the returns amount is calculated based on the total tax amount and the tax paid earlier and
the amount will be refunded after proper authentication. If the payer has to pay the tax more than
he paid already then he is intimated to pay the remaining amount. The CIO monitors the entire
process and the Audit specialist will audit the details furnished by the payers. Then various kinds
of reports required for payers and other officials are generated by the report specialist.

As a part of providing solution to the above case study, it is recommended to follow a


Brainstorming Approach. The Class of students can be divided in groups and they can
brainstorm to draw an ER Diagram. The Group leader should ensure that he gets an answer for
the following questions.

Questions

• Identify the Entities


• Find relationships
• Identify the key attributes for every Entity
• Identify other relevant attributes
• Identify the Primary Key

The Group leader will present their solution to the audience. The audience and the Facilitator
will judge best one. The facilitator will ensure that a consensus is getting evolved. The ER
Diagram then can be converted in to table design by logical Database Design steps.

They may also be asked to design the database by using Normalization (Bottom Up Approach).

59
FP Case Studies

Solutions

password panno Taxpayabl Totala


Return
amt
Login
Tax Tax Tax paid
reduction details

has
Audit
onds nam
panno age
status e

General appr
name Audience CIO
1 oveb

phone
address email
passwor id

city State Individual Firm

Race/Lottery
Other
1 income
Agricultur h
Loan for Inco
Higher h m me e 1
Education
House Other
propert sources Income
Insuranc Capi
for
e talga
Deductiondetails pension Salary

Income
Medical Donatio details
Salary

Subscrip Donat Expense


tion of ion Savin details
Profit
from
Entertai Staff Festival Schola
n expense Celebratio rship
n
name id

Audi Audit name


passwo
t specialist
id
Repeat
Vi specialist
e passwo

60
FP Case Studies

Schema diagram:

Learning Outcomes

1. Learners will learn by involving in brainstorming the case study to design any database
by applying the Top down Approach.
2. If, they also design the database by using Normalization (Bottom Up Approach), they can
compare the two approaches.

61
FP Case Studies

Case Study -15


Faculty Name Yegireddi Ramesh
College Name Aditya Institute of Technology and Management
(AITAM, Tekkali)
Infosys DC Hyderabad

Name of the Case Study University Examination System


FP Course Linkage RDBMS
Focus Area Database Design - Normalization
Complexity Medium

Problem Statement

Consider any University Examination System, which consists of the enrolled students result
details. Suppose the university wants to maintain not only the results, but also performance of the
faculty, then it enhances the existing system by adding the details of the Instructors.

62
FP Case Studies

The Table contains:

Results (S#, Sname#, DOB, C#, Cname,subject, Semester, Year, FID, Fname, CC, ColName,
DateOfExam, Marks, Grade)

S# Sname DOB C# Cname Sub Sem Year FID Fname CC ColNa DOE M Gr
me ar
ks
10A509 Ajay 20/10/9 5 CSE C- 1 1 FA5504 Ramesh A5 AITAM 22- 68 B
4 Pro 12-
2010
09W622 Vinay 06/06/9 5 CSE Java 3 2 FA5504 Vijay W6 SIVANI 18- 82 A
3 12-
2010
10A544 Devaki 4/5/94 4 ECE EDC 1 1 FA5403 Arun A5 AITAM 26- 77 B
12-
2010
103478 Padma 5/7/93 2 EEE PS 5 3 FA5206 Ratna 34 GMRIT 19- 62 C
12-
2010
10A548 Rekha 14/8/94 4 ECE EDC 1 1 FA5403 Arun A5 AITAM 26- 54 D
12-
2010
103478 Charan 11/6/93 2 EEE PS 5 3 FA5206 Ratna 34 GMRIT 19- 89 A
12-
2010

Questions

Eliminate the anomalies like redundancy, insertion anomaly, updation anomaly and deletion anomaly
from the above table.

Solutions

To eliminate the anomalies like redundancy, insertion anomaly, updation anomaly and deletion
anomaly from any table, it should be decomposed into smaller relations using Normalization
techniques.

Introduction:

Basically normalization eliminates the duplicate data and makes insert, update and delete operations
much more efficient in terms of performance and space requirement to store the data.

63
FP Case Studies

Hence we need to refine our design so that we make an efficient database in terms of storage space and
inserts, updates and deletes operations. The refining technique is called as Normalization

Decomposition of a large relation in to smaller relations is called as normalization

To solve the above problem the relation can be refined upto 3 NF.

First Normal Form (I NF):

A relation R is said to be in the first normal form (1 NF) if and only if all the attributes of the relation are
atomic in nature.

o There are no repeated groups in the table.


o All the attributes are defined.

In the above table, all the attributes are atomic, meaning they are not further decomposable. So the
above table satisfies the I NF.

Second Normal Form (2 NF):

A relation R is said to be in the second normal form (2 NF) if and only if

 it is in the first normal form.


 no partial dependency exists between non-key attributes and key attributes.

Note - 1: A key attribute a candidate key, which can uniquely defines the other attributes.

Note – 2: We can define functional dependency as,in a given relation R, X and Y are attributes. Attribute
Y is functionally dependent on attribute X if each value of X determines EXACTLY ONE value of Y. This is
represented as: X  Y.

64
FP Case Studies

Note – 3: We can define partial functional dependency as, in a given relation R, X and Y are attributes.
Attribute Y is partially functionally dependent on attribute X only if it is functionally dependent on sub-
set of X.

In the above table,

o S# is a key attribute.
o C# is a key attribute.
o S#, Subject is a composite key.
o FID is a key attribute.
o CC is a key attribute.
o S#, Subject is composite key
o other attributes like Sname#, DOB, Cname,subject, Semester, Year, Fname, ColName,
DateOfExam, Marks, Grade are non-key attributes.

To make this table 2NF, we have to remove all the partial dependencies.

o Sname and DOB depends only on S#.


o Cname, sem, Year and DOE depends only on C# Subject.
o Marks and Grade depends only on S# Subject CC.
o Fname depends only on FID CC.
o Cname depends only on C#.
o ColName depends only on CC.

In the above tables, No partial dependency exists between the key attributes and non-key attributes.
Hence the tables are in Second Normal Form (2 NF).

65
FP Case Studies

STUDENT COURSE

S# Sname DOB C# Cname


10A509 Ajay 20/10/94
5 CSE

09W622 Vinay 06/06/93 4 ECE


10A544 Devaki 4/5/94 2 EEE
103478 Padma 5/7/93

10A548 Rekha 14/8/94

103478 Charan 11/6/93

C# Subject Semester Year DateofExam

5 C-Pro 1 1 22-12-2010
FID Fname CC
5 Java 3 2 18-12-2010
FA5504 Ramesh A5

4 EDC 1 1 26-12-2010 FW6504 Vijay W6

2 PS 5 3 19-12-2010 FA5403 Arun A5

F34206 Ratna 34

66
FP Case Studies

Grade

CC ColName

A5 AITAM
S# subject CC Marks Grade
W6 SIVANI
10A509 C-Pro A5 68 B
34 GMRIT
09W622 Java W6 82 A

10A544 EDC A5 77 B

103478 PS 34 62 C

10A548 EDC A5 54 D

103478 PS 34 89 A

Third Normal Form (3 NF)

A relation R is said to be in the third normal form (3 NF) if and only if

 it is in the second normal form.


 no transitive dependency exists between non-key attributes and key attributes.

Note – 4: if A  B and B  C then A  C is Transitive.

There is no transitive dependency in the above sub tables except Grade Table. The GRADE is depends on
MARKS and in turn MARKS depends on S# Subject CC. To bring this table to third normal form we need
to take off this Transitive Dependence. To eliminate transitive dependency, we can decompose the
RESULT table into MARKS and GRADE.

67
FP Case Studies

MARKS

S# subject CC Marks

10A509 C-Pro A5 68

09W622 Java W6 82

10A544 EDC A5 77

103478 PS 34 62

10A548 EDC A5 54

103478 PS 34 89

GRADE

Upper
Bound Lower Bound Grade

100 80 A

79 65 B

64 55 C

54 45 D

44 0 E

68
FP Case Studies

Final Results:

 Student (S#, Sname, DOB)


 Corse (C#, Cname)
 Sub_Date(C#, Subject, Semester, Year, DOE)
 Faculty(FID, Fname, CC)
 Marks(S#, Subject, CC, Marks)
 Grade(lowaebound, upperbound, grade)

All the anomalies are removed and all dependencies are preserved.

Learning Outcomes

 The student able to learn the concept of functional dependencies and Normalization.
 The student able to convert a relation into different normal forms.
 The student able to recognize the difference between different normal forms.

69

Vous aimerez peut-être aussi