Pages

Monday, November 19, 2012

Getting Started With C and C++


Welcome to this blog which is about C and C++ programming language. This blog will discuss about the popular C and C++ programming language from beginning to professional level. Visiting step by step through this blog, you will able to know how to create professional software with this high-level language. So, no more talking but before starting, you need to be familiar with the background of C and C++ programming language. Below section will show the history and the necessary discussion before starting C and C++ language.

Programming Language 

Language is used to communicate with each other. But programming language is specially used for computer to communicate with its user. As computer understands nothing except 0 and 1, its user should build an instruction set which is combination with 0 and 1 named as machine language. So a compiler is necessary to interpret user’s symbolic word to computer readable instruction set. As a demand, programming language comes out.
From the above discussion, Programming Language is defined as an instruction set, word or code which is readable to the computer and used to solve any practical problem by the computer.

Types of programming language

Programming languages are divided into two types…
  •  Low-level language: This is directly readable by the computer. Such as machine language and assembly language.
  • High-level language: An interpreter is necessary for these languages to translate human readable code to machine readable code. C, C++, lava, C#, Visual Basic etc are the example of high-level language.
  What are C and C++?
  • C which was created by Dennis Ritchie at Bell Laboratories at 1972 is one of the most popular high-level  computer languages. It is treated as a God language of computer programming.
  •  C++, an extension of C, was developed by Bjarne Stroustrup in the early 1980s to overcome the limitation of C. C++ contains all the functionality of C language with some extra features including object-oriented capabilities discussed later in details in this blog. Today, most of the general-purpose operating system like windows is written in C or C++ language.         
Advantages of C and C++ language
  •   Easy to learn than other high-level programming language.
  •    Platform independent language.
  •   Easy to control both hardware and software.
  •     Both modular and object-oriented programming capability.
  •    Operating system programming capability.
  •   Capable of programming both microcontroller and microprocessors.
  •    The best hardware friendly programming language.
  •    More Speedy.
For the above functionalists, C and C++ are the most popular modern language.

Programmer view on C and C++

There are a lot of computer programming languages. All of these, C/C++ provides easy syntax and functionality. So, at the beginning most of the programmers suggest to start with C and C++ programming. I also started my programming concept with this language and it is one of my favorite languages. I think you are lucky if it is your starting point in programming language.   
 
Prerequisites to learn C and C++
  • Educational Quality: No specific certificate is necessary. Anyone who is eligible to read this tutorial is able to learn C and C++.
  •  Operating System Quality: Some basic knowledge about windows operating is suggested but not so necessary for this tutorial. Playing with C and C++ anyone can be familiar with the operating system. 
  • Necessary Software: A C++ compiler and an IDE (Integrated Development Environment) are strongly necessary. There are a lot of IDEs to edit and compile program but among these we will use a Turbo C++ 4.0 for windows operating system. Download Turbo C++ 4.0 or 4.5 and start coding.
Now you are ready to start first program in C and C++ programming. Open your IDE (Turbo C++ 4.0) and create a new file named first.cpp. Every C and C++ should have .cpp extension to indicate that it is a C and C++ file. Do the following code and run the program with Ctrl+F9 key or Run> Run. If everything is OK, you will get the below output.

First program in C and C++

#include<stdio.h>
#include<conio.h>

void main()
{
 clrscr();
 printf("Welcome to C and C++ programming.");
 getch();
}


Program Output




Sunday, September 4, 2011

Finding Maximum Logical Drives with C and C++

This article will show how to know the current drive’s name and the maximum logical drives that your system supports with C and C++. The getdisk () function is used to show the current drive name and the setdisk () function is used to know the maximum logical drives of any system. The programming code to find Maximum Logical Drives with C and C++ is given below.


#include<stdio.h>
#include<conio.h>
#include<dir.h>

void main()
{
  clrscr();
  int disk, maxdrive;
  disk=getdisk()+'A';
  maxdrive=setdisk(2);
  printf("Current drive is : %c\n",disk);
  printf("Maximum logical drive is:%d\n",maxdrive);
  getch();
}

Output

Wednesday, August 31, 2011

Two Dimensional Array Program with C and C++

This article will show how to find boundary elements and higher and lower level elements of a matrix or a two dimensional array with C and C++ program. The following program will first take user inputs to build a two dimensional array or a matrix and then show the matrix, the boundary elements and the sum of the boundary elements, diagonal elements and its sum. Here, for loop is used to set and retrieve array elements. 


Programming code to find boundary elements and higher and lower level elements of a matrix.

#include<stdio.h>
#include<conio.h>
void main()
{
  int a[5][5],m,n,sum=0;
  printf("Enter row :");
  scanf("%d",&m);
  printf("Enter coloum :");
  scanf("%d",&n);
  printf("Enter matrix element :\n");
  for(int i=0;i<m;i++)
  {
            for(int j=0;j<n;j++)
            {
              printf("a[%d][%d]=",i,j);
              scanf("%d",&a[i][j]);
            }
  }
  printf("\nMatrix is : \n");
  for(i=0;i<m;i++)
  {
            for(int j=0;j<n;j++)
            {
              printf("%d\t",a[i][j]);
            }
            printf("\n");
  }
  printf("\nBoundary element :");
  for(i=0;i<m;i++)
  {
            for(int j=0;j<n;j++)
            {
              if((i*j==0)||(i==m-1)||(j==n-1))
              {
                        printf("%d  ",a[i][j]);
                        sum=sum+a[i][j];
              }
            }
  }
  printf("\nSum of boundary element is : %d",sum);

 printf("\nHigher level : ");
 sum=0;
 for(i=0;i<m;i++)
 {
   for(int j=0;j<n;j++)
   {
             if(i==j)
             {

               printf("\t%d",a[i][j]);
               sum=sum+a[i][j];
             }
   }

 }
  printf("\nSum of higher level = %d",sum);

  printf("\nLower lavel : ");
  sum=0;
  i=m;
  for(int j=0;j<n;j++)
  {
            i=i-1;
            printf("\t%d",a[i][j]);
            sum=sum+a[i][j];
  }
  printf("\nSum of lower level = %d",sum);
  getch();
}

Output