page-header-img

C++

C++ Tutorial

c plus training in vizag

C++ tutorial provides basic and advanced concepts of C++. Our C++ tutorial is designed for beginners and professionals.

Programming in C++ follows an object-oriented design. It is a C programming extension.

Everything from the first example to control statements, objects and classes, inheritance, constructors and destructors, this, static, polymorphism, abstraction, abstract class, interface, namespace, encapsulation, arrays, strings, exception handling, File IO, and more is covered in this comprehensive C++ course.

c plus training in vizag

What is C++

Object-oriented, procedural, and generic programming are all supported by the general-purpose, case-sensitive, free-form programming language C++.

C++ is a middle-level language, as it encapsulates both high and low level language features.

Object-Oriented Programming (OOPs)

The four main pillars of object-oriented programming (OOPs), which are supported by C++, are as follows:

  1. Inheritance
  2. Polymorphism
  3. Encapsulation
  4. Abstraction

C++ Standard Libraries

Standard C++ programming is divided into three important parts:

  • The core library includes the data types, variables and literals, etc.
  • The standard library includes the set of functions manipulating strings, files, etc.
  • The Standard Template Library (STL) includes the set of methods manipulating a data structure.

c plus training in vizag

Usage of C++

The C++ programming language allows us to create a variety of reliable and safe programs, including:

  • Window application
  • Client-Server application
  • Device drivers
  • Embedded firmware etc

C++ Program

In this tutorial, all C++ programs are given with C++ compiler so that you can easily change the C++ program code.

File: main.cpp

  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.    cout << “Hello C++ Programming”;
  5.    return 0;
  6. }

C++ Control Statement

C++ if-else

In C++ programming, if statement is used to test the condition. There are various types of if statements in C++.

  • if statement
  • if-else statement
  • nested if statement
  • if-else-if ladder

C++ IF Statement

The C++ if statement tests the condition. It is executed if condition is true.

  1. if(condition){
  2. //code to be executed  
  3. }

Cpp If else 1


C++ If Example

  1. #include <iostream>
  2. using namespace std;
  3. int main () {
  4.    int num = 10;
  5.             if (num % 2 == 0)
  6.             {
  7.                 cout<<“It is even number”;
  8.             }
  9.    return 0;
  10. }

Output:/p>

It is even number

C++ IF-else Statement

The C++ if-else statement also tests the condition. It executes if block if condition is true otherwise else block is executed.

  1. if(condition){
  2. //code if condition is true  
  3. }else{
  4. //code if condition is false  
  5. }

Cpp If else 2


C++ If-else Example

  1. #include <iostream>
  2. using namespace std;
  3. int main () {
  4.    int num = 11;
  5.             if (num % 2 == 0)
  6.             {
  7.                 cout<<“It is even number”;
  8.             }
  9.             else
  10.             {
  11.                 cout<<“It is odd number”;
  12.             }
  13.    return 0;
  14. }

Output:

It is odd number

C++ If-else Example: with input from user

  1. #include <iostream>
  2. using namespace std;
  3. int main () {
  4.     int num;
  5.     cout<<“Enter a Number: “;
  6.     cin>>num;
  7.             if (num % 2 == 0)
  8.             {
  9.                 cout<<“It is even number”<<endl;
  10.             }
  11.             else
  12.             {
  13.                 cout<<“It is odd number”<<endl;
  14.             }
  15.    return 0;
  16. }

Output:

Enter a number:11
It is odd number

Output:

Enter a number:12
It is even number

c plus training in vizag

C++ IF-else-if ladder Statement

The C++ if-else-if ladder statement executes one condition from multiple statements.

  1. if(condition1){
  2. //code to be executed if condition1 is true  
  3. }else if(condition2){
  4. //code to be executed if condition2 is true  
  5. }
  6. else if(condition3){
  7. //code to be executed if condition3 is true  
  8. }
  9. else{
  10. //code to be executed if all the conditions are false  
  11. }
Cpp If else 3

C++ If else-if Example

  1. #include <iostream>
  2. using namespace std;
  3. int main () {
  4.        int num;
  5.        cout<<“Enter a number to check grade:”;
  6.        cin>>num;
  7.             if (num <0 || num >100)
  8.             {
  9.                 cout<<“wrong number”;
  10.             }
  11.             else if(num >= 0 && num < 50){
  12.                 cout<<“Fail”;
  13.             }
  14.             else if (num >= 50 && num < 60)
  15.             {
  16.                 cout<<“D Grade”;
  17.             }
  18.             else if (num >= 60 && num < 70)
  19.             {
  20.                 cout<<“C Grade”;
  21.             }
  22.             else if (num >= 70 && num < 80)
  23.             {
  24.                 cout<<“B Grade”;
  25.             }
  26.             else if (num >= 80 && num < 90)
  27.             {
  28.                 cout<<“A Grade”;
  29.             }
  30.             else if (num >= 90 && num <= 100)
  31.             {
  32.                 cout<<“A+ Grade”;
  33.             }
  34.     }

Output:

Enter a number to check grade:66
C Grade

Output:

Enter a number to check grade:-2
wrong number

Leave a Reply

Your email address will not be published. Required fields are marked *