Contact : +88 01840-723661

|

Email : info@jakafind.com

Cpp Programming Basic Concept

C++ Programming Basic Concept

 

Basic of C++ Programming

@. Father: Bjarne Stroustrup.

@. Institution: Bell Laboratory.

@. From: C -> C++

@. Use: Making operating system and gaming.

@. Some Topics of C++ language:

  1. Nested loop                         06. Structure
  2. If (condition)                      07. Enam
  3. Function                              08. Pointer
  4. String                                   09. Recursion
  5. Array                                    10. Header file

@. We cannot use 32 word

auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.

@. For Comment in code

Single line comment : \\ Md Jakaria Nur

Multiple line comment : \* I am a software designer and developer… *\

Skeleton of C++ Programming

#include <iostream>
using namespace std;
int main () {
cout << “ Hello Jakaria!\n”;
return 0; }
01. To print backspace = \b
02. To print form feed = \f
03. To print new line = \n
04. To print carriage return = \r
05. To print horizontal tab = \t
06. To print double quote = \"
07. To print single quote = \'
08. To print null = \0
09. To print backslash = \\
10. To print vertical tab = \v
11. To print alert = \a
12. To print question mark = \?
13. To print octal constant = \N
14. To print hexadecimal constant = \xN

Data Type and Variables

No Data Type Keyword Size in bytes Range Place hold
01 Character char 1 -128 to 127 %c
02 Unsigned Character Unsigned char 1 0 to 255 %c
03 Integer int 2 or 4

-32768 to 32767 or

-2147483648 to 2147483647

%d
04 Unsigned Integer Unsigned int 2 or 4

0 to 65535 or

0 to 4,294,967,295

%u
05 Long Integer long int 4

-2147483648 to 2147483647

 

%d
06 Long Long Integer long long int 8

(-2^63) to (-2^63-1)

 

%d
07 Float float 4 1.2E-38 to 3.4E +38 %f
08 Double double 8 2.3E-308 to 1.7E +308 %f

Use some variables

#include <iostream>
using namespace std;
int main () {
int a, b, sum, sub;
cout << "Enter your first number: ";
cin >> a;
cout << "Enter your second number: ";
cin >> b;
sum = a+b;
sub = a-b;
cout << "Summation = " << sum << endl;
cout << "Subtraction = " << sub << endl;
return 0; }

Details on Data Type

@.     Character – %c

Character is worked by only alphabet. Its value is in 0 – 256.

Only 25 letters write by Character.

Signed char and Unsigned char = 1 byte

@.     Integer – %d

Integer is worked by integer numbers. Its value is in 0 to 65535.

int and Unsigned int = 2 bytes

@.     Float – %f

Integer is worked by Fraction and decimal numbers.

It is showed only 6 digits.

Float = 4 or 32 bytes

@.     Double: %lf

Double is worked by big decimal and scientific numbers more than float numbers.    (6.44, 8.11, 2*10^2, 5.2*10^14)

It is showed only 16 digits.

To input data (use of scanf)

#include <stdio.h>
int main () {
int a;
int b;
Printf("Enter First Integer Number: ");
scanf("%d", &a);
Printf("Enter Second Integer Number: ");
scanf("%d", &b);
printf("Sum Two Integrer = %d", a+b);
return 0; }

Condition (use of if and else)

#include <stdio.h>
int main () {
int x;
Printf("Enter  Your Number: ");
scanf("%d", &x);
if (x>60); {
printf("Md Jakaria Nur\n");
}else{
printf("Md Jubayer Nur\n");}
return 0; }

Condition (use of if and else if)

#include <stdio.h>
int main () {
int age;
printf("Enter value of age: ");
scanf("%d", &age);
if (age<2);{
printf("Intant\n");}
else if (age<10);{
printf("Child\n");
} else if (age<20);{
printf("Teenage\n");
} else if (age<30);{
printf("Adult\n");
} else {
printf("%d\n"); }
return 0; }

Switch Case

#include <stdio.h>
int main () {
int x;
printf("Emter One Integer Number: ");
scanf("%d,&x");
switch(x){
case 1:
printf("Value is 1\n");
printf("Welcome!\n");
break;
case 2:
printf("Value is 2\n");
break;
case 3:
printf("Value is 3\n");
break;
default:
printf("Unknown!\n"); }
return 0; }

@. Case 1 = case 2 +4 use possible but case 2 + x is not possible.

@. Switch case just char and int use possible  but float and double use is not possible.

Operators, Precedence and Associativity

x = y + z
y = 5 - 5
Here,
Operator:  +, -, =, *, /, %, ++, -
Variable: x, y, z

Arithmetic Operators:

These are the operators used to perform arithmetic or mathematical operations on operands.

#. Arithmetic Operators are two types:

  1. Unary Operator
  2. Binary Operator

#. Unary Operator:

Operators that operates or works with a single operand are unary operators.

Such as: (z++, -x)

#. Binary Operator:

Operators that operates or works with two operand are binary operators.

Such as: (+, -, *, /)

#. Relation Operator

Relation Operators are used for compassion.

Checking if one operand is equal to other operand or not, an opearand is gratien than other operand or not etc.

Such as: (==, >=, <=)

@. Logical Operators

Logical Operators are used to combine two or more conditions or constraints or to complement the evaluation of the original condition in consideration.

The result of a logical operator is a boolean value either true of false.

 

 

 

Thank You!

 

 

 

 

Leave a Reply

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