Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 42

Record Programs

1)
Pseudo Code:
BEGIN
CLASS employee
READ String empname
READ int empcode
READ double basicpay

FUNCTION employee(String n, int p, double q)


SET empname=n
SET empcode=p
SET basicpay=q
END FUNCTION

FUNCTION double salarycal()


READ double hra, da, salary
COMPUTE hra=0.3*basicpay
COMPUTE da=0.4*basicpay
COMPUTE salary= basicpay+hra+da
IF(empcode<=15)
THEN
IF(salary<+15000)
THEN
salary=salary+(0.2*salary)
ENDIF
ENDIF
ELSE IF(empcode>15)
THEN
salary=salary+1000
END ELSE IF
RETURN salary
END FUNCTION
FUNCTION MAIN()
CALL FUNCTION employee(“Rayaan”, 20,
10000.0)
CALL FUNCTION salarycal()
PRINT(“Total salary= ”+salary)
END FUNCTION
END CLASS
END

Source Code:

import java.util.*;
class employee
{
String empname;
int empcode;
double basicpay;

employee(String n,int p, double q)


{
empname=n;
empcode=p;
basicpay=q;
}
double salarycal()
{
double hra, da,salary;
hra=0.3*basicpay;
da=0.4*basicpay;
salary=basicpay+hra+da;
if(empcode<=15)
{
if(salary <=15000)
salary=salary+(0.2*salary);
}
else if(empcode>15)
{
salary= salary+1000;
}
return salary;
}
public static void main(String args[])
{
employee obj=new employee("Rayaan", 20,
1000000.0);
double salary= obj.salarycal();
System.out.println("Total salary=" +salary);
}
}
Output:

VDT:

Sl.No Variable Datatype Objective


1 empname String To store
name of
employee
2 empcode Int To store
employee
code
3 basicpay double To store
employee
salary
4 n String To receive
input
5 p Int To receive
input
6 q double To receive
input
7 hra double To calculate
and store
house rent
allowance
8 da double To calculate
and store
dearer
allowance
9 salary double To calculate
and store
final salary
2)
Pseudo Code:
BEGIN
CLASS P_T
FUNCTION P_T(int limit)
READ int a,b
SET c=0, m=2
WHILE(c< limit)
THEN
FOR(int n=1; n<m; ++n)
COMPUTE a=(m*m)-(n*n)
COMPUTE b=2*m*n
COMPUTE c= (m*m)+(n*n)
IF(c>limit)
THEN
BREAK
PRINT (a +“ ” + b + “ ” + c)
ENDIF
ENDFOR
m++
END WHILE
END FUNCTION

FUNCTION MAIN()
SET limit=100
CALL FUNCTION P_T(limit)
END FUNCTION
END CLASS
END

Source Code:
import java.io.*;
import java.util.*;

class P_T {

static void P_T(int limit)


{

int a, b, c = 0;
int m = 2;
while (c < limit)
{
for (int n = 1; n < m; ++n)
{
a = (m * m )- (n * n);
b = 2 * m * n;
c = (m * m) +(n * n);

if (c > limit)
break;
System.out.println(a + " " + b + " " + c);
}
m++;
}
}
public static void main(String args[])
{
int limit = 100;
P_T (limit);
}
}
Output:
VDT:
Sl.No Variable Datatype Objective
1 a int To store
first
number of
triplet
2 b int To store
second
number of
triplet
3 c int To store
third
number of
triplet
4 Limit int To set
limit
5 m int To
calculate
triplet
6 n int Used in
‘for loop’

3)
Pseudo Code:
BEGIN
CLASS DDArray
READ int mat[][]= new int[50][50]
READ int m,n

FUNCTION DDArray(int nr, int nc)


SET m=nr, n=nc
END FUNCTION

