PART-1: MCS-021
Q.1.(a)
A.1.(a)
#include <stdio.h>
#include <conio.h>#define MAX 10
struct term
{
int coeff ;
int exp ;
} ;
struct poly
{
struct term t [10] ;
int noofterms ;
} ;
void initpoly ( struct poly *) ;
void polyappend ( struct poly *, int, int ) ;
struct poly polyadd ( struct poly, struct poly ) ;
struct poly polymul ( struct poly, struct poly ) ;
void display ( struct poly ) ;
void main( )
{
struct poly p1, p2, p3 ;
clrscr( ) ;
initpoly ( &p1 ) ;
initpoly ( &p2 ) ;
initpoly ( &p3 ) ;
polyappend ( &p1, 1, 4 ) ;
polyappend ( &p1, 2, 3 ) ;
polyappend ( &p1, 2, 2 ) ;
polyappend ( &p1, 2, 1 ) ;
polyappend ( &p2, 2, 3 ) ;
polyappend ( &p2, 3, 2 ) ;
polyappend ( &p2, 4, 1 ) ;
p3 = polymul ( p1, p2 ) ;
printf ( "\nFirst polynomial:\n" ) ;
display ( p1 ) ;
printf ( "\n\nSecond polynomial:\n" ) ;
display ( p2 ) ;
printf ( "\n\nResultant polynomial:\n" ) ;
display ( p3 ) ;
getch( ) ;
}
/* initializes elements of struct poly */
void initpoly ( struct poly *p )
{
int i ;
p -> noofterms = 0 ;
for ( i = 0 ; i < MAX ; i++ )
{
p -> t[i].coeff = 0 ;
p -> t[i].exp = 0 ;
}
}
/* adds the term of polynomial to the array t */
void polyappend ( struct poly *p, int c, int e )
{
p -> t[p -> noofterms].coeff = c ;
p -> t[p -> noofterms].exp = e ;
( p -> noofterms ) ++ ;
}
/* displays the polynomial equation */
void display ( struct poly p )
{
int flag = 0, i ;
for ( i = 0 ; i < p.noofterms ; i++ )
{
if ( p.t[i].exp != 0 )
printf ( "%d x^%d + ", p.t[i].coeff, p.t[i].exp ) ;
else
{
printf ( "%d", p.t[i].coeff ) ;
flag = 1 ;
}
}
if ( !flag )
printf ( "\b\b " ) ;
}
/* adds two polynomials p1 and p2 */
struct poly polyadd ( struct poly p1, struct poly p2 )
{
int i, j, c ;
struct poly p3 ;
initpoly ( &p3 ) ;
if ( p1.noofterms > p2.noofterms )
c = p1.noofterms ;
else
c = p2.noofterms ;
for ( i = 0, j = 0 ; i <= c ; p3.noofterms++ )
{
if ( p1.t[i].coeff == 0 && p2.t[j].coeff == 0 )
break ;
if ( p1.t[i].exp >= p2.t[j].exp )
{
if ( p1.t[i].exp == p2.t[j].exp )
{
p3.t[p3.noofterms].coeff = p1.t[i].coeff + p2.t[j].coeff ;
p3.t[p3.noofterms].exp = p1.t[i].exp ;
i++ ;
j++ ;
}
else
{
p3.t[p3.noofterms].coeff = p1.t[i].coeff ;
p3.t[p3.noofterms].exp = p1.t[i].exp ;
i++ ;
}
}
else
{
p3.t[p3.noofterms].coeff = p2.t[j].coeff ;
p3.t[p3.noofterms].exp = p2.t[j].exp ;
j++ ;
}
}
return p3 ;
}
/* multiplies two polynomials p1 and p2 */
struct poly polymul ( struct poly p1, struct poly p2 )
{
int coeff, exp ;
struct poly temp, p3 ;
initpoly ( &temp ) ;
initpoly ( &p3 ) ;
if ( p1.noofterms != 0 && p2.noofterms != 0 )
{
int i ;
for ( i = 0 ; i < p1.noofterms ; i++ )
{
int j ;
struct poly p ;
initpoly ( &p ) ;
for ( j = 0 ; j < p2.noofterms ; j++ )
{
coeff = p1.t[i].coeff * p2.t[j].coeff ;
exp = p1.t[i].exp + p2.t[j].exp ;
polyappend ( &p, coeff, exp ) ;
}
if ( i != 0 )
{
p3 = polyadd ( temp, p ) ;
temp = p3 ;
}
else
temp = p ;
}
}
return p3 ;
}
Q.2.
A.2.
{
//BFS uses Queue data structure
Queue q=new LinkedList();
q.add(this.rootNode);
printNode(this.rootNode);
rootNode.visited=true;
while(!q.isEmpty())
{
Node n=(Node)q.remove();
Node child=null;
while((child=getUnvisitedChildNode(n))!=null)
{
child.visited=true;
printNode(child);
q.add(child);
}
}
//Clear visited property of nodes
clearNodes();
}
PART-1: MCS-022
Q.1.A.1
A shell script is a computer program designed to be run by the Unix shell, a command – line Interpreter .The various dialects of shell scripts are considered to be scripting languages.
Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script which sets up the environment, runs the program, and does any necessary cleanup, logging, etc. is called a wrapper.
echo Enter a text
read text
w=`echo $text | wc -w`
w=`expr $w`
c=`echo $text | wc -c`
c=`expr $c - 1`
s=0
alpha=0
j=` `
n=1
while [ $n -le $c ]
do
ch=`echo $text | cut -c $n`
if test $ch = $j
then
s=`expr $s + 1`
fi
case $ch in
(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) alpha=`expr $alpha + 1`;;
esac
n=`expr $n + 1`
done
special=`expr $c - $s - $alpha`
echo Words=$w
echo Characters=$c
echo Spaces=$s
echo Special symbols=$special
sentences = Words+ Characters+ Spaces + Special Symbols
echo $SentencesQ.2.
A.2.
A.2. 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.
6. Click Next. Continue according to the instructions on the screen.
PART-1: MCS-023
Create Table :-
Step 2:- Inserting Values In Table:-
Step3:- Generate a Select Query Statment:-
Select * from t1 where Prorammes = 'MCA'
And Execute it.
Step 4:-
NameofStudyCenter CodeOfStudyCenter Prorammes NumberOfStudent
BHU 27109 MCA 45
MCMT 48012 MCA 10
BHUKamachha 48003 MCA 15
AryaMahila 48022 MCA 20
PART-1: MCS-024
A.1.Array equal to the number of rows of the matrix and the length of the sub arrays equal to the number of columns of the matrix. For example, a matrix of order 3*7 will be represented as a 2D array matrix[3][7]. A two level nested for loop will be used to read the input matrices from the keyboard. The outer loop counter, i ranges from 0 to the number of rows of the matrix while the inner loop counter, j ranges from 0 to the number of columns of the matrix. Within the inner loop, the input integers will be read using nextInt() method of the scanner class and stored at position [i][j] of the array.
import java.util.Scanner;
public class MatrixAddition {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = s.nextInt();
System.out.print("Enter number of columns: ");
int columns = s.nextInt();
int[][] a = new int[rows][columns];
int[][] b = new int[rows][columns];
System.out.println("Enter the first matrix");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
a[i][j] = s.nextInt();
}
}
System.out.println("Enter the second matrix");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
b[i][j] = s.nextInt();
}
}
int[][] c = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
c[i][j] = a[i][j] + b[i][j];
}
}
System.out.println("The sum of the two matrices is");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}
Here is a sample execution.
Enter number of rows: 2
Enter number of columns: 3
Enter the first matrix
3 4 7
1 8 4
Enter the second matrix
3 2 1
1 0 4
The sum of the two matrices is
6 6 8
2 8 8
A.2.
import java.sql.*; // Use classes in java.sql package
// JDK 7 and above
public class JdbcSelectTest { // Save as "JdbcSelectTest.java"
public static void main(String[] args) {
try (
// Step 1: Allocate a database "Connection" object
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:8888/ebookshop", "myuser", "xxxx"); // MySQL
// Connection conn = DriverManager.getConnection(
// "jdbc:odbc:ebookshopODBC"); // Access
// Step 2: Allocate a "Statement" object in the Connection
Statement stmt = conn.createStatement();
{
// Step 3: Execute a SQL SELECT query, the query result
// is returned in a "ResultSet" object.
String strSelect = "select title, price, qty from books";
System.out.println("The SQL query is: " + strSelect); // Echo For debugging
System.out.println();
ResultSet rset = stmt.executeQuery(strSelect);
// Step 4: Process the ResultSet by scrolling the cursor forward via next().
// For each row, retrieve the contents of the cells with getXxx(columnName).
System.out.println("The records selected are:");
int rowCount = 0;
while(rset.next()) { // Move the cursor to the next row}
String title = rset.getString("title");
double price = rset.getDouble("price");
int qty = rset.getInt("qty");
System.out.println(title + ", " + price + ", " + qty);++rowCount;
}
System.out.println("Total number of records = " + rowCount);
} catch(SQLException ex) {
ex.printStackTrace();}
}
}
Thank you so much Bharati..!!:-)
ReplyDelete