You are on page 1of 12

Assignment 1

Karnaugh Map and its Applications


Assignment 2
Boolean Algebra
Assignment 3 To Assignment 19(Program 1 to Program 17)
Program 1
To create a Pascals Triangle
STEP 1 START
STEP 2 - pas[0] = 1
STEP 3 - IF i=0 THEN GOTO STEP 4
STEP 4 - IF j=0 THEN GOTO STEP 5
STEP 5 - PRINT pas[j]+" "
STEP 6 - i++& IF i<n GOTO STEP 4
STEP 7 - j=0 & IF j<=i GOTO STEP 5
STEP 8 - IF j=i+1 THEN GOTO STEP 7
STEP 9 - pas[j]=pas[j]+pas[j-1]
STEP 10 - j--& IF j>0 GOTO STEP 9
STEP 11 END
Program 2
To display calendar of any month of any year
STEP 1 START
STEP 2 - INPUT int month,int year
STEP 3 - int i,count=0,b,c,d=1 & String w="SMTWTFS"
STEP 4 - IF (year%100==0 && year%400==0) || (year%100!=0
&& year%4==0)
STEP 5 - days[1]=29
STEP 6 - PRINT "================The Calendar
of"+month1[month-1]+" "+year+"is==================")
STEP 7 - IF i=0 THEN GOTO STEP 8

STEP 8 - PRINT (i)+"\t" & " "


STEP 9 - IF i=1 GOTO STEP 10
STEP 10 - IF (year%100==0 && year%400==0) || (year%100!
=0 && year%4==0)THEN GOTO STEP 11OTHERWISE
GOTO STEP 12
STEP 11 - count+=2
STEP 12 - count+=1
STEP 13 - IF i=0 GOTO STEP 14
STEP 14 - count+=days[i] , count+=1, count%=7 & b=7-count
STEP 15 - IF b!=1 || b!=7 GOTO STEP 16
STEP 16 - IF count>0 GOTO STEP 17,18
STEP 17 - PRINT ' '+"\t")
STEP 18 - count
STEP 19 - IF i=1 GOTO STEP 20
STEP 20 - IF b>0 && IF d<=days[month-1] GOTO STEP 21,22
STEP 21 - PRINT d+"\t"
STEP 22 - d++ & b
STEP 23 - b=7
STEP 24 - i++ & IF i<MONTH GOTO STEP14
STEP 25 - PRINT " "
STEP 26 END
Program 3
To calculate Factorial using Recursion
STEP 1 START
STEP 2 - INPUT n
STEP 3 - IF(n<2) THEN return 1 OTHERWISE return (n *
fact(n-1))
STEP 4 END

Program 4
To display Fibonacci Series using Recursion
STEP 1 START
STEP 2 - INPUT n
STEP 3 - IF(n<=1) THEN return 1 OTHERWISE return (fib(n1) +fib(n-2))
STEP 4 END
Program 5
To display Magic Square
STEP 1 START
STEP 2 - arr[][]=new int[n][n],c=n/2-1,r=1,num
STEP 3 - IF num=1;num<=n*n;num++ GOTO STEP 4
STEP 4 - r--,c++
STEP 5 - IF r==-1 GOTO STEP 6
STEP 6 - r=n-1
STEP 7 - IF c>n-1 GOTO STEP 8
STEP 8 - c=0
STEP 9 - IF arr[r][c]!=0 GOTO STEP 10
STEP 10 - r=r+2 & c
STEP 11 - num++ & IF num<=n*n GOTO STEP 4
STEP 12 - arr[r][c]=num
STEP 13 - IF r==0&&c==0 GOTO STEP 14
STEP 14 - r=n-1, c=1 & arr[r][c]=++num
STEP 15 - IF c==n-1&&r==0 GOTO STEP 16
STEP 16 - arr[++r][c]=++num
STEP 17 - PRINT ()
STEP 18 - IFr=0 GOTO STEP 19
STEP 19 - IF c=0 GOT STEP 20

STEP 20 - PRINT arr[r][c]+" " & ()


