Anda di halaman 1dari 11

Prepared By:

Muhammad Bilal

Roll No: 415

A Table of Data Types in C++ Language

Data ADT Primitive Non-Primitive Defined


Types By
Yes/ Description Yes/ Description Yes/ Description
No No No
int Yes ‘int’ takes 2 Yes ‘int’ data type can No Language
bytes and its store all positive
range is from and negative
-32768 to integers, so it is
32767. It stores different from
only integral part other data types.
of the numbers.
Unsigned Yes It stores only Yes ‘unsigned int’ can No Language
int positive integers. store only positive
It takes two integers, so it is
bytes in different from ‘int’
memory. Its data types.
range is from 0
to 65,535.
long / long Yes It is used to Yes ‘long int’ can No Language
int store large manipulate larger
integer values. It integer values.
takes 4 bytes in
memory. Its
range is from
-2,147,483,648
to
2,147,483,647
Unsigned Yes It is used to Yes ‘unsigned long int’ No Language
long int store large can only store
positive integer large positive
values. It lakes 4 values.
bytes in
memory. Its
range is from 0
to
4,294,967,295
float Yes ‘float’ takes 4 Yes It has two parts No Language
bytes and its “exponent” and
range is from “mandisa”.
3.4 * 10-38 to Exponent stores
3.4 * 1038. integral part and
mandisa stores
fractional part of
the number.
double Yes This data type is Yes It provides No Language
used to store accuracy of 15
large real values. decimal places.
It takes 8 bytes
of memory. Its
range is from
1.7 * 10-308 to
1.7 * 10308.
Long Yes It is used to Yes It provides No Language

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


double store very large accuracy of 19
real values. It decimal places.
takes 10 bytes
in memory. Its
range is from
1.7 * 10-4932 to
1.7 * 10493
char Yes ‘char’ data type Yes It is used to No Language
is used to store represent a letter,
character value. number, or
It takes 1 byte in punctuation mark
memory. and a few other
symbols.
boolean Yes ‘boolean’ data Yes It provides only the No Language
type has two functionality of
values: true or ‘yes’ or ‘no’.
false.
Theoretically it
fits in one single
bit of memory
which can
contain 0 or 1
queue Yes A queue is an No Yes A queue has two User
ordered ends front and
collection of rear. We can
items. insert data using
rear and can be
deleted from the
front. Queue has
a working
technique called
FIFO (First in
First Out) as
opposed to a
stack. (Stack
uses LIFO <Last
in First Out>)
stack Yes A stack is a data No Yes A stack is a type User
structure as it of data structure
contains data based on the
and has some technique of
operations on Last in First
that data i.e. Out (LIFO).
storing data and LIFO is a
retrieving it. technique for
sorting data in a
data structure
and retrieving it.
It contains two
functions push()
and pop(). A
stack is non-
primitive as it
may contain the
data of other
data type’s i.e
int, float, char,
and string.
tree Yes Tree is a data No Yes Binary tree is a User
structure that is finite set of
useful in many elements that is
applications. either empty or
Usually trees are is partitioned
in the form of into three

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


Binary Trees. disjoint subsets.
The first subset
contains a single
element called
the root of the
tree. The other
two subsets are
themselves
binary trees,
called the left
and right sub
trees of the
original tree. A
left or right tree
can be empty.
Each element of
a binary tree is
called a node of
the tree. There
are a number of
operations that
can be applied to
a binary tree. If
p is a pointer to
a node nd of a
binary tree, the
function info(p)
returns the
contents of nd.
The function
left(p),right(p)
,farther(p) and
brother(p)
return pointers
to the left son of
nd, the right son
of the nd, the
father of nd and
the brother of
nd, respectively.
These functions
returns the null
pointer if nd has
no left son, right
son, father, or
brother.
linked list Yes Linked list is an No Yes Linked list is one User
ADT as it of the
contains data fundamental
and set of data structures
operations. in programming.
It consists of a
(defined in non- sequence of
primitive nodes. Each
column) node contains
data fields and a
reference field
that points to the
next nodes. A
linked list allows
the insertion and
removal of nodes
at any point in
the list but it

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


