Posts

What is java

Java is a Object Oriented Programming Language. Java programming language is widely used in many areas like web development and gaming applications. Java is a simple, easy to use, platform independent programming language which is used for many purposes.   The features of Java Programming language are: Abstraction : is a process of hiding information and showing the essential information.  Encapsulation: storing data members and methods in a single unit called class Inheritance: Inheritance simply refer to code reusability. Where a class inherits properties from the class or interface. Platform independent programming language Multithreaded: Java programming language is a multithreaded programming language.   Java comes in various editions to cater to various types of application development needs. Two key editions of Java are: Java Standard Edition Java Enterprise Edition   To learn Java programming fundamentals, we need Java SE. Java SE (Standard Edition) This edit...

How to find Duplicate elements in an array in C

  #include<stdio.h> int main () { int n , i , j , flag = 0 , arr [ 20 ]; printf ( "Enter size of array : \n" ); scanf ( "%d" ,& n ); printf ( "array element are =\n" ); for (i = 0;i<n;i++) { printf("\n arr[%d]= ",i); scanf("%d",&arr[i]); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(arr[i]==arr[j]&&i!=j) { flag=1; printf("Duplicate number position are %d and %d",i,j); } } } if(flag==0) printf("no duplicate"); } Output: Enter size of array : 5 array element are =  arr[0]= 2  arr[1]= 3  arr[2]= 4  arr[3]= 3  arr[4]= 6 Duplicate number position are 1 and 3

The Days Calculator if User Enters the Count of Year

 #include<stdio.h> int main () { int days ; float yrs ; printf ( "Enter your age =\n" ); scanf ( "%f" ,& yrs ); days = yrs * 365 ; printf ( "%d days you are old" , days ); } Output: Enter your age = 18 6570 days you are old

Deleting an array element in C programming language

 #include<stdio.h> int main () { int i , n , pos , arr [ 10 ]; printf ( "Enter size of array =\n" ); scanf ( "%d" ,& n ); for ( i = 0 ; i < n ; i ++) { printf ( "\narr[%d]=", i ); scanf ( "%d" ,& arr [ i ]); } printf ( "\n Enter position want to delete =" ); scanf ( "%d" ,& pos ); for(i = pos ; i < n - 1 ; i ++) arr [ i ]= arr [ i + 1 ]; n --; printf ( "Array after deletion\n" ); for ( i = 0 ; i < n ; i ++) { printf ( "\narr[%d]=%d" , i , arr [ i ]); } } Output: Enter size of array = 4 arr[0]=3 arr[1]=4 arr[2]=2 arr[3]=1  Enter position want to delete =2 Array after deletion arr[0]=3 arr[1]=4 arr[2]=1

program to check odd even number by using C++ programming langiage

 #include<iostream> using namespace std ; int main () { int i , sum ; cout << "enter any number : " ; cin >> i ; if ( i % 2 == 0 ) { cout << i << " is a even number " ; } else { cout << i << " is a odd number " ; } return 0 ; } Output: enter any number : 22 22 is a even number

Imagine a publishing company that markets both book and audiocassette versions of its works. Create a class publication that stores the title (a string) and price (type float) of a publication.

  Question : Imagine a publishing company that markets both book and audiocassette versions of its works. Create a class publication that stores the title (a string) and price (type float)  of a publication. From this class derive two classes: Book, which adds a page count (type int), and Tape, which adds a playing time in minutes (type float). Each of these three classes should have a getdata() function to get its data from the user at the keyboard, and a putdata() function to display its data. Write a main() program to test the book and tape classes by creating instances of the asking the user to fill in data with getdata(), and then displaying the data with put. Program:   #include<iostream> #include<string> using namespace std; class publication {     protected:     string title ;     float price ;      public:     publication ()     {         title =" ";   ...

Binary search in C++

 #include<iostream> using namespace std ; int main () { int i , found = 0 , num , n , arr [ 100 ], mid , low , high ;  // declaration and initialization of variables cout << "enter the size of array\n" ;    //prints the msg in double colon cin >> n ;    //stores the value in n for ( i = 0 ; i < n ; i ++)   //for loop { cout << "\n arr[" <<i<< "] = " ;      //for block cin >> arr [ i ];        //for block } cout << "Enter number to be search\n" ;   //prints the msg in double colon cin >> num ;    //stores the value in n low = 0 ;    //initialization of low  to 0 high = n - 1 ;     //initialization of high to n-1 while ( low <= high )    //while loop { mid =(l ow + high )/ 2 ; if ( arr [ mid ]== num ) { cout << "Enter element is found" ; break ...

Selection sort in C++

 #include<iostream> using namespace std ; int main () { int min , i , j , temp , a [ 100 ], n ; cout << "\tSelection sort" ; cout << "\nEnter size of array=\t" ; cin >> n ; cout << "\nEnter actual array element:\n" ; for ( i = 0 ; i < n ; i ++) cin >> a [ i ]; for ( i = 0 ; i < n ; i ++) { min = i ; for ( j = i + i ; j < n ; j ++) { if ( a [ min ]> a [ j ]) min = j ; } temp = a [ i ]; a [ i ]= a [ min ]; a [ min ]= temp ; } cout << "\nResultant array=\n" ; for ( i = 0 ; i < n ; i ++) cout << a [ i ]<< " " ; } Output:  Selection sort Enter size of array=    5 Enter actual array element: 9 7 8 4 6 Resultant array= 4 6 7 8 9

Bubble sort in C++

  #include<iostream>  //header file using namespace std ;     //header file int main ()    //main function { int i , j , temp = 0 , n , a [ 20 ];      //declaration and initialization of variables cout << "Enter the array size : \n" ;    //prints the msg on output screen cin >> n ;  //stores value in variable n cout << "\nEnter the array element:\n" ;    //prints the msg on output screen for ( i = 0 ; i < n ; i ++)    //for loop runs from i=0 to i=n-1 cin >> a [ i ];       //stores value in a[i] for ( i = 0 ; i < n ; i ++)    //for loop runs from i=0 to i=n-1 { for ( j = 0 ; j < n - i ; j ++)      //for loop runs from j=0 to j=n-i { if ( a [ j ]> a [ j + 1 ])    //if block { temp = a [ j ];      //storing value of a[j] in temp a [ j ]= a [ j + i ];...

How to use pure virtual function in C++

 #include<iostream>    //header file using namespace std ;      // header file class shape    // creating class of name shape { protected :    // access specifier float dim ;    // protected variable of data type float of name dim is declared public :        // access specifier void getdim ()        // member function in public access specifier { cin >> dim ;        } virtual float caldata ()= 0 ;      // pure virtual function declaration };      //end of class shape  (end of class should be by the semicolon) class square : public shape    //class square derived from class shape   { public :        // access specifier float caldata ()        // function definition { return dim*dim ;      //functi...