Download presentation
Presentation is loading. Please wait.
1
DATA HANDLING
2
DATA HANDLING C++ Data Types Derived types Fundamental types
3
FUNDAMENTAL TYPES Those data types that are not composed
of other data types int Data types ( for integers) char Data type ( for characters) float Data type (for floating–point numbers) double Data type (for double precision floating– point numbers) void Data type (for empty set of values and non- returning functions)
4
int Datatype They have no fractional part. An identifier declared as int becomes an integer variables and can hold integer values only
5
char Datatype Characters can store any member of the C++ implementation’s basic character set. If a character from this set is stored in a character variable, its value is equivalent to the integer code of that character. An identifier declared as char becomes a character variable.
6
float Datatype A number having fractional part is known as floating point number. An identifier declared as float becomes a floating-point variable and can hold floating-point numbers only E.g (or E02) , 12.0 etc.,
7
double Datatype Occupies twice as much memory as type float.
Stands for double precision floating-point. Used when type float is too small or insufficiently precise.
8
void Datatype Specifies an empty set of values
Used as the return type for functions that do not return a value. No object of type void is declared
9
DATA TYPE MODIFIERS signed unsigned long short
10
Integer Types short unsigned Signed short 2 - 32768 to 32767
Approximate Size (in bytes) Minimal Range short unsigned Signed short 2 to 32767 0 to 65,535 same as short int unsigned int signed int 2 to 32767 0 to 65,535 same as int long unsigned long signed long 4 - 2,147,483,648 to 2,147,483,648 0 to 4,294,967,295 same as long
11
Character Types Char unsigned char signed short 1 - 128 to 127
Approximate Size (in bytes) Minimal Range Char unsigned char signed short 1 - 128 to 127 0 to 255 same as char
12
Floating-point Types 1.7 × 10-38 to 1.7 × 10-38 -1
Approximate Size (in bytes) Minimal Range Digits of precision float double long double 4 8 10 - 3.4 × to × 1.7 × to 1.7 × 3.4 × to 3.4 × 7 15 19
13
DERIVED DATA TYPE Arrays Function Pointer Reference Constant
14
ARRAYS Named list of finite number n of similar data element
Each of the data elements can be referenced respectively by a set of consecutive numbers, usually 0,1,2,3, …. n.
15
FUNCTION Its named part of a program that can be invoked from other parts of the program as often needed.
16
POINTER It’s a memory variable that can hold a memory address. This address is usually the location of another variable in memory Memory Addresses Value In Memory Variable Names A B Syntax type * ptr ; E.g. int * A, B; A= &B; 1053
17
REFERENCE An alternative name for an object.
Declaration consists of a base type, an & (ampersand), a reference variable name equated to a previously defined variable name. type & ref-var = var-name; E.g. int total = 100; int & sum = total; count<<sum<<total<<“\n”; Output 100 100
18
CONSTANT Value cannot be altered during the program run.
Must be initialized at the time of declaration. Const type name = value
19
USER-DEFINED DERIVED DATA TYPES
class structure union enumeration
20
objects of class department
A class bears the same relationship to an object as a type bears to a variable Eg. class department { char name[20] int empno; char hod[20]; public: void add( ); void get( ); void print( ); }; department sales, accounts; objects of class department
21
STRUCTURE It’s a collection of variables of different data types referenced under one name Eg. struct studrec { int rollno; char name[20]; int class; float marks; char grade; }; studrec newstu; The elements are referenced as newstu.rollno, newstu.name etc., objects of structure studrec
22
UNION A memory location that is shard by two ore more different variables of different types at different time. E.g., union share { int i ; char ch; }; union share cvt; cvt. i = 20; cout<<cvt.ch Output = 20; Union is used for both Declaration and definition
23
ENUMERATION An alternative method for naming integer constant.
Enum {START , PAUSE, GOO}; i.e., const int START = 0; const int PAUSE = 1; const int GOO = 2;
24
VARIABLES Named storage locations whose value can be manipulated during program run. Memory Addresses Data Value of varaible Variable’s Names A B Syntax type name ; E.g. int A, B; A= 10, B = 25; const int amount = 20; 10 25
25
FORMATTING OUTPUT setw ( ) setprecision( )
To use these i/o manipulators include the header file iomanip.h
26
setw( ) manipulator Sets the width of the field assigned for the output Takes the size of the field as a parameter Eg.,cout<<setw(8)<<2<<“\n”; cout<<setw(8)<<4444<<“\n”; cout<<setw(8)<<666666<<“\n”; OUT PUT
27
setprecision( ) manipulator
Sets the total number of digits to be displayed when floating point numbers are printed. Sets the number of decimal places to be displayed. Eg., 1. cout<<setprecision(5)<< ; OUT PUT = (rounding the digits) 2. cout.setf(ios :: fixed) ; cout<<setprecision(5)<< ; OUT PUT = (no rounding)
28
ADDITIONAL IOS FLAGS left right showpoint uppercase etc.,
Eg.; cout.setf(ios :: fixed); cout.setf(ios :: showpoint); cout<<setprecision(2); cout<<5.8 OUTPUT 5.80
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.