Professional Documents
Culture Documents
Experiment # 01
Student Name:
Roll Number:
Experiment evaluated by
Instructor Name:
Constants:
Constant is an entity that does not change.
Variables:
An entity that may vary during program execution.
Keyword:
A predefined word that cannot be used as a variable name. It is also called Reserved Words.
Character Set of C++:
It is a Combination of Alphabets, Digits, and Special symbols to form Constants, Variables
and Keywords.
Variable Declaration:
Variable is generally declared as:
TYPE VAR;
Here Type is C++ data type and VAR is the variable name. You can also declare more
than one variables of same type by using comma-separated list. For example
variable_name = value;
For Example:
a=10;
Basic Input and Output:
C++ I/O occurs in streams, which are sequences of bytes. If bytes flows from a device like a
keyboard, a disk drive, or a network connection etc. to main memory, this is called input
operation and if bytes flows from main memory to a device like a display screen, a printer, a
disk drive, or a network connection, etc, this is called output operation.
For Example:
cout <<Welcome to Programming Fundamentals Lab;
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus or Remainder
The +, -, /, * operators are used with any of the data type but % operator can only be
used with integer type only.
Operator Precedence:
For an expression it is necessary to know about the order of precedence of arithmetic
operators. The *, / and % operator are higher precedence than the + and operators.
However, a programmer can alter the order of evaluation using parentheses.
For example, the result of the following expression is 0.
40 - 10 * 4
(40 - 10) * 4
Operators Associatively:
Associatively may be left associative (left to right) or right associative (right to left). All
arithmetic operators are left associative; assignment operators (+=, -=, *=, =, %=, =)
are right associative.
For Example:
int a=10, b=5, c=2;
a + b * c; 10 + (5*2) = 20
a * b % c; (10 * 5) % 2 = 0
Program
#include <iostream>
using namespace std;
int main ()
{
// Variable declaration int a, b;
int c;
float f;
// initialization b = 20;
cout<<Enter value of a:\n;
cin >> a;
c = a + b;
cout << c << endl ;
f = 70.0/3.0;
cout << f << endl ;
return 0;
}
Do it yourself
Simple Task:
1. Write a program in C++ (already discussed in the class) to display the sizes of
various data types and complete the following table:
2. Take length & breadth of a square and radius of a circle as input through the
keyboard. Write a program to calculate the area of the square and the area and
circumference of the circle
3. Temperature of a city in Fahrenheit degrees in input through the Keyboard. Write a
program to convert this temperature into Centigrade.
5
= ( 32)
9
Home Task:
1. Write a program for which can perform simple arithmetical operations take input
from user.
(Hint: Perform Addition, Subtraction, Multiplication and division of two numbers)