Data Types in Data Types in C++
* The preview only display some random pages of manuals. You can download
full content via the form below.
The preview is being generated... Please wait a
moment!
- Submitted by: Nitin Menon
- File size: 1 MB
- File
type: application/pdf
- Words: 863
- Pages: 20
Report / DMCA this file
Add to bookmark
Description
Data types In C++
WHAT IS C++.. C++ is an object-oriented programming language. It was developed by bjarne stroustrup at AT & T bell lab in murray hill,new jersey,usa. Stroustrup an admirer of c wanted to combine the best of both the languages and create a more powerful language’s that could support object-oriented programming feature and still retain the power and elegance of c.The resut was c++.
2
3
C++ datatypes are divided into three types 1. User-define datatype. 2. Build-in datatype.
3. Derived datatype.
4
5
User-define datatype Structure and class: we have studied some userdefine data types like struct & union in c. it is legal in c++ but some more features are added into it to make suitable for oop.class specification has two parts: [i]class declaration. [ii]class function defination. Class declaration describe the type & scope of member.function defination describe how the is class function is implemented.
6
Enumeration Data Types A data type is • A set of values together with • A set of operations on those values.
In order to define a new simple data type, called enumeration type, we need: • A name for the data type. • A set of values for the data type. • A set of operations on the values.
7
Enumeration Data Types C++ allows the user to define a new simple data type by specifying: • Its name and the values
• But not the operations.
The values that we specify for the data type must be legal identifiers The syntax for declaring an enumeration type is: enum typeName{value1, value2, ...};
8
Declaration of Enumerated Types Consider the colors of the rainbow as an enumerated type: enum rainbowColors = { red, orange, yellow, green, blue, indigo, violate }
The identifiers between { } are called enumerators The order of the declaration is significant red < orange < yellow …
9
Declaration of Enumerated Types Why are the following illegal declarations? enum grades{'A', 'B', 'C', 'D', 'F'}; enum places{1st, 2nd, 3rd, 4th}; They do not have legal identifiers in the list
• What could you do to make them legal? enum grades{A, B, C, D, F}; enum places{first, second, third, fourth};
10
Declaration of Enumerated Types As with the declaration of any object • Specify the type name • Followed by the objects of that type
Given: enum daysOfWeek { Sun, Mon, Tue,Wed, Thu, Fri, Sat }
Then we declare: daysOfWeek Today, payDay, dayOff;
11
Build-in datatype Void:There are basically three advantages of keyword void: [i] To specify return type of function when it is not returning any value. [ii] To indicate an empty argument list to a function. Example: void display (void). [iii] In the declaration of generic pointer. Void *gp; gp becomes a generic pointer.
SIZE AND RANGE OF C++ BASIC DATA TYPE
12
13
Derived data types ARRAYS FUNTIONS POINTER
ARRAYS DEFINITION: The C language provides a capability that enables the user to design a set of similar data types called ARRAYS. Eg. # include void main() { int x; x=5; X=10; Printf(”\nx=%d”,x); }
14
15
FUNCTIONS
DEFINITION: A function is a self-contained block of statements that perform a coherent task of some kind.
16
Function Prototyping Function prototyping is one of the major improvement added to c++ functions. The prototype describe the function interface to the compiler by giving details like the numbers & the type of arguments & the type of return values. The function prototype is a declearation statement in calling programm a&is of the following form:
Eg. 1. float volume( int x, float y, float z); 2. float volume( int x, float y, z); 3. float volume( int , float , float);
17
THE MAIN FUCTION C does not specify any return type for the main() function which is the starting point for the execution of a program. Eg. main() { // main program statements } this is perfectly valid because the main() in C does not return any value.
18
In C++, the main() returns a value of type int to the operating system. C++, therefore, explicitly defines main() as matching one of the following prototypes. int main(); int main(int argc, char * argc[]); The function that have a return value should use the return statement for termination. The main() function in C++ is therefore, defined as follows: int main() { :::::::::::::::: return 0; }
19
The main difference between C and C++ The main difference between C and C++ is that C++ is object oriented while C is function or procedure oriented. Object oriented programming paradigm is focused on writing programs that are more readable and maintainable. It also helps the reuse of code by packaging a group of similar objects or using the concept of component programming model. It helps thinking in a logical way by using the concept of real world concepts of objects, inheritance and polymorphism. It should be noted that there are also some drawbacks of such features. For example using polymorphism in a program can slow down the performance of that program.
20
THANK YOU