Tuesday, June 30, 2020

CHAPTER-2(PART -1 C++ Input Output)

  •  In C++ input and output occurs in stream of bytes.

If the stream of sequence of bytes go from keyboard to the main memory is called as input stream.

If the stream of sequence of bytes’ flows from main memory to console display or a printer is called as output stream.

iostream header file will provide with “cin” for input operations and “cout” “cerr” “clog” for output operations. Specifically, istream provides with “cin” and ostream provides with “cout” “cerr” “clog”.

 

  • Basic C++ input and Output:
         EXAMPLE:


         Output:



We use cin for reading input and cout for output.
 C++ compiler will determine the data-type of the variable, we no longer need to use format specifier like “%d” or “%s”  as we use in c language.
 We will use extraction operator “>>” along with cin to accept a value from console and insertion operator “<<” with cout to print value to console.

  • Standard error:

We use “cerr” to display an error. “crr” is connected to standard error device. This is un-buffered stream; this means the error is displayed immediately as it occurs.

      EXAMPLE:



     Output:


  • Standard Log
We use “clog” to display an error. “clog” is connected to standard error device. This is buffered stream. This means the log is displayed once the buffer is filled.

     Example:

     Output:

  • Type Casting with “cout”:
Typecasting is a mechanism which enables a variable of one datatype to be converted to another datatype. when a variable is typecast into a different type the compiler treats the variable as of new datatype. 
In the below example, shows how to typecast different data-types with cout.



     Output:

  • get() and put() functions:

Both of these functions are used to accept a single character and print a single character respectively.

get(): It is used to accept single character. The function has 2 variants.

  1. get(char*): This will assign the input character to the argument given.
  2. get(void): This will return the input character, so the data should be assigned to the variable on left-hand side.

put(): It is used to display a single character to output.

Example to show usage of get() and put():

      Output:


  • getline() and write():

 Both of the above functions are used to read whole line from input and print a line to output.

getline function prototype:

cin.getline(variable, input_size);

 write function prototype:

cout.write(variable, output_size);

      EXAMPLE:

     OUTPUT:


CHAPTER-1(PART-3)

  •  C++ Tokens

Tokens are the smallest available unit of a program. In C++ tokens are divided into 5 types:

  1. Keywords Ex: if, for, while
  2. Identifiers Ex: num, name
  3. Constants Ex: 10, 20
  4. operators Ex: +, /, –
  5. Special Symbols Ex: { }, ()

 

  •  C++ keywords

break                    else                        for
case                      enum                     goto
asm                      dynamic_cast        namespace
bool                     explicit                  new
catch                    false                      operator
class                     friend                    private
const_cast            inline                     public
delete                   mutable                protected
auto                      const                     double
char                      do                          extern
continue           reinterpret_cast
long                    signed                     switch
register                sizeof                      typedef
static_cast                                           using
int                         short                      struct
throw                     this                        virtual
true                      wchar_t                signed
if                          return                    static
try                         void                        union
while                    volatile                   typeid

CHAPTER-1(PART-2)

C++ Hello World program with explanation

We shall learn about C++ program structure.
Open any c++ editor(i am using Dev-C++),create a new file and name it accordingly.here the name is Untitled.cpp



  1. #include<iostream>
Here #include is a pre-processor directive.
iostream is a header file name.in C++ we don't need to include ".h"extension as we do in C programming language.Older C++ compilers still need ".h"extension.
Newer compilers don't need that extension.For most of the programmes in C++ we use"iostream",it provides methods to take the input and print the output to the console. 

   2. using namespace std;

Here namespace is a special keyword used in C++. Here we are using std namespace . The compiler will check for classes,functions in the standard library.All of the standard library definitions are inside namespace std.

If we don't use standard namespace ,you need to write "std" behind every keyword.
ex-
std::cout<<"hello world"<<endl; 

  3.int main()

main() function is the starting point of a c++ program.
here {................},
these braces denotes the function body.

cout<<"hello world"<<endl;
cout is used to write the output to the console and endl is used to put a new line.


AFTER COMPILING AND RUNNING THE PROGRAM OUTPUT IS:



Monday, June 29, 2020

CHAPTER-1(PART1)

C++ is often considered as a first programming language to be learned. Because it is easy to learn. Our C++ PROGRAMMING blog has been designed in such a way that a newbie will be easily to learn the language.

C++ INTRODUCTION
  • C++ is an object oriented language. It is heavily influenced by C language. Any valid C program can be run as a C++ program.
  • C++ was developed by Bjarne Stroustrup in 1979.
  • Today most of the gaming libraries are written in C++
  • C++ is a middle level language. It has the features of High level language and also low level language.
  • The latest version C++ 17 was released on Dec 1st 2017.
  • “.cc” “.cpp” is the file extensions.
  • We shall learn about the latest features introduced from C++ 11 to C++ 17 in this blog.

C++ FEATURES
  • It is portable.
  • It has stronger type checking. Example, if a function is declared and it will accept int variable but in the declared function if you pass a float the compiler will give an error.
  • It is object oriented.
  • C++ is extensible; it means new features can be added easily.
  • New memory management features. Any dynamically allocated memory can be freed by calling free ().
  • C++ is platform independent. A program compiled and executed in one platform, same program can be used and compiled in another platform also.
  • Inline functions are available instead of macros.
  • C++ includes a Standard Template Library [STL]. This includes set of methods manipulating data structure.
  • C++ uses bottom up approach.









CHAPTER-2(PART -1 C++ Input Output)

 In C++ input and output occurs in stream of bytes. If the stream of sequence of bytes go from keyboard to the main memory is called as inpu...