C++ Programming Tutorial

 
 
 

Basic Programming

Input - Output - Variables - Constants

Print text Count number of words, lines and chracters Read 2 numbers from user - computes sum Size, addr of variable of type int , float, char Declaration , initialization, print constant vari Reference variables

Bitwise Operators

Bitwise operator OR ( | ) Bitwise Operator AND (&) Bitwise Operator XOR ( ^ ) Bitwise Operator Left Shift ( << ) Bitwise Operator Right Shift ( >> )

Conditional Statements

Reads marks - test of 100 marks - print pass Reads number and prints even or odd number Read, compute, display grade using switch case Read marks, compute grade using if else Compute, display result - ternary operator ( ? : ) Read integers, operator, evaluate - switch case

Loops - Continue/Break Statement

Prints 10 integers using for loop Display sum of ten integers using for loop Print odd numbers from 0 to 50 using for Loop Compute, displays num factorial using for loop Histogram using nested for loop Print a diamond using nested for loop Square of ten integers using for loop Print 20 integers using while loop Print 20 int in reverse order using while loop Odd num, even num, divisible by 5 b/w 0 to 50 Display num digits in reverse order - while loop Display num in reverse order - do while loop Display factorial using do-while loop Even num - 0 to 50 - while, do-while, for loop Use of the break statement Use of the continue statement

Functions

Use of parameterless function Largest int among 3 - function with no return type Largest int among 3 - function with return type Use of call-by-value method in functions Use of call-by-refrence method in functions Use of inline functions Use of default argument function Use of function overloading Find distance b/w 2 points - function overloading Example of function overloading Example if built-in function Compute nCr Built int functions strcomp, strcmpi, stricmp Storage class Auto, Static with global variable

Arrays

Find largest element of an array Initialize array by even numbers display sum Reverse the content of an integer array Histogram using array Print an array using function definition Read marks of students display total marks, status Whole array, single array elmt as parameter to fn Bubble sorting of arrays Search element in an array - Linear search Search element in an array - Binary search Read 2D array, display it row by row and sum

Pointers - Strings

Use of operator * and & Supplying of values to pointer variables Adding values to the contents of variables Use of pointer to pointers Functions returning pointers Operations performed on pointers 2D array of int using pointers 2D array of char (string) using pointers Srray before and after adding 5 to its contents Use of call-by-reference method using pointers Sum, smallest, largest element an array pointers Features of array of char known as string Example of constant pointers to non-constant data

Recursion

Computes and displays the factorial of number Computes n_th term of the fibonacci series Towers of Hanoi Problem

General Programs

Find Book in the list of Books Year is a leap year or not Swap two variables using header file swap.h Find day of a week of a given date using arrays Convert decimal into binary, octal, pental code Covert given decimal into Roman Code Covert given Decimal into English Code Add two integers without using + operator Factorial of first five elements of the fibonacci Add two integers of any length Non-Linear function in one variable and evaluate
 
 

Image

 # include <iostream.h>
 # include <conio.h>

 int binary_search(int [],int,int);


 main( )
    {
       clrscr( );

       const int array_size=10;
       int array[array_size]={0,6,9,12,20,23,29,32,47,79};

       cout<<\" ******************************************************************************\"<<endl;
       cout<<\" *******************************  Binary Search  ******************************\"<<endl;
       cout<<\" ******************************************************************************\"<<endl;

       gotoxy(1,24);
       cout<<\" ******************************************************************************\"<<endl;
       cout<<\" ******************************************************************************\";

       gotoxy(1,5);
       cout<<\"\\n The contents of the array are : \"<<endl;

       cout<<\"\\n     Elements :\"<<\"\\t\\t     Value:\"<<endl;

       for(int count=0;count<array_size;count++)
      {
         cout<<\"\\t\"<<\" array [\"<<count<<\"]\"<<\"\\t\\t\";
         cout<<array[count]<<endl;
      }

       int searching_element=0;
       int flag=0;

       cout<<\"\\n Enter the element you want to find  =  \";
       cin>>searching_element;

       flag=binary_search(array,array_size,searching_element);

       if(flag!=-1)
      cout<<\"\\n The given element is found at the position  array[\"<<
                                   flag<<\"]\";

       else
      cout<<\"\\n The given element is not found. \";

       getch( );
       return 0;
    }


 /***********************  binary_search(int [],int,int)  *****************/


 int binary_search(int array[],int array_size,int element)
    {
       int start=0;
       int end=array_size-1;
       int middle;
       int position=-1;

       middle=(start+end)/2;

       do
      {
         if(element<array[middle])
        end=middle-1;

         else if(element>array[middle])
        start=middle+1;

         middle=(start+end)/2;
      }
       while(start<=end && array[middle]!=element);

       if(array[middle]==element)
      position=middle;

       return position;
    }

    Related Post:
  1. Program that sorts numbers using topological sort method

  2. Program to illustrate pointers , structure and passing structure pointers to function.

  3. Program to read a Linear System of Equations,then evaluate it by using Gauss-Elimination Method and show the result

  4. Program that computes the n_th term of the fibonacci series using recursion

  5. Template based array input

  6. Problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs

  7. Program of construction overloading

  8. Implement a Matrix class representing 2-dimensional matrix with the following functionalities i.e. operators + , - , * , == , += &lt;&lt; , &gt;&gt; etc

  9. Linear Interpolation

  10. Program of class and objects using private and public data members

  11. Program to read a Non-Linear equation in one variable, then evaluate it using Simple Itrative Method and display its kD accurate root

  12. CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS

  13. Program to show the implementation of Window-to-Viewport Coordinate Transformaton

  14. Program of Graphical Representation of Stack And Queue

  15. Program of singly link list

  16. Program to estimate the value of Fourth Derivative of the function at the given points from the given data using Central Difference Formula of order 2

  17. Inventory Management System

  18. Program to find number of days b/w two given dates

  19. Program of addition and subtraction of large numbers

  20. Program to illustrate template classes

 
 
Didn't find what you were looking for? Find more on Program to search an element in an array using Binary search