MCSL-025 ASSIGNMENT SOLUTION (2019-20)

PART-1 : MCS-021

Q1. Write a program in C language for multiplication of two sparse matrices using Pointers.

Answer : - Solve it Yourself

Q2. Write a program in C language that will accept a Graph as input and will perform a Breadth First Search on it. Make necessary assumptions.

 #include #include //Global Function Declaration void BFS(); // Global Variable Declaration int number_of_vertices, number_of_edges, discover_top=-1, visited_top=-1, v, i, j, k; int edges[25][2], discovered[25], visited[25]; // main( ) function begins void main() { // Input number of vertices present in the graph printf("\n Enter number of vertices : "); scanf("%d",&number_of_vertices); // Input number of edges present in the graph printf("\n Enter number of edges : "); scanf("%d",&number_of_edges); for(i=0; i 0 means that the vertices present in the temp[ ] array are not discovered or visited if(pos > 0) { // Sort the temp[ ] array using Bubble Sort for(i=1;i temp[j]) { v=temp[j-1]; temp[j-1]=temp[j]; temp[j]=v; } } } // Put all the vertices present in the temp[ ] array into discovered[ ] array for(i=0;i

 Output Enter number of vertices : 8 Enter number of edges : 11 Enter an edge (u,v) : 4 3 Enter an edge (u,v) : 4 8 Enter an edge (u,v) : 3 8 Enter an edge (u,v) : 3 1 Enter an edge (u,v) : 3 7 Enter an edge (u,v) : 8 7 Enter an edge (u,v) : 1 7 Enter an edge (u,v) : 1 6 Enter an edge (u,v) : 1 9 Enter an edge (u,v) : 7 2 Enter an edge (u,v) : 6 9 Enter the start vertex : 4 Discover List : 4 Visited List : Discover List : 3     8 Visited List : 4 Discover List : 8     1     7 Visited List : 4     3 Discover List : 1     7 Visited List : 4     3     8 Discover List : 7     6     9 Visited List : 4     3     8     1 Discover List : 6     9     2 Visited List : 4     3     8     1     7 Discover List : 9     2 Visited List : 4   3     8     1     7     6 Discover List : 2 Visited List : 4     3     8     1     7     6     9 Final Visited List : 4     3     8     1     7     6     9     2

I use the following Graph for DFS output

PART-2 : MCS-022

Q1. Write a shell script in Linux/Unix that accepts a text file as input and prints the number of words that start with character B

 echo "Enter the file name : " read file # Check whether the inputed file is present or not if test -f \$file then count=0 while read line do # Pick each line from the given file line=`echo \${line}` # Calculate the length of each line pick from the file len=\${#line} vowel=0 start=1 for((i=1;i<=len;i++)) do # Pick each character from the line ch=`echo \$line | cut -c\$i` # Chech whether the picked character is a space or not if [ "\$ch" == " " -o \$i -eq \$len ] then word=`echo \$line | cut -c\$start-\$i` # Picked the first character of the word picked from the line letter=`echo \$word | cut -c1` # Check whether the first character of the word is B or not case \$letter in B) count=`expr \$count + 1` ;; esac # Identify and store the starting position of the next word in the line start=`expr \$i + 1` fi done done < \$file echo "Number of Words that start with Character B = \$count" else echo "File Not Found" fi Output Enter the file name : /shell/Test.txt Number of Words that start with Character B = 4

Q2. Your PC is on a network. Make necessary settings in your PC so that none of the folders are shared with Public.

Answer : - Solve it Yourself

PART-3 : MCS-023

Q1. Create a database consisting of Name of Hospital, Number of Branches, Total number of Clinical Specialities offered, Total Number of Visitors every day on average After creating the database, perform the following tasks:

List the names of those Hospitals which are having at least 200 Visitors per day

Table Name : list_of_hospital
Field NameField TypeDescription
hospital_namevarchar(100)Name of the Hospital
total_branchintTotal number of Branch present of that Hospital
total_specialitiesintTotal number of Clinical Specialities offered by the Hospital
total_visitorintPer day average Visitors of that Hospital

Create Database
CREATE DATABASE hospital;

Create Table
CREATE TABLE list_of_hospital
 (hospital_name VARCHAR(100), total_branch INT, total_specialities INT, total_visitor INT, PRIMARY KEY (hospital_name));

SQL Query
SELECT hospital_name FROM list_of_hospital WHERE total_visitor >= 200;

PART-4 : MCS-024

Q1. Write a program in Java for addition of two sparse matrices

 public class sparse_matrix { int data[][] = new int[100][3]; int row, col, len; public sparse_matrix(int r, int c) { row = r; col = c; len = 0; } // insert elements into sparse matrix public void insert(int r, int c, int val) { if (r > row || c > col) { System.out.println("Wrong Entry"); } else { // insert row value data[len][0] = r; // insert col value data[len][1] = c; // insert element's value data[len][2] = val; // increment number of data in matrix len++; } } public void add(sparse_matrix b) { // if matrices don't have same dimensions if (row != b.row || col != b.col) { System.out.println("Matrices can't be added"); } else { int apos = 0, bpos = 0; sparse_matrix result = new sparse_matrix(row, col); while (apos < len && bpos < b.len) { // if b's row and col is smaller if(data[apos][0] > b.data[bpos][0] || (data[apos][0] == b.data[bpos][0] && data[apos][1] > b.data[bpos][1])) { // insert smaller value into result result.insert(b.data[bpos][0], b.data[bpos][1], b.data[bpos][2]); bpos++; } // if a's row and col is smaller else if(data[apos][0] < b.data[bpos][0] || (data[apos][0] == b.data[bpos][0] && data[apos][1] < b.data[bpos][1])) { // insert smaller value into result result.insert(data[apos][0], data[apos][1], data[apos][2]); apos++; } else { // add the values as row and col is same int value = data[apos][2] + b.data[bpos][2]; if (value != 0) result.insert(data[apos][0], data[apos][1], value); apos++; bpos++; } } // insert remaining elements while (apos < len) result.insert(data[apos][0], data[apos][1], data[apos++][2]); while (bpos < b.len) result.insert(b.data[bpos][0], b.data[bpos][1], b.data[bpos++][2]); result.print(); } } // printing matrix public void print() { System.out.println("Addition Reasult"); for (int i=0; i { System.out.println(data[i][0] + " " + data[i][1] + " " + data[i][2]); } } public static void main(String args[]) { // Create two sparse matrices and insert values sparse_matrix a = new sparse_matrix(4, 4); sparse_matrix b = new sparse_matrix(4, 4); a.insert(1, 2, 10); a.insert(1, 4, 12); a.insert(3, 3, 5); a.insert(4, 1, 15); a.insert(4, 2, 12); b.insert(1, 3, 8); b.insert(2, 4, 23); b.insert(3, 3, 9); b.insert(4, 1, 20); b.insert(4, 2, 25); a.add(b); } }

Output
1   2   10
1   3   8
1   4   12
2   4   23
3   3   14
4   1   35
4   2   37

Q2. Write a program in Java that connects to a database and generates a report that consists of the list of names of Hospitals which are offering a particular speciality. Input to the Java program will be Speciality. Make assumptions wherever necessary.

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.

MORE TOPIC

WHAT WE DO