Posts

Showing posts from September, 2021

TABLE GENERATOR USING JAVASCRIPT

TABLE GENERATOR USING JAVASCRIPT   <script type="text/javascript"> </script> <script type="text/javascript"> // fACTOR 12 = 1,2,3,4,6, AND 12 function check() {   var number= document.getElementById('n1').value; var number2= document.getElementById('n2').value; var str2="";     for (var j=parseInt(number); j<= parseInt(number2); j++)     {          var str="";         for (var i=1; i<=10; i++)         {         str = str + `${j*i}  `;         }     str2= str2 + '\n'+ str;        console.log(str2);     } document.getElementById('tav').innerText=`${str2}`; } </script> <br> <input type="number" name="" id="n1"> <input type="number" name="" id="n2"> <br> <button onclick="check()">GENERATE</button> <h3 id="tav"> </h3>

GREATEST COMMON FACTOR

  Write a program in python to calculate greatest common divisor of a number   import math print("Greatest Common Divisor ")   # prints 12 print("The gcd of 60 and 48 is : ", end="") print(math.gcd(60, 48)) # The gcd of 98 and 56 is : 14 # The gcd of 60 and 48 is : 12 ''' def hcf(a, b):     if(b == 0):         return a     else:         return hcf(b, a % b)   a = 60 b = 48   # prints 12 print("The gcd of 60 and 48 is : ", end="") print(hcf(60, 48)) '''  

USING CHARACTER ARRAY GENERATE MARKSHEET

USING CHARACTER ARRAY GENERATE MARKSHEET /* Write a program to generate marksheet assuming that the following information can be read from keyboard. a. Student name, b. roll number. c, registration number, d. total marks, e. division/grade */ #include <iostream> #include <iomanip> class marksheet{ int tmarks, roll; char name[20], rgno[20], div[20]; public:     void uinput()     {         std::cout<<"Enter Values in Following Fields ";         std::cout<<std::endl<<"NAME: "; std::cin>>name;         std::cout<<"ROLL: "; std::cin>>roll;         std::cout<<"REG. NO.: "; std::cin>>rgno;         std::cout<<"TOTAL MARKS: "; std::cin>>tmarks;         std::cout<<"DIVISION: "; std::cin>>div;         std::cout<<"Successful."<<std::endl;     }     void uresult()     {         std::cout<<std::setw(10)<<"Student Name&qu

M TO CM AND IN TO FT TO INCH CONVERSION PROGRAM

 M TO CM AND IN TO FT TO INCH CONVERSION PROGRAM # PYTHON PROGRAM WITHOUT FRIEND FUNCTION class DM:     def __init__(self):         self.c1=self.c2=self.inc1=0.0         self.m=self.cm=self.ft1=0     def m_cm(self):         self.m=int(input("M= "))         self.cm=int(input("CM= "))     def convart1(self):         self.m=self.m*100         self.c1=self.m+self.cm         self.c2=self.c1*0.4         self.ft1=self.c2/12         self.inc1= self.c2-(self.ft1*12) class DB:     def __init__(self):         self.d1=self.d2=self.cm1=0.0         self.ft=self.inc=self.m1=0     def ft_inc(self):         self.ft=int(input("FT= "))         self.inc=int(input("INC= "))     def convart2(self):         self.ft=self.ft*12         self.d1=self.ft+self.inc         self.d2=self.d1*2.5         self.m1=self.d2/100         self.cm1=self.d2-(self.m1*100) def add1(M1,B1):     a=M1.m + B1.m1     b=M1.cm + B1.cm1     if(b>=100):         a+=1         b-=100     print("

