CHAPTER-data handling

26
CHAPTER-DATA HANDLING Data types-data types are means to identify the type of data and associated operation of handling it. Data type are three type: 1. Fundamental data types 2.derived data types 3.User defined data types fundamental data type –fundamental data types are those that are not composed of other data types Five fundamental are: int,char,float,double,void.

description

Data types-data types are means to identify the type of data and associated operation of handling it. Data type are three type: Fundamental data types 2.derived data types 3.User defined data types - PowerPoint PPT Presentation

Transcript of CHAPTER-data handling

Page 1: CHAPTER-data handling

CHAPTER-DATA HANDLING Data types-data types are means to identify the

type of data and associated operation of handling it. Data type are three type:1. Fundamental data types 2.derived data types 3.User defined data types fundamental data type –fundamental data types

are those that are not composed of other data types

Five fundamental are: int,char,float,double,void.

Page 2: CHAPTER-data handling

FIVE FUNDAMENTAL DATA TYPES ARE:

1.Int data types(for integers)-integer are whole numbers. They have not fractional part. integer data types are represented in c++ by int data types.For examples-32,87,-9 etc.

2. Char data types(for characters)-character can store any member of the c++ implementation’s basic character sets. Character are represented in c++ by char data types.For examples-any name,ASCIIcode ,sybbolsetc.

Page 3: CHAPTER-data handling

3.FLOAT DATA TYPE(FOR FLOATING POINT NO.)-A NO. HAVE FRACTIONAL PART IS FLOATING POINT NUMBER. FOR EXAMPLES-45 IS INTEGER BUT 45.0 IS FLOATING NO.,8.9,7.7 ETCADVANTAGES- THEY CAN REPRESENTED VALUES BETWEEN THE INTEGER AND THEY CAN REPRESENTED A MUCH GREATER RANGES OF VALUES.DISADVANTAGES-OPERATION ARE SLOWER THAN INTEGER OPERATION.4.DOUBLE DATA TYPE(FOR DOUBLE PRECISION FLOATING-POINT NUMBER)-THE DATA TYPE DOUBLE IS ALSO USED FOR HANDLING FLOATING-POINT NUMBER.IT OCCUPIES TWICE AS MUCH MEMORY.5.VOID DATA TYPE(FOR EMPTY SET OF VALUES AND NON-RETURNING FUNCTIONS)-IT IS USED AS THE RETURN TYPE FOR FUNCTIONS THAT DO NOT RETURN A VALUE.

Page 4: CHAPTER-data handling

DATA MODIFIERS-THE KEYWORDS WHICH, WHEN APPEAR BEFORE A DATA TYPE, CHANGES ITS MEANING ARE MODIFIERS. THESE ARE FOUR TYPE:1. SIGNED2.UNSIGNED3.SHORT4.LONG* INT DATA TYPE(FOR INTEGER)-INTEGER REQUIRED 2 BYTES TO STORE A NUMBER.-THE RANGE OF INTEGER IS -37768 TO 32767*FOR FLOAT DATA TYPE:-FLOAT REQUIRED 4 BYTES TO STORE A NUMBER.-RANGE OF FLOAT IS 3.4*10POW(-38) TO 3.5*10POW(38)* CHAR DATA TYPE(FOR CHARACTER):-CHARACTER REQUIRED 1 BYTES TO STORE A CHARACTER.-RANGE OF CHAR IS -128 TO 127

Page 5: CHAPTER-data handling

DERIVED DATA TYPE-THESE ARE THE DATA TYPES THAT ARE COMPOSED OF FUNDAMENTAL DATA TYPES.FOREXAMPLE –ARRAY, STRUCTURE, POINTER, REFERENCE, CONSTANT.

Array-array is a collection of similar of same data types in which memory a locate continues manner.Syntax-: Data type name of array[size];Example-int a[3](total bytes 3)Base address-first element in array is called base address of an array

base addressFunction-function is a piece of code or sub program that act on some data and after processing return a single value.

A[0] A[1]

Page 6: CHAPTER-data handling

Syntax-:Type*ptr;Example-char*b;

