Posts

Showing posts from March, 2021

DATA types in C++ languages .

                                                             Data types   We already introduced data types earlier in the variables section. Here is an example of a code with all the data types used for revision purpose. this is the data types -  Int - 4 bytes Float - 4 bytes Double - 8 bytes Char - 1 byte Bool – 1 byte #include <iostream> #include <string> using namespace std; int main () { // Creating variables int _Num = 5; // Integer float _Float = 5.99; // Floating point number double _Double = 9.98; // Floating point number char _Char= 'G'; // Character bool _Bool = true; // Boolean string _String = "Namaste"; // String // Print variable values cout << "int: " << _Num << "\n"; cout << "float: " << _Float << "\n"; cout << "dou...

Variables & Identifiers in c++ languages .

Image
                                                                         Variables Just as in C, there are different types of variables defined with some specific keywords. Variables are defined as ' a data item that may take on more than one value during the run time of a program'. Variable has to be of a specified data type.   int:  Stores all kinds of integers e.g. 12, 873 double:  Stores floating point numbers which are decimals e.g. 12.3, 16.1 char:  Stores single letters, or we can say characters of a string e.g. 'G', 'g' string:  Collection of characters makes a string. These are written in double quotes e.g."Demo Code" bool:  Stored values are either true or false. Shorthand for 'Boolean'.   How to declare a Variable? Just as in C, we need to mention it's data ty...

In C++ what is comment in c++ language.

Image
                                                                                                                                                 COMMENT  this is comment ,      Comments are used by the programmer to make the code understandable so that is can be improvised later and to make it more readable. It can also be used to prevent execution when testing alternative code.   There are two ways to write Comments: singled-lined or multi-lined.   Single line comments   Single-line comments are initiated with two forward sl...

HOW TO PRINT PRIVATE MEMBER FUNCTION USING C++ LANGUAGE .

Image
 HOW TO PRINT PRIVATE MEMBER FUNCTION USING C++ LANGUAGE .                                                                                                                                                                   In this blog we know  how to print private member so lets start it EXAMPLE - #include <iostream> using namespace std; class simple {     private:     void read();     public:     void display(); }; void simple::read() {     cout << "i am in private "; } void simple::display() {     cout <...

Add two number using class in c++ .

 HOW to add two number using class in c++ i will give only example -       how to add -   example -    #include  <iostream>                       using namespace std;                                               class add {                         int a,b,c;                         public:                          int addition(int x,int y);                                                       };               ...

OUTPUT

Image
 USING THE COUT OBJECT -     As discussed earlier the cout object, together with the << operator, is used to output values/print text. You can add as many cout objects as you want. However, note that it does not insert a new line at the end of the of each object all of them will be printed in a single line. #include <iostream>  using namespace std;  int main() { cout << "Demo Code.";  cout << "I am learning C++.";  cout << "Print text.";  return 0;  } Output:  Demo Code.I am learning C++.Print text. NEW LINE. In order to insert a new line after each object declaration \n is used. Or another way to do so is using end1 manipulator. EXAMPLE - #include <iostream>  using namespace std;  int main() {  cout << "Demo Code.\n";  cout << "I am learning C++" <<end1;  cout << "print text";  return 0;  } Output:  Demo Code. I am learning C++ print text...

In C++ Syntax

Image
SYNTAX IN C++     The following code is written in C++ We shall look at each element of the following code in detail to understand  the syntax of C++ EXAMPLE -  #include <iostream> using namespace std; int main() { cout << "Hello World." ; return 0 ; } HERE we explain it - #include <iostream>:  This is a header file library. <iostream> stands for standard input-output stream. It allows us to include objects such as cin and cout, cerr etc.   using namespace std:  Means that names for objects and variables can be used from the standard library. It is also used  as additional information to differentiate similar functions.    int main():  The function main is called just as in C. Any code inside its curly brackets {} will be executed.   cout:  is an object used to print a particular text after << in quotes. In our example it will output "Hello World". (for personal reference ...

INTRODUCTION ABOUT C++ .

Image
  INTRODUCTION ABOUT C++  C++ was developed by Bjarne Stroustrup at Bell labs in 1979, as an extension to the C language. The major difference between C and C++ is that C is a procedural programming language; which means that it is derived from sequential step by step structured programming. Some of it's applications includes scheduling running of other programs, designing games, graphics etc. On the other hand C++ is a combination of procedural programming as well as object oriented programming. Objects consists of Data in form of it's characteristics and are coded in the form of methods. In object oriented programming computer programs are designed using the concept of objects that interact with the real world. Some other differences include:   C                                                         C++ Since C...