Você está na página 1de 40

COMPUTER SCIENCE

SECOND YEAR (STD XII)

Volume 2 Notes
(2 marks,5 marks and one word questions and answers)

INDEX
CHAPTER 1: OBJECT ORIENTED CONCEPTS USING C++................................................................................... 3 IMPORTANT TWO MARKS QUESTIONS ................................................................................................................ 3 ONE WORD QUESTIONS ........................................................................................................................................... 3 CHAPTER 2: OVERVIEW OF C++ ................................................................................................................................. 5 IMPORTANT TWO MARKS QUESTIONS ................................................................................................................ 5 ONE WORD QUESTIONS ......................................................................................................................................... 10 CHAPTER 3: BASIC STATEMENTS ............................................................................................................................ 12 IMPORTANT TWO MARKS QUESTIONS .............................................................................................................. 12 IMPORTANT FIVE MARKS QUESTIONS ............................................................................................................... 12 ONE WORD QUESTIONS ......................................................................................................................................... 15 CHAPTER 4: FUNCTIONS ............................................................................................................................................ 16 IMPORTANT TWO MARKS QUESTIONS .............................................................................................................. 16 IMPORTANT FIVE MARKS QUESTIONS ............................................................................................................... 16 ONE WORD QUESTIONS ......................................................................................................................................... 20 CHAPTER 5: STRUCTURED DATA TYPES: ARRAYS ............................................................................................ 21 IMPORTANT TWO MARKS QUESTIONS .............................................................................................................. 21 ONE WORD QUESTIONS ......................................................................................................................................... 23 CHAPTER 6: CLASSSES AND OBJECTS.................................................................................................................. 24 IMPORTANT TWO MARKS QUESTIONS .............................................................................................................. 24 ONE WORD QUESTIONS ......................................................................................................................................... 25 CH 7 POLYMORPHISM ................................................................................................................................................. 27 IMPORTANT TWO MARKS QUESTIONS .............................................................................................................. 27 IMPORTANT 5 MARKS QUESTIONS...................................................................................................................... 27 ONE WORD QUESTIONS ......................................................................................................................................... 29 CHAPTER 8: CONSTRUCTORS AND DESTRUCTORS ......................................................................................... 31 IMPORTANT TWO MARKS QUESTIONS .............................................................................................................. 31 ONE WORD QUESTIONS ......................................................................................................................................... 31 CHAPTER 9: INHERITANCE ......................................................................................................................................... 32 IMPORTANT 2 MARKS QUESTIONS...................................................................................................................... 32 IMPORTANT 5 MARKS QUESTIONS...................................................................................................................... 33 ONE WORD QUESTIONS ......................................................................................................................................... 34 CHAPTER 10: IMPACT OF COMPUTERS ................................................................................................................. 36 IMPORTANT 2 MARKS QUESTIONS...................................................................................................................... 36 ONE WORD QUESTIONS ......................................................................................................................................... 36 Chapter 11: IT ENABLED SERVICES (ITES) ............................................................................................................. 37 IMPORTANT 2 MARKS QUESTIONS...................................................................................................................... 37 ONE WORD QUESTIONS ......................................................................................................................................... 38 Chapter 12: COMPUTER ETHICS ................................................................................................................................ 39 IMPORTANT TWO MARKS QUESTIONS .............................................................................................................. 39 ONE WORD QUESTIONS ......................................................................................................................................... 39

CHAPTER 1: OBJECT ORIENTED CONCEPTS USING C++ IMPORTANT TWO MARKS QUESTIONS Define object An object is a group of related functions and data that serves those functions An object is a kind of a self-sufficient subprogram with a specific functional area. The set of data items is split into smaller groups such that a set of operations can be performed on this group without calling any other function. This group of data and the operations together are termed - object. What is the significance of an object? Real life objects like a bank-account, a student, a bird, a car , a chair etc., embodies both state and behaviour and hence there is a resemblance with Objects in programming. Hence, Objects make it easy to represent real systems in software programs An object is a group of related functions and data that serves those functions. Define encapsulation The mechanism by which the data and functions are bound together within an object definition is called as ENCAPSULATION. Define polymorphism The ability of an object to respond differently to different messages is called as polymorphism. Polymorphism reduces software complexity, as multiple definitions are permitted to an operator or function Example: Consider the job of drawing different shapes like rectangle, square, circle and an arc. If we use one function, say, draw() which accepts different inputs and performs different functions accordingly for drawing different shapes, then as far as the user is concerned, he will use the function draw() to draw different objects with different inputs. This differential response of the function draw() based on different inputs is what is called as polymorphism. List advantages of object oriented programming Advantages of Object Oriented Programming Class data type allows programs to organize as objects that contain both data and functions . Data hiding or Abstraction of data provides security to data, as unrelated member functions(functions defined outside the class cannot access its data Polymorphism reduces software complexity, as multiple definitions are permitted to an operator or function Inheritance allows a class to be derived from an existing class , thus promoting reusability of code, and also promote insertion of updated modules to meet the requirements of the dynamic world What is meant by inheritance Inheritance allows a class to be derived from an existing class, thus promoting reusability of code, and also promote insertion of updated modules to meet the requirements of the dynamic world ONE WORD QUESTIONS __operates on a set of known input data items. input and output data items were represented as __ ___categorize the input data items. __help us in organizing our ideas about the solution of the problem. Solution of a problem was earlier viewed as two separate segments: Object oriented programming languages such as ___are based on the way human beings normally deal with the complex aspects facilitates the way of problem solving by combining data and operations that are to be performed on the data Group of data and operations together are termed as ___refers to physical features of an object ___refers to kind of functions that an object can perform. __is a group of related functions and data that serves those functions. _is a kind of a self sufficient subprogram with a specific functional area. ___communicates with one another sending data as inputs ___ (or abstraction of data) provides security to data The process of grouping data and its related functions into units called as objects is _ Mechanism by which data and functions are bound together is called __ Ability of an object to respond differently to different messages is called Different response to different inputs is called ___reduces software complexity ___provides multiple definitions to an operator or function The data type __conventionally represents an object in the real world __is a template for entities that have common behaviour. ___allows programs to organize as objects that contain both data and functions Computer program variables Data types Programming languages data and operations C++ Object Oriented programming objects State Behaviour Object Object object data hiding encapsulation encapsulation polymorphism. polymorphism. polymorphism Polymorphism Class Class Class data type

__are power packed as they include the functionality of the base class along with their own unique features process of acquiring base class is called ___ ___increases the functionality of a derived class. ___promotes reusability of code of the base class ___ promote insertion of updated modules to meet requirements of dynamic world

derived classes inheritance Inheritance Inheritance inheritance

CHAPTER 2: OVERVIEW OF C++ IMPORTANT TWO MARKS QUESTIONS What are tokens? Write the classification of tokens The basic types of elements used for coding are collectively called as TOKENS. A token is the smallest individual unit in a program. Tokens are classified as shown

What are keywords? Give examples Keywords have special meaning to the language compiler. These are reserved words for special purpose. These words cannot be used as normal identifiers. Examples: Auto, break const, case class, continue, default, delete, do, else, enum, for, friend, goto, if inline, new, operator, private, protected, public, return, signed, sizeof, static, struct, switch, this, unsigned, virtual, while. Write a short note on identifiers in C++ Identifiers are also called as variables. Variables are memory boxes that hold values or constants. A variable name must begin with an alphabet or underscore followed by alphabets or numbers. For example _test ; test ; sum12 are some valid identifiers. Write a note on string literal String Literal is a sequence of characters surrounded by double quotes. String literals are treated as array of characters. Each string literal is by default added with a special character \0 which marks the end of a string. For example testing Define operators. What are their classifications? Operator specifies an operation to be performed that yields a value. An operand is an entity on which an operator acts. For example: RESULT = NUM1 + NUM2 NUM1 and NUM2 are operands. + is the additional operator, that performs the addition of the numbers. The result (value) generated is stored in the variable RESULT by virtue of = (Assignment) operator. Operators are classified as Arithmetic Assignment Conditional Logical Manipulator Shift Preprocessor Relational Scope Resolution Type Cast Member dereferencing Memory Management Component Selection Which operators are specific to C++? The operators specific to C++ are

What are relational operators? List out the relational operators in C++ Relational Operators are used to compare values. The list of relational operators are : a)= = equal to b) > greater than c)< lesser than d)>=, <= greater than or equal to , lesser that or equal to e) != not equal to A relational expression is constructed using any two operands connected by a relational operator. The result of a relational operation is returned as true or false. The numeric constant zero (0) represents False value, and any nonzero constant represents true value. Example: a) 10 > 20 (is false, will return 0 ) b) 9==9 (is true, will return 1) Explain conditional operators with example ?: Is a ternary operator or is also called as the conditional operator The general syntax is E1 ? E2 : E3 where E1,E2,E3 are operands. E1 should essentially be of scalar type, E2 and E3 are values or statements. For example to find the maximum value of the two values one can express it as : max = (num1 > num2) ? num1 : num2; The variable max will take the value of num1 if num1 is greater than num2, otherwise max will be assigned with the value of num2. Write code using conditional operators for F=0.5 if x=30 otherwise f=5 F = (x == 30) ? 0.5: 5; Write a note on assignment operators = is the simple assignment operator. It is used to assign the result of an expression (on the right hand side) to the variable (on the left hand side of the operator). In addition to the simple assignment operator, there are 10 shorthand or compound assignment operators.They are: += , -=, *= , /= , %= (Bitwise assignment operators)&=, |=, ^=, <<= , >>=

