MCSL-025 ASSIGNMENT SOLUTION (2018-19)

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


PART-1 : MCS-021

Question 1 :

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

Answer : -

#include<stdio.h>
void main()
{
int *a, *b, *c, n, i, j, k;
printf("\n Enter the number of Row / Column present in the Matrix : ");
scanf("%d",&n);
n--;
// Input First Matrix
printf("\n Enter the Element of First Matrix");
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
{
printf("\n Enter the value of A[%d][%d] : ",i,j);
scanf("%d",(a+i+(i*n)+j));
}
}
// Input Second Matrix
printf("\n Enter the Element of Second Matrix");
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
{
printf("\n Enter the value of B[%d][%d] : ",i,j);
scanf("%d",(b+i+(i*n)+j));
}
}
// Matrix Multiplication
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
{
for(k=0;k<=n;k++)
{
*(c+i+(i*n)+j)=*(c+i+(i*n)+j) + ((*(a+i+(i*n)+k)) * (*(b+k+(k*n)+j)));
}
}
}
// Output Matrix
for(i=0;i<=n;i++)
{
printf("\n");
for(j=0;j<=n;j++)
{
printf("\t%d",*(c+i+(i*n)+j));
}
}
}

Output

Enter the number of Row / Column present in the Matrix : 2

Enter the Element of First Matrix
Enter the value of A[0][0] : 5

Enter the value of A[0][1] : 2

Enter the value of A[1][0] : 1

Enter the value of A[1][1] : 3

Enter the Element of Second Matrix
Enter the value of B[0][0] : 6

Enter the value of B[0][1] : 1

Enter the value of B[1][0] : 4

Enter the value of B[1][1] : 9

3823
1828




Question 2 :

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

Answer : -

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

/* Global Function Declaration */
void DFS();

/* 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("\n 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);
DFS();

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

/* DFS( ) function begins */
void DFS()
{
int temp[25];
int pos,z;
discover_top++;
discovered[discover_top]=v;
for(z=1; z<=number_of_vertices; z++)
{
printf("\n\n Step %d",z);
/* Print Discover List */
printf("\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 new discover vertex */
pos=0;
for(i=0; i<number_of_edges; i++)
{
if(edges[i][0] == discovered[discover_top])
{
temp[pos]=edges[i][1];
pos++;
}
if(edges[i][1] == discovered[discover_top])
{
temp[pos]=edges[i][0];
pos++;
}
}

/* 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 are connected with the last discover vertex are already discovered or visited. */
/* So the last discovered vertex is removed from the discovered array and add into the visited array. */
if(pos == 0)
{
visited_top++;
visited[visited_top]=discovered[discover_top];
discover_top--;
}

/* else find the lowest weighted vertex and add to it discovered array */
else
{
v=temp[0];
for(i=1; i<pos; i++)
{
if(v > temp[i])
{
v=temp[i];
}
}
discover_top++;
discovered[discover_top]=v;
}
}
/* After discover all the vertices add those vertices into visited array in decending order. */
while(discover_top != -1)
{
visited_top++;
visited[visited_top]=discovered[discover_top];
discover_top--;
}
}

Output

Enter number of vertices : 8

Enter number of vertices : 10

Enter an edge (u,v) : 4 1

Enter an edge (u,v) : 1 2

Enter an edge (u,v) : 1 3

Enter an edge (u,v) : 2 5

Enter an edge (u,v) : 2 6

Enter an edge (u,v) : 3 7

Enter an edge (u,v) : 3 8

Enter an edge (u,v) : 6 7

Enter an edge (u,v) : 7 8

Enter an edge (u,v) : 8 4

Enter the start vertex : 4

Step 1
Discover List :4
Visited List :

Step 2
Discover List :41
Visited List :

Step 3
Discover List :412
Visited List :

Step 4
Discover List :4125
Visited List :

Step 5
Discover List :412
Visited List :   5

Step 6
Discover List :4126
Visited List :   5

Step 7
Discover List :41267
Visited List :   5

Step 8
Discover List :412673
Visited List :   5


Final Visited List : 58376214

I use the following Graph for DFS output






PART-2 : MCS-022

Question 1 :

Write a shell script in Linux/Unix that accepts a text file as input and prints the number of words in the file which do not have a vowel.

Answer : -

echo "Enter the file name : "
read file
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 vowel or not
case $ch in
# increase the value of "vowel" until a space found
A|a|E|e|I|i|O|o|U|u) vowel=`expr $vowel + 1` ;;
esac

