MCSL-025 ASSIGNMENT SOLUTION (2018-19)

PART-1 : MCS-021

Question 1 :

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

 #include 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.

 #include #include /* 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 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.

 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

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

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_name VARCHAR(100), total_colleges INT, total_programmes INT, total_students INT, 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.

 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.

 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(); } } }

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