List any four punctuators in C++ and write a line about them Punctuators are characters with a specific function. Punctuators Purpose ; Terminates a C++ statement // Treats statements prefixed with this as comments /* */ Blocks enclosed within these character are treated as comment {} Used to group a set of c++ statements. Coding for a function is also enclosed within these symbols [] Index value for an element in an array is indicated within these brackets Is used to enclose a single character Is used to enclose a set of characters What is a datatype in c++. What are the different datatypes in C++ Data Types are the kind of data that variables hold in a programming language. The ability to divide data into different types in C++ enables one to work with complex objects. Data is grouped into different categories for the following two reasons : The compiler may use the proper internal representation for each data type 2) The programmer designing the programs may use appropriate operators for each data type. They can be broadly classified into the following three categories: a) User defined type b) Built-in type c) Derived type

What is a user defined data type? List out user defined data types User Defined Data Type enables a programmer to invent his/ her own data type and define values it can assume. This helps in improving readability of the program. The various user defined data types are: Structure, Union, Class and Enumeration Example: student is a user defined data type of class

What is meant by type definition? Or write about typedef in C++ Users can define a variable that would represent an existing data type. Type definition allows users to define such user defined data type identifier. The syntax : typedef data_type user_defined_data_type_identifier; For example: typedef int marks; The data type identifiers marks is user defined identifiers for int. Users can define variables of int as follows: marks eng_marks, math_marks; grade eng_grade, math_grade ; typedef helps in creating meaningful data type identifiers, that would increase the readability of the program.

Write a note on enumerated data type Enumerated data type is one of the user defined data type. Enumerated data type helps users in creating a list of identifiers, also called as symbolic numeric constants of the type int. The syntax: enum data type identifier (value 1, value 2, value n); Examples : enum working_days (Monday, Tuesday, Wednesday, Thursday, Friday); enum holidays (Sunday, Saturday); The identifiers working_days , holidays are user defined data type. Monday, Tuesday is the list of values also called as enumeration constants or numeric constants. Users can declare variables of this enumerated data type using the syntax : enum identifier variable1, variable2 ,variable n; For example variables first_workingday and last_workingday of type working_days may be declared as follows: working_days first_workingday, last_workingday; These variables can take only one of the values defined for working_days. The enumeration constants (Monday, Tuesday, Wednesday) are given integer constants starting with 0 (zero) by the compiler. first_workingday = Monday ; or first_workingday = 0 ; Users can also redefine these integer constants by assigning explicit values to the enumeration constants as enum working_days (Monday = 1, Tuesday, Wednesday, Thursday, Friday); Here, constant Monday is assigned value of 1. The remaining constants are assigned successive integer constants. What is the void data type? List important purposes of void data type void data type indicates the compiler that the function does not return a value, or in a larger context void indicates that it holds nothing. Void type has two important purposes: o To indicate the a function does not return a value o To declare a generic pointer In the example, the prototype void fun(void) indicates that the function does not return any value, nor does it receives values(in the form of parameters). Hence the call statement in the main() function is given as fun() .

What are modifiers? What is the impact of modifiers? Basic data types (like integral and floating) have several modifiers. These modifiers have a profound effect in the internal representation of data. The modifier alters the base data type to yield new data type. long, short, signed and unsigned are modifiers(qualifiers) that modify builtin data type with the exception of void. The impact of modifiers: o unsigned modifies the range of the integer values as the sign bit is also used to store data. o long increases the bytes for a particular data type, thus increasing the range of values. Example : unsigned int registration_number; long unsigned int index; short signed char c; Prefix the data type with modifiers at the time of declaring variables. Name the four storage specifiers The four storage specifiers are auto, static, extern and register. static and register variables are automatically intialized to zero when they are declared. Auto variables are not initialized. Auto variables get undefined values known as garbage. Write a note on storage classes in C++ Storage Class is another qualifier (like long or unsigned) that can be added to a variable declaration Storage Meaning Example Auto Defines local variable known to the block in which they are defined. void main() By default the local variables are auto hence rarely used { auto float ratio; Int kount;} The variables ratio and kount have storage specifiers as auto static Variables defined within a function or a block do not exist , the void fun(){ moment the function or the block loses its scope. Static modifier static int x; allows the variable to exist in the memory, even if its function or block x++; within which it is declared loses its scope. Hence static variable } retains the last assigned value.

extern register

Global variable known to all functions in the current program. These variables are defined in another program. The modifier register instructs the compiler to store the variable in the CPU register to optimize access.

extern int filemode; extern void factorial(); void fun(){ register int i;}

What is a pointer variable? Give example or How to declare pointer variable? A pointer is a variable that holds a memory address. Pointers provide the means through which the memory locations of a variable can be directly accessed. Every byte in the computers memory has an address. The address number starts at NULL and goes up from there.. 1, 2 , 3.. For example a memory size of 640 KB will have addresses commencing from NULL and goes up to 655, 358

Here, iptr is a pointer variable. The declaration statement int *ptr may be read as ptr is a pointer variable of the type int. The variable ptr can only store addresses that hold integer values. Examples of pointer variables: char *cptr declaring a pointer to character type float *fptr pointer to float type void *vptr a pointer that can point to any data type a generic pointer is declared in this way const int * ptr ptr is a pointer to a constant integer (cannot modify the value stored at the address pointed by ptr) char * const cp cp is a constant pointer. The address stored in cp cannot be modified How is a pointer variable different from ordinary variable? 1) Variables are allocated memory to store data. Compiler allocates memory, based on the data type of the variable. Pointer variables store the address of other variables. 2) A variable gets defined when memory is set aside .Some variables also get defined when they are declared but Pointer variables get defined only when memory is fetched. For example by using new memory operator What are the rules for implicit conversion? Implicit conversions: refers to data type changes brought about in expressions by the compiler. Consider a term, having a pair of operands and an operator. The conversions takes place as follows : 1. If one operand is of type long double , then the other value is also converted to long double. 2. If one operand is of type double, then the other value is also converted to double. 3. If one of the operands is a float, the other is converted to a float. 4. If one of the operands is an unsigned long int, the other is converted to unsigned long int. 5. If one of the operands is a long int, then the other is converted to long int. 6. If one operands is an unsigned int, then other is converted to an unsigned int. Write a note on sizeof operator sizeof is an operator . It returns the size (memory requirement) in terms of bytes, of the given expression or data type. For example, size of int is 2, size of float is 4, size of double is 4 etc. Explain & operator and the * operator with respect to the pointers? When dealing with pointer data type one needs to know about the address of (&) operator and the value at operator (*). & operator int i = 10; will display the address of the variable i and not the value 10 cout<<&i; int *iptr, num1; Here, the iptr is a pointer variable and the address of the num1 = 10; variable num1 is assigned to the pointer variable iptr iptr = &num1; * operator The asterix ( * ) is 1) Used to declare a pointer variable 2) Used to display the contents stored at a location ( value at the address operator ) 3) It is a unary operator Write a note on type cast Type cast refers to the process of changing the data type of the value stored in a variable . The statement (float) 7 , converts the numeric constant 7 to float type. Type cast is achieved by prefixing the variable or value with the required data type. The syntax is: (data type) <variable/value> or data type (variable/constant) Type cast is restricted only to fundamental or standard data types.

Evaluate the expressions If c = 5, d=6, choice=y and term=2 then evaluate the expression Result = (c==d) && (choice != term)

Result = 0 (false) PROBLEMS Evaluate: assume a=5, b=3, d=1.5 C is integer and F is float 1) F = a + b/a :5 + 3/5 = 5+ 0 = 5.000000 2) C = d * a + b : 1.5 * 5 + 3 = 7.5 + 3 = 10.5 = 10 { because C is an integer} Find the output of the foll: x=5; F=6; C = X++ + ++F; C = 5++ + ++6 = 5 + 7 = 12 . C=12, x=6 and F=7

Operator Precedance

Data Types sizes and range of values Type char unsigned char signed char int unsigned int,unsigned short int signed int,short int, signed short int long int,signed long int unsigned long int float double long double

Byte 1 1 1 2 2 2 4 4 4 8 10

Range -128 to 127 0 to 255 -128 to 127 -32768 to 32767 0 to 65535 -32768 to 32767 -2147483648 to2147483647 0 to 4294967295 3.4e-38 to 3.4e+38 1.7e-308 to1.7e+308 3.4e-4932 to 1.1e+4932

