My Smart Blog
Basic information before you start C++ programs, quite simple and intresting.
Make a program in C++ that tells Area of Rectangle and Perimeter of Rectangle
#include<iostream>
using namespace std;
int main()
{
int
width,height,area,perimeter;
cout<<"Enter Width of
Rectangle = ";
cin>>width;
cout<<"Enter Height of
Rectangle = ";
cin>>height;
area=height*width;
cout<<"Area of Rectangle ="<<area<<endl;
perimeter=2*(height+width);
cout<<" Perimeter of rectangle are =
"<<perimeter<<endl;
return 0;}
Ø Output
of Program
Make a program in C++ that tells the Area of Traingle
#include
<iostream>
#include<cmath>
using
namespace std;
int
main()
{
int
a,b,c,s,A;
cout<<"Enter
Value of first side"<<endl;
cin>>a;
cout<<"Enter
Value of second side"<<endl;
cin>>b;
cout<<"Enter
Valueof third side"<<endl;
cin>>c;
s=(a+b+c)/2;
cout<<"Sum
of all sides is ="<<s<<endl;
A=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"
The Area of Traingle is = "<<A<<endl;
}
Ø Output
of Program
Getting Familiar with Operators in C++
OPERATORS
IN C++
Operators
are special type of functions, that takes one or more arguments and produces a
new value.
• For
Example: addition (+), subtraction (-),
multiplication (*) etc,
Are
all operators and operators are used to perform various operations on variables
& constants.
Following
are the types of Operators used in C++.
1.
Assignment Operator
2.
Arithmetic Operators
3.
Relational Operators
4.
Logical Operators
5.
Bitwise Operators
6.
Shift Operators
7.
Unary Operators
·
Assignment
Operators
The
Assignment Operator evaluates an expression on the right of the expression and
substitutes it to the value or variable on the left of the expression.
·
Arithmetic Operators
All the
basic arithmetic operations can be carried out in C++, these are operators used
to perform basic mathematical operations. Addition (+) , subtraction (-) ,
diversion (/) multiplication (*) and modulus (%) are the basic mathematical
operators. Modulus operator cannot be used with floating-point numbers.
·
Relational Operators
These
operators establish a relationship between operands. The relational operators
are : less than (<) , grater that (>) , less than or equal to (<=),
greater than equal to (>=), equivalent (==) and not equivalent (!=).
·
Logical
Operators
The logical operators are AND
(&&) and OR (||). They are used to combine two different expressions
together. If two statement are connected
using AND operator, the validity of both statements will be considered, but if
they are connected using OR operator, then either one of them must be valid.
·
Bitwise
Operators
There are
used to change individual bits into a number. They work with only integral data
types like char
, int
and long
and not
with floating point values.
·
Shift
Operators
Shift
Operators are used to shift Bits of any variable. It is of three types,
1.
Left Shift Operator <<
2.
Right Shift Operator >>
·
Unary
Operators
These
are the operators which work on only one operand. There are many unary
operators, but increment ++
and decrement --
operators are most used.,
other examples are unary minus -
and unary plus +
.
Subscribe to:
Posts (Atom)