Type &ref-var=var-name;Example-int total ;Int&sum= total;Total=50;Cout<<“sum=“<<sum<<“\n”;Cout<<“total=“<<total<<“\n”;

Page 7: CHAPTER-data handling

5. constant- the keyword const can be added to the declaration of an object a constant rather than a variableSyntax -:Const type name = value;Example: Const int sum=80;USER DEFINED DERIVED DATA TYPESThere are some derived data types that are defined by the user.

Example:-class, structure, union, enumeration. Class- a class represents a group of similar object. Like group of

student , department, employee etc. Structure –a collection of variable referenced under one name,

provided a convenient means of keeping related information together. Like a student record of rollno., name, class, grade etc.

Example-: struct stud { int rollno. ; char name[10]; int class; float marks; } ;

Page 8: CHAPTER-data handling

Union- a union is a memory location tjat is shared by two or more different variable,generally of different types at different times.

Enumeration- an alternative method for naming integer constants is often more convenient const.

enumeration using keyword enum For Example-:Const int start = 0;Const int pause =1;Const int goo= 2;Enum{ status, pause, goo}; variable-variablerepresent named storage location,whose

valuescanbe manipulated during run. The variables are called symbolic variables because these are named

location. Two associated with a symbolic variable : rvalue in which stored at some location in memory. lvalue in which the addressin memory at which its data value is Stored. constant values and constant identifiers are not lvalues and can only

appear to the right side of an assignment operater .

Page 9: CHAPTER-data handling

WHERE TYPE IS ANY C++ DATA TTYPE AND NAME IS THE NAME OF A VARIABLE. A VARIABLE. ALL RULES OF IDENTIFIER NAMING APPLY TO THE NAME OF A VARIABLE. WHEN MORE THAN ONE IDENTIFIER OF A TYPE IS BEING DEFINED, A COMMA SEPARATED LIST OF IDENTIFIER MAY FOLLOW THE TYPE SPECIFIER.FOR EXAMPLE-:INT MONTH,DAY, YAER;DOUBLE SALARY, WAGES;DYNAMIC INITIALIZATION-:INITIALIZATION OF A VARIABLE AT RUNTIME USING THE INFORMATION AVAILABLE, IS CALLED DYNAMIC.FOR EXAMPLE- FLOAT AVG=SUM/COUNT;IF WILL INITIALIZATION AVG USING THE INFORMATION AVAILABLE AT RUNTIME .USING THE VALUE OF SUM AND COUNT KNOWN AT RUNTIME.

Declaration of variable-:

Page 10: CHAPTER-data handling

Formatting output:-Formatting output is important in the development of output screens,which can be easily read and understood++ offers the programmer several output/input manipulators.two of these I/o manipulators are sete() and setpreciasion().Stew() manipulator-:The setw() manipulator sets the width of the field assigned for the output.it takes the size of the field (in no. of character)as a parameter. For Example: Cout<<setw(6)<<“r”;Setprecision()manipulator-: The setprecision() manipulator sets the total number of digits to be displayed when floating point numbers are printed.For example:- cout << setprecision(5) << 123.456; The setprecision()manipulator can also be used to set the number of decimal places to be displayed.

Page 11: CHAPTER-data handling

TYPE A Q.What are the main types of c++ data types?Write data types of each type. Ans.Main two types of c++ (i)fundamental types (ii)derived types Fundamental are five types: (i)int data type(for integer) (ii)char data type(for character) (iii)float data type (iv)double data type(for double precision floating-point numbers) (v)void data type(for empty set of values and non-returning function) Derived type are divided into five types: (i)array (i)function (iii)pointer (iv)references (v)constants

Page 12: CHAPTER-data handling

Q.What do you mean by fundamental data types?How many fundamental data does c++ provide.

Ans.These are the data types that are not composed of any other data type.C++ provide five fundamental data types:char,int,float,double and void.

Q.The data type char is used to represent character.Then why is it often termed as an integer type?

Ans.Char type is often said to be an integer type.It is said because letters,symbol etc. are represented in memory by associated number codes.It is very easy to code number into binary.

Q.What are the advantages of floating-point number over integers?

Ans.Advantages of floating number: (i)They can represent the values between the integers. (ii)They can represent a much greater range of values.