ONE WORD QUESTIONS C++ was developed by AT&T BELL Laboratories C++ was developed by __in___ Bjarne Stroutstrup, 1980 C++ was coined by ___ Rick Mascitti Tokens ___are the basic elements essential for programming coding Basic types are collectively called as ___ __ is the smallest unit of a program Keywords ___have special meaning to the language compiler __are reserved words for special purpose ___are also called as variables Identifiers ____ are memory boxes that hold values or constants Identifiers ___are data items whose values cannot be changed Constants Octal constant starts with __ 0 (ZERO) hexadecimal constant starts with __ 0x ___constant is a signed real number floating point _is a constant that contains a single character enclosed within single quotes Character constant __are non graphic character constants and are prefixed with a backslash (\) Escape sequences Escape Sequences horizontal tab \t Vertical tab \v bell \a Newline/linefeed \n Backslash Single quotes \ Null \0 Octal \o Double quotes \ String literal \0 Operator Operand :: .* ->* unary, binary and ternary One Two Three :: # and ## Arithmetic operators associativity Relational operators Logical operators Conditional operator (? :) assignment operator 10 Punctuators // [] Multi line comment Enclose single character /* */ Hexadecimal ___is a sequence of characters surrounded by double quotes ___are treated as array of characters ___marks the end of string ___specifies operations to be performed that yields a value ___is an entity on which operator acts there are 3 types of operators SPECIFIC to C++ Based on operand requirements, operators are classified as ___operators Unary operators require ___operand Binary operator requires ___ operands Ternary operator requires ___ operands. __ is the scope resolution operator The operators ___are used only by the preprocessor __are used to perform mathematical operations logical grouping of operators and operands are called __ __are used to compare values ___combine the result of one or more conditions ___is a ternary operator = is an ___ There are ___shorthand assignment operators ___are characters with specific functions Punctuators ; terminates c++ statement single line comment { } Index value for array element group a set of c++ statements Enclose set of characters ___are kind of data that variable can hold There are 3 categories of data types: ___data type improves readability of the program ___enables programmers to invent their own data type and define values it can assume ___allow users to define user defined data type identifiers Users can define a variable that would represent an existing data type, can be achieved by ___ ___data type helps in creating list of identifiers ___ data type is also called as symbolic numeric constants of the type int There are 4 storage specifiers: ___variables are not initialized automatically and is default storage class ___ variables get undefined values known as garbage

\\ \x

Data types User defined, Built-in & Derived User defined Type definition (typedef)

Enumerated auto, static, extern and register Auto

10

___ variables retain the last assigned value Built in data types is the other name for ___ They are predefined in the compiler. There are 3 fundamental data types: ___type is further divided into int and char. ___ type is further divided into float and double ASCII value of A is ___does not have a return value ___ is used to declare a generic pointer __is a variable that holds memory address of other variables Every byte in the computer memory has an A memory size of ___ will have addresses commencing from NULL and goes up to 655, 358 Amount of memory allocated depends on the ___ __ is the address of operator __is the value at operator The pointer variable ___ is a unary operator pointer variable __ is used to display the contents stored at a location Names assigned to a data field that can assume any set of values are called ___ ___are user defined named entities of memory locations that store data ___are allocated memory to store data There are nine words for data types such as: long, short, signed and unsigned are ___that modify a built-in data type with the exception of void. The ___alters the base data type to yield new data type variable names should be separated by __ Integer values are stored in ___format bits are used to store data maximum value stored in an ___is +32767 and minimum value is -32768 ___ bit is the most significant bit When the modifier ___is used integer data type will store only positive values, sign bit is also used to store data. _increases the bytes for a particular data type, thus increasing the range of values __qualifier specifies value of a variable will not change at run time ___refers to the data type changes brought about by the compiler _returns the size or memory requirement in term of bytes process of changing the data type of the value stored in a variable is __.

Static fundamental or basic data type Integral, float and void Integral floating 65 Void pointer address 640KB data type & * * variables

char , int , double , float, void, short, signed, long and unsigned qualifiers or modifiers modifier comma 16 bit integer 16th unsigned long Const implicit conversions Sizeof operator typecast

11

CHAPTER 3: BASIC STATEMENTS IMPORTANT TWO MARKS QUESTIONS What are the various sections of a C++ program A C++ program has primarily three sections viz., Include files Declaration of variables, data type, and user defined functions. main() function On successful compilation, when the program is executed the main() function will be automatically executed. It is from this block, that one needs to give call statements to the various modules that need to be executed and the other executable statements. What do you know about assignment statements in C++ An assignment statement, assigns value on the right hand side of an expression to the variable on the left hand side of the assignment operator. = is the assignment operator. For example: num = 5; total = english+maths; sum += class_marks; During assignment operation, C++ compiler converts the data type on the right hand side of the expression to the data type of the variable on the left hand side of the expression. What are control structures? What are the two main categories of control structures? OR Define control statements in C++ Program statements that cause a jump of control from one part of a program to another are called Control Structures. The control structures are implemented in C++ using control statements The two major categories of control structures are Decision making statements or selection statements and Looping statements. The selection statements are: if-else and switch statements The looping statements are: do.while() loops, for loops and while() loops

Explain entry check and exit check loops Based on the position of the condition, the loops are classified as Entry-Check loop and Exit Check Loop. If the condition is placed at the entry of the body of the loop, then it is called as Entry Check loop and if it is placed at the end of the body of the loop then it is called as exit check loop There are three kinds of loops in C++, the for loop, the while loop and the do .. while loop. The for loop and the while loop are Entry check loop whereas the dowhile loop is an exit check loop List the rules for formation of nested loops The rules for the formation of nested loops are: 1. An outer loop and inner loop cannot have the same control variable, as it will lead to logical errors 2. The inner loop must be completely nested inside the body of the outer loop. IMPORTANT FIVE MARKS QUESTIONS

Explain if else statement with example The decision making or selection statements are: if-else and switch statements if statement : is the simplest of all the decision statements. It is implemented in two forms: 1) Simple if statement 2) if .. else statement which chooses between two alternatives, executes the chosen block based on the condition Else block is executed only if True block is not executed.

12

Example: // Demonstrates use of if else statement # include <iostream.h> # include <conio.h> void main(){ int a; clrscr(); cout << \nEnter a number ; cin >> a; if ( a%2 == 0) cout <<\nThe given number << a << is even; else cout <<\nThe given number << a << is odd; getch(); } In the above program The given number 10 is even is printed if the expression is evaluated to true, otherwise statement following else option will be executed. Explain switch statement in detail Switch statement is a decision making or selection statement. This is a multiple branching statement where, based on a condition, the control is transferred to one of the many possible points. Example: # include <iostream.h> # include <conio.h> void main() { int a, remainder; cout << \nEnter a number ...; cin >> a; remainder = a % 3; switch (remainder) { case 1 : cout << \nRemainder is one; break; case 2 : cout << \nRemainder is two; break; default: cout << \nThe given number is divisible by 3; break; } getch();} Above program checks for divisibility by 3 and prints messages accordingly Every action block should be terminated with a break statement. Otherwise all action blocks are executed sequentially from the point where the control has been transferred based on the condition. Switch selection expression must be of integral type which means that switch expression should be evaluated to an integer constant only

Explain nested if statement with example of c++ Nested if statement : The statement sequence of if or else may contain another if statement ie., the if .. else statements can be nested within one another as shown below : if (grade = = A) if (basic > 5500) incentive = basic * 10/100; else incentive = basic * 5/100; else cout << Try to attain Grade A; In an nested if .. else statement, Each else matches with the nearest unmatched preceding if

Discuss about the general working of loops Loops execute a set of instructions repeatedly for a certain number of times. A looping block consists of two segments viz., the body of the loop and the control statement.

13

The control statement checks the condition, based on which directs the control back to the body of the loop to execute the segment repeatedly. In general, a looping process would work in the following manner: 1. Initializes the condition variable 2. Executes the segment of the body 3. Increments the value of the condition variable as required 4. Tests the condition variable in the form of a relational expression. Based on the value of the relational expression the control is either transferred to the beginning of the block, or it quits the loop. There are three kinds of loops in C++, the for loop, the while loop and the do .. while loop. Explain for loop with suitable example for (; ; ) .. loop : is an entry controlled loop and is used when an action is to be repeated for a predetermined number of times. The syntax is for(intial value ; test-condition ; increment) { action block; } The general working of for(;;)loop is: 1. The control variable is initialized the first time when the control enters the loop for the first time 2. Test condition is evaluated. The body of the loop is executed only if the condition is TRUE. Hence for(;;) loop is called as entry controlled loop. 3. On repetition of the loop, the control variable is incremented and the test condition will be evaluated before the body of the loop is executed. 4. The loop is terminated when the test condition evaluates to false. # include <iostream.h> # include <conio.h> void main() { int i,fact = 1; for(i = 1; i < 6; i++) fact *= i; cout << \n Factorial of the number is .. << fact; } Example:The program below calculate factorial of 6. Write a note on break and continue statements Break statement A loops execution is terminated when the test condition evaluates to false. Under certain situations one desires to terminate the loop, irrespective of the test expression. Example: # include <iostream.h> # include <conio.h> void main(){ clrscr(); int a[] = {1,2,3,4,5,6,7,8,9}; int search_item = 7; for(int x=0; x<9;x++) { if (a[x] == search_item) { cout << \nItem found at position .. << x; break;} } cout << \n << value of index position is .. << x; getch(); } The result of the index position will be 6, and as soon as the match occurs, the break statement will terminate the loop. Hence, break statement accomplishes jump from the current loop Continue statement The continue statement forces the next iteration of the loop to take place, skipping any code following the continue statement in the loop body. Example # include <iostream.h> # include <conio.h> void main(){ int i = 1,sum = 0; for(;i<10;i++) { if( i % 2 == 0){ sum += i; continue;}

