Blog Archive

PG -TRB COMPUTER INSTRUCTOR C plus plus Class : 1

 

C++ is an object-oriented programming language. It is an extension to C programming.

C++ programming language was developed in 1980 by Bjarne Stroustrup at bell laboratories of AT&T (American Telephone & Telegraph), located in U.S.A.

Bjarne Stroustrup is known as the founder of C++ language.

 


What is C++

C++ is a case-sensitive, free-form programming language that supports object-oriented, procedural and generic programming.

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

Object-Oriented Programming (OOPs)

The four major pillar of object-oriented programming (OOPs) used in C++ are:

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.

Usage of C++

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

C++ Program

#include <iostream.h>  

#include<conio.h>  

void main()

 {  

   clrscr();  

   cout << "Welcome to C++ Programming.";   

   getch();  

}  

#include<iostream.h> includes the standard input output library functions. It provides cin and cout methods for reading from input and writing to output respectively.

#include <conio.h> includes the console input output library functions. The getch() function is defined in conio.h file.

void main() The main() function is the entry point of every program in C++ language. The void keyword specifies that it returns no value.

cout << "Welcome to C++ Programming." is used to print the data "Welcome to C++ Programming." on the console.

getch() The getch() function asks for a single character. Until you press any key, it blocks the screen.

 

 

 

How to compile and run the C++ program

There are 2 ways to compile and run the C++ program, by menu and by shortcut.

By menu

Now click on the compile menu then compile sub menu to compile the c++ program.

Then click on the run menu then run sub menu to run the c++ program.

By shortcut

Or, press ctrl+f9 keys compile and run the program directly.

You will see the following output on user screen.

You can view the user screen any time by pressing the alt+f5 keys.

Now press Esc to return to the turbo c++ console.

 

C++ Basic Input/Output

C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data. It makes the performance fast.

If bytes flow from main memory to device like printer, display screen, or a network connection, etc, this is called as output operation.

If bytes flow from device like printer, display screen, or a network connection, etc to main memory, this is called as input operation.

Standard output stream (cout)

The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console

Standard input stream (cin)

The cin is a predefined object of istream class. It is connected with the standard input device, which is usually a keyboard. The cin is used in conjunction with stream extraction operator (>>) to read the input from a console.

 

Standard end line (endl)

The endl is a predefined object of ostream class. It is used to insert a new line characters and flushes the stream.

#include <iostream>  

int main( ) {  

cout << "C++ Tutorial";     

cout << " Javatpoint"<<endl;   

cout << "End of line"<<endl;   

}   

 

Output:

C++ Tutorial Javatpoint

End of line

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

PG -TRB COMPUTER INSTRUCTOR C plus plus Class : 4 switch do while

  C++ switch The C++ switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement in C++. sw...