FUNCTION readMatrix()
PRINT(“Enter matrix elements”)
FOR(int i=0; i<m; i++)
FOR (int j=0;j<n;j++)
INPUT=mat[i][j]
ENDFOR
ENDFOR
END FUNCTION
FUNCTION Sums()
SET int lsum=0, rsum=0, bound=0
FOR (int i=0;i<m;i++)
FOR(int j=0;j<n; j++)
IF(i==j)
THEN
COMPUTE lsum= lsum+mat[i][j]
ENDIF
ENDFOR
ENDFOR

FOR (int i=0;i<m;i++)


FOR(int j=0;j<n; j++)
IF(i+j== n-1)
THEN
COMPUTE rsum= rsum+mat[i][j]
ENDIF
ENDFOR
ENDFOR
FOR (int i=0;i<m;i++)
FOR(int j=0;j<n; j++)
IF(i==0||i==(n-1)||j==0||j==(n-1))
THEN
COMPUTE bound= bound+mat[i][j]
ENDIF
ENDFOR
ENDFOR

PRINT ("Sum of left diagonal= "+lsum);


PRINT("Sum of right diagonal= "+rsum);
PRINT("Sum of boundary elements= "+bound);
END FUNCTION

FUNCTION Show_Mats()
PRINT(“Oringinal Matrix”)
FOR( int i=0; i<m; i++)
FOR(int j=0; j<n; j++)
PRINT (mat[i][j]+" ")
ENDFOR
PRINT()
ENDFOR
PRINT(“Inner Matrix”)
FOR( int i=0; i<m; i++)
FOR(int j=0; j<n; j++)
IF(i==0||i==(n-1)||j==0||j==(n-1))
PRINT(“ ”)
ENDIF
ELSE
PRINT(mat[i][j]+ “ ”)
END ELSE
ENDFOR
PRINT()
ENDFOR
END FUNCTION

FUNCTION MAIN()
PRINT(“Enter Rows and Columns”)
INPUT m
INPUT n
CALL FUNCTION DDArray(m,n)
CALL FUNCTION readMatrix()
CALL FUNCTION Sums()
CALL FUNCTION Show_Mats()
END FUNCTION
END CLASS
END

Source Code:
import java.io.*;
import java.util.*;
public class DDArray

{
static Scanner in=new Scanner(System.in);
int mat[][]=new int[50][50];
int m,n;
DDArray(int nr,int nc)
{
m=nr;
n=nc;
}
void readMatrix()
{
System.out.println("Enter matrix elements");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
mat[i][j]=in.nextInt();
}
}
}
void Sums()
{
int lsum=0,rsum=0, bound=0;
for(int i=0;i<m;i++)
{
for (int j=0;j<n;j++)
{
if(i==j)
lsum=lsum+mat[i][j];
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i+j==n-1)
rsum=rsum+mat[i][j];
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==(n-1)||j==0||j==(n-1))
bound=bound+mat[i][j];
}
}
System.out.println("Sum of left diagonal=
"+lsum);
System.out.println("Sum of right diagonal=
"+rsum);
System.out.println("Sum of boundary
elements= "+bound);
}
void Show_Mats()
{
System.out.println("Original Matrix");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(mat[i][j]+" ");
}
System.out.println();
}
System.out.println("Inner Matrix");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==(n-1)||j==0||j==(n-1))
System.out.print(" ");
else
System.out.print(mat[i][j]+" ");
}
System.out.println();
}
}
public static void main(String args[])
{
System.out.println("Enter rows and
cloumns");
int m= in.nextInt();
int n= in.nextInt();
DDArray obj= new DDArray(m,n);
obj.readMatrix();
obj.Sums();
obj.Show_Mats();
}
}
Output:
VDT:
Sl.No Variable Datatype Objective
1 mat int To store
matrix
2 m int To store
no. of
rows
3 n int To store
no. of
columns
4 nr int To take
input for
no. of
rows
5 nc int To take
input for
no. of
columns
6 i int Used in
‘for loop’
7 j int Used in
‘for loop’
8 lsum int To
calculate
and store
sum of
left
diagonal
9 rsum int To store
sum of
right
diagonal
10 bound int To store
sum of
boundary
elements