14

cout <<i; } cout << \nSum of even nos..<<sum; getch();}

ONE WORD QUESTIONS There are __methods for assigning data to the variable. They are assignment statement and reading the data during runtime of the program __is a predefined object that corresponds to a standard input stream The declaration for the object cin are available in a header file called ___ The declaration for the object cout are available in a header file called ___ __combines the properties of istream and ostream. The declaration for the objects cin and cout are available in a header file called __ A __comprises of all standard declarations and definitions for predefined functions. One can include a header file using a __directive. A preprocessor directive starts with __ __is a typical preprocessor directive. __is the extraction operator or get from operator. __is called the insertion operator or put to operator cascading of __facilitates sending of multiple output via a single statement A c++ program has primarily __sections. If a declaration sets aside memory for the variable it is called___. Pointer variable gets defined by using a new memory operator. Program statements that causes flow of control from one part to another part is called variables used in control structures are called __ There are __ categories of control structures: Decision making & Looping statements Decision making statements are __statement chooses between two alternatives __ is the simplest of all decision and has 2 forms (simple if and if-else statement) __creates branching for multiple alternatives sections of code. ___ is a multiple branching statement To exit from switch statement, in each action block one has to include __ statement __execute a set of instructions repeatedly for certain number times. A looping block consists of __ segments: the body of the loop and control statement there are __ kinds of loops in C++: for, while and do-while loops Based on the position of the condition, the loops are classified as: Loops are unconditionally executed at least once, if the condition is do while is an __loop while loop and for loops are _____loop A for loop consists of __ segments (initialisation of control variable, test condition and increment) Each segment of the for loop is separated by __ operator inner loop must be completely nested inside the body of the __ __forces the next iteration of the loop to take place skipping any code following continue. __would exit the current loop only ___ accomplishes jump from the current loop Programs are written in ___ language Program in high level language is called source code is converted into machine readable code called __ Compiler creates__. __are translator programs that create machine-readable program from source code __checks for the grammar of the language (SYNTAX) object file is linked with libraries to generate __

two cin istream.h ostream.h Iostream.h Header file preprocessor # #include >> (get from) << (put to) Insertion operator Three (3) definition control structures. control variables Two (2) If and switch if-else If statement Switch break Loops Two (2) Three (3) Entry and exit check Exit check exit check entry check Three (3) ; outer loop Continue statement break statement high level source code object file object files Compilers Compilers executable file

15

CHAPTER 4: FUNCTIONS IMPORTANT TWO MARKS QUESTIONS What are the advantages of functions? Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. Functions are advantageous because 1) They can be shared by other programs by compiling it separately and loading them together. 2) They reduce the size of the program 3) They induce reusability of code Give a general syntax and example for function prototype (2) Functions should be declared before they are used in a program. Declaration of a function is made through a function prototype. The general syntax of a function prototype <type > <function identifier > (<arguments>); For example: void fun (char); int max (int, int); int max (int a, int b); The prototype provides the following information to the compiler: Number and type of arguments and the type of return values What is the main purpose of function prototype The main purpose of function prototype is to help the compiler to check the data requirement of the function. With function prototyping, a template is always used when declaring and defining a function. When a function is called, the compiler uses the template to ensure that proper arguments are passed, and the return value is treated correctly. Any violation in matching of the arguments or the return types will be treated as errors by compiler, and flagged at the time of compilation. Why do you think the prototype int max (int, int) is valid?? In a function declaration, the names of the arguments are dummy variables and therefore they are optional. The variables in the prototype act as place holders. The arguments names are required in function definition, as the arguments are referenced inside the function Define parameters The call statement communicates with the function through arguments or parameters. Parameters are the channels through which data flows from the call statement to the function and vice versa. Define actual parameters and formal parameters Actual parameters are parameters associated with the call statement Formal parameters are the parameters associated with function header List the two types of parameter passing in function (2) In C++, functions that have arguments can be invoked by 1) Call by value 2) Call by reference Differentiate between call by value and call by reference (2) Call by value Call by reference The called function creates new variables to store the value Formal and actual parameters in reference type of the arguments passed to it. Also, the flow of data is point to the same storage area always from the call statement to the function definition. Any change in the formal parameter is not reflected back to Any change made in the formal parameter is the actual parameter. reflected back in the actual parameter List the types of scope rules of variables in C++ (2) There are four types of scopes in C++. They are: 1. Local scope 2. Function scope 3. File scope

4. Class scope

IMPORTANT FIVE MARKS QUESTIONS How is a function called? Give example (5) A function can be called or invoked from another function by using its name. The function name may include a set of actual parameters, enclosed in parentheses separated by commas. For example,

16

Explain call by value with example (5) In the call by value method, the called function creates new variables to store the value of the arguments passed to it. This method copies the values of actual parameters into the formal parameters, thus the function creates its own copy of arguments and then uses them. Example: # include <iostream.h> # include <conio.h> int add (int a, int b) { return a + b;} void main ( ) { int x1, x2, sum; cin >> x1 >> x2; sum = add (x, x2); cout << sum; } When arguments are passed by value, the called function creates new variables of the same data type as the arguments passed to it. The values of these arguments are copied into the newly created variables. Hence, changes or modifications that are made to formal parameters are not reflected in the actual parameters Explain call by reference with example (5) In the call by reference method, the called function arguments formal parameters become alias to the actual parameters in the calling function. This means that when the function is working with its own arguments, it is actually working on the original data Example: # include <iostream.h> #include <conio.h> void swap (int &n1, int &n2) { int temp; temp = n1; n1 = n2; n2 = temp; cout<<\n<< n1 <<\t<<n2<<\n; } void main ( ) { int m1 = 10, m2 = 20; clrscr(); cout<<\nValues before swap call <<\t<<m1<<\t<< m2; swap(m1,m2); cout<<\n Calling swap..; cout<<\n Back to main.Values are << \t << m1 << \t<< m2; getch ( ); }

17

The modifications made to formal parameters are reflected in actual parameters, because formal and actual parameters in reference type point to the same storage area What are the rules for actual parameters? Rules for actual parameters are: 1. The actual parameters can be passed in the form of constants or variables or expressions to the formal parameters which are of value type. For example, For a function prototype : int add (int n1, int n2); - the call statements may be as follows : x = add (5, 10); x = add (a1, a2); where a1 and a2 are variables 2. The actual parameters can be passed only as variables to formal parameters of reference type. For example, int add (int &n1, int &n2); x = add (a1, b1) ; where a1 and b1 are variables The following call statements are invalid: x = add ((a1 + b1), a1); x = add (5,101); What are default arguments? Give example In C++, one can assign default values to the formal parameters of a function prototype # include <iostream.h> # include <conio.h> float power (float n, int p = 1) { float prd = 1; for (int i = 1; i<= p; i++) prd *= n; return prd; } void main ( ) { clrscr ( ); int x = 4, b = 2; cout << \n Call statement is power(b, x)... << power (b, x); cout << \n Call statement is power(b).. << power (b); getch ( ); } In the call statement power (b,x), initialization is n= b, p = x In the second form power (b), the variable n is initialized, whereas p takes the value 1 (default argument), as no actual parameters is passed. Explain inline function with example (5) Call statement to a function makes a compiler to jump to the functions and also to jump back to the instruction following the call statement. This forces the compiler to maintain overheads like STACKS that would save certain special instructions pertaining to function call, return and its arguments. This reduces the speed of program execution. Hence under certain situations specially, when the functions are small, the compiler replaces the function call statement by its definition ie., its code during program execution. This feature is called as inlining of a function technically called as inline function. An inline function looks like a normal function in the source file but inserts the functions code directly into the calling program. Inline functions execute faster but require more memory space. Example: # include <iostream.h> # include <conio.h> inline float convert_feet(int x) { return x * 12; } void main() { clrscr(); int inches = 45; cout << convert_feet(inches); getch(); }

18