Page 13: CHAPTER-data handling

Q.How many ways can a floating-point written into? Ans.Floating-point numbers can also be written in

exponent notation. Q.Write 147.9205 into exponent form and

2.4301E04 into fractional form: Ans.147.9205- 0.1479205*10pow (3 )

=0.1479205E03 2.4901E04=2.4901*10pow (4 ) Q.Why is float type preferred for real quantities? When should the type double be preferred over the

shorter type float. Ans.Floating point variables represent real

numbers,which are used for measurable quantities like distance,area,tempreture etc.It is used when type float too small or insufficiently precise.

Page 14: CHAPTER-data handling

Q.The data type double is another floating type.Then why is it treated as a distinct data type?

Ans.Because double data type occupies twice as much memory as type float and stores floating-point number with much larger range and precision.

Q.What is use of void data type? Ans.It is used as the return type for function that do not

return a value.No object of type void may be declared. Q.why does c++have type modifier? Ans.Modifier are used in c++ to alter the meaning of

the base type to fit various situation more precisely. Q.what is wrong with the following c++ statement long

float x;? Ans.Long float x; Long is never used with float.

Page 15: CHAPTER-data handling

Q.on a machine, short integer is 2 bytes long. What can be the possible size for unit integer short integer and long integer on the same machine,keeping in mind c++ standard?

Ans.int integer – 2 bytes short integer – 2 bytes long integer – 4 bytes Q.if short integer on a machine is 4 bytes, what will be the size on the machine? Ans.unsigned short- 2 bytes signed short short – 2 bytes Q.what are the variation char type? How are the of char type different from one another? Ans.character from this set is shorted in a character variable. The memory implementation of char data type is in the number code it is said to be

another integer data type. Q.what are the variation in floating point type ? How are the variation of floating point

type different from one another? Ans.i) floating point number can written into exponent notation. ii) floating point number are represent real number but floating point number are

slower than integer operation . iii) double data type are used for handling floating point number .double data type

occupies twice memory as munch memory as type float. Double is larger and slower than type float.

Q.arrange the following data type from smallest to largest ? Ans. char , short =int , long =float , double, long double.

Page 16: CHAPTER-data handling

Q.Explain the different among o, ‘o’, “o”and ‘/o’? Ans. o – integer constant ‘o’ – character constant ‘/o’ – character constant “o” – string constant Q.What is the distinction between 33L and 33? Ans.An l or L suffix indicates it is long integer contant.Thus 33L is a long

integer constant and 33 is an integer constant. Q. What do you understand by the following-: i)array:-Named list of finite number of similar data element. ii)Structure:-Collection of variables of different data types referenced

under one name. iii)Function:-A function is a named part of a program that can be invoked

from the other parts of the program. iv)pointer:-A variable that holds a memory address. v)Union:-Memory location that is shared by two or more different

variables. vi)enumeration:-Method of association integer constant to name. Q.what is a reference variable?How is it defined in C++. Ans.A reference variable is an alias for a preciously defined variable.

Page 17: CHAPTER-data handling

Q.What is wrong with the following statement constantly? Ans.Y being a constant is not initialized correct version is const int Y=5. Q.what do you understand by a class in C++?What does a structure represent

in C++? Ans. Class-:Group of similar objects structure represent in C++.Example:-struct

sturec {int roll no; char name [zo]; int class; }; sturec newstu Q.Find errors, if any, in the following C++ statement: i)int code = three ii)enum (green,yellow,red) iii)const int size; iv)size=10 Ans.i)It is valid only when enumeration are treated as integer. ii)Wrong brackets, it should be: enum {green,yellow,red}; iii)initialization not done.It should be const int size=20; iv)No, We can’t assign a value to a constant variable.

Page 18: CHAPTER-data handling

Q.What are derived data types?Name the user defined data types in C++?

Ans.These are the data type that are composed of fundamental data type.These are array,function,pointer,reference and constant.User defined data types in C++ are class,structure,union and enumeration.

Q.what is variable?In C++ two values are associated with a symbolic variable.What are these?

Ans.Named storage location whose values can be manipulated during program run.Two values associated with a symbolic variable are: rvalues that gives its contents and Ivalue that gives its address.

