-Computer Project
-Computer Project
PROJECT
NAME:SAHIL PALIT
CLASS:XI
SECTION:B
ROLL NO:20
SESSION:2022-23
QUESTION NO. 1
Design a class BinToDec to convert a binary number to its equivalent decimal number.
Some
of the members of the class are given below:
Class name : BinToDec
Data members/instance variables
n : an integer to store the binary number
Member functions:
BinToDec( ) : non-parameterized constructor
void accept( ) : to accept a binary number
int convert(int) : to convert a binary number to its equivalent
decimal number and return it
void display( ) : to convert the binary number to decimal
number by calling the function int convert(int)
and display the result.
ALGORITHM
STEP 1: Start
STEP 3:Declaring integer variable n to store the number inputted by the user
n 0
n sc.nextInt()
Declaring integer variable decimal to store the value returned by int convert(int b)
while b!=0
d b%10
deci deci+(d*(int)(Math.pow(2,p)))
p++
b b/10
End of while
Return deci
decimal convert(n)
Printing decimal
int n;
BinToDec(){
//initializing n
n=0;
void accept(){
n=sc.nextInt();
int p=0;
int d;
int deci=0;
//converting to decimal
while(b!=0){
//adding to deci the last digit multiplied by 2 raised to the power of the position of the digit taken from right to left
deci=deci+(int)(d*(Math.pow(2,p)));
b=b/10;
p++;//incrementing position
return deci;
void display(){
int decimal=convert(n);
System.out.print(decimal);
ob.accept();
ob.display();
}
SAMPLE INPUT AND OUTPUT
VARIABLE TABLE
Example: BALL
Potential = 66 + 65 + 76 + 76 = 283
Write a program to accept a sentence which may be terminated by either “ . ” , “ ? ” or “ ! ”
only. The words of sentence are separated by single blank space and are in UPPER CASE.
Decode the words according to their potential and arrange them in ascending order of their
potential strength. Test your program with the following data and some random data:
Example 1:
INPUT: HOW DO YOU DO?
OUTPUT: HOW = 238
DO = 147
YOU = 253
DO = 147
DO DO HOW YOU
Example 2:
INPUT: LOOK BEFORE YOU LEAP.
OUTPUT: LOOK = 309
BEFORE = 435
YOU = 253
LEAP = 290
YOU LEAP LOOK BEFORE
Example 3:
INPUT: HOW ARE YOU#
OUTPUT: INVALID INPUT
ALGORITHM
STEP 1:Start
STEP 3:Declaring string variable s to store the sentence and integer variable l to store the length of the string
STEP 4:Creating main() for the creation of object of the class Potential to call the member functions of the
class
s “”
l 0
s sc.nextLine()
l s.length()
wn str.countTokens()
s1[k++] str.nextToken()
p1 p1+ (int)(s1.charAt(j))
End of for
P[i] p1
p1 0
End of for
for i 0 to i<s1.length – 1 step value 1
if P[j]>P[j+1]
temp P[j]
P[j] P[j+1]
P[j+1] temp
t1 s1[j]
s1[j] s1[j+1]
s1[j+1] t1
End of if
End of for
End of for
Printing s[i]
End of for
End of if
Else
End of else
STEP 10:End
PROGRAM
import java.util.*;
String s;
int l;
Potential()
s="";
l=0;
void sentencePotential_Sort()
s = sc.nextLine().toUpperCase();
int k = 0;
int i;
int j;
int temp = 0;
String t1="";
int p1 = 0;
P[i] = p1;
p1 = 0;
//arranging sentence in ascending order of their potential strength using bubble sort
temp= P[j];
P[j + 1] = temp;
t1 = s1[j];
s1[j + 1] = t1;
else {
System.out.println("INVALID INPUT");
ob.sentencePotential_Sort();
}
SAMPLE INPUT/OUTPUT
VARIABLE TABLE
NAME TYPE DESCRIPTION
sc Scanner Helps to accept input
form user
str StringTokenizer Helps to break string into
tokens
s String Stores sentence input by
the user
l int Stores length of
sentence input by user
wn int Stores number of words
in the sentence
s1 String array Stores words of the
sentence
k int Array index for each
iteration
t int Stores temporary value
of elements of P[]