MATRICS OPERATIONS USING OPERATOR OVERLOADING

  /* DEFINE A CLASS MAT OF SIZE M*N, DEFINE +, -, AND * OPERATOR OF MAT OBJECTS. WRITE A CPP PROGRAM TO TEST ABOVE CLASS FOR ABOVE OPERATIONS ON THE MAT OBJECTS */ #include <iostream> #include <iomanip> class MAT {     int m,n, mat[100][100]; public:     void operator+(MAT);     void operator-(MAT);     void operator*(MAT);     void getdata();     void display(); }; void MAT::getdata() {     std::cout<<"Enter m: ";     std::cin>>m;     std::cout<<"Enter n: ";     std::cin>>n;     mat[m][n];     for(int i=0; i<m; i++)     {         for(int j=0; j<n;j++){             std::cout<<"Array["<<i<<"]["<<j<<"]: ";             std::cin>>mat[i][j];}     } } void MAT::display() {     for(int i=0; i<m; i++)     {         for(int j=0; j<n; j++)         {             std::cout<<mat[i][j]<<" ";         }         std::cout<<std::endl;     }   

CONSTRUCTOR COPY CONSTRUCTOR & DESTRUCTOR

 /* CONSTRUCTOR & DESTRUCTOR WRITE A PROGRAM IN CLASS THAT CAN STORE AN INTEGER ARRAY OF DIFFERENT WITH FOLLOWING MEMBER FUCTIONS A) CONSTRUCTOR WITH ARRAY SIZE =0 B) COPY CONSTRUCTOR C) DESTRUCTOR */ #include <iostream> class arr{     int a[100],size; public:     arr(){         std::cout<<"CONSTRUCTOR INITIALIZED ARRAY SIZE TO 0";         size=0; a[size];     }     arr(arr &x);     ~arr()     {         std::cout<<std::endl<<"DESTRUCTOR INVOLVED ~~ FREE MEMORY";     } };  arr::arr(arr &x) {     std::cout<<std::endl<<"COPY CONSTRUCTOR INVOLVED";     size=x.size;     a[size];     for(int i=0; i<x.size; i++)     {         a[i]=x.a[i];     } } int main() {     arr a1;     arr a2(a1); } /* CONSTRUCTOR INITIALIZED ARRAY SIZE TO 0 COPY CONSTRUCTOR INVOLVED DESTRUCTOR INVOLVED ~~ FREE MEMORY DESTRUCTOR INVOLVED ~~ FREE MEMORY */

USING OVERLOADING '+' OPERATOR TO CONCATENATE TWO STRING OBJECT

 /* USING OVERLOADING '+' OPERATOR TO CONCATENATE TWO STRING OBJECT */ #include <iostream> #include <cstring> class string{ public:     char s[20];     int size;     void getstring(char str[])     {         strcpy(s,str);     }     void operator+(string); }; void string::operator+(string ob) { strcat(s,ob.s); std::cout<<"\nConcatenated String is: "<<s;     } int main() {     string ob1,ob2;     char string1[10],string2[10];     std::cout<<"Enter First string: ";     std::cin>>string1;     ob1.getstring(string1);     std::cout<<"\nEnter second string: ";     std::cin>>string2;     ob2.getstring(string2);     ob1+ob2; } /* Enter First string: Shout Enter second string: coders Concatenated String is: Shoutcoders */

C++ OPERATOR OVERLOADING AND BUILD A CLOCK

 /* C++ OPERATOR OVERLOADING AND BUILD A CLOCK WRITE A PROGRAM CLASS NAME CLOCK WITH DATA MEMBERS, HOURS, MINUTES, AND SECONDS. WRITE A PROGRAM TO ADD TWO INPUT TIME USING  OPERATOR OVERLOADING. */ #include <iostream> class clockk {     int m,s,h; public:     clockk()     {    }     void getdata()     {         std::cout<<"Enter values: "<<std::endl<<"Hour: ";         std::cin>>h;         std::cout<<"minutes: ";         std::cin>>m;         std::cout<<"seconds: ";         std::cin>>s;     }     clockk operator+ (clockk b)     {         clockk temp;         temp.h = h+b.h;         temp.m=m+b.m;         temp.s=s+b.s;         return (temp);     }     void display(void)     {         if(s>=60)         {             m++;             s-=60;         }         if(m>=60)         {             h++;             m-=60;         }         std::cout<<h<<"h "<<m<<"