4)
Pseudo Code:
BEGIN
CLASS Vowels
FUNCTION Sentences()
INPUT STREAM READER in
BUFFERED READER br
PRINT(“Enter a sentence”)
SET String sentence= br.readLine()
COMPUTE sentence= sentence.toUpperCase()
SET StringTokenizer st1=new
StringTokenizer(sentence, ".?!");
COMPUTE int count st1.countTokens()
IF(count>10)THEN
PRINT (“Maximum 10 sentences allowed.”)
RETURN
ENDIF

SET String str= new String[count]


SET int a[] = new int[count]
SET int b[] = new int[count]
FOR (int i = 0; i < str.length; i++)
str[i] = st1.nextToken();
FOR (int i = 0; i < str.length; i++)
COMPUTE StringTokenizer st2 = new
StringTokenizer(str[i], " ")
COMPUTE a[i]= st2.countTokens()
FOR (int j = 0; j < str[i].length(); j++)
COMPUTE char ch= str[i].charAt(j)
SWITCH(ch)
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
COMPUTE b[i]++
END SWITCH
ENDFOR
ENDFOR
ENDFOR

PRINT("Sentence\tNo. of Vowels\tNo. of Words")


FOR(int i = 0; i < str.length; i++)
PRINT ((i + 1) + "\t"+"\t" + b[i] + "\t"+"\t" + a[i])
PRINT ("Sentence\tNo. of Vowels/Words")
FOR (int i = 0; i < str.length; i++)
PRINT ((i + 1) + "\t\t")
FOR (int j = 0; j < b[i]; j++)
PRINT ("VVV")
PRINT()
PRINT ("\t"+"\t")
FOR(int j = 0; j < a[i]; j++)
PRINT("WWW")
PRINT()
ENDFOR
ENDFOR
ENDFOR

END FUNCTION

FUNCTION MAIN()
CALL FUNCTION Sentences()
END FUNCTION
END CLASS
END

