Q1: Write A Program in C Language For Addition of Two Polynomials Using Pointers
Q1: Write A Program in C Language For Addition of Two Polynomials Using Pointers
Q1: Write a program in C language for addition of two polynomials using Pointers.
ANS
return sum;
}
// Driver code
public static void Main()
{
// The following array represents
// polynomial 5 + 10x^2 + 6x^3
int[] A = {5, 0, 10, 6};
// The following array represents
// polynomial 1 + 2x + 4x^2
int[] B = {1, 2, 4};
int m = A.Length;
int n = B.Length;
Console.WriteLine("First polynomial is");
printPoly(A, m);
Console.WriteLine("\nSecond polynomial is");
printPoly(B, n);
int[] sum = add(A, B, m, n);
int size = max(m, n);
Console.WriteLine("\nsum polynomial is");
printPoly(sum, size);
}
}
Q2: 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.
Ans
// Constructor
Graph(int v)
{
V = v;
adj = new List<int>[v];
for (int i = 0; i < v; ++i)
adj[i] = new List<int>();
}
// Driver Code
public static void Main(String[] args)
{
Graph g = new Graph(4);
g.AddEdge(0, 1);
g.AddEdge(0, 2);
g.AddEdge(1, 2);
g.AddEdge(2, 0);
g.AddEdge(2, 3);
g.AddEdge(3, 3);
g.DFS(2);
Console.ReadKey();
}
}
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 have at least one vowel
Ans .
#!/bin/bash
file=$1
v=0
if [ $# -ne 1 ]
then
echo "$0 fileName"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file"
exit 2
fi
while read -n 1 c
do
l=$(echo $c | tr [:upper:] [:lower:])
[[ "$l" == "a" || "$l" == "e" || "$l" == "i" || "$l" == "o" || "$l" == "u" ]] && (( v++ ))
done < $file
echo "Vowels : $v"
echo "Characters : $(cat $file | wc -c)"
echo "Blank lines : $(grep -c '^$' $file)"
echo "Lines : $(cat $file|wc -l )"
OUTPUT:
Q2:Your PC is on a network. Find the number of Printers on whom you can command a Print from
your PC.
STEPS To Connect Printer: -
1. Click on Start in the bottom left corner of your screen. A popup list will appear.
2. Select Control Panel from the popup list. Type the word network in the search box.
3. Click on Network and Sharing Center.
4. Click on Change advanced shared settings, in the left pane.
5. Click on the down arrow, which will expand the network profile.
6. Select File and printer sharing and choose Turn on file and printer sharing.
7. Click on Save changes.
You're now ready to share your printer.
1. Click on Start in the bottom left corner of your screen. A popup list will appear.
2. Click on Devices and Printers, from the popup list.
3. Right click the printer you want to share. A dropdown list will appear.
4. Select Printer properties from the dropdown list.
5. Click on the Sharing tab
6. Select the Share this printer check box.
In order for other people to connect to the printer, they just have to add the network printer that you just opened for sharing to their
computers. Here's how to do this.
1. Click on Start in the bottom left corner of your screen. A popup list will appear.
2. Click on Devices and Printers from the popup list.
3. Select Add a printer.
4. Click on Add a network, wireless or Bluetooth printer.
5. Click the shared printer.
Q1: (10 marks) create a database consisting of Name of Bank, Number of Branches, Total number of
Customers, Average number of Customers who visit Bank in a Day After creating the database,
perform the following tasks:
(i) List the names of Banks which have more than 1000 branches
Ans:
Step 1
Show Databases;
OUTPUT
Step 2
create Table Bank_Info (
-> );
Step3
SQL QUERY
INSERT INTO Bank_Info (Bank_Name,Number_of_Branches,Total_Customer,Avg_no_of_customer_perday)
OUTPUT
(i) List the names of Banks which have more than 1000 branches
Part-4: MCS-024
Ans.
The Code:
1. import java.util.Scanner;
2.
3. class MatrixMultiplication
4. {
5. public static void main(String args[])
6. {
7. int m, n, p, q, sum = 0, c, d, k;
8.
9. Scanner in = new Scanner(System.in);
10. System.out.println("Enter the number of rows and columns of first matrix");
11. m = in.nextInt();
12. n = in.nextInt();
13.
14. int first[][] = new int[m][n];
15.
16. System.out.println("Enter elements of first matrix");
17.
18. for (c = 0; c < m; c++)
19. for (d = 0; d < n; d++)
20. first[c][d] = in.nextInt();
21.
22. System.out.println("Enter the number of rows and columns of second matrix");
23. p = in.nextInt();
24. q = in.nextInt();
25.
26. if (n != p)
27. System.out.println("The matrices can't be multiplied with each other.");
28. else
29. {
30. int second[][] = new int[p][q];
31. int multiply[][] = new int[m][q];
32.
33. System.out.println("Enter elements of second matrix");
34.
35. for (c = 0; c < p; c++)
36. for (d = 0; d < q; d++)
37. second[c][d] = in.nextInt();
38.
39. for (c = 0; c < m; c++)
40. {
41. for (d = 0; d < q; d++)
42. {
43. for (k = 0; k < p; k++)
44. {
45. sum = sum + first[c][k]*second[k][d];
46. }
47.
48. multiply[c][d] = sum;
49. sum = 0;
50. }
51. }
52.
53. System.out.println("Product of the matrices:");
54.
55. for (c = 0; c < m; c++)
56. {
57. for (d = 0; d < q; d++)
58. System.out.print(multiply[c][d]+"\t");
59.
60. System.out.print("\n");
61. }
62. }
63. }
64. }
The Output:
Q2:(5Marks)
Write a program in Java that connects to a database and generates a report that consists of the list of
Universities which are offering a specific Programme of Study. Input to the Java program will be
name or abbreviation of a Programme of Study (such as MCA). Make assumptions wherever
necessary.
Ans:
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();
}
}
}