METHOD OVERLOADING

 METHOD OVERLOADING class std {     String n;     int a;     String ad;     std()     {         n="unknown";         a=0;         ad="not availavle";     }     void setInfo(String na, int ag)     {         n=na;         a=ag;     }     void setInfo(String na, int ag, String add )     {         n=na;         a=ag;         ad=add;     }     void prints()     {         System.out.println("Name: "+n);         System.out.println("AGE: "+a);         System.out.println("ADDRESS: "+ad);     }     public static void main(String ar[])     {         std s[]=new std[10];         for(int i=0;i<10;i++)         {             s[i]=new std();             if(i%5==0)             s[i].setInfo(("ab"+i),(40-i));             else             s[i].setInfo(("xy"+i),(20+i),("ww"+i+"s"));         }         for(int i=0;i<10;i++)         {s[i].prints();         }              }      }

THIS KEYWORD IN CONSTRUCTOR OVERLOADING

 THIS KEYWORD IN CONSTRUCTOR OVERLOADING class show {     int i;     char c;      show(int n,char c)     {i=n; this.c=c;         System.out.print("\n Number: "+i);         System.out.print("\n Char: "+c);              }      show(char c,int n)     {i=n; this.c=c;         System.out.print("\n Number: "+i);         System.out.println("\n Char: "+c);              }     public static void main(String at[])     {         show ob1=new show(1,'f');         show ob2=new show('s',2);              } }

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

 SAME NAME IN CLASS METHOD AND CONSTRUCTOR, STATIC VARIABLE class Emp {     String ename;     int age;     int sal;     static int count=0;     int empno;          Emp()     {         }     void Emp(String n, int a, int s)     {         count+=1;         empno=count;         ename=n;         age=a;         sal=s;     }          void show()     {         System.out.println("Emp_no: "+empno);         System.out.println("Emp_name: "+ename);         System.out.println("Emp_age: "+age);         System.out.println("Emp_Salary: "+sal);     } public static void main(String a[]) {    Emp e1[]=new Emp[5];     for(int i=0;i<5;i++)     {         e1[i]=new Emp();     }     for (int i=0;i< 5 ; i++)     {         e1[i].Emp(("A"+i),(22+i+2),(2000+100*i));     }     for (int i=0;i< 5 ; i++)     {         e1[i].show();     }      } }

