Day3 - Cpp - Input and Output
-
Upload
vishal-shah -
Category
Documents
-
view
230 -
download
0
Transcript of Day3 - Cpp - Input and Output
-
7/30/2019 Day3 - Cpp - Input and Output
1/13
DAY3
-
7/30/2019 Day3 - Cpp - Input and Output
2/13
User-definedData Types
Structure
Union
Class
Enumeration
Built-In DataTypes
Integral int, float
Void
Float, double
DeriveTyp
A
Fu
P
Re
-
7/30/2019 Day3 - Cpp - Input and Output
3/13
Data Types
Type Typical Bit Width Typical Range
signed char 1byte -127 to 127
int 4bytes-2147483648 to
2147483647
unsigned int 4bytes 0 to 4294967295
signed int 4bytes -2147483648 to2147483647
short int 2bytes -32768 to 32767
unsigned short int Range 0 to 65,535
signed short int Range -32768 to 32767
-
7/30/2019 Day3 - Cpp - Input and Output
4/13
Type Typical Bit Width Typical Range
long int 4bytes-2,147,483,647 to
2,147,483,647
signed long int 4bytes same as long int
unsigned long int 4bytes 0 to 4,294,967,29
float 4bytes +/- 3.4e +/- 38 (~
double 8bytes +/- 1.7e +/- 308 (
long double 8bytes +/- 1.7e +/- 308 (
char 1byte -127 to 127 or 0 t
unsigned char 1byte 0 to 255
-
7/30/2019 Day3 - Cpp - Input and Output
5/13
INPUT/OUTPUT (I/O)
C++ supports input/output statements which can be usto feed new data into the computer or obtain output o
output device such as: VDU, printer etc.
The following C++ stream objects can be used for the
input/output purpose. 1. cin - console input
2. cout - console output
-
7/30/2019 Day3 - Cpp - Input and Output
6/13
Output Operator
The statement [cout
-
7/30/2019 Day3 - Cpp - Input and Output
7/13
Input Operator
The statement [cin >> num1 ] is an input statement ancauses the program to wait for user input for a number
The >> operator is called Extraction operator
-
7/30/2019 Day3 - Cpp - Input and Output
8/13
Declaration of Variable
C++ allows the declaration of variable anywhere in thescope.
A variable can be declared right at the place of its first
-
7/30/2019 Day3 - Cpp - Input and Output
9/13
Program N0 5 : Addition of two number
-
7/30/2019 Day3 - Cpp - Input and Output
10/13
Dynamic Initialization of Variable
C++ permits initialization of variable at run time.
This is referred as Dynamic Initialization of variable
A variable can be initialized at run time using expressio
the place of declaration
Ex.
float area = 3.14159 * rad * rad
-
7/30/2019 Day3 - Cpp - Input and Output
11/13
Program No. 6: Calculate Area of Circ
-
7/30/2019 Day3 - Cpp - Input and Output
12/13
Program NO. 7 : Input Price, Qty and calculate biamount with discount of 5.00% if price is greaterthan 50
-
7/30/2019 Day3 - Cpp - Input and Output
13/13
Program No. 8
Input a number anddisplay factorialvalue using loopstatement
Factorial :
A factorial of a non-negative number nis the product of allpositive integersless than or equal ton