0% found this document useful (0 votes)
107 views17 pages

Assignment: Course Code: MCS-025 Course Title: Lab Course Assignment Number - MCA (2) /025/assign/2010-11

This assignment has four parts with questions about data structures, algorithms, shell scripting, Windows commands, Telnet, and setting job execution times in Unix/Linux. The student provided answers for each question in the parts including code samples for heap sort in C, creating and traversing a binary tree, a shell script to find lines with capitalized words of a certain length, using Telnet and issues that may occur, and using Unix commands to set two jobs to run automatically at specific times tomorrow.

Uploaded by

Alka Dwivedi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views17 pages

Assignment: Course Code: MCS-025 Course Title: Lab Course Assignment Number - MCA (2) /025/assign/2010-11

This assignment has four parts with questions about data structures, algorithms, shell scripting, Windows commands, Telnet, and setting job execution times in Unix/Linux. The student provided answers for each question in the parts including code samples for heap sort in C, creating and traversing a binary tree, a shell script to find lines with capitalized words of a certain length, using Telnet and issues that may occur, and using Unix commands to set two jobs to run automatically at specific times tomorrow.

Uploaded by

Alka Dwivedi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 17

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
}

Question 2: Write a program in ‘C’ language for the creation of a


Binary tree. After creation complete, it should print the
preorder, postorder and inorder traversal outputs of the
binary tree.
Ans. #include <stdio.h>
#include <process.h>
#define max 50
Tydef struct tree
{
Int infor;
Struct tree * left;
Struct tree * right;
} node;
Struct stack
{
Node * insert node (node * r, node * p)
{
If (r =Null)
R = p;
Else
{
If (p infor > = info)
R right = insert node (r right p);
Else
R left = insert node (r left p);
}
Return r;
}
Void pre (node * root)
{
If (root)
{

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);

Post (root right);


Printf(“%d \ t”, root infor);
}
}
Void travin order (node * root)
{
Node * p = root;
Stk . top = -1;
While (( p 1= null) 111 (stk top 1 = -1))
{
If (P1 = null)
{
Push (p);
P=p left;
}
Else
{
P = pop ( );

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

Question 1: Write a shell script in Unix/Linux to find the lines numbers


of a text file are having word which is 5 to 10 characters
long and having first letter as a capital letter.
Ans. shell script :- Once you have found a sequence of command
you use often. You can commit them permanently to a file.
You can have the shell read the file and follow the script of
commands.
Echo here is the date & time:
Date the echo commaqns prints out its arguments to run this
script we can give the file name as an argument to the sh.
$ sh example
Here is the date and time:
Tue jun 12 16 : 43 : 02 PST 1984

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

Question 2:Use Windows 2000 command and communicate with your


friend sitting on a different machine but in a same domain
group.
Ans. Create if you are not familiar with NSLOOKUP those
options are clear as mud but for know in the DNS and type
in the following.
Ns lookup kubla urwrite .Net
This command return the following
Server kubla uwrite .Net
Address 10.225.10.190
Name kubla. Uwrite .Net
Address 10,225,10,190
In this example you need the name of DNS server for the
test. You can use any host in the DNS table.
*** can’t find the server name for address (the address of
configured DNS server) no existence domain
*** Default server are unavailable.

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.

Real terminal Local Host Remote Host


TELNET
TELNET SERVER
CLIENT

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.

Ans. You can implement synchronization for many cases


through t5he uses of system calls. One example of
implementing mutual exclusion is the centralized approach.
In this approach, some process of chosen to coordinate the

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.

After creating the database you must perform the following


tasks:
(i) Design a report to display the daily, monthly and annual
income of each motion picture. Also, show the profit/loss
statistics.

(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.

Ans. The entities and relationship of the system are:-


COMPANY (C_name, C_address)
WORK (W_name, W_department)
Motion Picture (Films, TV serial, Documentation)
EMPLOYEE (Name, E_id, E_add)
STUDIO (S_owner, address, contact, banner)

ER- Diagram with Aggregation:

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

PRODUCTION COMPANY EMPLO PRODUCER AD


Y D
P_I
DOCUMEN SERIA D
T L FIL
HA M
S DIRECTOR CHEC
AD K
D

F_I
D
STAFF CONDUCTO FILM
R F_NAM
E
F_ADD
S_I S_NAM
D E

F/G : E.R DIAGRAM FOT Apex Entertainment

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

You might also like