# Chech whether the picked character is a space or not
if [ "$ch" == " " -o $i -eq $len ]
then
# If the value of "vowel" is equal to 0 then print the word
if [ $vowel -eq 0 ]
then
word=`echo $line | cut -c$start-$i`
echo "$word"
else
vowel=0
fi
start=`expr $i + 1`
fi
done
done < $file



Question 2 :

Your PC is on a network. Make necessary settings in your PC so that one of the folders in any drive is always shared with Public

Answer : -

Step 1 - Make sure the PCs are in the same homegroup or workgroup and that each PC has a unique name.

To change the PC name or workgroup - Go to Control Panel → System and then click on Change Settings option.

In System Properties dialog box, under Computer Name tab, click on Change... button.

After clicking on Change... button a Computer Name/Domain Changes dialog box will be appear. Here you can enter your new Computer name and Workgroup.

Step 2 - Make sure you’ve turned on sharing for the network you’re connected to. You’ll need to do this on each PC that you want to use for sharing items.

To turn sharing on - Go to Control Panel → Network and Sharing Center and then click on Change advanced sharing settings option.

In Advanced sharing settings page, turn on the following features -

  • Turn on network discovery
  • Turn on file and printer sharing
  • Turn on sharing so anyone with network access can read and write files in the Public folder
  • Turn off password protection sharing

Step 3 - Right-click on the folder you want to share.

Click Properties. In the Sharing tab, click Advanced Sharing.

Click Share this folder

In the appropriate fields, type the name of the share (as it appears to other computers), the maximum number of simultaneous users, and any comments that should appear beside it.

Click Permissions button and give the full permission to Everyone and then click Ok.

In the Security tab click on Advanced button

Click Add button. Add Everyone with full control and then click Ok






PART-3 : MCS-023

Question 1 :

Create a database consisting of Name of University, Number of affiliated Colleges, Total number of Programmes offered, Total number of students enrolled. After creating the database, perform the following tasks :

i) List the names of those Universities which are having total number of more than 100 affiliated colleges

Answer : -

Table Name : University
Field NameField TypeDescription
university_namevarchar(100)Name of the University
total_collegesintTotal number of affiliated Colleges present under the University
total_programmesintTotal number of Programmes offered by the University
total_studentsintTotal number of students enrolled under the University

CREATE TABLE University
(university_nameVARCHAR(100),
total_collegesINT,
total_programmesINT,
total_studentsINT,
PRIMARY KEY (university_name));


SELECT university_name FROM University WHERE total_colleges > 100;






PART-4 : MCS-024

Question 1 :

Write a program in Java for the 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);
}
}



Question 2 :

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

Answer : -

import java.io.*;
import java.sql.*;
public class Univercity
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
// Input programme name from the user
System.out.println("Enter the programme name ...");
String pname=br.readLine();
// SQL query for search Universities for the given programme
String SQL="SELECT university_name FROM university_details WHERE programme_name="+pname+"'";
String url="jdbc:mysql://localhost:3306/University";
String user="Admin";
String password="Admin1234";
int count=0;
try
{
// Connect to the database and retrieve data for the above query
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(SQL);
while(rs.next())
{
System.out.println(rs.getString("university_name"));
count++;
}
con.close();
if(count == 0)
System.out.println("University not found");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


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


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us