- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
C++ Programming tutorial
C++ is used to create computer programs.C++ is an effective general-motive programming language. It may be used to develop working systems, browsers, games, and so on. C++ supports distinct approaches to programming like procedural, object-oriented, functional, and so on. This makes C++ effective as well as flexible. C++ is portable and can be used to develop applications that can be adapted to multiple platforms.About C++ Programming
Multi-paradigm Language - C++ supports a minimum of seven different sorts of programming.
Developers can choose any of the styles.
General Purpose Language - you'll use C++ to develop games, desktop apps, operating systems, and so on
. Speed - Like C programming, the performance of the optimized C++ code is outstanding. Object-oriented - C++ allows you to divide complex problems into smaller sets by using objects.
A program must have exactly one and only one function named main
1. The main is the starting point of the program
2. Every function is divided into two sections
Local declaration: variables declared are only known to the function and not known outside
Statements
#include<iostream>
Create a Calculator with C++ using switch case
#include <iostream>
# include <iomanip>
using namespace std;
int main()
{
int num1, num2;
char opr;
cout<<" enter two integers value:";
cin>>num1 >>num2;
cout<<"enter operator: +(addition), -(substraction),"
<<" *(multi),/(div):";
cin>>opr;
cout<<endl;
cout<<num1<<""<<opr<<" "<<num2 <<"=";
switch (opr)
{
case '+':
cout<<num1 +num2<<endl;
break;
case'-':
cout<<num1-num2<<endl;
break;
case'*':
cout<<num1*num2<<endl;
break;
case'/':
if(num2 !=0)
cout<<num1/num2<<endl;
else
cout<<"error,cannot divided by zero"<<endl;
break;
default:
cout<<"illegal operation"<<endl;
cout<<endl;
}
return 0;
}
For Loop In C++
while you realize precisely how usually you need to loop via code, use the for loop in place of some while loop:
First statement : In for loop first we initialize
2nd statement: we have a condition
3rd statement: have an increment
EXAMPLE:
will print the numbers 0 to 4:
for (int i = 0; i < 5; i++)
{
cout << i << "\n";
}
cout << i << "\n";
}
true
is while loop .
Example
the code in the loop will run, over and over again, as long as a variable (i
) is less than 5:
int i = 0;while (i < 5)
{
cout << i << "\n";
i++;
}
Do-while loop
do {
cout << i << "\n";
i++;
}
while (i < 5);
Comments