the call statement to the function (convert_feet(inches) will be replaced by the expression in the return statement (inches * 12) as shown below: # include <iostream.h> # include <conio.h> void main() { clrscr(); int inches = 45; cout << inches * 12 ; getch(); } Define scope. Explain various types of scopes in C++ language. (5) Scope refers to the accessibility of a variable Local Scope 1) A local variable is defined within a block 2) The scope of a local variable is the block in which it is defined. 3) A local variable cannot be accessed from outside the block of its declaration. 4) A block of code begins and ends with curly braces { }. 5) Local variables exist only while the block of code in which they are declared is executing. A local variable is created upon entry into its block and destroyed upon exit Code Snippet: if (a > b) { int temp; The scope of the variable temp is not available outside its block and temp = a; hence the compiler will throw an error at cout a= b; b = temp; } cout << a << b << temp; Function scope The scope of variables declared within a function is extended to the function block, and all sub-blocks therein. The life time of a function scope variable, is the life time of the function block. The scope of formal parameters is function scope. Code: # include <iostream.h> void main ( ) { int flag = 1; a = 100; while (flag) { int x = 200; if (a > x) { int j; } else { int h; }}} Here, the variable flag is accessible in the function main() and also in the while block and the if block, whereas x is accessible inside the while block only File scope A variable declared above all blocks and functions (precisely above main ( )) has the scope of a file. The scope of a file scope variable is the entire program. The life time of a file scope variable is the life time of a program. // scope of a variable declared at file level # include <iostream.h> # include <conio.h> int i = 10; void fun ( ) { cout << i; } void main ( ) { cout << i; while (i) { } }

19

Define scope operator The scope operator or scope resolution operator reveals the hidden scope of a variable. :: is called as scope resolution operator. It is used to refer variables declared at file level. This is helpful only under situations where the local and file scope variables have the same name. Code: # include <iostream.h> # include <conio.h> int num = 15; void main() { clrscr(); int num = 5; num = num + ::num; cout << num << \t << ++::num; getch(); } The variable num is declared both at file scope level and function main() level

ONE WORD QUESTIONS

__are the building blocks of a c++ programs __ are the executable segments in a program __reduce the size of the program and induce reusability of code. the starting point of the execution of a program is __ declaration of a function is made through a __ __helps the compiler to check the data Variables in the prototype act as__. a function can be called from another using its __ __are channels through which data flows from the call statement to the function __ parameters are parameters associated with call statement __ parameters are parameters associated with function header. function creates its own copy of the __ In a __any change in the formal parameter is not reflected back to the actual parameter In __actual parameters can be passed in the form of constants or variables or expressions. In a __any change in the formal parameter is reflected back in the actual parameter In __actual parameters can be passed in the form of variables only actual parameters can be passd only as variables to formal parameters of __type In c++ one can assign default values to the parameters of a function prototype using__. default value is given in the form of Compiler maintains overheads like __ that would save certain special instructions pertaining to a function call, return and its arguments __ reduces the speed of program execution __ inserts the function code directly into the calling program __execute faster but require more memory space __refers to the accessibility of a variable. there are __ types of scopes in c++: local, function, file and class scopes _is defined within a block __ cannot be accessed from outside the block __ is created upon entry and destroyed upon exit of a block life time of a __ variable is the life time of the function block variables declared above all blocks above main has __scope scope of __variable is the entire program Scope operator :: reveals the __of a variable.

Functions

main() function prototype place holders name parameters actual Formal arguments call by value

call by reference

Reference type default arguments variable initialization stacks

inline functions inline function Scope Four (4) local variable

function scope file file scope hidden scope

20

CHAPTER 5: STRUCTURED DATA TYPES: ARRAYS IMPORTANT TWO MARKS QUESTIONS What is an array? Write in brief about types of arrays An array is a collection of variables of the same type that are referenced by a common name Arrays are of two types: 1) One dimensional: comprises of finite homogenous elements. Example: int num_array [5]; 2) Multi dimensional: comprises of elements, each of which is itself a one-dimensional array An array marks [3][4] is a table with 3 rows, and 4 columns. Ex: float marks[3][4]; Write a note on array of characters or strings Strings are otherwise called as literals, which are treated as single dimensional array of characters. The declaration of strings is same as numeric array. For example, i. char name [10]; ii. char vowels [ ] = {a, e, i, o, u}; iii. char rainbow [ ] = VIBGYOR; A character array (used as string) should be terminated with a \0 (NULL) character. Write a note on gets() or write the syntax of gets() To treat spaces as part of string literal, then one has to use gets ( ) defined in stdio.h or getline ( ) - a member function of standard input stream. Syntax for gets ( ) is gets (char array identifier) or gets (char *) write the syntax of getline() getline() is a member function of standard input stream Syntax for getline is cin.getline (char *, no.of characters, delimiter); Write the syntax of 2D array declaration OR What is a 2D array? How can it be declared? A two-dimensional array is an array in which each element is itself an array. For instance, an array marks [3] [4] is a table with 3 rows, and 4 columns. A 2-D array is declared as: Type array-id [Rows] [Columns]; Example: 1. int a[3] [2]- declares 3 rows and 2 columns for the array a 2. const i=5; float num [i] [3] - declares a 2-D table num with 5 rows and 3 columns 3. short fine [A] [E] - declares a 2-D table of 65 rows and 69 columns Write a note on memory representation of 2D array A 2-D array is stored in sequential memory blocks. The elements are stored either 1. row-wise manner (this method is called as row-major order) 2. column-wise manner (this method is called as column-major order) Write a note on write() in C++ write( ) is a member function of standard output stream, i.e., ostream. All member functions of a class, should be accessed through an object / instance of class. The two parameters required for write () function are identifier string characters, and the no. of characters to be displayed. Example: cout.write (pincode, 7); # include <iostream.h> Output will be # include <conio.h> void main() { T clrscr ( ); Te char name[] = Tendulkar; Ten int i=1; Tend while (i<10) { Tendu cout.write (name, i); Tendul cout << \n; Tendulk i++;} Tendulka getch ( );} Tendulkar What are the different ways to indicate the dimensions (row/columns) of an array

21

The dimensions (rows/columns) of an array can be indicated 1. using integer constants 2. using const identifier of integer or ordinal 3. using char constants 4. using enum identifiers Write about any two string functions in C++ Function Format Purpose and value returned strlen() strlen (char *) Returns the number of characters stored in the array. For example char name[]=hello len = strlen(name); The variable len will have the value 5 which is the length of the string name. strcpy() strcpy (char *,char *) Copies source string to target string. For example, strcpy(name1,name2); where name1 and name2 are strings, then the name2 string will be copied into name1 string strcmp() strcmp (char *,char *) Compares the two given strings, and returns 0 if strings are equal, value >0, if string 1 is greater than string 2. Otherwise value less than 0. For example, strcmp(Abc, Abc) returns 0 strcmp (Abc, abc) returns a value less than 0 strcmp (abc, Abc) returns a value greater than 0 strcmp can be used to arrange a given set of strings in ascending or descending order Write a note on array of strings with examples An array of strings is a two-dimensional character array. The size of first index (rows) determines the number of strings and the size of second index (column) determines maximum length of each string. For example, char day-names [7] [10] = {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; An individual string is accessed as day-names [0], i.e., by specifying the 1st index only. A specific character or an element is accessed as day-names [0] [5] How does an array behave when passed to a function? Arrays can be passed on as arguments to functions. The actual parameter is passed only by the identifier, ignoring dimensions. Array parameters by default behave like a reference parameter, as the array identifier unlike other identifiers, represents the base address of the array. Hence, it results in sending an address to the formal parameter (like reference parameters). What will be the output of the program? void main() { int a[] = {1,2,3,4,5}; for (int i = 0; i<4; i++) a[i+1] = a[i]; for(i = 0; i<5; i++) cout << \n<< a[i]; } Find errors int a[5.5]; Output: 1 1 1 1 1

The size of the array has to be a positive integer and cannot be a fraction. Here, 5.5 is a fractional value The size of array has to be a constant positive integer and not a variable.

float num[A];

22

ONE WORD QUESTIONS

___is a derived data type. __can hold several values of the same type. For handling large data elements belonging to same data type __can be used An __ is a collection of variables of same type referenced by a common name. Array is of __ types: one dimensional and multi-dimensional __ array comprises of finite homogenous elements __ array comprises of elements, each of which is itself a one- dimensional array __dimensional array is suitable for processing list of items of identical types. Size of the array should always be__. array subscript should always commence from __ Process of rearranging data in a given array either in a ascending or descending order is called__. Strings are otherwise called as __ __are single dimensional array of characters character array or string should be terminated with a __ Cin treats __as terminator for string. __treats spaces as a part of string literal. __belongs to stdio.h __belongs to standard input stream(istream) syntax for __is gets(char array identifier) or gets(char *) syntax for __is cin.getline(char *, no of characters, delimiter); __is a member function of standard output stream __has 2 parameters.(identifier, no of characters) __returns no of characters. __copies source string to target string. __compares two string. return value of strcmp() is __when strings are equal Value is ___ than 0 if string1 is greater than string2, in strcmp(string1,string2) Value is ___ than 0 if string1 is less than string2, in strcmp(string1,string2) number of elements in a __is determined by multiplying the no of rows with number of columns __of an array can be indicated using integer, const identifier, ordinal, Char constants, enum A __array is an array in which each element is itself an array. 2-d array is stored in ___memory blocks __of the array is no of elements *memory req. for one element If the elements are stored in row-wise manner, then this method is called as If the elements are stored in column-wise manner, then this method is called as While passing__, actual parameters is passed only by identifier ignoring dimensions array parameters by default behave like __parameter The array identifier represents the __of the array A __is a set of mn numbers arranged in the form of rectangular array of m rows and n columns. __is a 2 dimensional array An array of ___is a 2 dimensional character array size of the first index(row) in a string represents size of the second index(column) in a string represents __ of each string if null character is not included in a string ___will automatically attach it.

Array

Two (2) One dimensional Multi-dimensional Single zero sorting literals strings \0 null character white space or carriage return Gets getline gets getline write() strlen() strcpy() strcmp() 0 greater less 2 dimensional array dimensions 2-dimensional 2D sequential size row-major order column-major order arrays reference base address matrix

strings number of strings length compiler

23

CHAPTER 6: CLASSSES AND OBJECTS IMPORTANT TWO MARKS QUESTIONS Define class. Give example A class is a new way of creating and implementing a user defined data type. Classes provide a method for packing together data of different types. A class is a way to bind the data and its associated functions together.

List the specifications of a class A class specification has two parts: 1) Class declaration 2) Class Function Definitions Write the general form of class declaration General Form Example