STEP 21 - c++ & IF c<n GOTO STEP 20STEP 21 - r++ & r<n
GOTO STEP 19
STEP 22 END
Program 6
To search an array using Linear Search
STEP 1 START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n REPEAT STEP 7
STEP 7 - IF (a[i] == v) THEN flag =i
STEP 8 - IF (flag=-1) THEN GOTO STEP 9 OTHERWISE
GOTO STEP 10
STEP 9 - PRINT not found
STEP 10 - PRINT v+" found at position - "+flag
STEP 11 END
Program 7
To search an array using Binary Search
STEP 1 START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1 , l=0, u=n-1
STEP 6 - IF(l<=u && flag=-1) REPEAT STEP 7 AND Step 8
STEP 7 - m = (l+u)/2

STEP 8 - IF (a[m] == v) THEN flag =m OTHERWISE GOTO


STEP 9
STEP 9 - IF (a[m] < v) THEN l = m+1 OTHERWISE u =m-1
STEP 10 - IF (flag=-1) THEN GOTO STEP 11 OTHERWISE
GOTO STEP 12
STEP 11 - PRINT not found
STEP 12 - PRINT v+" found at position - "+flag
STEP 13 - END
Program 8
To sort an array using Bubble Sort
STEP 1 START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 9
STEP 7 - FROM j=i+1 to j<n REPEAT STEP 8
STEP 8 - IF(a[j] > a[j+1]) THEN GOTO STEP 9
STEP 9 - temp = a[i], a[i] =a[min], a[min] = temp
STEP 10 END
Program 9
To sort an array using Selection Sort
STEP 1 START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1

STEP 6 - FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 11


STEP 7 - min =i
STEP 8 - FROM j=i+1 to j<n REPEAT STEP 8
STEP 9 - IF(a[j]<a[min]) then min =j
STEP 10 - IF (min!=i) GOTO STEP 11
STEP 11 - temp = a[i], a[i] =a[min], a[min] = temp
STEP 12-END
Program 10
To convert Decimal number into its Binary Equivalent
STEP 1 START
STEP 2 - n = 30
STEP 3 - INPUT int no
STEP 4 - c =0 , temp = no
STEP 5 - IF (temp!=0) REPEAT STEP 6
STEP 6 - a[c++] = temp%2, temp = temp / 2
STEP 7 - FROM i=c-1 to i>0 REPEAT STEP 8
STEP 8 - PRINT a[i]
STEP 9 END
Program 11
To display date from entered day number
STEP 1 START
STEP 2 - INITIALISE a[ ] , m[ ]
STEP 3 - INPUT n , yr
STEP 4 - IF ( yr%4=0) THEN a[1] = 29
STEP 5 - t =0 , s = 0
STEP 6 - IF ( t<n) REPEAT STEP 7
STEP 7 - t =t + a[s++]

STEP 8 - d = n + a[--s] t
STEP 9 - IF ( d ==1|| d == 21 || d == 31 ) then PRINT d + "st" +
m[s] + ", "+yr
STEP 10 - IF ( d ==2|| d == 22 ) then PRINT d + "nd" + m[s] + "
, "+yr
STEP 11 - IF ( d ==3|| d == 23 ) then PRINT d + "rd" + m[s] +
" , "+yrOTHERWISE GOTO STEP 12
STEP 12 - PRINT d + "th" + m[s] + " , "+yr
STEP 13 END
Program 12
To decode the entered string
STEP 1 START
STEP 2 - INPUT name, n
STEP 3 - l=name.length()
STEP 4 - PRINT original string is "+name
STEP 5 - IF i=0 THEN GOTO STEP 6
STEP 6 - char c1=name.charAt(i)
STEP 7 - c=(int)c1
STEP 8 - IF n>0 THEN GOTO STEP 9 THERWISE GOTO
STEP 12
STEP 9 - IF (c+n)<=90 THEN GOTO STEP 10 OTHERWISE
GOTO STEP 11
STEP 10 - PRINT (char)(c+n)
STEP 11 - c=c+n;c=c%10,c=65+(c-1) & PRINT (char)(c)
STEP 12 - ELSE IF n<0 THEN GOTO STEP 13 OTHERWISE
GOTO STEP 19
STEP 13 - n1=Math.abs(n)
STEP 14 - IF (c-n1) >=65 THEN GOTO STEP 15
OTHERWISE GOTO STEP 16

