GVNS I PUC Science Notes Chapter 7 – INTRODUCTION TO ++

UNIT C – Chapter 7 – INTRODUCTION TO C++ BLUEPRINT 1 MARK 2 MARK 3 MARK 5 MARK TOTAL 1 0 1 1 9 ONE Mark Questions and Answers 1. Who developed “ C++ “ and where? Bjarne Stroustrup designed C++ programming language at AT & T Bell Labs. 2. C++ is a subset of C. True or false? True 3. How can comments be included in a program? Comments can be included in C++ program by writing the comment between the symbols /* and */ or by starting the comment with double front slash ( // ). 4. Define token. A token is the smallest individual unit in a program. 5. Mention two tokens. Two tokens are keyword, identifier. (Note: refer to your textbook for more tokens) 6. What are keywords? Keywords are predefined word with some meanings. 7. Mention any four keywords in C++. The four keywords are int, if, do, for. (Note: refer to your textbook for more keywords) 8. What is a constant? Constants are quantities whose value cannot be changed during the execution of a program. 9. What are escape sequences? Escape sequences are characters that as special meaning and it starts with back slash ( \ ). 10. Mention any two escape sequences. Two escape sequences are \n and \t (Note: refer to your textbook for more escape sequences) 11. What is a string? String is a sequence of characters enclosed in double quotes. 12. What are punctuators? Punctuators are symbols used in a C++ program as seperators. 13. What is an operand? The data items on which operators act are called operands. 14. What is an expression?

Prepared by: Krishna S Shetty Page 1 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

An expression is the combination of operators and operands which results in some definite value. 15. What is the difference between / and %? / gives quotient value in a division operation whereas % gives the remainder. 16. What are unary operators? Unary operators are the operators that act on only one operand. 17. What are ternary operators? Ternary operators are the operators that act on three operands. 18. What is the difference between = and == operators? = operator is used as assignment operator, which is used to assign a value to a variable. ==operator is used as comparison operator, which is used to compare two values. 19. What is type casting? Type casting is the process to change from one data type to another data type. 20. Mention the types of type casting. The types of type casting are: • Implicit type casting • Explicit type casting 21. What does main() signify in a “C++” program? main() signifies the start of the main part of the program.

FIVE Mark Questions and Answers Note: These questions can be also asked for THREE Mark. 1 Explain the characteristics of C++ in detail. The characteristics of C++ are: • Object-Oriented Programming - It allows the programmer to design software using class and object. It allows a greater reusability of code in a more logical and productive way. • Portability -We can compile the same C++ code in almost any type of computer & operating system without making any changes. • Modular Programming -An application’s body in C++ can be made up of several source code files that are compiled separately and then linked together saving time. • C Compatibility - Any code written in C can easily be included in a C++ program with slight changes. • Speed - The resulting code from a C++ compilation is very efficient. Prepared by: Krishna S Shetty Page 2 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

• Machine independent – C++ program can run on any machines. • Flexibility - It is highly flexible language and versatility. • Wide range of library functions - It has huge library functions; it reduces the code development time and also reduces cost of software development. • System Software Development - It can be used for developing System Software features like Operating system, Compilers, Editors and Database.

2 Explain the different C++ set. Character Set means the valid set of characters that a language can recognizes. The character set of C++ includes the following: • Digits : 0 -9 • Alphabets : a – z (lowercase alphabets) and A – Z (uppercase alphabets) • Special characters: + - / { } ( ) % “ ? : != * blank space \ |& (these are some of characters which are the building blocks and they form the basic program elements).

3 Explain the various tokens of C++ The various tokens of C++ are: 1. Identifier 2. Keyword 3. Constant or Literal 4. Punctuator 5. Operator Identifier - Identifier is a name given to programming elements such as variables, functions, arrays, objects etc. Keyword - Keyword is a predefined word that gives special meaning to the complier such as int, float, friend, class etc. Constant - A constant is an identifier whose value does not change during program execution. Integer constant, floating constant, character constant, string constant are some of the constants. Punctuator - Punctuators in C++ have special meaning to the compiler but do not by themselves specify an operation that yields a value. +, -, [ ], { }are some of the punctuators. Operator - An operator is a symbol that tells the compiler to perform specific mathematical or logical or relational or other operations. C++ is rich in built-in operators and there are almost 45 different operators. Prepared by: Krishna S Shetty Page 3 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

4 Explain the different rules of naming an identifier. The different rules of naming an identifier are: • Identifiers are a sequence of characters which should begin with the alphabet either from A-Z (uppercase) or a-z (lowercase) or _ (underscore). • C++ treats uppercase and lowercase characters differently. • No Special character is allowed except underscore (_). • No blank spaces are allowed in identifier. • Keywords should not be used as identifiers. • Identifiers should be of reasonable length.

5 What are escape sequences? Mention any four escape sequences. Escape Sequence is a special string used to control output on the monitor and they are represented by a single character and it starts with back slash ( \).

6 Explain Arithmetic Operator with an example. Arithmetic operators are used to performing the basic arithmetic operations such as arithmetic, subtraction, multiplication, division and mod (remainder after division).

Prepared by: Krishna S Shetty Page 4 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

Let us assume that variable a=10 and variable b=20

7 Explain Relational Operator with an example. Relational Operator is used to comparing two operands given in expressions. The relational operators supported by C++ are: ==, !=, >, <, >=. <= Let us assume that variable a=10 and variable b=20

8 Explain implicit and explicit type conversions with suitable examples. Implicit Conversion type conversion converts from one data type to another data type. This conversion is done by the complier.

Prepared by: Krishna S Shetty Page 5 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

For Example: short int a = 100; int b; b = a; Explicit Conversion type conversion converts from one data type to another data type like implicit type conversion, but the data type conversion as to mentioned in the coding. For example: float amt; int netamt; input amt; netamt=(int)amt;

9 Explain unary and ternary operators with suitable examples. Unary operator has only one operand; they are evaluated before any other operation containing them gets evaluated. Example • Post Increment Operator - a++ • Pre Increment Operator - ++a • Post Decrement Operator – a-- • Pre Decrement Operator - --a

Ternary operator has three operands. Syntax: exp1? exp2: exp3 where exp1,exp2, and exp3 are expressions. Exp2 is performed if exp1’s condition is true or else exp3 is performed. Example: If a=20; b=10 x = (a>b) ? a:b; In the above example, a’s value get stored in x.

10 Explain the detailed structure of C++ with a suitable programming example. Line 1 - //Program to display Welcome message Line 2 - #include Line 3 - void main( ) Line 4 - { Line 5 - cout<<”Welcome”; Line 6 - }

Prepared by: Krishna S Shetty Page 6 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

Line 1 – It is a comment section. It gives the basic idea of the program. Line 2 – This is a linker section. It is used to add header file to the program. The instructions for cout is found in header file iostream.h. Line 3 – All the statements that has to be performed are placed under this built-in function main( ). void is a data type indicates that this function doesn’t pass any value to any other functions (if any) in the program. Line 4 & 6 – Statements to be performed are placed in this brace (flower) brackets. Line 5 – cout command is used the sequence of characters from the program to the output device such as Monitor. In this case, ‘Welcome’ message is sent.

11 Explain any five mathematical functions (math.h). The following table lists the mathematical functions:

Prepared by: Krishna S Shetty Page 7 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

12 Explain any five character functions (ctype.h). The following table lists the character functions:

13 Explain any five string functions (string.h). The following table lists the string functions:

Prepared by: Krishna S Shetty Page 8 of 9 GVNS I PUC Computer Science Notes Chapter 7 – INTRODUCTION TO C++

14 Explain any four Console I/O functions The following table lists Console I/O function:

15 Explain precedence of operators or Hierarchy of operators If the expression contains multiple operators, the order in which operations are carried out is called precedence of operators. It is also called as priority or hierarchy. The precedence of operators along with its associativity is given in the below table:

______

Prepared by: Krishna S Shetty Page 9 of 9