OUTLINE Introduction of C++ Why Use C++ Keyword Operators Manipulators C++ Main() Control Statement File Handling 2
I NTRODUCTION 3 The C++ programming language was created by Bjarne Stroustrup and his team at Bell Laboratories (AT&T, USA) to help implement simulation projects in an object-oriented and efficient way. C++ is a superset of C because; any valid C program is a valid C++ program too but not vice versa is not true. C++ can make use of existing C software libraries with the major addition of " Class Construct ". This language was called " C with classes " and later in 1983 . As the name C++ implies, C++ was derived from the C programming language: ++ is the increment operator in C. History of C++:
I NTRODUCTION C++ is one of the world's most popular programming languages. C++ can be found in today's operating systems, Graphical User Interfaces , and embedded systems. C++ is an object-oriented programming language that gives a clear structure to programs and allows code to be reused, lowering development costs. C++ is portable and can be used to develop applications that can be adapted to multiple platforms. C++ is fun and easy to learn! 4 Why Use C++:
KEYWORD Keyword is a predefined word that gives special meaning to the compiler. The programmer is not allowed to change its meaning. Case Sensitive These are reserved for special purpose. Example: . 5 Reserve words cin else switch cout do bool for float break if while continue etc… Keyword in C++:
OPERATORS Operators are used to perform operations on variables and values. C++ Operators Types : C++ divides the operators into the following groups. 6 C++ Operators: Arithmetic operators Assignment operators Comparison operators Logical operators Bitwise operators
MANIPULATORS Manipulators are the operators used with the insertion operator " << " to format the data display. To use a manipulator it is a must to include a header file <iomanip.h> Example: endl manipulator: Causes a line feed to be inserted. It has the same effect as using the new line character "\n" . cout<<"Entered the two number"<< a << b <<endl; The setw() manipulator sets the width of the field assigned for the output. cout<< setw(6)<< “ IUIC "; 7 Manipulators: endl setw()
C++ MAIN( ) The starting point of all C++ programs is the main function. This function is called by the operating system when your program is executed by the computer. 8 C++ Main( ): int main() { cout << “ Welcome to IUIC " << endl; //Function body section return 0; }
CONTROL STATEMENTS Control statements are statements that alter the sequence of flow of instructions. The order in which statements are executed in a program is called the flow of control. Types of control statements: C++ supports two basic control statements. 9 ■ Selection statements ■ Iteration statements
CONTROL STATEMENTS This statement allows us to select a statement or set of statements for execution based on some condition . It is also known as a conditional statement . This structure helps the programmer to make accurate decisions. The different selection statements are: 10 Selection Statements: if statement if-else statement Nested - if statement switch statement
CONTROL STATEMENT The process of repeated execution of a sequence of statements until some condition is satisfied is called as iteration or loop . Iterative statements are also called as repetitive statements or looping statements . There are three types of looping structures in C++: 11 Iteration Statement: while loop do while loop for loop
FILE HANDLING The following classes in C++ have access to file input and output functions: ifstream - This data type represents the input file stream and is used to read information from files ofstream - This data type represents the output file stream and is used to create files and to write information to files. fstream - This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files. 12