Write declaration for:- i)a pointer to a character and an array of 10 integer. ii) a reference to a floating point variable. iii) a constant character and a constant integer. Ans.char*a and char n[10] ii) float& ref –var=var name iii) const char a

Page 19: CHAPTER-data handling

Q.Define the following : A short integer with the value 90. An unsigned int integer with the value 31240. An integer with the value 3000000000. Ans.i) short int a =90; ii) unsigned int b=31240; iii) unsigned long c=3000000000; Q.what is the impact of access modifier const over a

variable? Ans.use this keyword before a variable’s definition, it

modifiers its access type. The access of the constant variable is readable only; it can no more be written on to.

Page 20: CHAPTER-data handling

TYPE B Q.What is different between fundamental data types and derived data

types? Ans.Fundamental data :-These are the data types that are not composed

of any other data type.These are five fundamental data types:char,Int,float,double and void.

Derived data types:-These are the data types that are composed of fundamental data types.These are:-array,function,pointer,reference,constant.

Q.What main integer types are offered by C++? Ans.Five main integer types are offered by C++:- i)int data type(for integer):-integer are whole number. ii)char data type(for character):-characters can store any member of the C++ implementation’s basic character set. iii)float data type(for floating-point number);-A number having fractional part. vi)double data type(for double precision floating-point number):-The

data type of double is also used for handling floating-point number. v)void data type(for empty set of values and non returning function).

Page 21: CHAPTER-data handling

Q.Explain floating types offered by C++ along with the minimal ranges and digits?

Ans.Double data type occupies twice as much memory as type float and stores floating-point numbers with much larger range and precision.It stands for double precision floating-point.It is used when type float is too small or insufficiently precise.

Q.Write declaration for a structure that holds information of a student like roll number, name,class,marks and grade.

Ans. Struct stude { int rollno.; char name [20]; int class; float marks; char grade [10]; }; Q.why are Providing so many data types provided in C++? Ans. So many data type is to allow programme to allow to take advantage of

hardware characteristics. Machines are significantly different in their requirement memory access time and computation.

Page 22: CHAPTER-data handling

Q.write program to find area of a triangle?Ans.#include< iostream,h> #include<conio.h> Void main() { Clrscr(); Int b,h; Cout<<“enter the value of base and height of triangle? Cin>>b; Cin>>h; Ar =1/2*b*h; Cout<<“area= “<<ar; Getch();

Page 23: CHAPTER-data handling

Q.write aprogram to find whether a given number is even or odd? Ans.# include<iostream.h> #include<conio.h> Void main( ) { Clrscr( ); Int a; Cout<<“enter the value of a”; Cin>>a; If ( a% 2=0) { cout<<a<<“ is even number “; } else cout<<a<< “is odd number “; } getch( ) } Q.write a program to convert given inches into its equivalent yards ,feet and inches. Ans.# include<iostream.h> #include<conio.h.> Void main ( ) { Clrscr ();

Page 24: CHAPTER-data handling

float yards , feets , inches, num ; Cout<<“enter inches”; Cin>>inches ; Feet=inches/12; Num=inches%12; Yards=inches/36; inches=num%12; Cout<<“/n feet are”<<feet<<“/n inches “<<inches; <<“/n yard are”<<yard; getch ( ); } Q.write a program compute simple interest and compoud interest? Ans. #include<iostream.h> #include<conio.h> Void main () { Clrscr ( ); Float sI , p ,r , t , I ,x; Cout<<“enter the value of p,r,t”; Cin>>p>>r>>t; sI=( p*r*t)/100; X=(1+r/100); cI=p*pow(x,t);

Page 25: CHAPTER-data handling

Cout<<“value of sI=“<<sI; Cout<<“value of cI =“<<cI; getch ( ); } Q- explain the function and variable with

example. Ans- function is a subprogram that act on data

and Often returnsa single value. Variable- variable represent named storage

location, Whose value can be manipulated during program

run. For example- int i ; float a;

Page 26: CHAPTER-data handling

FROM:- POOJA Class:- XI-B Roll no.:- 7 Subject:- computer science