Assignment: Course Code: MCS-025 Course Title: Lab Course Assignment Number - MCA (2) /025/assign/2010-11
Assignment: Course Code: MCS-025 Course Title: Lab Course Assignment Number - MCA (2) /025/assign/2010-11
ASSIGNMENT
This assignment has four parts. Answer all questions of each part. Each
part is of 10 marks. Lab records of each part will carry 10 marks. Rest
20 marks are for viva voce. You may use illustrations and diagrams to
enhance the explanations. Please go through the guidelines regarding
assignments given in the programme guide for the format of
presentation.
PART-I : MCS-021
Question 1: Sort the following data using heap sort and show all the
intermediate steps.
78, 17, 34, 93, 11, 26, 55, 45, 35, 19, 88
Write an algorithm in C to implement this and find its time
complexity
Ans. Heap sort
#include <stdio.h>
Int n, element [100];
Void restore heap uup (int Pos)
{
Int val, temp;
Val = element [Pos];
While ((((Pos/2)1=0 &&(element [Pos/2]< = element [Pos])
{
Temp=element [Pos];
Element [Pos] = element [Pos/2];
Element [Pos/2] = temp;
1
Pos = Pos/2;
}
}
Void add (int new val)
{
Element [++ n] = new val;
Restorte heap up (n);
}
Void restore heap down (int Pos)
{ int i, val;
Val = elements [Pos];
While (pos < = n/2)
{
I = 2 * pos;
If (( i <n) && (element (i) < elements [i + 1]))
L++;
If (val > = element [i])
Break;
Elements[pos] = element[i];
Pos = I;
}
Elements[POS] = val;
}
Int delete ( )
{
Int val;
Val = element [1];
Elements [1] = elements [n - ];
Restore heap down (1);
Return val ;
*/
}
Void create ( )
{ int I;
Printf (“\n enter the number of elements;”);
2
Scanf(“%d”, & n);
Printf (“\ n enter the elements:”);
For (I = 1; i< = n ++)
Scanf (“%d”, & element [i]);
}
Void heap sort ( )
{
Int i,t,m;
/* creating heap */
For (i=n/2; i > 1; i_)
Restore heap down (i);
M = n;
While (n>1)
{
T=element [1];
Element [n] = t;
N= n-1;
Restore heap down (1);
}
N=m;
}
Void construct heap ( )
{ int I;
For (i= n1; i>= 1; i_)
Restore heap down (1);
}
Void display ( )
{
Int I;
For (i=1; i<=n; i++)
Printf (“| tr %d”, elements [1])
}
Void main( )
{
Int ch, val;
3
clrscr();
do
{
Printf(“| n menu”);
Printf (“| n1) create an array of elements”);
Printf (“| n2) create an array to heap”);
Printf (“| n3) sort thee elements in the array”);
Printf (“| n4) add the elements to the heap”);
Printf (“| n5) display”);
Printf (“| n6) exit”);
Printf(“| n enter your choice”);
Scanf(ch)
{
Case1: create ( );
Break;
Case 2: construct heap( );
Break;
Case 3: Heap sort ( );
Break
Case 4: printf(“\n enter a value”);
Scanf (“%d”, & val);
add (val);
break;
Case 5: Display( );
Getch ( );
Break ;
Case 6: printf(“\ n - quilting”);
Getch( );
Break;
Default:
Printf (“\ n wrong choice”);
Getch( );
}
}
While (chi = 6);
4
}
5
Printf (“%d\t”, root info);
Pre (root left);
Pre (root right);
}
Void in (node * root)
{
Int (root left);
Print (“%d/ t”, root info);
Int (root right);
}
}
Void post (node * root)
{
If (root)
{
Post (root left);
6
Printf(“%d\t”, p info);
P=p right;
}
}
}
Void travpre (node * root)
{
Node * p = root; * q= null;
Strk.top = -1;
Do
{
While (p!=null)
{
Printf(“%d \ t”, P info);
Push (p);
P =p left;
}
P=pop( );
If (( p right ! = q) & & (P right = null))
{
Push (p);
P=p right;
}
Else
{
Q = p;
P = null;
}
} while (stk.top = -1);
}
Void trav post (node * root
{
Node * p =root, * q = null;
Stk top = -1;
Do
7
{
Push (p);
P=p left;
}
}
P = pop ( );
If (( p right ! = q) & & ( p right != null)
{
Else
{
Printf (“ %d\t”, p info);
Q=P;
P= NULL;
}
}
}
while (stk.top ! = 1);
}
Void push (node * p )
{
Stk. Arr ( ++ stk. Top) = p;
}
Node * pop ( )
{
Return stk.arr (stk.top -);
}
Void count node (node * root)
{
Int I =0;
Node * p = root; * q= null;
Stk.top = -1;
Do
{
While (p! = null)
{
8
L++;
Push (p);
P=p left;’
}
P = pop ( );
If ( p right I = q) && ( p right !=null ))
{
Push (p);
P= p right;
}
Else
{
Q=p;
P= null;
}
} while (stk.top ! = -1);
Printf (“the total number of node in binary tree is %d\t”)
}
PART-II : MCS-022
9
$
When we create a new file it is normally created with read
and write command and execute permission turned off.
$ chmod u + x example
$ example
Here is the date & time:
Tue jun 12 16 44 : 52 PST 1984
$ example
Here is the date & time:
Tue jun 12 16 : 45 : 23 PST 1984
10
Question 3:Use Telnet to get connected with other remote machine.
Write the problems you encounter during connection with
remote machine.
Ans. The ensure compatibility between the user and the remote
server. TELNET uses translation services between two
machine.
VERTICAL TERMINAL
Tcp/IP
STANDARD CODE
The TELNET client translate the output from the actual terminal to
standard code. The information in the standard code is sent to the
TELNET server in the remote hodt. The Telnet server transfer the
information into character accepted by remote host.
Question 4:How can you change the time of execution of the job,
Explain? Set the execution time of two jobs so that it run
automatically tomorrow one at 11:00 a.m and stop at 12:00
noon and for another job starts at 1:00 p.m and stop after its
completion.
11
entry to the critical section any process that wants to
common mutual exclusion must send a request message to
the coordinator.
Another approach is fully distributed approach. When a
process wants to enter its critical section. It generate a new
lime stamp and sent a request message to the other process
in the system. The decision whether a process replies
immediately or delay a request depend on three factors, if
one process in critical section then it display it replies to
other process.
If a process don’t want to enter its critical section it then
send a reply immediately to another process.
If a process wants to enter its critical section but has not yet
entered it.
PART-III : MCS-023
Question 1:
A film production named “Apex Entertainment”, which
produces motion pictures like films, TV serials and
documentaries. It maintains information about different
team member’s like actors, directors, assistants, co-
producers and other team members and their salary/contract
amount. Each motion picture has a title , year of production,
certification details , length and the type. Each team
member has a name, job title, contact detail and address.
These films, TV serials and documentaries can be shot in
studio has an owner, address, contact detail and a banner.
This production company sales its products to various
distribution company through bidding and contract. Team
members are connected to one or more type of motion
pictures. Create a database in MS-Access, which must
provide the following functionalities:
12
Query support
Report generation
Easy input facility for new data
Keep details about Expenditure, Performances,
Distribution and sales of each motion picture.
Maintain necessary details about Distributors, Team
members, Studios etc.
(ii) Find out how many distributors placed the orders last
year but did not made full payment till now.
(iii) Design a report to display performance of the Directors
and Actors, Motion Picture wise in term of sales.
(iv) Design a suitable form for storing basic information
about motion pictures to evaluate the performance and
appreciation by general public. Design and implement
the necessary tables.
13
DIRECTOR
RELATIO
NSHIP
ACTOR
GENERALIZATION
AD NAM
D E
PERSON DATE
IS- IS-
A A
DIRECTOR D- PRODUCER P-
ID ID
14
P_NAM
E
P_COMPANY P_ID
IS- IS-
A F- A S-
NAME NAME
FILM F- SERIAL S-
ID ID
C_ID
P_i P_NAM
C_NAM C_AD E
d DEPARTMEN
E D
T
F_I
D
STAFF CONDUCTO FILM
R F_NAM
E
F_ADD
S_I S_NAM
D E
PART-IV : MCS-024
15
Question 1: Create a java class (i.e. do not use any library class) to
represent linked lists of integers. Provide it with methods that
can be used to reverse a list and to append two lists.
Comment on whether your design has led you to make the
methods for append and reverse static.
Ans. Class calculator
{
Public int add (int a, int b)
{
System out print in (“int and int”);
Return a + b
}
Public void reverse (“int a and int b”);
{
System out. Print\ n (“int and int”)
}
Public node * search = Null;
Current next = head;
Previous = head;
Head = head next;
Previous next = null;
{
System.out print (“previous and head and next”);
Return previous next = Null;
}
Public search head
{
System. Out.println “ (“search = head”);
{
Calculator C=new calculator ( );
System.out.println (reverse (1, 10);
System.out.println (c.add(search(all int )));
}
}
16
Question 2: To make a fraction to a representation base 16 (i.e.
hexadecimal) we can multiply it by 16, and the resultant
integer part is the first digit and so on. Write a method that
accepts an array of digits (base 10) and creates and returns a
new array representing the same fraction but now base 16.
Your code should work for any length input array, not just
one of length 1000, and you may make the output array have
the same length as your input array.
Ans. # include <stdio.h>
# include <conio.h>
Void main ( )
{
Int a [1000], l, n, max, min;
Clrscr( );
Print (“ how many element in the array”);
Scanf (“%d”, & n);
Printf(“enter the element : \n”);
For (i=0, i< = n – 1; i++);
{
Scanf (“%d”, &a [a]);
}
Max = a(o);
Min = c(o);
For (i = 1; i< = n – 1; i++)
{
If (max <a [i])
Max = a[i];
If (min > a[i])
Min = a[i];
}
Printf(“maximum element in the array is :%d\ n”, max);
Printf(“minimum element in the array is: % \n”, min);
Getch ( );
}
17