Download presentation
Presentation is loading. Please wait.
Published byJemima Grant Modified over 9 years ago
1
CHAPTER 7 DATA HANDALING Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND
2
DATA TYPE :- T o identify the data & associated operation of handling it. There are 2 type of data types in c++ 1.Fundamental data type 2.Derived data type
3
1)FUNDAMENTAL TYPES – IT IS THOSE THAT ARE NOT COMPOSED OF OTHER DATA TYPE (2)DEIVED TYPES-IT IS THOSE THAT ARE CONSTRUCATED FROM THE FUNDAMENTAL TYPE.
10
IT ALTER THE MEANING OF THE BASE TYPE TO FIT VARIOUS SITUATION MORE PRECISELY THE LIST OF MODIFIRES ARE- SIGNED: Number starting with negative to positive UNSIGNED: All are positive value LONG SHORT
11
TYPEAPPROXIMATE SIZE(IN BYTES) MINIMAL RANGE SHORT2-32768 TO 32767 UNSINGED SHORT20 TO 65,535 SINGED SHORT2SAME AS SHORT INT2-32768 TO 32767 UNSIGNED INT20 TO 65,535 SINGED INT2SAME AS INT LONG4-2,147,483,648 TO 2,147,483,647 UNSIGNED LONG40 TO 4,294 967 295 SIGNED LONG4SAME AS LONG
12
TYPE APPROXIMAT E SIZE(IN BYTES) MINIMAL RANGE CHAR1 -128 TO 127 UNSINGED CHAR 1 0 TO 255 SINGRD CHAR 1 SAME AS CHAR
13
TYPE APPROXIM ATE SIZE(IN BYTE) MINIMAL RAGEDIGIT OF PRECISIO N FLOAT4 3.4*10 -38 TO 3.4 10 -38 -1 7 DOUBLE8 1.7* 10 -308 TO 1.7* 10 -308 -1 15 LONG DOUBLE 10 3.4* 10 -4932 TO 1.1 10 -4932 -1 19
17
FUNCTION: It is a collection of statement that perform a specific tasks and return a value. Example: /* w.a.p(using function) to accept a number and print its cube. */ #include #include float cube(float); int main() { clrscr(); float num; cout >num; cout<<“\n” <<the cube of “<<num<<“is”<<cube(num)<<“\n”; getch(); return 0; } float cube(float a) { return a*a*a; }
19
EXAMPLE FOR POINTER: int X = 547; int *ptr; ptr=X; HERE: Veriable nameContentsLocation X 547 4000 ptr 4000 4036 According to above figure, By the help of ptr variable we stored the address of variable X in address 4036
28
A union is like a structure in which all members are stored at the same address. Members of a union can only be accessed one at a time. The union data type was invented to prevent memory fragmentation. The union data type prevents fragmentation by creating a standard size for certain data. Just like with structures, the members of unions can be accessed with the. and -> operators.
31
Variables: Variables are locations in memory in which values can be stored. Each one has a name,a type, and a value. => There are two values associated with a symbolic variable: 1.rvalue(are-value):Its data value, stored at some location in memory. 2.lvaue(el-value): its location value, that is, the address in memory at which its value is stored.
32
int A=10,C=25; 1051 1052 1053 1054 1055 A C Memory Address Data value of Variable Variable's name 10 25 rvalue of A=10 lvalue of B=1052 rvalue of C=25 lvalue of C=1055
33
=>Declaring Variables: Variable declaration consist of a type and a variable name: Example: int age,x; // declares age and x of integer type Note: 1. Variable names in C++ can start with a letter or an underscore( _ ). 2. They cannot start with a number. After the first character. your variable names can include any letter or number. => Incorrect variable names 1. 6abc 2. /abc => correct variable names 1. ABC 2. _6abc
34
Initialization of variables : Variables are initialized (assigned an value) with an equal sign followed by a constant expression. The general form of initialization is: =>variable name = value; Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows: =>type variable name = value;
35
Example:- int y; y=10; int y=10; int y(10); For declarations without an initializer: variables with static storage duration are implicitly initialized with NULL (all bytes have the value 0); the initial value of all other variables is undefined.
36
=>Dynamic Initialization: A variable can be initialized at run time using expression at the place of declaration. Example: float avg,sum; int count; avg =sum/count; // Dynamic Initialization =>The Access Modifier Const: The const keyword create constant. The access of the constant variable is readable only. Example: int val=10;// its value can be changed in the program at any time. const int total=100; //it value can never be changed during program run.
37
=> Formatting OUTPUT: It is used to set the output screens. There are two type of I/O manipulator. 1. setw( ) 2.setprecision( ). Above two I/O manipulator include in header file iostream.h 1.setw( ): The setw( ) manipulator sets the width of the field assigned for the output.It takes the size of the field(in number of character) as a parameter. By default, values are right-justified in the space provided. We can change this. For example: cout<<setw(6)<<“R”; output: _ _ _ _ _R
38
=>Setprecision( ): The setprecision manipulator sets the total number of digits to be displayed when floating point numbers are printed. Example: cout<<setprecision(5)<<123.456; Output: 123.46 It is used to set the number of decimal places to be displayed. cout.setf(ios::fixed); Once the flag has been set, the number you pass to setprecision( ) is the number of decimal places you want displayed. cout<<setf(ios::fixed); cout<<setprecision(5)<<12.345678; Output: 12.345678
39
=> Additional IOS flags: cout.setf(ios::fixed); “fixed”i.e., ios::fixed is referred to as a format option. Other option are following: 1.left-> left justify the output. 2.right-> right justify the output. 3.howpoint-> display decimal point and trailing zeros for all floating point number. 4.uppercase-> display the “e” in E notation as “E” rather than “e”. 5.showpos-> display a leading plus sign before positive values. 6.scientific-> Display floating point number in scientific (“E”) notation. 7.fixed->display floating point number in normal notation.-no trailing zeroes and no scientific notation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.