CONSTRUCTOR OVERLOADING TO CREATE DIFFERENT OBJECT

 CONSTRUCTOR OVERLOADING TO CREATE DIFFERENT OBJECT  import java.util.*; class Area {     float l,b;     int aa;     Area(float l,float b)// Rectan     {         this.l=l;         this.b=b;     }     Area(int l)// Area     {         aa=l;     }     float aRc()     {         return (l*b);     }     int aSc(int count)     {         if(count==1)             return aa;         else             return (aa * aSc(count-1));     }          public static void main(String ar[])     {         Scanner sc=new Scanner(System.in);         float rl,rb;         int sa;                  System.out.println("\n Enter the Length of Rectangel: ");         rl=sc.nextFloat();                  System.out.println("\n Enter the breadth of Rectangle: ");         rb=sc.nextFloat();                  System.out.println("\n Enter the length of Square: ");         sa=sc.nextInt();                  Area square=new Area(sa);         Area rec=new Area(rl,rb);                  System.out.prin

CONSTRUCTOR OVERLOADING IN JAVA TO PRINT NUMBERS OF DIFFERENT TYPES

 CONSTRUCTOR OVERLOADING  IN JAVA TO PRINT NUMBERS OF DIFFERENT TYPES class Print_Num { int i; float f; char c; double d; long l;     Print_Num(int ii)     {         i=ii;     }     Print_Num(float ff)     {         f=ff;     }     Print_Num(double dd)     {         d=dd;     }     Print_Num(long ll)     {         l=ll;     }     Print_Num(char cc)     {         c=cc;     }      } class Print {     public static void main(String ar[])     {         Print_Num i1=new Print_Num(11111);         Print_Num f1=new Print_Num(2.2f);         Print_Num c1=new Print_Num('3');         Print_Num d1=new Print_Num(23121321314.444);         Print_Num l1=new Print_Num(55555555l);                                    System.out.print("\ni1= "+i1.i);         System.out.print("\nf1= "+f1.f);         System.out.print("\nc1= "+c1.c);         System.out.print("\nd1= "+d1.d);         System.out.print("\nl1= "+l1.l);              } }

STATIC METHOD IN INTERFACE USING IMPLEMENTS KEYWORD

 STATIC METHOD IN INTERFACE USING IMPLEMENTS KEYWORD     interface Drawable{       void draw();       static int cube(int x){return x*x*x;}       }       class Rectangle implements Drawable{       public void draw(){System.out.println("drawing rectangle");}       }              class TestInterfaceStatic{       public static void main(String args[]){       Drawable d=new Rectangle();       d.draw();       System.out.println(Drawable.cube(3));       }} 

ABSTRACT CLASS AND INTERFACE INHERITANCE

ABSTRACT CLASS AND INTERFACE INHERITANCE interface IF1{    void m1();     void m2();} interface IF2{     void m3();} abstract class AC1 {          abstract void m4();         public void m5()         {                 System.out.println("THIS is method 5 in abstract class");         } } class Test1 extends AC1 implements IF1 {     public void m1()    {        System.out.println("THIS is method 1 in Test1 class");    }     public void m2()    {        System.out.println("THIS is method 2 in Test1 class");    }     public void m4()    {        System.out.println("THIS is method 4 in Test1 class");    } } class Test2 extends Test1 implements IF2 {     public void m3()     {         System.out.println("THIS is method 3 in Test2 class");     }     public void m6()     {         System.out.println("THIS is method 6 in Test2 class");         } } class ApplyTest {     public static void main(String srgs[]){     Test2 ob=new Test2();  

MULTIPLE INHERITANCE USING EXTENDS AND INTERFACE IN JAVA

MULTIPLE INHERITANCE USING EXTENDS AND INTERFACE IN JAVA    interface A1 {     void print(); } interface A2 {     void print2(); } interface All extends A1, A2 { void print3(); } class demo implements All { public void print()     {         System.out.println("PRINT DONE");     } public void print2()     {         System.out.println("PRINT DONE");     }      public void print3()     {         System.out.println("PRINT DONE");     } public static void main(String args[]) { demo obj=new demo(); obj.print(); obj.print2(); obj.print3(); } }

INTERFACE IMPLEMENTS AND DEFAULT METHOD IN INTERFACE

 INTERFACE IMPLEMENTS AND DEFAULT METHOD IN INTERFACE interface Drawable{   void draw();   default void msg(){System.out.println("default method");}   }   class Rectangle implements Drawable{   public void draw(){System.out.println("drawing rectangle");}   }   class TestInterfaceDefault{   public static void main(String args[]){   Drawable d=new Rectangle();   d.draw();   d.msg();   }} 

INTERFACE IMPLEMENTS IN JAVA

INTERFACE, INHERITANCE, IMPLEMENTS import java.util.Scanner; interface Employee {  String name;  int ecode;  void accept(); } class Manager implements Employee { Scanner sc=new Scanner(System.in);         int salary;     public void accept()     {         System.out.print("\nENTER VALUES\nNAME: ");         Employee.name=sc.next();             System.out.print("\nCODE: ");         Employee.ecode=sc.nextInt();         System.out.print("\nSALARY: ");         salary=sc.nextInt();     }     public void show()     {         System.out.print("\n NAME: "+Employee.name);         System.out.print("\n CODE: "+Employee.ecode);         System.out.print("\n SALARY: "+salary);     } } class Worker implements Employee {     Scanner sc=new Scanner(System.in);         int wages;     public void accept()     {         System.out.print("\nENTER VALUES\nNAME: ");         Employee.name=sc.next();             System.out.print("\nCODE:

SINGLE LEVEL INHERITANCE IN JAVA

SINGLE LEVEL INHERITANCE IN JAVA   class Employee {     String ename;     int ecode;     Employee()     {}     Employee(String n,int c)     {         ename=n;    ecode=c;     }     void show()     {         System.out.print("\nNAME: "+ename);         System.out.print("\nCODE: "+ecode);     } } class Manager extends Employee {     String dept_name;     int salary;     Manager()     {}     Manager(String n,int e,String d,int s)     {         super(n,e);         dept_name=d;        salary=s;     }     void show()     {         System.out.print("\nNAME: "+ename);         System.out.print("\nCODE: "+ecode);         System.out.print("\nDEPT_NAME: "+dept_name);         System.out.print("\nSalary: "+salary);     } } class pcsk {     public static void main(String[] args) {         Manager m=new Manager("ABC",23,"XYZ",2000);         System.out.print("\nDETALS OF MANAGER\n");         m.show();     } }

CALCULATE CYLINDER AND RECTANGLE USING INTERFACE

CALCULATE CYLINDER AND RECTANGLE USING INTERFACE AND INHERITANCE interface Area {     float pi=3.14f;     float compute(float a, float b); } class Rectangle implements Area {     public float compute(float a,float b)     {     return (a*b);     }      } class Cylinder implements Area {     public float compute(float a,float b)     {     return (pi*a*b);     }      } class Exe {     public static void main(String a[])     {         Area ob;         ob=new Rectangle();         System.out.println("RECTANGLE: "+ob.compute(22.5f,77.3f));                  ob=new Cylinder();         System.out.println("CYLINDER: "+ob.compute(22.5f,77.3f));              } }

HYBRID INHERITANCE

 HYBRID INHERITANCE class Employee {     String ename;     int ecode;     void accept(String n, int e)     {ename=n;     ecode=e;}     void show()     {System.out.print("Name: "+ename+" Age: "+ecode);} } class Manager extends Employee { int salary; void accept_s(int s) {salary=s;} void show_s() {System.out.print("\nSalary= "+salary);} } class Worker extends Employee { int wages; void accept_N(int w) {wages=w;} void show_W() { System.out.print("\nWages= "+wages); } } class Apprentice extends Worker { int noOfDays; void accept_a(int a) {noOfDays=a;} void show_a() { System.out.print("\nNo of days= "+noOfDays); } public static void main(String a[]) { Apprentice ob=new Apprentice(); System.out.print("\n"); ob.accept("AAA",111); ob.accept_N(4444); ob.accept_a(5555); ob.show(); ob.show_W(); ob.show_a(); Manager obb= new Manager(); obb.accept_s(22222); obb.show_s(); } }  

MULTI LEVEL INHERITANCE

 MULTI LEVEL INHERITANCE class Employee {     String ename;     int age;     void accept(String s,int a)     {         ename=s;         age=a;     } } class Manager extends Employee {     int sal;     void accept_sal(int m)     { sal=m;             } } class Dept extends Manager {     String deptname;     void accept_dept(String d)     {         deptname=d;     }     void show_all()     {         System.out.print("\nEmployee\n Name: "+ename);         System.out.print("\nAge: "+age);         System.out.print("\nSalary: "+sal);         System.out.print("\nDepartment: "+deptname);              }     public static void main(String ar[])     {         Dept ob=new Dept();         ob.accept("AAA",1);         ob.accept_sal(2000);         ob.accept_dept("XYYYZZZZ");         ob.show_all();     } }

PUSH POP DISPLAY STACK IN PYTHON

PUSH POP DISPLAY STACK  IN PYTHON   class stack:     def __init__(self):         self.top=0         self.stack=[]         self.maxx=int(input("Enter the array size: "))              def pushh(self,item):         self.top+=1         self.stack.append(item)              def popp(self):         if self.top!=0:             self.top-=1             print self.stack.pop()         else:             print "stack underflow"                  def display(self):         if self.top!=0:             print self.stack         else:             print("StacK underflow")      s1=stack() while(True):     print("\n\n1. display")     print("2. Pop top element" )     print("3. push an element")     print("4. exit")     ch=int(input("Enter the choice: "))     if ch==1:         s1.display()     elif ch==2:         s1.popp()             elif ch==3:         if s1.top<s1.maxx:             m=int(input("Enter value: "))     

REVERSE USING STACK

 REVERSE USING STACK IN PYTHON class stack:     def __init__(self):         self.top=0         self.stack2=[]         self.stack=[]         self.maxx=int(input("Enter the array size: "))         self.top2=self.maxx-1              def pushh(self,item):         self.top+=1         self.stack.append(item)              def popp(self):         if self.top!=0:             self.top-=1             print self.stack.pop()         else:             print "stack underflow"                  def display(self):         print "STACK IS: \n"         if self.top!=0:             print self.stack         else:             print "StacK underflow"         print "REVERSE STACK IS: \n"         if self.top2!=(self.maxx-1):             print self.stack2         else:             print("StacK underflow")                  def reverse(self):         self.stack2=[]         if self.top2!=0:             for i in range(len(self.stack)-1,-1,-1):               

FACTORIAL USING STACK

FACTORIAL USING STACK class stack:     def __init__(self):         self.top=0         self.stack=[]         self.m=0              def pushh(self,item):         self.top+=1         self.stack.append(item)              def popp(self):         if self.top!=0:             self.top-=1             print (self.stack.pop())         else:             print ("stack underflow")                  def display(self):         if self.top!=0:             print (self.stack)         else:             print("StacK underflow")          def factorialx(self):         for i in range(1,self.m +1 ):             self.stack.append(i)         n=1             for i in range(self.m,0,-1):             n=n*self.stack.pop()         return n                  s1=stack() while(True):     print("\n\n1. Enter value: " )     print("2. Factorial")     print("4. exit")     ch=int(input("Enter the choice: "))     if ch==1:         s1.m=int(input("Enter the value:

STACK IMPLEMENT IN PYTHON

 STACK class stack:     def __init__(self):         self.fb=0         self.sb=0         self.tb=0         self.top=0         self.stack=[]         self.maxx=int(input("Enter the array size: "))              def pushh(self,item):         self.top+=1         self.stack.append(item)              def popp(self):         if self.top!=0:             self.top-=1             print (self.stack.pop())         else:             print ("stack underflow")                  def display(self):         if self.top!=0:             print (self.stack)         else:             print("StacK underflow")      s1=stack() while(True):     print("\n\n1. display")     print("2. Pop top element" )     print("3. push an element")     print("4. check balanced or not")     print("5. exit")     ch=int(input("Enter the choice: "))     if ch==1:         s1.display()     elif ch==2:         s1.popp()             elif ch==3:        

QUEUE

 QUEUE   class Queue:     def __init__(self):         self.que=[]         self.fr=1         self.rr=0         self.maxx=int(input("Enter the array size: "))              def enque(self,item):         if self.rr<self.maxx:             self.rr+=1             self.que.append(item)         else:             print "Queue overflow"         #print "EN: ",q1.fr, q1.rr     def deque(self):         if self.fr<=self.rr:                          self.que=self.que[self.fr : ]             print self.que, self.fr         else:             print "Queue underflow"         #print "DE: ",q1.fr, q1.rr              def display(self):                  if self.fr<=self.rr:             print self.que         else:             print("Queue underflow")         #print "DD: ",q1.fr, q1.rr          q1=Queue() #print q1.fr, q1.rr while(True):     print("\n\n1. display")     print("2. Dequeue an element" )     print(&q

CIRCULAR QUEUE

 CIRCULAR QUEUE #circular queue class Queue:     def __init__(self):         self.que=[]         self.fr=1         self.rr=0         self.maxx=int(input("Enter the array size: "))     def enque(self,item):         if self.rr<self.maxx:             self.rr+=1             self.que.append(item)         else:             print "Queue overflow"         #print "EN: ",q1.fr, q1.rr     def deque(self):         if self.fr<=self.rr:             self.rr=self.rr-1             self.que=self.que[self.fr : ]             #print self.que, self.fr         else:             print "Queue underflow"         #print "DE: ",q1.fr, q1.rr     def display(self):         if self.fr<=self.rr:             print self.que         else:             print("Queue underflow")         #print "DD: ",q1.fr, q1.rr q1=Queue() #print q1.fr, q1.rr while(True):     print("\n\n1. display")     print("2. Dequeue an element" )     pri

PRIORITY QUEUE

  PRIORITY QUEUE  # 7. write a p to implement a priority queue? class PriorityQueue(object):     def __init__(self):         self.queue=[]     def __str__(self):         return ' '.join([str(i) for i in self.queue])     def isEmpty(self):         return len(self.queue)==[]     def insert(self,data):         self.queue.append(data)         def delete(self):         try:             max=0             for i in range(len(self.queue)):                 if self.queue[i] >self.queue[max]:                     max=i             item=self.queue[max]             del self.queue[max]             return item         except IndexError:             print()             exit() myQueue=PriorityQueue() myQueue.insert(12) myQueue.insert(1) myQueue.insert(14) myQueue.insert(7) print("INSERTED ELEMENTS ARE: ",myQueue) while not myQueue.isEmpty():     print("DELETED: ",myQueue.delete())

CONVERT INFIX EXPRESSION INTO POSTFIX EXPRESSION

 CONVERT INFIX EXPRESSION INTO POSTFIX EXPRESSION   #Formulate a program to convert infix #expression into postfix expression. class Stack:     def __init__(self):         self.items=[]         self.length=0     def push(self,val):         self.items.append(val)         self.length+=1     def pop(self):         if self.empty():             return None         self.length-=1         return self.items.pop()     def size(self):         return self.length     def peek(self):         if self.empty():             return None         return self.items[0]     def empty(self):         return (self.length==0)     def __str__(self):         return str(self.items) def convert(expression):     print(__convert(expression.split())) def __convert(tokens):     postfix=[]     opstack=Stack()     precedence={}     precedence['*']=3     precedence['/']=3     precedence['+']=2     precedence['-']=2     precedence['(']=1     for token in tokens:         if token.iside

CONVERT INFIX EXPRESSION TO PREFIX EXPRESSION

 CONVERT INFIX EXPRESSION TO PREFIX EXPRESSION   #3. Compose a program to convert infix exp  into prefix expr. class infix_to_prefix:     precedence={'^':5,'*':4,'/':4,'+':3,'-':3,'(':2,')':1}     def __init__(self):         self.items=[]         self.size=-1     def push(self, value):         self.items.append(value)         self.size+=1     def pop(self):         if self.isempty():             return 0         else:             self.size-=1             return self.items.pop()     def isempty(self):         if self.size==-1:             return True         else:             return False     def seek(self):         if self.isempty():             return False         else:             return self.items[self.size]     def isOperand(self,i):         if i.isalpha() or i in '1234567890':             return True         else:             return False     def reverse(self,expr):         rev=""         for i in expr:   

EVALUATE POSTFIX EXPRESSION

EVALUATE POSTFIX EXPRESSION #2. W.a.p. to evaluate any postfix expression class Evaluate:     #Consider to evaluate the class variable     def __init__(self,capacity):         self.top=-1;                 self.capacity=capacity;        #This array is used a stack         self.array=[]     #check if the stack is empty     def isEmpty(self):         return True if self.top==-1 else False     #Return the value of the top of the stack     def peek(self):                 return self.array[-1]     #Pop the element from the stack     def pop(self):         if not self.isEmpty():             self.top-=1;                         return self.array.pop()         else:                         return "$"     #Push the element to the stack     def push(self,op):         self.top+=1         self.array.append(op) #The main function that converts given infix expression #to postfix expression     def evaluatePost(self,exp):         #Iterate over the expression for conversion         for i in e

EVALUATE PREFIX EXPRESSION

EVALUATE PREFIX EXPRESSION   class evaluate_prefix:     def __init__(self):         self.items=[]         self.size=-1     def isEmpty(self):         if self.size==-1:             return True         else:             return False     def push(self,item):         self.items.append(item)         self.size+=1     def pop(self):         if self.isEmpty():             return 0         else:             self.size-=1             return self.items.pop()     def seek(self):         if self.isEmpty():             return False         else:             return self.items[self.size]                  def evaluate(self,expr):         for i in reversed(expr):             if i in '0123456789':                 self.push(i)             else:                 op1=self.pop()                 op2=self.pop()                 result= self.cal(op1, op2, i)                 self.push(result)         return self.pop()     def cal(self,op1, op2, i):         if i is "*":             return int(op1)*

EVALUATE PREORDER TO POSTORDER EXPRESSION

EVALUATE PREORDER TO POSTORDER EXPRESSION class preTOpost:     def __init__(self):         self.items=[]         self.size=-1     def  push(self,value):         self.items.append(value)         self.size+=1          def popp(self):     #    print("pop")         if self.isempty():             return 0         else:             self.size-=1             return self.items.pop()     def isempty(self):         if self.size==-1:             return True         else:             return False                      def reverse(self,expr):         rev=""         for i in expr:             if i is '(':                 i=')'             elif i is ')':                 i='('             rev=i+rev         return rev            def pretoPOST(self,rev):         for i in rev:             if i in '-/*+^':                 a=str(self.popp())                 b=str(self.popp())                 #print(type(a))                 temp=a+b+i                

PYTHON STRING REVERSE

PYTHON STRING REVERSE def reverse(str):     revstr=""     for i in str:         revstr=i+revstr     print("reversed string is : ",revstr) string=input("Enter the string: ") print("Entered string is: ",string) reverse(string)

JAVA STRING ANAGRAM PROGRAM

JAVA  STRING ANAGRAM PROGRAM /* Exercise: An anagram is a word or a phrase made by transposing the letters of another word or phrase; for example, "parliament" is an anagram of "partial men" and "Software" is an anagram of "swear oft". Write a program that figures out whether ine string is an anagram of another string. The Program should ignore white space and punctuation. */ import java.util.*; import java.io.*; class demo {     static boolean areAnagram(char []str1, char []str2)     {         int n1=str1.length;    int n2=str2.length;         //System.out.print(n1);         if(n1!=n2)             return false;         Arrays.sort(str1);         Arrays.sort(str2);         for(int i=0; i<n1; i++)         {             if(str1[i] != str2[i])                 return false;         }         return true;     }     public static void main(String[] args) {         char str1[]={'t','e','s','t'};         char str2[]={&#

JAVA STRING TOKENIZER

JAVA STRING TOKENIZER /*counting word in String using StringTokenizer */ import java.util.*; public class StringTokenizerx //extends Object implements Enumeration<Object> {     public static int countWordsUsingStringTokenizer(String sentence)     {         if(sentence==null || sentence.isEmpty())         {             return (0);         }         StringTokenizer tok = new StringTokenizer(sentence);         return (tok.countTokens());     }          public static void main(String[] args) {         Scanner sc=new Scanner(System.in);         System.out.print("\nEnter : ");         String input;         input=sc.nextLine();         int len=countWordsUsingStringTokenizer(input);         System.out.println("\nTotal Number of Words Are: "+len);     } }

JAVA STRING BYTE ARRAY OBJECT

 JAVA STRING BYTE ARRAY OBJECT /* 6. WAP in Java to print the palindrome word from a sentence. */ import java.lang.*; import java.io.*; import java.util.*; class ReverseString {         static void cal(String input)     {         //getBytes() method to convert string         //into bytes[]         byte strAsByteArray[]=input.getBytes();         byte result[]=new byte[strAsByteArray.length];         //store result in reverse order         // into the result byte[]         for (int i=0; i< strAsByteArray.length; i++)         {             result[i]=strAsByteArray[strAsByteArray.length-i-1];         }         String n=new String(result);         if(n.equals(input))             System.out.print("\n "+n);                           }     public static void main(String[] args) {         String input;         Scanner sc=new Scanner (System.in);         System.out.print("\nInput: ");         input=sc.nextLine();         int i=0,p=0;         int len=input.length();       

JAVA .REPLACE

JAVA STRING  .REPLACE   /* 5. WAP in Java to print when letters and corresponding frequency in a sentence. */ import java.util.*; class Test {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         String name;         System.out.print("\nENTER ANY NAME: ");         name=sc.nextLine();         String ns2=(name.charAt(0)+". ");         String ns="";                int i=0,j=1;         int sch=0;          name.toLowerCase();         int len=name.length();         name.toLowerCase();         System.out.print("\n"+name+"\n");         String s;         char n;         char m2=' ';         while(i<len)         {                name=name.replace(m2,' ');             sch=1;             n=name.charAt(i) ;             s=Character.toString(n);                 j=i+1;                        while(j<len)             {                     char m=name.charAt(j);                    if(m=