You are on page 1of 34

Course Code Course Title Assignment Number Maximum Marks Weightage Last Date of Submission

: : : : :
:

MCSL-025 Lab Course MCA (2)/025/Assign/11 100 25%


15th October, 2011 (for July, 2011 session) 15th April, 2012 (for January, 2012 session)

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: Write a program in C to determine if two binary trees are similar. Remember two Binary trees are similar if they are both empty or if they are both non-empty and left and right subtrees are similar. (6 Marks) Solution: Algorithm: sameTree(tree1, tree2) 1. If both trees are empty then return 1. 2. Else If both trees are non -empty (a) Check data of the root nodes (tree1->data == tree2->data) (b) Check left subtrees recursively i.e., call sameTree( tree1->left_subtree, tree2->left_subtree) (c) Check right subtrees recursively i.e., call sameTree( tree1->right_subtree, tree2->right_subtree) (d) If a,b and c are true then return 1. 3 Else return 0 (one is empty and other is not) Program :
#include <stdio.h> #include <stdlib.h> /* A binary tree node has data, pointer to left child and a pointer to right child */ struct node { int data; struct node* left; struct node* right; }; /* Helper function that allocates a new node with the given data and NULL left and right pointers. */ struct node* newNode(int data) {
1|P age

struct node* node = (struct node*) malloc(sizeof(struct node)); node->data = data; node->left = NULL; node->right = NULL; return(node); } /* Given two trees, return true if they are structurally identical */ int identicalTrees(struct node* a, struct node* b) { /*1. both empty */ if (a==NULL && b==NULL) return 1; /* 2. both non-empty -> compare them */ else if (a!=NULL && b!=NULL) { return ( a->data == b->data && identicalTrees(a->left, b->left) && identicalTrees(a->right, b->right) ); } /* 3. one empty, one not -> false */ else return 0; } /* Driver program to test identicalTrees function*/ int main() { struct node *root1 = newNode(1); struct node *root2 = newNode(1); root1->left = newNode(2); root1->right = newNode(3); root1->left->left = newNode(4); root1->left->right = newNode(5); root2->left = newNode(2); root2->right = newNode(3); root2->left->left = newNode(4); root2->left->right = newNode(5); if(identicalTrees(root1, root2)) printf("Both tree are identical."); else printf("Trees are not identical."); getchar(); return 0; }

2|P age

