You are on page 1of 21

Recape

•Computing problems
• Solved by executing a series of actions in a
specific order
•Algorithm is a procedure determining
• Actions to be executed
• Order to be executed
• Example: recipe
•Program control
• Specifies the order in which statements are
executed
Who remember?
• Write your programs on
your machine
• Compile
• Debug
• Execute
Objectives

• We will introduce key words in C++


• Data types in C++
• Built in types
• User defined types
• Derived types

3
Common key words in C++
Data Type
• A data type is a classification that specifies the
types of value a variable can hold
• General syntax of declaration of data type is
Syntax: data_type variable_name
Variable name: it can be a combination of a-z, 0-9.
• Example: int number;
float number 2;
char choice;
C++ Data Types
Built in Data Types 1/4
• Integer Data Types:
• Keyword: int (INT)
• Storage space: Two bytes
• Range: -32768 to 32767
• Types of integer
• Short int
• Int
• Long int
Built in Data Types 2/4
• Character Data Types:
• Keyword: char (CHAR)
• Storage space: One byte
• Range: -128 to 127
Built in Data Types 3/4
• Float Data Types:
• Keyword: float (FLOAT)
• Storage space: Four bytes
• Range: 3.4e-38 to 3.4e+38
• Floating types
• Float
• Double
• Long Double
Built in Data Types 4/4
•Void Data Types:
It was introduced in ansi C
•To specify the return type of a function
when it is not returning any value.
•To indicate an empty argument list to a
function
•Example: void function name (void)
User Defined Types 1/5
•Structure
•Union
•class
•enumeration
User define Type 2/5
• Structure:
• They are used for grouping together elements with
dissimilar types
• The general syntax of a structure is

Struct name
{
Data types 1;
Data types 2;
};
User define Type 3/5
• Unions:
• They are conceptually similar to structures as they
allow us to group together dissimilar types
elements inside a single unit.
• The size of union is equal to the size of its largest
member elements
User define Type 4/5
• Classes:
• Entire set of data and code of an object can be
made a user-define data the with the help of a
classes
• Once a class has been defined, we can create any
number of objects belonging to that class.
• Example: fruit mango;
• Will create an object mango belonging to the class
fruit.
User define Type 5/5
• Enumerate:
• An enumerated dyat type is another user defined
data thpe which provides a way for attaching
number to names.
• General syntax of enumerated data types is
Enum identifier
{
value1, value2…..valuen
};
Derived types 1/3
• An array is a fixed sequence collection of
elements of same data types that share a
common name.
• General syntax to declare is:
• Data type name[size];
• Example:
int data[10];

16
Derived types 2/3
Functions:
•A function is a group of statements that work
together to perform a task
•Every C++ program has at least one function which
is main().

Void main()
{
statements;
}
17
Derived types 3/3
Pointers:
•A pointer is a variable that holds a memory
address
•General syntax to declare pointer is:
• Data_type *pointer_name;
•Every:

Int *ptr;

18
Lecture Recap
• We discuss following
• key words in C++
• Data types in C++
• Built in types
• User defined types
• Derived types
End of Lecture
Any Questions
Home work
• Write a program to check the overflow and under flow of
built in data types.
• Write a program that input a number and find whether its
even or odd
• Write a program that input a integer and print its ASCI
character.
• Write a program that inputs salary and grade. It adds 50%
bonus if grade is greater than 15. It adds 25% bonus if
grade is 15 or less, and then displays the total salary.
• Write a program for calculator. (use different data types)

Submit within 4 days

You might also like