Académique Documents
Professionnel Documents
Culture Documents
“I never teach my pupils; I only attempt to provide the conditions in which they can learn.”
~ Albert Einstein
FP Case Studies
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
1
FP Case Studies
1) These are not actual case studies or projects but developed scenarios
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
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
3
FP Case Studies
a=b +
}
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);
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.
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()
5
FP Case Studies
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];
//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
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
8
FP Case Studies
Case Study -2
Faculty Name Malarvizhi R
College Name Kamaraj College of Engineering & Technology
Infosys DC Chennai
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.
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)
10
FP Case Studies
Learning Outcomes
11
FP Case Studies
Case Study -3
Faculty Name H Harshavardhan
College Name Srinivas Institute of Technology,
Mangalore
Infosys DC Karnataka DCs
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:
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
13
FP Case Studies
Solutions
ROUND I
2 3
1 0
1 0
1 0
2 5
1 0
ROUND II
2 1
2 3
ROUND III
1 1
2 1
14
FP Case Studies
ROUND IV
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
15
FP Case Studies
Case Study -4
Faculty Name Dr Jaba Sheela L
College Name Panimalar Engineering College
Infosys DC Chennai
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 */
16
FP Case Studies
void Askdoubts() {
q_mutex.P();
void GetClarified() {
q_avail.V();
ans_avail.P();
q_mutex.V();
void Student() {
while (true) {
void Cleardoubts() {
q_avail.P();
void ClearDone() {
ans_avail.V();
17
FP Case Studies
void Faculty() {
while (true) {
Cleardoubts();
// give an answer
ClearDone();
void MFCTutoring() {
CreateThread("Ms.Joshi",Faculty);
CreateThread("Akash",Student);
CreateThread("Ritesh",Student);
CreateThread("Vinisha",Student);
Learning Outcomes
18
FP Case Studies
Case Study -5
Faculty Name Ram Mohan
College Name MLR Institute of Technology
Infosys DC Karnataka DCs
Problem Statement
2 13 Reminder
2 6 1
2 3 0
1 1
19
FP Case Studies
Solutions
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
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).
Jaipur Mumbai
Delhi
Ahmedabad Delhi Goa
Jaipur
Goa Ahmedabad
Pune
Mumbai
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.
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
25
FP Case Studies
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
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
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.
Step 4: CPTR=POP()
then CPTR=CPTR->right
29
FP Case Studies
Step 7: EXIT
Procedure Traverse_Level_N(ROOT, N)
Step 1: Set Pointer MPTR = ROOT, Pointer SEP = dummy node, FLAG=0 and level=1
Step 5: SEP = VAL_FRONT() //Peek the value at the FRONT of the QUEUE
then level=level+1
ENQUEUE(SEP)
Step 7: IF level == N
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).
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
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.
#include <stdio.h>
void fnTest( );
34
FP Case Studies
fnTest( );
printf(“iValue1=%d ivalue2=%d\n\n”,iValue1,iValue2);
void fnTest( )
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
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:
35
FP Case Studies
iValue1=iValue2 * 2;
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.
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
TE: [perplexed] Usssssshhhhh…. Time up! We‟ll discuss the problem in the next class.
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”.
I
iNum1=100 iNum1=100 N
iNum2=200 iNum2=200 V Inaccessible
A none
L to main( )
I
fnTest() fnTest() D none
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
Problem Statement
Can we fine tune the following program to reduce execution time of the program?
// sample code
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
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
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
Problem Statement
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)
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.
FileName:1.Makefile
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
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.
vi Calc.c
#include<stdio.h>
#include"../inc/calcdefs.h"
int main()
{
int first,second,result;
int 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
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:
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
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
47
FP Case Studies
Solutions
• fire,hold
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 setStatus();
int getStatus();
};
class Bomb;
Balloon:
class Balloon{
int radius;
int xPosition,yPosition;
int state; int
color; Bomb
b; public:
int getXCurrentPosition();
int getYCurrentPosition();
49
FP Case Studies
Weapon:
class Weapon{
int numberOfBullets;
int firingSpeed;
int status;
public: Weapon(int
n);
Weapon();
int fire();
int hold();
};
Class Bomb
{
int radius;
int timeToBlast;
50
FP Case Studies
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
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
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
Solutions
Student: Sid,Sname,City,Pin,Phno,EmaiIId.
Course: Cid,Cname,Credits.
Faculty: Fid,FName, City,Pin,Phno,EmaiIId
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.
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
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
56
FP Case Studies
Learning Outcomes
57
FP Case Studies
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.
Questions
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
has
Audit
onds nam
panno age
status e
General appr
name Audience CIO
1 oveb
phone
address email
passwor id
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
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
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
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
To solve the above problem the relation can be refined upto 3 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.
In the above table, all the attributes are atomic, meaning they are not further decomposable. So the
above table satisfies the I NF.
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.
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.
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
5 C-Pro 1 1 22-12-2010
FID Fname CC
5 Java 3 2 18-12-2010
FA5504 Ramesh 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
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:
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