c++
TRANSCRIPT
CREATIVE HEAD: KHALILEDAPAL
CHAPTER 6 INTRODUCTION TO C++
PROGRAM
• Program is a sequence of instructions given to a computer to be executed to perform a desired task.
• Every program is written in some programming language and C++ is such a language developed at AT & T Bell Laboratories by Bjarne Strostrup in the 1980s.
• It has become the most popular language for object oriented programming (OOP), which is a programming style.
C++ CHARACTER SET
• It is a set of valid characters that are recognized by the C++ language.
They are• Letters: A-Z, a-z• Digits: 0-9• Special characters: ~ ! @ # $ % ^ & * ( ) _ - + / : , . ; ’ ” =
< > ? { } [ ] \ |• White spaces• Other characters: Non graphic characters (Back space,
Horizontal tab, Carriage return) and ASCII characters
TOKENS
• They are smallest individual units of a programming language.
• It is same as words in English and other languages.They are• Key words• Identifiers• Literals• Punctuators• Operators
KEYWORDS
• They are reserved words for C++ language, which are used for special purposes.
• There are 48 keywords. They are,• asm, double, new, switch, auto, else, operator, template,
break, enum, private, this, case, extern, protected, throw, catch, float, public, try, char, for, register, typedef, class, friend, return, union, const, goto, short, unsigned, continue, if, signed, virtual, default, inline, sizeof, void, delete, int, static, volatile, do, long, struct, while.
IDENTIFIERS
• It includes letters and digits used to identify memory locations (variables), or naming a function, labels etc.
• So they should follow the rules given below. (Variable/function naming rules)
• It should be unique but not a keyword.• First letter should be an alphabet.• White space, symbols, special characters are not allowed.• Underscore can use (_).• Uppercase and lowercase letters are evaluated differently.
LITERALS• They are represents data items that never change their values during a
program run. • They are also called constants. • They may be numeric literals, character literals, string literal and escape
sequence.• Numeric literals may be integer or floating literals. (125, 9876.3455)• Character literals are a single character enclosed in single quotes. (‘d’, ‘s’)• String constants group of characters enclosed in double quotes. (“Haritha”,
“Good Batch”)• Non graphic characters (Back space, Horizontal tab, Carriage return) are
represented by using escape sequences, which consist of a backslash (\) followed by one or more characters.
• \b for backspace• \r for carriage return• \n for new line• \t for horizontal tab
PUNCTUATORS
• They are symbols used as punctuation marks in the syntax of various codes and as separators to enhance program readability.
• They are, parentheses ( ), brackets [ ], braces { } , ; : asterisk * = pre-processor directive #
OPERATORS
• They are symbols that are used in operations such as input, output, computation, assignment etc. + - * / % << >> ++ etc are examples.
STRUCTURE OF A C++ PROGRAM
A sample program to display the string “My first program in C++” on the monitor
#include<iostream.h>//to include header files for working library functions#include<conio.h>//A sample program to display a stringvoid main()// It is the function invoked by the compiler first{clrscr();// Function for clearing screencout <<“My first program in C++”;getch();}
USE OF C++ IDE
• The C++ IDE (Integrated Development Environment) is used to enter the code, save, run, debug, compile, link, edit, execute a C++program.
• The file extension of a C++ program is .cpp.• To open IDE double click on Turbo C++ icon in the
desktop.
SHORTCUT KEYS IN C++ IDE
Shortcut key Usage
Alt+f To open file menu
F2 To save the program
F9 To compile the code
Ctrl+F9 To execute the code
Alt+F3 To close the current code window
Alt+F5 To display user screen
Alt+X To quit from the IDE
CHAPTER AT GLIMPSE
• Character set, tokens, structure of C++ program, use of I/O operators, usages of IDE:
• Editing, compiling, linking executing, saving.
MODEL QUESTIONS
• Suppose one of your friends was absent when the teacher demonstrated the C++ IDE and the process of compilation and program execution. Can you help him by explaining the various steps involved?
• A student types a C++ program and saves it in his personal folder as ‘sample.cpp’. After getting the output of the program, he checks the folder and finds three files namely sample.cpp, sample.obj, and sample.exe. Write the reason for the generation of the two new files in the folder.
• You are about to study the fundamentals of C++ programming language. Do a comparative study of the basics of the new language with that of a formal language like English or Malayalam to familiarize C++. Provide sufficient explanations for the compared items in C++ language.
CE ACTIVITIES
• Lab work: Write a simple program to display “My first program in C++” on the screen and test logical, syntax errors.