What is data abstraction? Instruments allowing only selected access of components to objects and to members of other classes is called as Data Abstraction. Data abstraction is achieved through data hiding. Data hiding provides security to data. List out the four characteristics of member function in program development 1. Several different classes can use the same function name. The membership label will resolve their scope 2. Member functions can access the private data of a class. A non-member function cannot do so. 3. A member function can call another member function directly, without using the dot operator. (This is called as nesting of member functions ) 4. The member functions can receive arguments of a valid C++ data type. Objects can also be passed as arguments 5. The return type of a member function can be of object data type 6. Member functions can be of static type What is meant by array of objects in C++? Arrays of variables of type "class" is known as "Array of objects".

Define data hiding The members and functions declared under private are not accessible by members outside the class, this is referred to as data hiding.

24

What does a class comprise? Class comprises of members. Members are further classified as Data Members and Member functions. Data members are the data variables that represent the features or properties of a class. Member functions are the functions that perform specific tasks in a class. What are the access specifiers or visibility modes in the class? The three class specifiers or visibility modes in the class body are: private, public and protected How is memory allocated to an object of a class? The member functions are created and placed in the memory space only when they are defined as a part of the class specification. Since all the objects belonging to that class use the same member function, no separate space is allocated for member functions when the objects are created. Memory space required for the member variables are allocated separately for each object. Separate memory allocations for the objects are essential because the member variables will hold different data values for different objects Write a note on static data members in C++ A data member of a class can be qualified as static. The static member variable Is initialized to zero, only when the first object of its class is created. No other initialization is permitted Only one copy of the member variable is created (as part of the common pool ) and is shared by all the other objects of its class type Its scope or visibility is within the class but its lifetime is the lifetime of the program. ONE WORD QUESTIONS Bjarne Stroustrup initially gave the name for c++ as A ___ is a new way of creating and implementing user defined data type __ is a way to bind data and its associated functions together ____ provide a method for packing together data of different types CLASS DECLARATION and CLASS FUNCTION DEFINITIONS are the TWO parts of The class name is also called as The body of a class is enclosed within ___ and is terminated by a ___ The class body has ____ access specifiers The access specifiers are also called as ____ The access specifiers are Specifying _____visibility label or access specifier is optional. By default the members will be treated as ____ if a visibility label or access specifier is not mentioned The members that have been declared as ____, can be accessed only from within the class ___ members are accessible by only its own members and certain special functions called as friend functions The members that have been declared as ___can be accessed from within the class, and the members of the inherited classes. The members that are declared as ___can be accessed from outside the class also Access allowed by other members in addition to class member & objects The binding of data and functions together into a single entity is referred to as ____ The process of grouping data and its related functions into units called as objects paves way for ____. The mechanism by which the data and functions are bound together within an object definition is called as _____ The members and functions declared under private are not accessible by members outside the class is referred to as ___ Instruments allowing only selected access of components to objects and to members of other classes is called as ___ ____is achieved through DATA HIDING Class comprises of __ Members are further classified as ___ are data variables that represent the features or properties of a class C with Classes class Classes Class specification Class tag {} braces ; semicolon three visibility labels private , public and protected private

private

protected public

encapsulation

Data hiding Data Abstraction

members Data Members and Member functions Data members

25

___ are also called as attributes ___ are the functions that perform specific tasks in a class. ___ are called as methods Classes include special member functions called as ___ and ___ In C++ the class variables are known as ___ Another name for the object is The members of a class are accessed using the ____ operator The objects declared outside the class cannot access members or functions defined under ____ Member functions or methods of a class can be defined in ___ ways: Member function or methods can be declared and defined within the class Member function or methods can be declared within the class but defined outside the class The members defined within the class behave like ___ functions Member functions defined outside the class has the prototype as The ______ (class_name :: ) tells the compiler that the function (function_name) belongs to the class The scope resolution operator is Several different classes can use the same function name. The ___ label will resolve their scope ______ can access the private data of a class. A member function can call another member function directly, without using the dot operator is called as The ____can receive arguments of a valid C++ data type. Objects can also be passed as arguments to ____ The return type of a member function can be of ___ data type Member functions can be of ___type The ___ are created and placed in the memory space only when they are defined as a part of the class specification. No separate space is allocated for ___when the objects are created Memory space required for the ___ are allocated separately for each object. Separate memory allocations for the objects are essential because the member variables will hold different data values for different objects The ___ is initialized to zero, only when the first object of its class is created (No other initialization is permitted) Only one copy of the ___ is created and is shared by all the other objects of its class type The ___of the static member variable is within the class The __ of the static member variable is the lifetime of the program The initial value to a static member variable is done

Member functions constructors and destructors objects Instance of a class Dot (.) operator private or protected 2

inline functions type class_name :: function name(); membership label :: membership Member functions nesting of member functions member functions object data type static member functions member functions member variables static member variable static member variable scope or visibility lifetime outside the class

26

CH 7 POLYMORPHISM IMPORTANT TWO MARKS QUESTIONS How are functions invoked in function overloading? The compiler adopts BEST MATCH strategy. As per this strategy, the compiler will o Look for the exact match of a function prototype with that of a function call statement. o In case an exact match is not available, it looks for the next nearest match. That is, the compiler will promote integral data promotions and then match the call statement with function prototype. What are the steps in operator overloading? Or What does the process of overloading involve? The process of overloading involves: o Create a class that defines the data type that is to be used in the overloading operations o Declare the operator function operator () in the public part of the class. o Define the operator function to implement the required operations. IMPORTANT 5 MARKS QUESTIONS Define function overloading. (2) Give an example. List the rules for function overloading (2) Function Overloading: The ability of the function to process the message or data in more than one form is called as function overloading Example for function overloading: To compute area, for different shapes using a single function header can be written in the following manner float area ( float radius); float area ( float half, float base, float height ); float area ( float length , float breadth); #include<iostream.h> void main() { #include<conio.h> clrscr(); float r,b,h; float area ( float radius ) int choice = 0 ; { cout << \nCircle ; do { return ( 22/7 * radius * radius ); clrscr(); } cout << \n Area Menu ; cout << \n 1. Circle ... ; float area (float half, float base, float cout << \n 2. Traingle ...; height) cout << \n 3. Rectangle ... ; { cout << \nTriangle ..; cout <<\n 4. Exit ... ; return (half* base*height); cin>> choice; } switch(choice) { case 1 : cout << \n Enter radius ... ; float area ( float length, float breadth ) cin>>r; { cout << \nRectangle ; cout<<\n Area of circle:<< area(r); return ( length *breadth ) ; getch(); } break; case 2: cout<< \n Enter base, height ... ; cin>>b>>h; cout<<\n Area of triangle:<< area (0.5, b, h); getch(); break; case 3: cout<< \n Enter length, breadth.. ; cin>>h>>b; cout<<\n Area of rectangle: << area(h,b); getch(); break; } }while (choice <=3); } Rules for function overloading 1) Each overloaded function must differ either by the number of its formal parameters or their data types 2) The return type of overloaded functions may or may not be the same data type 3) The default arguments of overloaded functions are not considered by the C++ compiler as part of the parameter list 4) Do not use the same function name for two unrelated functions

27

What is operator overloading? (2) Give an example of operator overloading. List the rules of operator overloading(2) Operator Overloading: The term operator overloading, refers to giving additional functionality to the normal C++ operators like +,++,-, ,+=,-=,*.<,>. The statement sum = num1 + num2 would be interpreted as a statement meant to perform addition of numbers (integer/float/double) and store the result in the variable sum. Example of operator overloading: # include <iostream.h> # include <conio.h> # include <string.h> class strings { char s[10]; public : strings() { s[0] = \0; } strings(char *c) { strcpy(s,c); } char * operator+(strings x1) { char *temp; strcpy(temp,s); strcat(temp,x1.s); return temp; } };

void main() { clrscr(); strings s1(test), s2( run\0); char *concatstr ; concatstr = s1 + s2; cout << \nConcatenated string ... << concatstr; getch(); }