does not allow
random access.
Any node in the
list can be
accessed only by
starting the first
node
sequentially.
Linked list has
3 types : Singly
linked lists,
Doubly linked
lists, Circular
linked lists.
Dictionary Yes Dictionary is a No Yes Dictionary User
data type which contains words
has a collection which are
of English or any ‘strings’ and it
other words of a have an
specific field. operation to give
the meaning or
details of a
desired word.
String Yes A string is No Yes In computer User
generally programming, a
understood as a string is,
data type storing essentially, a
a sequence of sequence of
data values, characters.
usually bytes, in
which elements
usually stand for
characters
according to a
character
encoding,
Union Yes Aunio is also a No Yes The difference User
data structure as between
it also contains structure and
members of union is in
different data memory
types. allocation. A
structure takes
the memory
equal to the sum
of all the bytes
of structure
members while
the size of union
is equal to the
largest byte that
is taken by the
member.
Consider the
example.

Struct test{
Int data1;
Float data2;
Char data3;
}

The size of the


structure is 4 as

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


the largest byte
is 4 taken by the
float data
member.

Class test{
Int data1;
Float data2;
Char data3;
//class body
}

The size of the


class is 7 i.e.
2+4+1 bytes.

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415

How ‘array’ is ADT? Relate array with


matrices.
Array is an ADT. According to the definition of ADT, a data type is an ADT when it contains some
data and has some functionality. In respect to ‘array’, array contains data and has functionality of
searching, sorting and merging.

Usually one dimensional array is also called a vector. Whereas, the matrix have rows or
coloumns. So, two dimensional array can perform a complete functionality. For example, we can add two
matrices, similarly we can do this with two dimensional array.

Consider the addition of two matrices:

1 2 3 11 12 13 12 14 16
4 5 6 + 14 15 16 = 18 20 22
7 8 9 17 18 19 24 26
28

Now, consider in C++ using two dimensional array:

void main()

clrscr();

int aar1[3][3], arr2[3][3];

arr1[3][3]={1,2,3,

4,5,6,

7,8,9};

*/it may be as

arr1[3][3]={1,2,3,4,5,6,7,8,9};

*/

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415

arr2[3][3]={11,12,13,

14,15,16,

17,18,19};

//add the two arrays

for(int i=0;i<3;i++)

for(int j=0;j<3;j++)

arr1[i][j] = arr2[i][j];

getch();

Discussion on ‘class’ with example

A class is an abstract data type as it contains a collection of data types and


structures (function). Class has a unique feature of ‘access specifier’. ‘private’ access
specifier is the default access specifier of the class.

Here is an example of class which shows running clock:

#include<conio.h>

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


#include<iostream.h>

#include<dos.h>

class Time

private :

int hh,min,sec;

public :

Time()

hh=0;

min=0;

sec=0;

void tim()

for(int i=0;sec<65;i++)

clrscr();

cout<<"\n\n\n\n\t\t\t\t"<<hh<<" : "<<min<<" : "<<sec;

if(sec>59)

sec=0;

min++;

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


if(min>59)

min=0;

hh++;

delay(1000);

sec++;

};

void main()

clrscr();

Time TimeObj;

TimeObj.tim();

getch();

Discussion on ‘structure’ with example


Structure is also an Abstract Data Type. It is a collection of different data types. It
contains the sum of all the bytes taken by its members. Here is an example of structure in
which different features are discussed.

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


#include<conio.h>

#include<iostream.h>

struct date

int dd;

int month;

int year;

};

void main()

clrscr();

date d1;

d1.dd=15;

d1.month=9;

d1.year=1430;

if(d1.month>29)

d1.month++;

else if(d1.year>12)

d1.year++;

cout<<"\n\n\n\n\n\n\t\t\t"<<d1.dd<<" : "<<d1.month<<" : "<<d1.year;

getch();

Comparison of ‘class’ with ‘structure’


A structure is an entity that is defined in terms of other structures or primitive
data types. As a result, a structure is normally considered to be a complex-, or
compound data type. With structures the default access type is public. Classes are
similar to structures in that they are made up of other data types, but they differ in

bilal.it@live.com 3
Prepared By:

Muhammad Bilal

Roll No: 415


one significant respect - classes contain information on the program functions
(formally termed "methods") that will be used to manipulate the data that the class
can store. The default access type for classes is private.

bilal.it@live.com 3

Anda mungkin juga menyukai