Vahe Agazaryan
Download
Report
Transcript Vahe Agazaryan
Data Types, Data Structures & File Organizations
Vahe Agazaryan
CS 490
10-04-03
Jeff Miller
DATA TYPES
• The numbers 2 & 2.0 are the same numbers
but c++ considers them to be of different
types. The whole number 2 is of type int
and 2.0 is of type double because it contains
a fraction type. Numbers of type int are
stored as exact values. The precision with
which double values are stored varies from
one computer to another, but can expect
them to be store with 14 or more digits of
accuracy.
Here are some examples of
DATA TYPES
Type Name Memory Used Size Range Precision
Short (Short
Int)
Int
2 Bytes
Long (Long Int)
4 Bytes
Float
4 Bytes
Double
8 Bytes
Long Double
10 Bytes
4 Bytes
-32,767 to
32,767
-2,147,483,647
to +
-2,147,483,647
to +
Approx:10^-38
to 10^38
Approx:10^308 to 10^308
Approx:10^4932 to +
N/A
N/A
N/A
7 digits
15 digits
19 digits
The types for whole numbers, such as int and similar types, are called
integer types. The type for numbers with a decimal point such as the
type double are called floating point types.
Type char:
Values of type char are single symbols such as a letter, digit or
punctuation mark.
ex: char symbol.
A variable of type char can hold any single character on the keyboard.
Note that uppercase and lower case of a letter are considered different
characters.
Type Bool:
Boolean expressions evaluate to one of the two values true or false.
Boolean expressions are used in branching and looping statements.
A data type is called an abstract data type(ADT) if the programmers
who use the type do not have access to the details of how the values
and operations are implemented. The predefined type such as int, are
abstract data types. You do not know how the operations such as +
and *, are implemented for the type int. Even if you did know you
would not use this information in a c++ program.
DATA STRUCTURES
Data Structure is a representation of the logical relationship
among individual elements of data. Data structure dictates the
organization, methods of access, degree of associativity, and
processing alternatives for information.
Scalar item - is the simplest of all data structures. A scalar item
represents a single element of information that may be addressed by an
indentifier; that is, access may be achieved by specifying a single
address in memory.
It is important to note that data structures, like program structure, can
be represented at different levels of abstraction. For example, a stack
is a conceptual model of a data structure that can be implemented
as a vector or a linked list.
Example of a DATA
STRUCTURE
-Suppose that you wanted a data structure to store both the
names and salaries of a group of employees. You could use the
following c++ statement.
const int MAX_NUMBER = 500;
const int MAX_NAME_LENGTH = 20;
typedef char nameType[MAX_NAME_LENGTH+1];
nameType Names[MAX_NUMBER];
double Salaries[MAX_NUMBER];
The two arrays, Names and Salaries together form a data structure.
FILE ORGANIZATIONS
• While many simple programs fit into a
single C or CPP source file, any serious
project is going to need splitting up into
several source files in order to be
manageable.
• WHY SPLIT INTO SEVERAL FILES?
• Speed up compilation - most compilers
work on a file at a time. So if you have
10000 lines of codes in one file, and you
change one line, than you have to recompile
10000 lines, however if the code is in 5
files, then you only have to recompile
maybe about 2000 lines .
• Increase Organization - Splitting your code
along lines will make it easier for you to
find functions, ariable, class declarations,
etc.
• Share Code between projects - By carefully
separating code into certain files, you make
it possible for multiple projects to use some
of the same code files without duplicating
them.
• Split coding responsibilities among
programmers - for large projects, this is the
main reason for separating code into
multiple files. Each programmer can be
working on a separate part of the code
without affecting the file that the other
programmers are editing.
When implementing classes in C++ each class should be defined in a
separate header file. When writing large programs, organize your
program as a collection of "header" files (.h) and implementation files
(c or c++). The header files containing the class definitions are included
in the implementation files.
The .h files contain:
-#include of the other .h files
-preprocessor macros (#define)
-constant declarations
-class declaration
The .C files contain:
- #include of .h files
- extern/static data and object definitions.
REFRENCES
• Data Abstraction and Problem Solving with
C++
By Robert Lafore
• Software Engineering Approach
By Roger S Pressman
• Problem Solving with C++
By Walter Savitch