operator overloading provides: o Operator overloading provides New function definitions for basic C++ operators like +, *, -, ++, - -, >, <, += and the like. One cannot overload C++ specific operators like membership operator (.), scope resolution operator (::), sizeof operator and conditional operator. o The overloaded function definitions are permitted for user defined data type. o Operator functions must be either member functions or friend functions. o The new definition that is provided to an operator does not overrule the original definition of the operator. For example, if the + operator has been used to merge two strings, one can also perform addition of numbers in the usual way. The compiler applies user defined definition based on the style of call statement. Rules for operator overloading:

28

Only existing operators can be overloaded. New operators cannot be created. The overloaded operator must have at least one operand of user defined type. _ The basic definition of an operator cannot be replaced or in other words one cannot redefine the function of an operator. One can give additional functions to an operator _ Overloaded operators behave in the same way as the basic operators in terms of their operands. _ When binary operators are overloaded, the left hand object must be an object of the relevant class _ Binary operators overloaded through a member function take one explicit argument.
ONE WORD QUESTIONS

This differential response of a function based on different inputs is ___ The ability of an object to respond differently to different messages is _ ___ reduces software complexity as multiple definitions are permitted to an operator or function Polymorphism is achieved in ___ ways polymorphism is achieved through ___ and ___

polymorphism polymorphism polymorphism 2 Function overloading and operator overloading Function overloading overloading function overloading overloaded function BEST MATCH Integral promotions Overloaded functions Overloaded functions Overloaded functions operator overloading operator overloading operator overloading Member functions or friend functions C++ Specific operators membership operator (.), scope resolution operator (::), sizeof operator and conditional operator. operator () existing operators one operator operator binary operators 29

___ is one of the facets of C++ that supports object oriented programming The term ___means a name having two or more distinct meanings The ability of the function to process the message or data in more than one form is called as An ___ refers to a function having more than one distinct meaning The compiler adopts ___ strategy in function overloading _____ are purely compiler oriented Each ___ must differ either by the number of its formal parameters or their data types The return type of ____may or may not be the same data type The parameter list in ___differ either by number or types. The term ___refers to giving additional functionality to the C++ operators The functionality of + operator can be extended to strings through ___ ___ provides new function definitions for basic C++ operators like +, *, -, ++, - -, >, <, += Operator functions must be The __ operators cannot be overloaded The C++ specific operators which CANNOT be overloaded are:

The process of operator overloading involves the declaration of the operator function ____ in the public part of the class. Only ___can be overloaded The overloaded operator must have at least __operand of user defined type. The basic definition of an ___cannot be replaced one cannot redefine the function of an ___ When ___are overloaded, the left hand object must be an object of the relevant

class ___ overloaded through a member function take one explicit argument

binary operators

30

CHAPTER 8: CONSTRUCTORS AND DESTRUCTORS IMPORTANT TWO MARKS QUESTIONS What are constructors and destructors? When an instance of a class comes into scope, a special function called the constructor gets executed. The constructor function initializes the class object. When a class object goes out of scope, a special function called the destructor gets executed. The constructor function name and the destructor have the same name as the class tag. List the functions of constructor The functions of constructor are: 1) The constructor function initializes the class object 2) The memory space is allocated to an object Give two rules for constructor definition and usage The rules for constructor definition and usage are: 1) The name of the constructor must be same as that of the class 2) A constructor can have parameter list or arguments 3) The constructor function can be overloaded 4) The compiler generates a constructor, in the absence of a user defined constructor 5) The constructor is executed automatically 6) constructor cannot have return type Write down four rules for definition and usage of destructor 1) The destructor has the same name as that of the class prefixed by the tilde character ~. 2) The destructor cannot have arguments 3) It has no return type 4) Destructors cannot be overloaded i.e., there can be only one destructor in a class 5) In the absence of user defined destructor, it is generated by the compiler 6) The destructor is executed automatically when the control reaches the end of class scope Tabulate any two differences between constructor and destructor Constructor Destructor The name of the constructor must be same as that of the The destructor has the same name as that of the class class prefixed by the tilde character ~. A constructor can have parameter list Destructor cannot have parameter list The constructor function can be overloaded Destructor function cannot be overloaded When is copy constructor executed? A copy constructor is executed: 1) When an object is passed as a parameter to any of the member functions Example void add::putdata( add x); 2) When a member function returns an object For example, add getdata(); 3) When an object is passed by reference to constructor For example, add a; b(a); ONE WORD QUESTIONS When an instance of a class comes into scope a special function called __gets executed. ___function initializes class object. when a class object goes out of scope, special function called __gets executed. Non parameterized constructor is called as ___constructor. __constructors are referred to compiler generated constructors (i.e., constructors defined by the computers in the absence of user defined constructor). A __constructor is executed when an object without parameters is declared. The constructor add (int s1, int s2) is called as __constructor. The constructor add (add &a) is called as ___constructor. __is executed when an object is passed as a parameter when a member functions returns an object an object is passed by reference to constructor Name of the constructor must be same as that of the ___ ___ generates constructor in the absence of a user defined constructor. __is a function that removes memory of an object __is prefixed with tilde. __ cannot have arguments and has no return type constructor Constructor destructor default default non-parameterized parameterized copy copy constructor

class compiler Destructor

31

__ is executed automatically when the control reaches the end of the class scope

CHAPTER 9: INHERITANCE IMPORTANT 2 MARKS QUESTIONS List the types of inheritance There are different types of inheritance: Single Inheritance Multiple inheritance Hybrid inheritance Hierarchical inheritance

Multilevel inheritance

Write a note on single inheritance, multilevel inheritance and multiple inheritance (each 2 marks) Single Inheritance: When a derived class inherits only from one base class, it is known as single inheritance.

Multiple Inheritance: When a derived class inherits from multiple base classes it is known as multiple inheritance

Multilevel inheritance: When a class is derived from a class which is a derived class itself then this is referred to as multilevel inheritance The transitive nature of inheritance is reflected by this form of inheritance.

Write the syntax for deriving a class from its base class The syntax for deriving a Example: class from its base class is: class der_name : visibility mode base class-id { data members of the derived_class functions members of derived_class }

32

What is an abstract class? Classes used only for deriving other classes are called as Abstract Classes ie., to say that objects for these classes are not declared. What are the three access specifiers used to inherit a derived class? The three access specifiers used are private, protected and public. What is accessibility? An important feature in Inheritance is to know as to when a member of a base class can be used by the objects or the members of the derived class. This is called as accessibility. The three access specifiers are private, protected and public. Access specifier is also referred to as visibility mode. The default visibility mode is private. IMPORTANT 5 MARKS QUESTIONS

Define inheritance. Explain the advantages of inheritance in detail. Inheritance: Inheritance is a process of creating new classes called derived classes, from the existing or base classes. The derived class inherits all the properties of the base class Inheritance is the most powerful feature of an object oriented programming language. It is a power packed class, as it can add additional attributes and methods and thus enhance its functionality. Advantages of Inheritance: 1) Reusability of code : Many applications are developed in an organization. Code developed for one application can be reused in another application if such functionality is required. This saves a lot of development time. 2) Code sharing : The methods of the base class can be shared by the derived class. 3) Consistency of interface: The inherited attributes and methods provide a similar interface to the calling methods. In the example below, the attributes and methods of the class vehicle are common to the three derived classes Aeroplane, Car and Bicycle. These three derived classes are said to be having a consistence interface.

Explain the scope and accessibility of the base members in the derived classes

33

When a base class is inherited with private visibility mode the public and protected members of the base class become private members of the derived class When a base class is inherited with protected visibility mode the protected and public members of the base class become protected members of the derived class When a base class is inherited with public visibility mode , the protected members of the base class will be inherited as protected members of the derived class and the public members of the base class will be inherited as public members of the derived class ONE WORD QUESTIONS __is the process of creating new classes called derived classes from the existing class called base class __class is a class from which other classes are derived. __class is a power packed class that inherits the members of the base class. __saves a lot of development time. Code sharing is the method of sharing the base class methods by the __class. Inherited attributes and methods provide a similar interface to __methods. __is knowing when a member of a base class can be used by the objects or the members of the derived class. Access specifiers are also called as __ The three access specifiers are__. default visibility mode is __ when a base class is inherited with private visibility mode, public and protected members of the base class become __of the derived class when a base class is inherited with protected visibility mode, public and protected members of the base class become __of the derived class when a base class is inherited with public visibility mode, protected members of the base class become __of the derived class when a base class is inherited with public visibility mode, public members of the base class become __of the derived class When classes are inherited publicly, protectedly or privately, the __of the base class are not inherited, but they are only visible __of base class are not inherited but executed when an instance of the derived class is created. When a derived class inherits only from one base class it is called__. When a derived class inherits from multiple base classes it is known as __ The transitive nature of inheritance is reflected by __inheritance Inheritance Base Derived Reusability of code derived calling Accessibility visibility mode private, protected and public private private members protected members protected members public members private members Constructors single inheritance Multiple inheritance multilevel

34

