First C++ Program

how to write your first c++ program

Last Reviewed and Updated on February 7, 2020
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

My C/C++ Videos on Youtube

Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.

About C and C++

  1. A C/C++ program is a sequence of sentences called statements.
  2. C program is written inside a file with extension .c, and a C++ program is written inside a file with extension .cpp.
  3. C was the first to come. C++ came afterwards. C++ is an extended form of C. It is not something different. Everything of C is a part of C++.
  4. A compiler is a software. It is used to compile your statements into an executable file that can be double clicked and run.

What is a preprocessor?

  1. Used to transform your code before compilation. The transformation means including external pre-written header files, and making replacements and substitutions for macros wherever required. In the code below a macro called SIXTY has been defined as 60. Wherever your files contain SIXTY, it will be replaced it by 60. This is just an example.
    
    #define SIXTY    60
    
    cout << SIXTY << endl;
    
    wll become
    
    cout << 60 << endl;
    
  2. Macros are used to increase the readability of code.

What are the various steps in compilation of a C/C++ code?

  1. Program writes code in a .c or .cpp file.
  2. Preprocessing is done with the preprocessor
  3. Compiler software does syntax checks
  4. Linker software does the job of memory allocation for various variables and objects.
  5. Lastly, the code is converted into an exe file.

Example 1

Write a program that displays the following output using printf or cout.

C language developed at AT & T Bell labs in 1972 by Dennis Ritchie.
C-C++ is the base of every programming language.
Used to develop softwares, websites etc...

#include<iostream>
#include<cstdio>

using namespace std;
 
int main()
 {
    cout << "C language developed at AT & T Bell labs ";
      
    cout << "in 1972 by Dennis Ritchie.\n";
     
     cout << " C-C++ is the base of every programming language.\n";
      
     printf("Used to develop softwares, websites etc... \n");
      
     return 0;
          
 }

Print your name

Write a program to display your name on the screen.
#include<iostream>
#include<cstdio>
 
int main()
{
     printf("Hoven Trainings") ;
     
      return 0;
}

Area of a square

Write a program to find area of square whose side is 20.

#include<iostream>
#include<cstdio>
 
int main()
{
    cout << "Area = " << (20 * 20) << endl;
     
     return 0;
}

Circumference of circle

Write a program to find the circumference of circle whose radius is 10.

#include<iostream>
#include<cstdio>
 
int main()
{

    cout << "Circumference = " << (2 * 3.14 * 10) << endl;
     
     return 0;

}

Print about yourself using printf

Print some statements about yourself using printf.

#include<iostream>
#include<cstdio>
 
int main()
{ 

    printf("My name is Hoven \n");
 
    printf("I live in Punjab \t");
 
    printf("I am a student of Engineering");
 
    return 0; 

}

Display

Write a program to print following using printf and cout

Program's execution always starts with main() function.
printf use to print or display the output.
cout is alternate method to print or display the output. 

#include<iostream>
#include<cstdio>

using namespace std;
 
int main()
{ 

     printf("Program's execution always starts with main() function.\n");

     printf("printf use to print the value.\n");

     cout << "cout and print are used to display the output." << endl;
 
     return 0;

}
 

Draw a pattern

Write a program to display "C++" using spaces and stars.
#include<iostream>
#include<cstdio>

using namespace std; 
 
int main() 
{ 
 cout << " * * * * * " << endl;

 cout << " * * * " << endl;    

 cout << " * * * " << endl;

 cout << " * * * * * * * * * * * * * " << endl;

 cout << " * * * " << endl;

 cout << " * * * " << endl;

 cout << " * * * * * " << endl;
     
 return 0;

}

Display pattern using cout and reverse using printf

Display the following pattern. The upper part should be displayed with cout, and the lower part should be done with printf.

 *
 * *
 * * *
 * * * *
 * * * * *
-----------
 * * * * *
 * * * *
 * * *
 * *
 *
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    cout << " * " << endl;

    cout << " * * " << endl;

    cout << " * * * " << endl;

    cout << " * * * * " << endl;

    cout << " * * * * * " << endl;

    cout << "-----------" << endl;

    printf(" * * * * * \n");

    printf(" * * * * \n");

    printf(" * * * \n");

    printf(" * * \n");

    printf(" * \n");


    return 0;

}

 

Classroom Training

Classroom training in C/C++ is available at our training institute. Click here for details. You can also register yourself here.

Video Tutorial

We have created a video tutorial that can be downloaded and watched offline on your windows based computer. It is in the form of an exe file. No installation is required, it runs by double clicking the file. Since the exe file is hosted on the Google Drive, it should be very safe because Google itself checks for any virus or malware. The video can be watched offline, no internet is required.

Pricing

This single video will cost you USD $5. When you download the video, you will be able to watch the first few minutes for free, as a sample. The video app will prompt you for payment through PayPal and other payment options. If you want ALL VIDEOS, NOT JUST THIS ONE then go here: Complete Set of C/C++ Video Tutorials The entire set is priced at USD $50.

Screenshots

This is a screenshot of the software that should give you a good idea of the available functionality. Click on the image to see a larger view.screenshot of the video being played in the software

Installation

This software doesn't require any installation. Just download and double-click to run it. It doesn't require administrative priviliges to run. It runs in limited access mode, so should be very safe.

supports windows xp and later Supported Operating Systems

These videos can be run on 32-bit as well as 64-bit versions of the Microsoft Windows Operating Systems. Windows XP and all later OS are supported. If you want to run it on Windows XP and Windows Vista, then you must also have the .NET Framework Version 3.5 installed on your machines. Those users who have Windows 7 and later donot have to worry because these operating systems already have the .NET Framework installed on them.

Download Links

IMPORTANT NOTE: This download contains ONLY ONE video. The video is about the topic of this tutorial.

Want ALL Videos? If you want ALL VIDEOS, NOT JUST THIS ONE then go here: Complete Set of C/C++ Video Tutorials. TIP: If you plan to buy these videos, then it would be more economical to buy the entire set.

DISCLAIMER: Even though every care has been taken in making this software bug-free, but still please take a proper backup of your PC data before you use it. We shall not be responsible for any damages or consequential damages arising out of the use of this software. Please use it solely at your own risk.

Please download the software here.
download the video First C++ Program



Creative Commons License
This Blog Post/Article "First C++ Program" by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2020-02-07. Published on: 2015-10-05