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()"...

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;    ...

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): ...

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<<"]: ";         ...

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]; ...

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: co...

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;        ...

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: "+...

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_ag...

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));     }        ...

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);    ...

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()    {   ...

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); ...

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()    ...

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();       ...

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("\nSalar...

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"         ...

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:     ...

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): ...

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:   ...

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:        ...

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=se...

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  ...

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       ...

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:       ...

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():        ...

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()    ...

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:  ...

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++)    ...

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;        ...

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];         }      ...

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();  ...