STEP 15 - DISPLAY (char) (c-n1)


STEP 16 - IF c>65 THEN GOTO STEP 17 OTHERWISE
GOTO STEP 18
STEP 17 - c=c-65,
STEP 18 - c=n1 & PRINT (char)(90-(c-1))
STEP 19 - ELSE IF n==0
STEP 20 - DISPLAY "no change "+name
STEP 21 END
Program 13
To convert Celsius into Fahrenheit using Inheritance
STEP 1 START
STEP 2 -- Input temperature celsius in celsius
STEP 3 far=1.8*celcius + 32
STEP 4 Display far
STEP 5 END
Program14
To calculate GCD using Recursion
STEP 1 START
STEP 2 - INPUT p,q
STEP 3 - IF(q=0) THEN return p OTHERWISE return calc(q,p
%q)
STEP 4 END
Program 15
To display Spiral Matrix
STEP 1 START
STEP 2 - INPUT a[][]

STEP 3 - IF p!=(int)Math.pow(l,2) GOTO STEP 4


STEP 4 - IF co!=0 GOTO STEP 5
STEP 5 - re=1
STEP 6 - IF ri=1;ri<=k1-re;ri++ GOTO STEP 7
STEP 7 - p++,c++
STEP 8 - IF c==l GOTO STEP 9
STEP 9 BREAK
STEP 10 - a[r][c]=p
STEP 11 - IF c==l GOTO STEP 12
STEP 12 BREAK
STEP 13 - IF dw=1 GOTO STEP 14
STEP 14 - p++,r++,a[r][c]=p
STEP 15 - IF le=1 GOTO STEP 16
STEP 16 - p++,c--,a[r][c]=p
STEP 17 - IF up=1 GOTO STEP 18
STEP 18 - p++,r--,a[r][c]=p
STEP 19 - k1=k1+2, k2=k2+2 & co++
STEP 20 - up++ & IF up<=k2-1 GOTO STEP 18
STEP 21 - le++ & IF le<=k2-1 GOTO STEP 16
STEP 22 - dw++ & IF dw<=k1-1 GOTO STEP 14
STEP 23 - IF y=0 GOTO STEP 24
STEP 24 - IF yy=0 GOTO STEP 25
STEP 25 - PRINT "\t"+a[y][yy]) & ()
STEP 26 - yy++ & IF yy<l GOTO STEP 25
STEP 27 - y++ & IF y<l GOTO STEP 24
STEP 28 END
Program 16
A perfect square is an integer which is the square of another
integer. For example, 4, 9,

16 .. are perfect squares. Design a Class Perfect with the


following description:
Class name : Perfect
Data members/instance variables
n : stores an integer number
Member functions:
Perfect( ) : default constructor
Perfect(int) : parameterized constructor to assign a
value to n
void perfect_sq() : to display the first 5 perfect squares
larger than n (if n = 15, the next 3
perfect squares are 16, 25, 36)
void sum_of() : to display all combinations of
consecutive integers whose sum is
equal to n. ( the number n = 15 can be
expressed as
12345
456
78
Specify the class Perfect giving details of the constructors, void
perfect_sq( ) and
void sum_of(). Also define the main function to create an object
and call methods
accordingly to enable the task.
Program 17
A class Author contains details of the author and another class
Book List contains
details of the books written by him. The details of the two
classes are given below:

Class name : Author


Data members
authorno : stores the authors number
name : stores the authors name
Member functions
Author ( ) : default constructor
Author ( ) : parameterised constructor to assign values
to author number and name
void show( ) : to display the authors details
Class name : Booklist
Data members/instance variables
bookno : Long type variable to the store book number
bookname : stores the book name
price : float variable to store the price
edition : integer type variable to store the edition
number
Member functions
Booklist () : parameterized constructor to assign values to
data members of both the classes
void show( ) : to display all the details
Specify the class Author giving details of the constructors and
member function void
show( ). Using the concept of Inheritance, specify the class
Booklist giving details of the
constructor and the member function void show( ). Also define
the main function to
create an object and call methods accordingly to enable the task.
Note: Every program should be prefixed with suitable
algorithm and then followed by variable description,
program description and output.

Assignment 20
Computational Complexcity

You might also like