MCSL-025 ASSIGNMENT SOLUTION (2019-20)

If you have any queries please leave a message here
Your Message
×


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.

Answer : -

#include<stdio.h>
#include<stdlib.h>

//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<number_of_edges; i++)
{
printf("Enter an edge (u,v) : ");
scanf("%d%d",&edges[i][0],&edges[i][1]);
}
// Input the vertex from where searching process is start
printf("\n Enter the start vertex : ");
scanf("%d",&v);
BFS();
printf("\n\n\n Final Visited List : ");
for(i=0; i<=visited_top; i++)
printf("\t%d",visited[i]);
}

// BFS( ) function begins
void BFS()
{
int temp[25];
int pos,z;
discover_top++;
discovered[discover_top]=v;
printf("\n\n\n Discovered List : \n");
printf("\t%d",v);
for(z=1; z<=number_of_vertices; z++)
{
// Print Discover List
printf("\n\n Discover List : ");
for(i=0;i<=discover_top;i++)
{
printf("\t%d",discovered[i]);
}

// Print Visited List
printf("\n Visited List : ");
for(i=0;i<=visited_top;i++)
{
printf("\t%d",visited[i]);
}

// Find the vertices which connected with the discover vertex
pos=0;
for(i=0; i<number_of_edges; i++)
{
if(edges[i][0] == discovered[0])
{
temp[pos]=edges[i][1];
pos++;
}
}

visited_top++;
visited[visited_top]=discovered[0];
for(i=1;i<=discover_top;i++)
{
discovered[i-1]=discovered[i];
}
discover_top--;

// Check whether the vertices which connected with the new discover vertex are already discover or not
for(i=0; i<=discover_top; i++)
{
for(j=0;j<pos;j++)
{
if(discovered[i] == temp[j])
{
for(k=j; k<pos-1; k++)
temp[k]=temp[k+1];
pos--;
}
}
}

// Check whether the vertices which connected with the new discover vertex are already visited or not
for(i=0; i<=visited_top; i++)
{
for(j=0;j<pos;j++)
{
if(visited[i] == temp[j])
{
for(k=j; k<pos-1; k++)
temp[k]=temp[k+1];
pos--;
}
}
}

// pos > 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<pos;i++)
{
for(j=1;j<=pos-i;j++)
{
if(temp[j-1] > 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<pos;i++)
{
discover_top++;
discovered[discover_top]=temp[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

Answer : -

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

Answer : -

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_nameVARCHAR(100),
total_branchINT,
total_specialitiesINT,
total_visitorINT,
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

Answer : -

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
Addition Reasult
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.

Answer : -

import java.io.*;
import java.sql.*;
public class SpecialityReport
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String SQL = "";
String url = "jdbc:mysql://localhost:3306/hospital";
String user = "Admin";
String password = "Admin1234";
try
{
// Connect to the MySQL Database
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(url,user,password);
// Print the List of Speciality present in the Database
SQL = "SELECT speciality FROM hospital_offers";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
int index = 1;
System.out.println("List of Speciality");
while(rs.next())
{
System.out.println(index + ". " + rs.getString("speciality"));
index++;
}
System.out.println();
// Input Speciality to view Hospital details
System.out.println("Enter the Speciality to view Hospital details :");
String str = br.readLine();
// Find Hospital Name and Address based on input
SQL = "SELECT * FROM hospital_offers WHERE speciality='" + str + "'";
rs = stmt.executeQuery(SQL);
int count = 0;
if(rs.next())
{
System.out.println(rs.getString("hospital_name"));
System.out.println(rs.getString("address"));
count = 1;
}
if(count == 0)
System.out.println("Record Not Found");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Output
List of Speciality
1. Heart
2. Kidney
3. Liver
4. Lungs

Enter the Speciality to view Hospital details :
Kidney
Fortis Hospital and kidney Institute
111A, Rash Behari Avenue, Gariahat, Kolkata, West Bengal 700029



ABOUT US

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


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us