1 / 40

CHAPTER 7 DATA HANDALING

CHAPTER 7 DATA HANDALING. Prepared By : VINAY ALEXANDER (विनय अलेक्सजेंड़र) PGT(CS) ,KV JHAGRAKHAND. 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.

gefen
Télécharger la présentation

CHAPTER 7 DATA HANDALING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER 7 DATA HANDALING Prepared By : VINAY ALEXANDER (विनय अलेक्सजेंड़र) PGT(CS) ,KV JHAGRAKHAND

  2. DATA TYPE:- To identify the data & associated operation of handling it.There are 2 type of data types in c++1.Fundamental data type2.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.

  4. FUNDAMENTAL DATA TYPE:-There are 5 data types of fundamental data type:-1.int2.char3.void4.double5.float.

  5. 1. int data type:- It is a integer or whole number that is NUMBER WITHOUT FRACTIONS such as 5,9,-10,0 etc. Width of a data type refers to the amount of memory space required to store the data type.Range: Range for int type is calculated as:Range: - 2 n-1 to 2 n-1-1 where n is the width of a data type

  6. 2.Char data type( FOR CHARACTER)-ANY THING ENCLOSED IN SINGLE QUOTES REPRESENTED CHARACTER DATA IN C++ . They can store any member of the c++ implementation’s basic character from this set is stored in a character variable, its value is equivalent to the integer code of that character. Example:-char ch=‘A’ ;

  7. FLOAT DATA TYPE(FOR FLOATING-POINT NUMBERS)-A NUMBER HAVINGFRACTIONAL PART IS A FLOATING NUMBER EXAMPLE:-float x=10.2

  8. DOUBLE DATA TYPE(FOR DOUBLE PRECISIONS FLOATING-POINT NUMBERS): It is also useful in handling floating point number. It occupies twice as much memory as type float and stores floating-point numbers with much larger range and precision.

  9. VOID DATA TYPE(FOR EMPTY SET OF VALUES AND NON-RETURNINIG FUNCTION): It specifies an empty set of value.It is used as return type for function that do not return a value.

  10. DATA TYPE MODIFIERS 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. INTEGER TYPES

  12. CHARACTER TYPE

  13. FLOATING –POINT TYPES

  14. //program to display ASCII code#include<iostream.h>#include<conio.h>void main( ){clrscr( );char ch=‘A’;int num=ch;cout<<“The ASCII code for “<<ch<<“is”<<num<<“\n”;cout<<“Adding 1 to the character code:\n”;ch=ch+1;num=ch;cout<<“The ASCII code for”<<ch<<“is”<<num<<“\n”;getch( );}

  15. DERIVED DATA TYPE: It constructed from the fundamental data types.Ex. Of derived data type:-Array, Functions, Pointers, References, Constants, Classes, Structures, Union and Enumerations.

  16. ARRAY: It is a collection of element of same data type under a common name.EXAMPLE:-int x[4]

  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<iostream.h>#include<conio.h>float cube(float);int main(){clrscr();float num;cout<<“enter a number:”;cin>>num;cout<<“\n” <<the cube of “<<num<<“is”<<cube(num)<<“\n”;getch();return 0;}float cube(float a){return a*a*a;}

  18. POINTER: It is a variable that store the address of another variables.

  19. int X = 547; int *ptr; ptr=X; EXAMPLE FOR POINTER: HERE: Veriable name Contents Location X 547 4000 ptr 4036 4000 According to above figure, By the help of ptr variable we stored the address of variable X in address 4036

  20. QUESTION:-How many value return by a function?ANSWER:- ONE

  21. REFERENCE: It is a variable provides an alias(alternative name) for previously defined variables. A reference declaration consist of base data (ampersand(&)) a reference variables name (previously defined). EXAMPLE:-int total;int & sum=total;total=100;cout<<sum<<total;

  22. CONSTANT: Constant Variables: its value cannot be alter during program run or execution of program.EXAMPLE:-const int x=100;

  23. User defined derived Data typesCLASS: It is a collection of member data and member function. And it is also a collection of objects.

  24. EXAMPLE:- Class department{ char name[20]; int num_emp; char h_o_d[20];public : add( ) ; delete( ) ; modify ( ); print( );};department sales, purchase, import, accounts;

  25. STRUCTURE: A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together.EXAMPLE:-

  26. Struct sturec { int rollno; char name [20]; int class ; float marks; char grade;};sturec newstu;

  27. UNION: It is a memory location that shared by two or more different variables of different types at different time and defining union is a similar to defining structure.

  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.

  29. EXAMPLE:-union share { int i; char ch;}; union share cnvt;

  30. ENUMERATION: It is an alternative method for naming integer constants is often more convenient than const. Example:enum{ START,PAUSE,GOO } ;enumeration values are by default assigned increasing from 0.

  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. Memory Address Data value of Variable Variable's name 1051 1052 1053 1054 1055 int A=10,C=25; A C

  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

  40. THE END…

More Related