Source Code:
import java.io.*;
import java.util.StringTokenizer;
class Vowels
{
void Sentences()throws IOException
{
InputStreamReader in = new
InputStreamReader(System.in);
BufferedReader br = new
BufferedReader(in);
System.out.println("Enter sentence:");
String sentence = br.readLine();
sentence = sentence.toUpperCase();
StringTokenizer st1 = new
StringTokenizer(sentence, ".?!");
int count = st1.countTokens();
if(count > 10)
{
System.out.println("Maximum 10
sentences allowed.");
return;
}
String str[] = new String[count];
int a[] = new int[count];
int b[] = new int[count];
for(int i = 0; i < str.length; i++)
str[i] = st1.nextToken();
for(int i = 0; i < str.length; i++)
{
StringTokenizer st2 = new
StringTokenizer(str[i], " ");
a[i] = st2.countTokens();
for(int j = 0; j < str[i].length(); j++)
{
char ch = str[i].charAt(j);
switch(ch){
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
b[i]++;
}
}
}
System.out.println("Sentence\tNo. of
Vowels\tNo. of Words");
for(int i = 0; i < str.length; i++)
System.out.println((i + 1) + "\t"+"\t" + b[i]
+ "\t"+"\t" + a[i]);
System.out.println("Sentence\tNo. of
Vowels/Words");
for(int i = 0; i < str.length; i++)
{
System.out.print((i + 1) + "\t\t");
for(int j = 0; j < b[i]; j++)
System.out.print("VVV");
System.out.println();
System.out.print("\t"+"\t");
for(int j = 0; j < a[i]; j++)
System.out.print("WWW");
System.out.println();
}
}
public static void main(String args[])throws
IOException
{
Vowels obj= new Vowels();
obj.Sentences();
}
}
Output:

VDT:
Sl.No Variable Datatype Objective
1 sentence String To take input
from user
2 St1 StringTokenizer To transfer the
input to
SringTokenizer
to count the
number of
sentences
3 count int To store the
number of
sentences
4 str Array(String) To take each
letter of the
input in array
form
5 a Array(int) To calculate
the number of
words in each
sentence
6 b Array(int) To calculate
number of
vowels in each
sentence
7 i int Used in ‘For
loop’
8 j Int Used in ‘For
loop’
9 St2 StringTokenizer To take each
word of the
input in array
form
10 ch Char Used as input
for switch case
to find out the
number of
vowels present
in each word

5)
Pseudo Code:

BEGIN
CLASS DECODE
READ String Decryptmsg
READ int[] codeValues

FUNCTION Decrypt(String msg)


SET Decryptmsg= msg
SET codeValues= int[LENGTH OF Decryptmsg]
END FUNCTION

FUNCTION reverseString()
SET int j= 0
FOR(int i = Decryptmsg.length()-1; i >= 0; i--)
COMPUTE codeValues[j++]=
Decryptmsg.charAt(i)-48
END FOR
END FUNCTION

FUNCTION decryptCode()
READ int tmp
SET i= 0
WHILE(i< Decryptmsg.length())
THEN
IF (i < Decryptmsg.length() && i+1 <
Decryptmsg.length() && i+2 <
Decryptmsg.length())
THEN
COMPUTE tmp =
codeValues[i]*10*10+codeValues[i+1]*10+code
Values[i+2];
ELSE
tmp = codeValues[i]*10+codeValues[i+1];
END IF
IF(tmp>=&& tmp<=122)
THEN
PRINT((char)tmp)
i+ =3
END IF
ELSE
PRINT((char)tmp)
IF(tmp==32)
PRINT(“ ”)
i+ =2
END IF
END WHILE
END FUNCTION

FUNCTION MAIN()
READ String msg
SET BufferedReader br= new BufferedReader()
PRINT(“Enter the encoded message”)
SET msg= br.readLine()
CALL FUNCTION Decrypt(msg)
CALL FUNCTION reverseString()
PRINT(“Output: The Decoded Message”)
CALL FUNCTION decryptCode()
END FUNCTION
END CLASS
END

Source Code:
import java.util.*;
import java.io.*;
public class DECODE {
String Decryptmsg;
int[] codeValues;

void Decrypt(String msg) {


Decryptmsg = msg;
codeValues = new int[Decryptmsg.length()];
}
public void reverseString() {
int j = 0;
for ( int i = Decryptmsg.length()-1; i >= 0;
i--) {
codeValues[j++] = Decryptmsg.charAt(i)-
48;
}
}
public void decryptCode() {
int tmp,i=0;
while ( i < Decryptmsg.length() ) {
if (i < Decryptmsg.length() && i+1 <
Decryptmsg.length() && i+2 <
Decryptmsg.length())
tmp =
codeValues[i]*10*10+codeValues[i+1]*10+code
Values[i+2];
else
tmp =
codeValues[i]*10+codeValues[i+1];
if (tmp >= 97 && tmp <=122) {
System.out.print((char)tmp);
i +=3;
}
else {
System.out.print((char)tmp);
if(tmp==32)
System.out.print("");
i +=2;
}
}
}
public static void main(String[] args) throws
IOException
{
String msg;
BufferedReader br = new
BufferedReader(new
InputStreamReader(System.in));
System.out.println(" Enter the Encoded
Message:");
msg = br.readLine();
Decrypt ob = new Decrypt(msg);
ob.reverseString();
System.out.println("OUTPUT:The Decoded
Message: ");
ob.decryptCode();
}

}
Output:

VDT:
Sl.No Variable Datatype Objective
1 Decryptmsg String Used to
perform
various
functions in
order to obtain
the decoded
message
2 codeValues Array(int) To store the
encoded
message in an
array
3 msg String To get the
input(Encoded
message)
from the user
4 i Int Used in ‘For
Loop’
5 j Int Used in ‘For
Loop’
6 tmp int Used in
converting the
numbers to
corresponding
ASCII value

You might also like