When a class is derived from a class which is a derived class itself it is called __. classes used only for deriving other classes are called __ _are executed in the order of inherited class. i.e from base constructor to derived ___are executed from derived class to base class

Multilevel inheritance abstract classes Constructors destructors

35

CHAPTER 10: IMPACT OF COMPUTERS IMPORTANT 2 MARKS QUESTIONS What is meant by e-banking? e-Banking permits banking from the comfort of the home by using internet facilities. It has truly improved the reach and services of banks. What is ATM? Advanced machines like ATM enable withdrawal of money from the accounts in a particular bank anytime and anywhere. This helps the user in emergency situations where money is needed during the nights and holidays. However, the user has to go to the nearest ATM facility. What are meant by emotion containers? Emotion containers are small compartments with a screen, speaker and a scent to derive emotional comfort. This can prevent people from acquiring bad habits What is meant by e-learning? e-Learning enables online educational programs leading to degrees and certifications. e-Learning uses technology to enable people to learn anytime and anywhere How are computers used in education? Computers are used in many areas of Education including: Buying and browsing the latest edition of books by both local and foreign author Educational CDROMs Computer Based Tutorials (CBT). Spreading information about schools, colleges, universities and courses offered, admission procedures, accommodation facilities, scholarships, educational loans, career guidance. e-Learning that enables online educational programs leading to degrees and certifications

ONE WORD QUESTIONS To reach out the benefits of IT to the common man, we need __ technical elements: Connectivity, Affordable computers and Software __ of computer usage is word processing __enables data storage and management. __are small compartments with screen, speaker and scent to derive emotional comfort. __prevents people from acquiring bad habits. _is used to store personal details and enable connectivity to other people. __features allow one to sing along with the audio coming from the original source. __functions as electronic pets. Easy interaction with other people through touch screen, scanner and microphone facilities is called__. __is used to draw capture and work with multimedia elements. Banks are the key factor in the __ CBT is an acronym for: __provides banking from the comfort of the home by using internet facilities. __enables online educational programs leading to degree and certification. __help farmers plan which crops will produce the highest profits ___is used to decide on the crops.

3 85% Archive unit Emotion containers Personal archive Kara-oke Robots memo frame Personal creativity tool national economy computer based tutorials E-banking E-learning revenue estimators Satellite imagery

36

Chapter 11: IT ENABLED SERVICES (ITES) IMPORTANT 2 MARKS QUESTIONS What is meant by IT Enabled service? Information Technology that helps in improving the quality of service to the users is called IT Enabled Services [ITES]. IT Enabled Services are human intensive services that are delivered over telecommunication networks or the Internet to a range of business segments. List some of the IT Enabled services Some of the IT enabled services are: e-Governance Medical [Telemedicine and Transcription].

Call Centers Data Digitization

Data Management Website Services

What is meant by call center? A call center is sometimes defined as a telephone based shared service center for specific customer activities and are used for number of customer-related functions like marketing, selling, information transfer, advice, technical support and so on. A call center has adequate telecom facilities, trained consultants, access to wide database, Internet and other online information support to provide information and support services to customers. It operates to provide round the clock and year round service i.e.24 x 365 service. What is meant by digitization? Digitization refers to the conversion of non-digital material to digital form. A wide variety of materials as diverse as maps manuscripts, moving images and sound may be digitized. Digitization offers great advantages for access, allowing users to find, retrieve, study and modify the material. However, reliance on digitization as a preservation strategy could place much material at risk. Digital technologies are changing rapidly. Preservation is a long term strategy and many technologies will become obsolete soon. This instability in technology can lead to the loss of the digitized objects. What are the application areas of digitization? Some application areas of the digital technology are as follows: Annual reports and price list Books Electronic Catalogues & Brochures Engg. & Design Movies, Sounds and High quality image preservation Product/Service Training Manuals

Data Management Geographical Information System Research Journals and Conference Papers

What are the steps in digitization? The steps in data digitization are: Understanding the customer needs Customer needs are used as the basis for defining the objectives of digitization A pilot application is built After the pilot application is approved, the full digitization of data identified by the customer is undertaken. Different types of data are digitized using different techniques. Many advance software packages are available to improve the quality of the digitized form of the original document. The digitized data is indexed and a table of contents is produce to improve accessibility. Highly advanced and reliable storage facilities are used to stock the digitized data. What are the benefits of digitization? There are many benefits of digitization. Some of the key benefits are: 1) Long term preservation of the documents. 2) Storage of important documents at one place. 3) Easy to use and access to the information. 4) Quick and focused search of relevant information in terms of images and text. 5) Easy transfer of information in terms of images and text. 6) Easy transfer of information through CD-ROM, internet and other electronic media Give the importance of ITES ITES greatly increases the employment opportunities. ITES can improve the quality of the service either directly or indirectly. Improved customer satisfaction, better look and feel and an improved database are some direct benefits. Indirect benefits are seen after sometime. Data collected for one purpose may be useful for some other purpose also after some time. In what way e-Governance can help us?

37

Computers help you to look at the government websites and the services provided by them. The various websites provided by the government give the details about the departments, specific functions, special schemes, documents, contacts, links, IAS intranet, site map, search, whats new, press releases, feedback. These websites are both in English and Tamil. ONE WORD QUESTIONS The facility that allows the user to speak into a special device called ___ The expansion for BPO is ____ ___help us to look at the government and services provided by them. A ____ is a telephone based shared service center for specific customer activities. ___is a category of ITES pertaining to collection, digitization and processing of data coming from various sources. ____ is the key for effective and profitable used of IT in organization. Banking , Financial Services and insurance sectors are popularly termed as __ ___ and __ are two important aspects that must be ensured by the ITES provider. ___is a permanent , legal document that formally states the result of a medical investigation. There are __main steps involved in medical transcription. The conversion of non-digital material to digital form is __ Dictaphone Business Process Outsourcing e governance call center data management data management BFSI Data Security customer privacy Medical transcription three digitization

38

Chapter 12: COMPUTER ETHICS IMPORTANT TWO MARKS QUESTIONS Define piracy Making and using duplicate hardware and software is called piracy. We tend to pirate because: 1) We like free things 2) Why pay for something when we can get it for free? 3) Our thinking and actions are self-serving 4) If we have the opportunity to get away with something, benefit financially, and minimal risk is involved, the way in which weve been conditioned by our capitalist society to do it. What is meant by theft of computer time? Most of the computers in an organization have lot of free computer time to spare. Many solutions for using this spare time are being researched. However, this idle time of computers in an organization is being stolen illegally. Some other software runs on an idle computer without the knowledge of the organization. This is called theft of computer time. Define computer ethics Ethics is the set of rules for determining moral standards or what is considered as socially acceptable behaviours. Today, many computer users are raising questions on what is and is not ethical with regard to activities involving information technology. General guidelines on computer ethics are needed for: Protection of personal data Computer Crime Cracking Define computer crime A computer crime is any illegal activity using computer software, data or access as the object, subject or instrument of the crime. Common crimes include: Crimes related to money transfer on the internet Hardware and software piracy Making long distance calls illegally using computers Virus Illegal access to confidential files Cracking Stealing hardware Theft of computer time Selling or misusing personal Define virus A virus is a self-replicating program that can cause damage to data and files stored on your computer. These are programs written by programmers with great programming skills who are motivated by the need for a challenge or to cause destruction. 57000 known virus programs are in existence. 6 new viruses are found each day. Write a note on cracking Cracking is the illegal access to the network or computer system. Illegal use of special resources in the system is the key reason for cracking. The resources may be hardware, software, files or system information. Revenge, business reasons and thrill are other common reasons for committing this crime. What is the need for a password to log into a computer system? User Id and passwords are tools that offer personal security that refers to software setups that permit only authorized access to the system. Only those with a need to know have Ids and password for access to log into a computer system ONE WORD QUESTIONS ___refers to the protection of hardware, facilities magnetic disks etc., ___ refers to software setup that permits only authorized access to the system. ____ refers to protecting data and computer system against dishonesty or negligence of employees. ___ is any illegal activity using computer software data or access as the object, subject or instrument of the crime. Making and using duplicate hardware and software is called __ ___is a self-replicating program that causes damage to data and files stored on our computer. ___is a program written by programmers to cause damage to data and files stored. Some other software runs on an idle computer without the knowledge of the organization is called theft of ___ The Ten commandments of Computer Ethics written by __ India has ___ to prevent computer crimes. __ is the illegal access to the network or computer system. __ use of special resources in the system is the key reason for cracking How many virus programs are in existence physical security personal security Personnel security Computer crime piracy virus virus computer time computer ethics institute cyber laws cracking illegal 57000

39

How many viruses are found each day ___ and ____have created the condition where people can take their work anywhere with them and do it any time. Computer ethics has its roots in the work of ___ during World War II. ___ percent of computer crimes happen within the company out of which 60% goes undetected In which year was formal course in ethics introduced In the mid 1960s, ____ began to examine unethical and illegal uses of computers by computer professionals.

6 Portable computers and telecommuting Norbert Wiener 80% 1990s Donn Parker of SRI International in Menlo Park, California

40

Você também pode gostar