Question 2: Write a program in C function, which takes the value of a pointer to the root of the tree, then computes and prints the height of the tree and a path of that length (the height of a tree is the length of the longest path in the tree from root to any leaf). (4 Marks) Solution: /* Compute the "maxDepth" of a tree -- the number of nodes along the longest path from the root node down to the farthest leaf node. */ int maxDepth(struct node* node) { if (node==NULL) { return(0); } else { // compute the depth of each subtree int lDepth = maxDepth(node->left); int rDepth = maxDepth(node->right); // use the larger one if (lDepth > rDepth) return(lDepth+1); else return(rDepth+1); } }

3|P age

PART-II: MCS-022 Question 1: (i) Write a shell script that prints a sorted list of files in the user directory that contain a user specified word inside them. User need to specify the file extension of files to be searched and the word need to be searched. (3 Marks)

Solution: Command : Examples

$ find . | xargs grep 'string' sl

For example search for a string called redeem reward in all text files located in /home/tom/*.txt directory, use $ grep "redeem reward" /home/tom/*.txt Task: Search all subdirectories recursively You can search for a text string all files under each directory, recursively with -roption: $ grep -r "redeem reward" /home/tom Task: Only print filenames By default, grep command prints the matching lines You can pass -H option to print the filename for each match. $ grep -H -r redeem reward /home/tom Output: ... filename.txt: redeem reward ... To just print the filename use cut command as follows: $ grep -H vivek /etc/* -R | cut -d: -f1 Output: ... filename.txt ... (ii) What is the output of ls-lm and ls-ml? Which option takes procedure? What is the result of ls-d? (3 Marks) Solution: $ ls lm ak1.php, ak2.java, ak3.sql, ak4.txt, command.txt, file1, file2.txt, file3.sql, file4.php, ls_lm.txt, ls_ml.txt, touch

$ ls -ml total 20 -rw-rw-r--. 1 anupam anupam 40 Aug 19 16:12 ak1.php


4|P age

-rw-rw-r--. 1 anupam anupam 109 Aug 19 16:15 ak2.java -rw-rw-r--. 1 anupam anupam 0 Aug 19 16:11 ak3.sql -rw-rw-r--. 1 anupam anupam 0 Aug 19 16:11 ak4.txt -rw-rw-r--. 1 anupam anupam 96 Aug 19 16:25 command.txt -rw-rw-r--. 1 anupam anupam 0 Aug 19 16:11 file1 -rw-rw-r--. 1 anupam anupam 47 Aug 19 16:13 file2.txt -rw-rw-r--. 1 anupam anupam 0 Aug 19 16:11 file3.sql -rw-rw-r--. 1 anupam anupam 0 Aug 19 16:11 file4.php -rw-rw-r--. 1 anupam anupam 0 Aug 19 16:43 ls_ml.txt -rw-rw-r--. 1 anupam anupam 12 Aug 19 16:24 touch $ ls -d ls -d merely lists the entry for the directory, or '.' Question 2: Install and Configure the DHCP Server services. Configure Windows 2000 Client to use DHCP, DNS, and WINS services. Solution: Install and Configure the DHCP Server Service

(4 Marks)

5|P age

6|P age

Click the This Server radio button and click OK. If you have other servers in your network that you wish to configure, click the Browse button and select another server.

v
7|P age

Figure 2: Selecting the server Now that you have allocated the server which will act as the DHCP server, click the server name and then select Action followed by New Scope.

8|P age

9|P age

10 | P a g e

11 | P a g e

12 | P a g e

13 | P a g e

14 | P a g e

15 | P a g e

16 | P a g e

17 | P a g e

18 | P a g e

19 | P a g e

20 | P a g e

21 | P a g e

Configure Windows 2000 Client to use DHCP, DNS, and WINS services.
There are two paths to the Windows 2000 Professional TCP/IP configuration panel. Choose the access method that you prefer: Click Start -> Control Panel -> Network and Dial-up Connections. Alternatively, click Start, then right-click My Network Places, and select Properties. The following procedure steps through the Windows XP Professional TCP/IP configuration process: 1. Right-click on Local Area Connection, then click Properties.

Figure 8.6. Local Area Connection Properties. 2. The Local Area Connection Properties is used to set TCP/IP protocol settings. Click on Internet Protocol (TCP/IP) in the Components checked are used by this connection: box, then click the Properties button. 3. The default setting is DHCP-enabled operation (i.e., Obtain an IP address automatically).

Figure 8.7. Internet Protocol (TCP/IP) Properties.

22 | P a g e

Many network administrators will want to use DHCP to configure all client TCP/IP protocol stack settings. (For information on how to configure the ISC DHCP server for Windows client support, see, DHCP Server). If it is necessary to provide a fixed IP address, click on Use the following IP address and enter the IP Address, the subnet mask, and the default gateway address in the boxes provided. For this example we are assuming that all network clients will be configured using DHCP. 4. Click the Advanced button to proceed with TCP/IP configuration. Refer to Advanced Network Settings.. Figure 8.8. Advanced Network Settings.

Fixed settings may be required for DNS and WINS if these settings are not provided automatically via DHCP. 5. Click the DNS tab to add DNS server settings. The example system uses manually configured DNS settings. When finished making changes, click OK to commit the settings. See DNS Configuration.. Figure 8.9. DNS Configuration.

23 | P a g e

6. Click the WINS tab to add manual WINS server entries. This step demonstrates an example system that uses manually configured WINS settings. When finished making changes, click OK to commit the settings. See WINS Configuration.. Figure 8.10. WINS Configuration.

Domain Logon Configuration


1. Right-click on the Network Neighborhood icon. 2. The Network Configuration Panel allows all common network settings to be changed. See The Network Panel.. Figure 8.20. The Network Panel.

Make sure that the Client for Microsoft Networks driver is installed as shown. Click on the Client for Microsoft Networks entry in The following network components are installed: box. Then click the Properties button. 3. The Client for Microsoft Networks Properties panel is the correct location to configure network logon settings. See Client for Microsoft Networks Properties Panel..

24 | P a g e

Figure 8.21. Client for Microsoft Networks Properties Panel.

Enter the Windows NT domain name, check the Log on to Windows NT domain box, and click OK. 4. Click on the Identification button. This is the location at which the workgroup (domain) name and the machine name (computer name) need to be set. See Identification Panel.. Figure 8.22. Identification Panel.

5. Now click the Access Control button. If you want to be able to assign share access permissions using domain user and group accounts, it is necessary to enable User-level access control as shown in this panel. See Access Control Panel.. Figure 8.23. Access Control Panel.

25 | P a g e

26 | P a g e

PART-III: MCS-023

Question 1: Consider the following relations and database details. Where, the regno and phone_no identify the doctor and the patient uniquely respectively. DOCTOR (regno, name, telno, city, age) DEPARTMENT (dept_name, head-doctor regno, no. of Doctors) PATIENT (pname, street, city, phone_no, age) VISIT (pname, phone_no, regno, date_of_visit, fee) After creating the database you must perform the following tasks: (i) Get the name and regno of physicians who are in Delhi. (ii) Find the name and city of patient(s) who visited a doctor with regno 675374 on 31st January 2010. (iii) Get the name of the doctors along with the total number of patients those have visited them in the month of June 2011.
(iv) (v) Find out number of department name and its head-doctor name in which maximum number of patients had visited in year 2010. Produce a report of doctors who are going to retire within 6 months. ( Note: Age of retirement is 65 years for doctors) (10 arks)

create table DOCTOR( regno varchar(16) primary key, name varchar(16), telno varchar(10), city varchar(10), age varchar(2));

create table PATIENT( pname varchar(16), street varchar(16), city varchar(10), phone_no varchar(10)primary key, age varchar(2)); create table DEPARTMENT( dept_name varchar(16), head_doctor_regno varchar(16)references DOCTOR, no_of_Doctors number(2)); create table VISIT( pname varchar(16), phone_no varchar(16)references PATIENT, regno varchar(16)references DOCTOR, date_of_visit varchar(16), fee number(5,2));

27 | P a g e

//data insertion insert into DOCTOR(regno,name,telno,city,age)values('1','A.A.Farooqui','9835111111','hazaribag','50 '); insert into DOCTOR(regno,name,telno,city,age)values('2','A.Ekram','9835122222','new delhi','49'); insert into DOCTOR(regno,name,telno,city,age)values('3','S.Samanta','9835133333','new delhi','40'); insert into DOCTOR(regno,name,telno,city,age)values('4','L.Jain','9976856452','Kolkata','60'); insert into DOCTOR(regno,name,telno,city,age)values('675374','D.N.Jain','9999878834','delhi','56'); insert into DOCTOR(regno,name,telno,city,age)values('675343','David Hopkins','9999875534','delhi','65');

insert into PATIENT(pname,street,city,phone_no,age)values('Sameer Arya','New Street,42a','mumbai','9431140003','25'); insert into PATIENT(pname,street,city,phone_no,age)values('Manish Tiwary','94, gandhi road','kolkata','9941141232','36'); insert into PATIENT(pname,street,city,phone_no,age)values('Amit Kumar Sinha','main road','ranchi','8002467788','15'); insert into PATIENT(pname,street,city,phone_no,age)values('Naveen Patnaik','Kalinga Marg','Puri','7676389863','67'); insert into PATIENT(pname,street,city,phone_no,age)values('Kalpesh Gandhi','31,Temple Road','Jamnagar','7999347683','50');

insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Sameer Arya','9431140003','1','01/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Sameer Arya','9431140003','2','05/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Sameer Arya','9431140003','2','11/07/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Sameer Arya','9431140003','3','01/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Sameer Arya','9431140003','4','01/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Manish Tiwary','9941141232','1','15/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Amit Kumar Sinha','8002467788','2','11/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Naveen Patnaik','7676389863','3','21/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Kalpesh Gandhi','7999347683','4','10/06/2011',150.00);

28 | P a g e

insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Sameer Arya','9431140003','675374','01/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Manish Tiwary','9941141232','675374','15/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Amit Kumar Sinha','8002467788','675374','11/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Naveen Patnaik','7676389863','675374','21/06/2011',150.00); insert into VISIT(pname,phone_no,regno,date_of_visit,fee)values('Kalpesh Gandhi','7999347683','675374','10/06/2011',150.00);

insert into department(dept_name, head_doctor_regno, no_of_doctors) values ('Medicine', '1', 1); insert into department(dept_name, head_doctor_regno, no_of_doctors) values ('Surgery', '675374', 2); insert into department(dept_name, 'Opthalmology', '4', 2); head_doctor_regno, no_of_doctors) values (

(i) Sol:

Get the name and regno of physicians who are in Delhi. select name, regno from doctor where city in('Delhi');

(iii)

Find the name and city of patient(s) who visited a doctor with regno 675374 on st 31 January 2010.
select pname, city from patient where phone_no in(select phone_no from visit where regno='675374');

Sol:

(iv)

Get the name of the doctors along with the total number of patients those have visited them in the month of June 2011. select doctor.name,visit.count(pname) where visit.regno in(select regno from visit where date_of_visit like%/06/2011);
Find out number of department name and its head-doctor name in which maximum number of patients had visited in year 2010. select dept_name, head_doctor_regno from department where no_of_doctors in(select regno from doctor where regno=select max(count(regno))from visits);

Sol:

(v)

Sol:

Ans5: Produce a report of doctors who are going to retire within 6 months. ( Note: Age of

retirement is 65 years for doctors)

Sol:

select * from doctors where age>64;

29 | P a g e

PART-IV: MCS-024 Question 1:

Write a method in Java that reads and validates a matrix of size n x n, where n is passed as an argument to the method. A matrix is valid if and only if all diagonal entries are positive and all non diagonal entries are negative or zero. The program should print the message The matrix is valid if it is valid and if not print the message The matrix is invalid.
(5 Marks)

Ans:
/* Write a method in Java that reads and validates a matrix of size n x n, where n is passed as an argument to the method. A matrix is valid if and only if all diagonal entries are positive and all non diagonal entries are negative or zero. The program should print the message "The matrix is valid" if it is valid and if not print the message "The matrix is invalid". */ import java.lang.*; import java.io.*;

public class matrixValidator { public static void Validate(int n) { int mat[][]; mat=new int[n][n]; int i,j,diagValid=0,ndiagValid=0; //Entering Values in matrix for(i=0;i<mat.length;i++) { for(j=0;j<mat.length;j++) { if(i==j) { mat[i][j]=i+1;//Put a Positive value in Diagonal // mat[i][j]=i; //would Give Invalid Matrix } else { mat[i][j]=-j; //Put 0 or Negative Value in Non Diagonal //mat[i][j]=j; //would Give Invalid Matrix } } } //Printing The Matrix for(i=0;i<n;i++) { for(j=0;j<n;j++) { System.out.print(mat[i][j]+"\t"); }

30 | P a g e

System.out.println(); } //Validating Matrix for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i==j) { if(mat[i][j]>0) { diagValid++; //Flag Variable for Diagonal } } else { if(mat[i][j]<=0) { ndiagValid++; //Flag Variable for Non Diagonal } } } } //Printing Result of Validation if(diagValid==n && ndiagValid==((n-1)*n)) { System.out.println("The Matrix is Valid"); } else { System.out.println("The Matrix is Invalid"); } }

//---------------------------------------------------------public static void main(String args[]) { int n=5; Validate(n); //Call Validate() method } } //--------------------------------------------End of Program-------------------------------------------------------------

31 | P a g e

Question 2: Design a class employee of an organisation. An employee has a name, empid, and salary. Write the default constructor, a constructor with parameters (name, empid, and salary) and methods to return name and salary. Also write a method increasesalary that raises the employees salary by a certain user specified percentage. Derive a subclass Manager from employee. Add an instance variable named department to the manager class. Supply a test program that uses theses classes and methods.
(5 Marks) Note: You must execute the program and submit the program logic, sample inputs and outputs along with the necessary documentation for this question. Assumptions can be made wherever necessary.
Ans: // Program Starts import java.lang.*; import java.io.*; class employee{ //Variables String name; int empid; float salary; //Default Constructor employee() { name=null; empid=0; salary=0; } //Parameterized Constructor employee(String name1,int empid1,float salary1) { name=name1; empid=empid1; salary=salary1; } //Method to return Name public String getName() { return name; } //Method.to return Salary public float getSalary() { return salary; } //Method to Increase Salary by percent public int increasesalary(float increment) { 32 | P a g e

salary+=salary*increment*0.01; return 1; } } //Subclass Manager Derived from employee class manager extends employee{ String department; //Default Constructor manager() { super(); department=null; } //Parameterized Constructor manager(String name1,int empid1,float salary1,String department1) { super(name1,empid1,salary1); //Call to Base Class Constructor department=department1; } }

public class employeeProg{ public static void main(String[] args) { employee e1=new employee(); employee e2=new employee("Christine",51,65000); System.out.println("First Employee : Name : " + e1.getName() +", Salary = "+ e1.getSalary()); System.out.println(); System.out.println("Second Employee : Name : " + e2.getName() +", Salary = "+ e2.getSalary()); System.out.println(); //Increment Salary of e2 by 10% int res=e2.increasesalary(10); if(res==1) { System.out.println("Salary Incremented by 10% New Salary is :"); System.out.println("Second Employee : Name : " + e2.getName() +", Salary = "+ e2.getSalary()); System.out.println(); } else { System.out.println("Salary Increment by 10% Failed Current Salary is :"); System.out.println("Second Employee : Name : " + e2.getName() +", Salary = "+ e2.getSalary()); System.out.println();

33 | P a g e

} //Manager Class manager m1=new manager("Jacobs Robert",21,90000,"Sales"); System.out.println("Managers: Name : " + m1.getName() +", Salary = "+ m1.getSalary()+", Department :"+m1.department); System.out.println();

} } //End of Program Output:

34 | P a g e

You might also like