Beruflich Dokumente
Kultur Dokumente
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 Pre (root left); Pre (root right); } Void in (node * root) { Int (root left); Print (%d/ t, root Int (root right); } } Void post (node * root) { If (root) { Post (root left);
info);
info);
Post (root right); Printf(%d \ t, root infor); } } Void travin order (node * root) { Node * p = root; Stk . top = -1; While (( p 1= null) 111 { If (P1 = null) { Push (p); P=p left; } Else { P = pop ( );
6
(stk
top
-1))
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 { 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
right = null))
{ 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. *** cant 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
TELNET CLIENT
Remote Host
TELNET SERVER
VERTICAL TERMINAL
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 dont 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 members like actors, directors, assistants, coproducers 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
RELATION SHIP
ACTOR
GENERALIZATION
ADD
NAME DATE
PERSON
IS-A
IS-A
DIRECTOR
D-ID
PRODUCER
P-ID
14
P_NAME P_ID
P_COMPANY
IS-A
F-NAME F-ID
IS-A
S-NAME S-ID
FILM
SERIAL
PRODUCTION COMPANY
PRODUCER
ADD P_ID
DOCUMENT
HAS
CHECK
FILM F_ADD
F_NAME
S_ID
S_NAME
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