TN Board 11th Computer Science Important Questions Chapter 15 Polymorphism

TN State Board 11th Computer Science Important Questions Chapter 15 Polymorphism

Question 1.
Define polymorphism.
Answer:
The word polymorphism means many forms (poly – many, morph – shapes). Polymorphism is the ability of a
message or function to be displayed in more than one form.

Question 2.
In C++ how the polymorphism is achieved.
Answer:
In C++, polymorphism is achieved through function overloading and operator overloading.

Question 3.
What does the overloaded function refers to?
Answer:
An ‘overloaded function’ refers to a function having more than one distinct meaning.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 4.
Define overload resolution.
Answer:
The process of selecting the most appropriate overloaded function or operator is called overload resolution.

Question 5.
What is function’s signature?
Answer:
The number and types of a function’s parameters are called the function’s signature.

Question 6.
Write the output for the following code.
#include<iostream>
using namespace std;
class Data
{
public:
void print(int i)
{
cout<<“printing int: “<<i<<endl ;
}
void print(double f)
{
cout<<“printing float: “<<f<<endl;
}
void print(char ch)
{
cout<<“printing character: “<<ch<<endl ;
}
};
int main(void)
{
Data d;
d.print(7); //call print to print integer
d.print (50.3) //call print to print float
d.print(“function overloading”)
//call print to print character
return 0;
}
Answer:
Output:
printing int : 7
printing float : 50.3
printing character : function overloading.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 7.
Rewrite the following program after removing the syntactical error(s) if any. Underline each correction.
#include[iostream]
Class Employee
{
int Empld=101;
char Ename[20];
public
Employee{ } { }
void Join( )
{
cin>>EmplD;
gets(EName);
}
void list( )
{
cout<<Empld<< “:”<<Ename<<endl;
}
};
int main( )
{
Employee E;
Join.E( );
E.List( )
}
Answer:
#include<iostream>
using namespace std;
class Employee
{
int Empld;
char Ename[20];
public:
Employee( )
{
EmpId=101;
}
void Join( )
{
cin>>EmpId;
gets(Ename);
}
void list( )
{
cout<<EmpId<<“: “<<Ename<<endl;
}
};
int main( )
{
Employee E;
Join.E ( ) ;
E. List ( ) ;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 8.
Write the definition of a function Fixpay( ) (float Pay[ ],int N), which should modify each element of the array salary pay N elements, as per the following rules.

TN State Board 11th Computer Science Important Questions Chapter 15 Polymorphism 1

Answer:
void Fixpay (float pay[ ], int N)
{
for(int i=0; i<N; i:++)
{
if(pay[i]<50000)
pay[i] += pay[i] * 0.35;
else if(pay[i]>50000 && pay[i] < 100000)
pay[i] += pay[i] * 0.30;
else
pay[i] += pay[i] * 0.20; .
}
}

Question 9.
Find the syntax errors in the following program segment. Give your reason as well,
class MNQ
{
int x = 30;
float y;
MNQ( )
(y = 33;}
~ ( ) { }
int main( )
{
MNQ M1, M2
}
Answer:
The following are the errors in the given program segment:

TN State Board 11th Computer Science Important Questions Chapter 15 Polymorphism 2

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 10.
Answer the questions (i) and (ii) after going through the following program,
class Match
{
int Time;
public:
Match( ) //Function 1
{
Time = 0;
cout<< “Match commences”<<endl;
}
void Details( ) //Function 2
{
cout<< “Inter Section Basketball Match”<<endl;
}
Match(int Duration) //Function 3
{
Time = Duration;
cout<< “Another Match begins now”«endl;
}
Match(Match & M) //Function 4
{
Time = M.Duration;
cout<< “Like Previous Match”<<endl;
}
};
(i) Which category of Constructor-Function 4 belongs to and what is the purpose of using it?
(ii) Write statements that would call the member functions 1 and 3.
Answer:
(i) Copy constructor, it is invoked when an object is created and initialized with values of an already existing object.
(ii) Match M1; //for function 1
Match M2(90); //for function 3

Question 11.
Answer the questions (i) and (ii) after going through the following program.
class Train
{
int Train No, Track;
public:
Train( ); //Function 1
Train (int TN); //Function 2
Train (Train & T); //Function 3
void Allocate( ); //Function 4
void move( ); //Functions 5
void main( )
{
Train T;
}
(i) Out of the following, which of the option is correct for calling function 2?
Answer:
Option 1-Train N(M);
Option 2-Train P(10);

(ii) Name the feature of object oriented programming, which is illustrated by function 1, function 2 and function 3 combined together.
Answer:
(i) Option 2 is correct for calling function 2.
(ii) Function overloading, i.e., Polymorphism.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 12.
Write a C++ program to find the perimeter of a rectangle using constructor overloading in a class. To find the perimeter of a rectangle using constructor overloading in a class.
Answer:
// constructor declared as outline member function
#include<iostream>
using namespace std;
class Perimeter
int 1, b, p;
public:
Perimeter ( );
Perimeter (int);
Perimeter (int,int);
Perimeter (Perimeters);
void Calculate( );
};
Perimeter::Perimeter( )
{
cout<<“\n Enter the value of length and breadth”; cin>>1>>b;
cout<<“\n\nNonParameterized constructor”;
}
Perimeter::Perimeter(int a)
{
1=b=a;
cout<<“\n\n Parameterized constructor with one argument”;
}
Perimeter::Perimeter(int 11, int b1)
{
cout<<“\n\n Parameterized constructor with 2 argument”;
1=11;
b=b1;
}
Perimeter::Perimeter(Perimeter&p)
{
l = p.1;
b = p.b;
cout<<“\n\n copy constructor”;
}
void Perimeter::Calculate( )
{
p = 2*(l+b);
cout<<p;
}
int main( )
{
Perimeter Obj ;
cout<<“\n perimeter of rectangle is”;
Obj.Calculate( );
Perimeter Obj1(2);
cout<<“\n perimeter of rectangle”;
Obj1.Calculate( ) ;
Perimeter Obj2(2, 3);
cout<<“\n perimeter of rectangle”;
Obj 2.Calculate( );
Perimeter obj3 (0bj2);
cout,<<“\n perimeter of rectangle”;
obj 3.Calculate ( );
return 0;
}
Output:
Enter the value of length and breadth 10 20
Non Parameterized constructor perimeter of rectangle is 60
Parameterized constructor with one argument
perimeter of rectangle 8
Parameterized constructor with 2 argument
perimeter of rectangle 10 copy constructor
perimeter of rectangle 10

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 13.
What is function overloading? Write a C++ program to demonstrate function overloading?
Answer:
The ability of the function to process the message or data in more than one form is called as function overloading.
C++ program to demonstrate function overloading.
#include<iostream>
using namespace std;
void print(inti)
{cout<<“It is integer” <<i<<endl;
void print(double f)
{
cout<<“It is float”<<f<<endl;
}
void print(string c)
{
cout<<“It is string”<<e<<ertdl;
}
int main( )
{
print(10);
print(10.10);
print(“Ten”);
return 0;
}
Output:
It is integer 10
It is float 10.1
It is string Ten

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 14.
What do you mean by constructor overloading? Explain with example.
Answer:
Function overloading can be applied for constructors, as constructors are special functions of classes. A class can have more than one constructor with different signature.
Constructor overloading provides flexibility of creating multiple type of objects for a class.
Constructor overloading
#include<iostream>
using namespace std;
class add
{
int num1, num2, sum;
public:
add ( )
{
cout<<“\n Constructor without parameters…”;
num1 = 0;
num2= 0;
sum =0;
}
add(int s1, int s2)
{
cout<<“\n Parameterized constructor…
num1=s1;
num2-s2;
sum=0;
}
add(add &a)
{
cout<<“\h Copy Constructor…”;
num1=a.num1;
num2=a.num2;
sum=0;
} _
void getdata( )
{
cout<<“\nEnter data ….”;
cin>>num1 >>num2 ;
}
void addition( )
{
sum=num1 + num2;
}
void putdata( )
{
cout<<“\n The numbers are…”;
cout<<numl<< ‘\t’ <<num2; cout<<“\n The sum of the numbers are. . . “<< sum;
}
};
int main( )
{
add a,b(10,20), c(b);
a. getdata ( );
a.addition ( );
b. addition ( );
c. addition( );
cout<<“\n Object a :”;
a. putdata ( );
cout<<“\n Object b :”;
b. putdata( );
cout<<“\n Object c…”;
c. putdata( );
return 0;
}
Output:
Constructor without parameters….
Parameterized constructor…
Copy Constructor …
Enter data … 20 30
Object a :
The numbers are.. 20 30
The sum of the numbers are… 50
Object b :
The numbers are..10 20
The sum of the numbers are… 30
Object c..
The numbers are..10 20
The sum of the numbers are… 30

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 15.
Suppose you have a Kitty Bank with an initial amount of ? 500 and you have to add some more amount to it. Create a class ‘Deposit’ with a data member named ‘amount’ with an initial value of ? 500. Now make three constructors of this class as follows:
(i) Without any parameter – no amount will be added to the Kitty Bank.
(ii) Having a parameter which is the amount that will be added to the Kitty Bank.
(iii) whenever amount is added an additional equaly amount will be deposited automatically.
Create an object of the ‘Deposit’ and display the final amount in the Kitty Bank.
Answer:
#include<iostream>
using namespace std;
class Deposit
{
int amount;
public:
AddAmount( )
{
amount = 500;
}
AddAmount(int a)
{
amount = 500;
amount = a+amount;
}
void Print_amount( )
{
cout<<amount<<endl;
}
} ;
int main( )
{
Deposit a1;
Deposit a2(150);
a1.Print_amount( );
a2.Print_amount ();
return 0;

Question 16.
What is function overloading?
Answer:
The ability of the function to process the message or data in more than one form is called as function overloading.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 17.
List the operators that cannot be overloaded.
Answer:
The operator that cannot be overload are:
(i) scope operator::
(ii) sizeof
(iii) member selector.
(iv) member pointer selector *
(v) ternary operator ?:

Question 18.
class add{int x; public: add(int)}; Write an outline definition for the constructor.
Answer:
add::add(int y)
{
x=y;
}

Question 19.
Does the return type of a function help in overloading a function?
Answer:
No, the return type of a function does not help in overloading a function.

Question 20.
What is the use of overloading a function?
Answer:
Function overloading is not only implementing polymorphism but also reduces the number of comparisons in a program and makes the program to execute faster. It also helps the programmer by reducing the number of function names to be remembered.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 21.
What are the rules for function overloading?
Answer:
Rules for function overloading:

  1. The overloaded function must differ in the number of its arguments or data types.
  2. The return type of overloaded functions are not considered for overloading same data type.
  3. The default arguments of overloaded functions are not considered as part of the parameter list in function overloading.

Question 22.
How does a compiler decide as to which function should be invoked when there are many functions? Give an example.
Answer:
When an overloaded function is called, the compiler determines the mo§t appropriate
definition to use, by comparing the argument types that has been used to call the function with the parameter types specified in the definitions.
Eg:
float area (float radius);
float area (float half, float base, float height) ;
float area (float length , float breadth);

Question 23.
What is operator overloading? Give some example of operators which can be overloaded.
Answer:
The term operator overloading, refers to giving additional functionality to the normal C++ operators like +, + +, -, —, + =, – =, *.<, >. It is also a type of polymorphism in which an operator is overloaded to give user defined meaning to it.
Eg: ‘+’ operator can be overloaded to perform addition on various data types, like for Integer, String(concatenation) etc.

Question 24.
Discuss the benefit of constructor overloading?
Answer:
Function overloading can be applied for constructors, as constructors are special functions of classes. A class can have more than one constructor with different signature. Constructor overloading provides flexibility of creating multiple type of objects for a class.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 25.
class sale (int cost, discount jpublic: sale(sale &); Write a non-inline definition for constructor specified;
Answer:
sale::sale(sale&s)
{
cost-s.cost;
discount=s.discount;
}

Question 26.
What are the rules for operator overloading?
Answer:
(i) Precedence and Associativity of an Operator cannot be changed.
(ii) No new operators can be created, only existing operators can be overloaded.
(iii) Cannot redefine the meaning of an operator’s procedure.
(iv) Overloaded operators cannot’ have default arguments.
(v) When binary operators are overloaded, the left hand object must be an object of the relevant class.

Question 27.
Answer the question (i) to (v) after going through the following class.
classBook
{
intBookCode;
char Bookname[20];
float fees;
public:
Book( ) //Function X
{
fees=1000;
BookCode=l;
strcpy (Bookname “C++”);
}
void display(float C) //Function 2
{
cout«Book code <<“:”<< Bookname << “:” << fees << endl;
}
~Book( ) //Function 3
{
cout<<“End of Book Object”<<endl;
}
Book (intS[ ], char S[ ], float F); //Function 4 };
(i) In the above program, what are Function 1 and Function 4 combined together referred as?
(ii) Which concept is illustrated by Function3? When is this function called/ invoked?
(iii) What is the use of Function 3?
(iv) Write the statements in main to invoke functionl and function 2.
(v) Write the definition for Function 4.
The concept demonstrated is constructor overloading.
(i) Function 1 and Function 4 are called overloaded constructor of the class Book.
(ii) Function 3 is destructor of class Travel. The destructors are called automatically when the objects are destroyed.
(iii) Function 3 is used to deallocate memory.
(iv)
Book B;
B.display(1000);
(v)
Book(int sc, char s[ ], float F)
{
Bookcode = sc; strcpy(Bookname, s);
Fees = F;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 28.
Write the output of the following program
#include<iostream>
using namespace std;
class Seminar
{
int Time;
public:
Seminar( )
{
Time =30;
cout<<“Seminar starts now”<,endl;
}
void Lecture( )
{
cout<<“Lectures in the seminar on”«endl;
}
Seminar(int Duration)
{
Time =Duration;
cout<<“Welcome to Seminar” <<endl;
}
Seminar(Seminar &D)
{
Time =D.Time;
cout<<“Recap of Previous Seminar Content”<<endl;
}
~Seminar( )
{
cout<<“Vote of thanks”<<endl;
}
};
intmain( )
{
Seminar s1, s2(2), s3(s2);
s1.Lecture( );
return 0;
}
Answer:
Output:
Seminar starts now
Welcome to Seminar
Welcome to Seminar
Lectures in the Seminar on
Vote of thanks
Vote of thanks
Vote of thanks

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 29.
Debug the following program.
#include<iostream>
using namespace std;
class String
{
public:
charstr[20];
public:
void accept_string
{
cout<<“\n Enter String:”; cin»str;
}
display_string( )
{
cout<<str;
}
String operator *(String x) //Concatenating String
{
String s;
strcat(str,str);
strcpy(s.str,str);
goto s;
}
}
int main( )
{
String str1, str2, str3;
str1.accept_string( );
str2.accept_string( );
cout<<“\n\n First String is:”;
str1=display_string( );
cout<<“\n\n Second String is:”;
str2.display_string( );
str3=str1 + str2;
cout>>”\n\n Concatenated String is:”;
str3.display_string( );
return 0;
}
Answer:
#include<iostream>
using namespace std;
class String
{
public: char str[20];
public:
void accept_string( )
cout<<“\n Enter String:”;
cin>>str;
}
void display_string( )
{
cout<<str;
}
String operator +(String x) //Concatenating String
{
string s
strcat(str,x.str) ; strcpy(s.str, str) ; return s;
};
int main ( )
{
String str1, str2, str3;
strl.accept_string( );
str2.accept_string( );
cout<<“\n\n First String is:”;
str1.display_string( );
cout<<“\n\n Second String is:”;
str2.display_string();
str3=str1+str2;
cout>>”\n\n Concatenated String is : “;
str3.display_string( );
return 0;
}
Output:
Enter String : COMPUTER
Enter String : SCIENCE
First String is : COMPUTER
Second String is : SCIENCE
Concatenated String is : COMPUTER SCIENCE

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 30.
Answer the questions based on the following program.
#include<iostream>
#include<$tring.h>
using namespace std;
class comp
{
public:
chars[10];
void getstring(char str[10])
{
strcpy(s,str);
}
void operator==(comp);
};
void comp::operator==f(comp ob)
{
if(strcmp(s,ob.s)==0)
cout<<“\nStrings are Equal”;
else
cout<<“\nStrings are not Equal”;
}
int main( )
{
comp ob, ob1;
char string1[10], string2[10];
cout<<“Enter First String:”;
cin>>string1;
ob.getstring(string1);
cout<<“\nEnter Second String:”;
cin>>string2;
ob1.getstring(string2);
ob==ob1;
return 0;
}
(i) Mention the objects which will have the scope till the end of the program.
(ii) Name the object which gets destroyed in between the program.
(iii) Name the operator which is overloaded and write the statement that invokes it.
(iv) Write out the prototype of the overloaded member function.
(v) What types of operands are used for the overloaded operator?
(vi) Which constructor will get executed? Write the output of the program.
Answer:
(i) ob, ob1
(ii) ob1
(iii) The operator that is overloaded is == The statement that invokes it ob==ob1
(iv) void operator ==(comp ob);
(v) string
(vi) default constructor is executed
Output:
Enter First String : Computer
Enter Second String : Computer
Strings are Equal

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Choose the correct answer:

Read the following C++ program carefully and answer questions from 1-3.
#include<iostream.h>
class negative
{
int i;
public:
void accept( )
{
cin>>i;
}
void display( )
{
cout<<i;
}
void operator-( )
{
i=-i;
}
};
void main( )
{
negative n2;
n2.accept ( );
-n2;
n2.display( ) ;
}

Question 1.
Identify the operator that is overloaded:
(a) =
(b) – (Unary)
(c) – (Binary)
(d) negative
Answer:
(c) – (Binary)

Question 2.
The prototype of the overloaded member function is:
(a) negative operator – ( )
(b) void operator minus
(c) void operator – ( )
(d) void operator – (negative)
Answer:
(c) void operator – ( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 3.
Which of the following statements invokes the overloaded member function?
(a) Negative n1 ( )
(b) – – n2 ( )
(c) n2 +;
(d) – n2;
Answer:
(d) – n2;

Question 4.
The mechanism of giving special meaning to an operator is called:
(a) Operator Overloading
(b) Function Overloading
(c) Inheritance
(d) Object
Answer:
(a) Operator Overloading

Question 5.
Which of the following is not a valid function prototype?
(a) void fun (int x) ;
void fun (int y);
(b) void fun (int x, int y);
void fun (int x, float y) ;
(c) int fun(: int x);
void fun (float x) ;
(d) void fun (char x) ;
void fun(char x, int y) ;
Answer:
(a) void fun (int x) ;
void fun (int y);

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 6.
Polymorphism is achieved in C++ through:
(a) Encapsulation
(b) Inheritance
(c) Overloading
(d) Function
Answer:
(c) Overloading

Question 7.
Which of the following operators cannot be overloaded?
(a) +
(b) ++
(c) +=
(d) ::
Answer:
(d) ::

Question 8.
While overloading functions, the possible integral promotions are:
(a) char → int
(b) int → char
(c) both (a) and (b)
(d) none of these
Answer:
(c) both (a) and (b)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 9.
In operator overloading the operator functions must be defined as:
(a) member function
(b) friend function
(c) either (a) or (b)
(d) neither (a) nor (b)
Answer:
(c) either (a) or (b)

Question 10.
The functionality of ‘+’ operator can be extended to strings through:
(a) operator precedence
(b) operator overloading
(c) operator definition
(d) none of the given
Answer:
(b) operator overloading

Question 11.
The overloaded operator must have at least one operand of:
(a) built-in type
(b) user-defined type
(c) array
(d) derived
Answer:
(b) user-defined type

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 12.
Which one of the following cannot be overloaded?
(a) Constructor
(b) Destructor
(c) Operator
(d) Function
Answer:
(b) Destructor

Question 13.
The __________ arguments of overloaded functions are not considered by the C++ compiler as part of the parameter list.
(a) actual
(b) reference
(c) formal
(d) default
Answer:
(d) default

Question 14.
During overloading of which of the following operators,the left hand object must be an object of the relevant class?
(a) Unary
(b) Binary
(c) Ternary
(d) None of these
Answer:
(b) Binary

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 15.
Which of the following terms means a name having two or more distinct meanings?
(a) Data Abstraction
(b) Encapsulation
(c) Inheritance
(d) Overloading
Answer:
(d) Overloading

Question 16.
The overloaded function definitions are permitted for which of the following data types?
(a) Built in
(b) User defined
(c) Derived
(d) All of these
Answer:
(b) User defined

Question 17.
Which of the following is not true related to function overloading?
(a) Each overloaded function must differ by the number of its formal parameter
(b) The return type of overloaded functions may be the same data type
(c) The default arguments are considered by the C++ compiler as part of the parameter list
(d) Do not use the same function name for two unrelated functions
Answer:
(c) The default arguments are considered by the C++ compiler as part of the parameter list

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 18.
By integral promotions, int data type can be converted into which of the following?
(a) char
(b) double
(c) float
(d) all of these
Answer:
(d) all of these

Question 19.
Integral promotions are purely:
(a) compiler oriented
(b) computer oriented
(c) data oriented
(d) program oriented
Answer:
(a) compiler oriented

Question 20.
In polymorphism, the compiler adopts which strategy to match-function call statement?
(a) Best match
(b) Worst match
(c) Good match
(d) Next match
Answer:
(a) Best match

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 21.
In overloaded function, which are not considered by the C++ compiler as part of the parameter list:
(a) Dummy arguments
(b) Actual parameters
(c) Formal parameters
(d) Default arguments
Answer:
(d) Default arguments

Question 22.
Which operator cannot be overloaded?
(a) ::. size of ? :
(b) : size of + *
(c) + – * 7 :
(d) + . ? size of
Answer:
(a) ::. size of ? :

Question 23.
Which of the following C++ operators can be overloaded ?
(a) ::
(b) .
(c) ?:
(d) +
Answer:
(d) +

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 24.
The function operator( ) is declared in which part of the class ?
(a) public
(b) private
(c) protected
(d) static
Answer:
(a) public

Question 25.
Which of the following statements is false in case of operator overloading?
(a) Only existing operators can be overloaded
(b) The basic definition of an operator can be replaced
(c) The overloaded operator must have at least one operand of user defined type
(d) Binary operators overloaded through member function take one explicit argument.
Answer:
(b) The basic definition of an operator can be replaced

Question 26.
Operator <symbol>( ) must be declared under which access of the class?
(a) private
(b) prptect
(c) public
(d) protected
Answer:
(c) public

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 27.
Which of the following operators can be overloaded?
(a) size of ( )
(b) ::
(c) ++
(d) (.) membership operator
Answer:
(c) ++

Question 28.
In how many ways is polymorphism achieved in C++?
(a) 2
(b) 3
(c) 1
(d) 4
Answer:
(a) 2

Question 29.
How many explicit argument(s) is/are taken by binary operators overloaded through a member function?
(a) One
(b) Two
(c) Three
(d) Six
Answer:
(a) One

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 30.
Polymorphism is achieved through:
(a) function overloading
(b) operator overloading
(c) both (a) and (b)
(d) encapsulation
Answer:
(c) both (a) and (b)

Question 31.
The parameter list in function overloading must differ by:
(a) number of arguments
(b) function name
(c) function size
(d) number of functions
Answer:
(a) number of arguments

Question 32.
The operator that can be overloaded is:
(a) ::
(b) .
(c) sizeof( )
(d) + =
Answer:
(d) + =

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 33.
In C++, each overloaded function must differ either by the number of:
(a) function name
(b) actual parameter
(c) default parameter
(d) formal parameter
Answer:
(d) formal parameter

Question 34.
The ability of the function to process the message or data in more than one form is called as:
(a) function overloading
(b) operator overloading
(c) destructor overloading
(d) data overloading
Answer:
(a) function overloading

Question 35.
Which one of the following operator overload through a member function take one explicit argument?
(a) Unary
(b) Ternary
(c) Binary
(d) Conditional
Answer:
(c) Binary

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 36.
The overloaded operator must have at least how many operand of user defined data type?
(a) Two
(b) One
(c) Three
(d) Four
Answer:
(b) One

Question 37.
The overloaded operator must have atleast one operahd of:
(a) user definded
(b) class
(c) static
(d) Built in data
Answer:
(a) user definded

Question 38.
Which access specifier is used to declare operator () function in operator overloading?
(a) Private
(b) Protected
(c) Public
(d) Unprotected
Answer:
(c) Public

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 39.
The ability of an object to respond differently to different messages is called as:
(a) Encapsulation
(b) Polymorphism
(c) Inheritance
(d) Object
Answer:
(b) Polymorphism

Question 40.
The word ‘poly’ means:
(a) Class
(b) Shape
(c) Many
(d) Constructor
Answer:
(c) Many

Question 41.
In C++ which is achieved through overloading?
(a) Data hiding
(b) Encapsulation
(c) Inheritance
(d) Polymorphism
Answer:
(d) Polymorphism

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 42.
In C++, when binary operators are overloaded through a member function they take how many explicit arguments?
(a) Four
(b) Two
(c) One
(d) Three
Answer:
(c) One

Question 43.
Hierarchical database were primarily used in which computers?
(a) Super
(b) Mainframe
(c) Personal
(d) Micro
Answer:
(b) Mainframe

Question 44.
In C++, double data type can be converted into which data type during integral promotion?
(a) char
(b) int
(c) string
(d) void
Answer:
(b) int

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 45.
In C++, which of the following is achieved through function overloading and operator overloading?
(a) encapsulation
(b) data abstraction
(c) polymorphism
(d) inheritance
Answer:
(c) polymorphism

Question 46.
Identify the odd man out:
(a) Scope operation (::)
(b) Sizeof
(c) Member selector (.)
(d) Plus (+)
Answer:
(d) Plus (+)

Question 47.
Identify the incorrect statement in operator overloading:
(a) Precedence and Associativity can be changed.
(b) No new operators can be created only existing operators can be overloaded.
(c) Cannot redefine the meaning of an operator’s precedence.
(d) Overloaded operators cannot have default arguments.
Answer:
(a) Precedence and Associativity can be changed.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 48.
Identify the incorrect statement:
(a) Overloaded function refers to function having only one meaning.
(b) A class can have more than one constructor with different signature.
(c) ?: operator can be overloaded.
(d) Function overloaded makes the program to execute slower.
Answer:
(b) A class can have more than one constructor with different signature.

Question 49.
Which of the following refers to a function having more than one distinct meaning?
(a) Function overloading
(b) Member overloading
(c) Operator overloading
(d) Operations overloading
Answer:
(a) Function overloading

Question 50.
Which of the following reduces the number of Comparisons in a program?
(a) Operator overloading
(b) Operations overloading
(c) Function overloading
(d) Member overloading
Answer:
(c) Function overloading

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 51.
void dispchar(char ch=‘$’,int size=10)
{
for (int i=1; i<=size; i++) ;
cout<<Ch;
}
How will you invoke the function dispchar( ) for the following input?
To print $ for 10 times
(a) dispchar( );
(b) dispchar(ch,size);
(c) dispchar($,10);
(d) dispchar(‘$’, 10 times);
Answer:
(a) dispchar( );

Question 52.
Which of the following is not true with respect to function overloading?
(a) The overloaded functions must differ in their signature.
(b) The return type is also considered for overloading a function.
(c) The default arguments of overloaded functions are not considered for Overloading.
(d) Destructor function cannot be overloaded.
Answer:
(b) The return type is also considered for overloading a function.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 53.
Which of the following is invalid prototype for function overloading?
(a) void fun (int x); void fun (char ch);
(b) void fun (int x); void fun (int y);
(c) void fun (double d); void fun (char ch);
(d) void fun (double d); void fun (int y);
Answer:
(b) void fun (int x); void fun (int y);

Question 54.
Which of the following function(s) combination cannot be considered as overloaded function(s) in the given snippet?
void print(char A,int B); // F1
void printprint (int A, float B) ; // F2
void Print(int P=10); // F3
void print( ); // F4
(a) F1,F2,F3,F4
(b) F1,F2,F3
(c) F1,F2,F4
(d) F1,F3,F4
Answer:
(a) F1,F2,F3,F4

Question 55.
Which of the following operator is by default
overloaded by the compiler?
(a) *
(b) +
(c)+=
(d) = =
Answer:
(d) = =

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Based on the following program answer the questions (8) to (10)
#include<iostream>
using namespace std;
class Point
{
private:
int x, y;
public: .
Point (int x1,int y1)
{ ,
x=x1;y=y1;
}
void operatort+(Point &pt3);
void show( )
{
cout<<“x=”<<x<<“, y=”<<y;
}
};
void Point::operator+(Point &pt3)
{
x += pt3.x;
y += pt3.y;
}
int main( )
Point pt1 (3, 2), pt2(5, 4);
pt1 + pt2;
pt1.show ( );
return 0;
}

Question 56.
Which of the following operator is overloaded?
(a) +
(b) operator
(c) ::
(d) =
Answer:
(a) +

Question 57.
Which of the following statement invoke operator overloading?
(a) pt1 + pt2;
(b) point pt1 (3,2), pt2(5,4);
(c) ptl.show( );
(d) return 0;
Answer:
(a) pt1 + pt2;

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 15 Polymorphism

Question 58.
What is the output for the above program?
(a) x = 8, y = 6
(b) x = 14, y = 14
(c) x = 8, y = 6
(d) x = 5, y = 9
Answer:
(a) x = 8, y = 6

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 14 Classes and Objects

TN State Board 11th Computer Science Important Questions Chapter 14 Classes and Objects

Question 1.
What is a class?
Answer:
In C++ a class is defined using the keyword class followed by the name of the class. The body of the class is defined inside the curly brackets and terminated either by a semicolon or a list of declarations at the end.

Question 2.
What are the features present in OOP languages?
Answer:
Abstraction, Encapsulation, Inheritance and Polymorphism.

Question 3.
What is data hiding?
Answer:
Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 4.
What are access specifiers?
Answer:
The keywords public, private and protected are called access specifiers.

Question 5.
What are the ways to define the member functions of a class?
Answer:
The member functions of a class can be defined in two ways. They are:

  1. Inside the class definition
  2. Outside the class definition

Question 6.
What do you mean by Array of objects?
Answer:
An array which contains the class type of element is called array of objects. It is declared and defined in the same way as any other type of array.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 7.
What is scope resolution operator?
Answer:
If there are multiple variables with the same name defined in separate blocks then :: (scope resolution) operator will reveal the hidden file scope(global) variable.

Question 8.
How the objects are passed to a function?
Answer:
Objects can be passed as arguments to a member function just like any other data type of C++.
Objects can also be passed in both ways:

  1. Pass By Value
  2. Pass By Reference

Question 9.
What do you mean by Nested class?
Answer:
When one class become the member of another class then it is called Nested class and the relationship is called containership.
Classes can be nested in two ways.

  1. By defining a class within another class.
  2. By declaring an object of a class as a member to another class.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 10.
Why constructors are advised to define in the public section? Give reason.
Answer:
A constructor can be defined either in private or public section of a class. But it is advisableto defined in public section of a class, so that 16. What do you mean by Inline member its object can be created in any function. functions.

Question 11.
What are the functions of Constructor?
Answer:

  1. To allocate memory space to the object and
  2. To initialize the data member of the class object.

Question 12.
What do you mean by default constructor?
Answer:
A constructor that accepts no parameter is called default constructor. For example in the class data program Data ::Data( ) is the default constructor. Using this constructor, objects are created similar to the way the variables of other data types are created.
int num; //ordinary variable declaration
Data dl; //object declaration
If a class does not contain an explicit constructor (user defined constructor) the compiler automatically generate a default constructor implicitly as an inline public member.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 13.
What are the ways to create an object using parameterized constructor?
Answer:
There are two ways to create an object using parameterized constructor. They are:

  1. Implicit call
  2. Explicit call

Question 14.
What is explicit call?
Answer:
An explicit call to constructor creates temporary instance which remains in the memory as long as it is used and after that it get released.

Question 15.
What is Destructor?
Answer:
When a class object goes out of scope, a special function called the destructor gets executed. The destructor has the same name as the class tag but prefixed with a ~(tilde). Destructor function returns nothing and it is not associated with anydata type.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 16.
What do you mean by Inline member functions?
Answer:
When a member function is defined inside a class, it behaves like inline functions. These are called Inline member functions.

Question 17.
What is container class?
Answer:
Whenever an object of a class is declared as a member of another class it is known as a container class. In the container-ship, the object of one class is declared in another class.

Question 18.
Write the general form of a class definition.
Answer:
The General Form of a class definition
class class-name
{
private:
variable declaration;
function declaration;
protected:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
};
(i) The class body contains the declaration of its members (Data member and Member functions).
(ii) The class body has three access specifiers, private, public and protected.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 19.
Why do you need a class?
Answer:
Class is a way to bind the data and its associated functions together. Classes are needed to represent real world entities that not only have data type properties but also have associated operations. It is used to create user defined data type.

Question 20.
Explain the access specifiers with example.
Answer:
The access specifiers are public, private and protected.

The Public Members:
A public member is accessible from anywhere outside the class but within a program. User can set and get the value of public data members even without using any member function. ,

The Private Members:
A private member cannot be accessed from outside the class. Only the class member functions can access private members. By default all the members of a class would be private.

The Protected Members:
A protected member is very similar to a private member but it provides one additional benefit that they can be accessed in child classes which are called derived classes (inherited classes).

TN State Board 11th Computer Science Important Questions Chapter 14 Classes and Objects 1

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 21.
Write short note on outside the class definition.
Answer:
When a member function defined outside the class is just like normal function definition then it is be called as outline member function or non-inline member function. Scope resolution operator (::) is used for this purpose. The syntax for defining the outline member function is
Syntax:
return_type class_name :: function_name (parameter list) .
{
function definition
}

TN State Board 11th Computer Science Important Questions Chapter 14 Classes and Objects 2

Question 22.
What are the methods to create objects?
Answer:
A class specification defines the properties of a class. To make use of a class specified, the variables of that class type have to be declared. The class variables are called object. Objects are also called as instance of class.
Eg: student s;
In the above statement s is an instance of the class student. Objects can be created in two methods,
(i) Global object
(ii) Local object.

(i) Global Object:
If an object is declared outside all the function bodies or by placing their names immediately after the closing brace of the class declaration then it is called as Global object. These objects can be used by any function in the program.

(ii) Local Object:
If an object is declared within a function then it is called local object. It cannot be accessed from outside the function.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 23.
How will you declare and define the constructor?
Answer:
When an instance of a class comes into scope, a special function called the constructor gets executed. The constructor function name has the same name as the class name. The constructors return nothing. They are not associated with any data type. It can be defined either inside class definition or outside the class definition.
Eg: A constructor defined inside the class specification.
#include<iostream>
using namespace std;
class Sample
{
int i, j;
public :
int k;
Sample ( )
{
i=j=k=0;//constructor defined
inside the class
}
};

Question 24.
What is a copy constructor? When will the copy constructor is called?
Answer:
A constructor having a reference to an already existing object of its own class is called copy constructor.
A copy constructor is called
(i) When an object is passed as a parameter to any of the member functions.
Eg: void simple: :putdata(simple x);
(ii) When a member function returns an object.
Eg: simple getdata() {}
(iii) When an object is passed by reference to an instance of its own class.
Eg: simples 1, s2(s1); // s2(s1) calls copy constructor

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 25.
Why there is a need for constructors?
Answer:
Need for Constructors:
An array or a structure in C++ can be initialized during the time of their declaration.
Eg:
struct sum
{
int n1,n2;
};
class add
{
int num1,num2;
};
int main ( )
{
int arr[ ]={1,2,3}; //declaration and initialization of array
sum s1={l,l}; //declaration and initialization of structure object
add a1={0,0}; // class object declaration and initialization throws compilation error
}
The initialization of class type object at the time of declaration similar to a structure or an array is not possible because the class members have their associated access specifiers (private or protected or public). Therefore Classes include special member functions called as constructors. The constructor function initializes the class object.

Question 26.
Write short note on memory allocation of objects. Give example.
Answer:
(i) The member functions are created and placed in the memory space only when they are defined as a part of the class specification.
(ii) 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.
(iii) Memory space required for the member variables are only allocated separately for each object because the member variables will hold different data values for different objects.
Eg:
Memory allocation for objects:
#include<iostream>
using namespace std;
class product
{
int code,quantity;
float price;
public:
void assignData( );
void Print( );
};
int main( )
{
product p1, p2;
cout<<\n Memory allocation for object pi “<<sizeof (pi) ; cout<<\n Memory allocation for object p2 “<<sizeof(p2); return 0;
}
Output:
Memory allocation for object p1 12
Memory allocation fdr object p2 12

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 27.
How will you reference a class member?
Answer:
The members of a class are referenced (accessed) by using the object of the class followed by the dot (membership) operator and the name of the member.
The general syntax for calling the member function is:
Object_name. fimction_name(actual parameter);

TN State Board 11th Computer Science Important Questions Chapter 14 Classes and Objects 3

Question 28.
Explain pass by value with example.
Answer:
When an object is passed by value, the function creates its own copy of the object and works on it. Therefore any changes made to the object inside the function do not affect the original object.
C++ program to illustrate how the pass by value method work:
#include<iostream>
using namespace std;
class Sample
{
private: int num; public:
void set(int x)
{
num = x;
}
void pass(Sample obj1, Sample obj2) //objects are passed
{
obj1.num=100; // value of the object is changed inside the function
obj2.num=200; // value of the object is changed inside the function
cout<<“\n\n Changed value of object1″<<obj 1. num;
eout<<“\n\n Changed value of object2″<<obj2 .num;
}
void print( )
{
cout<<num;
}
};
int main( )
{
//object declarations
Sample s1;
Sample s2;
Sample s3;
//assigning values to the data member of objects
s1.set (10);
s2.set (20);
cout<<“\n\t\t Example program for pass by value\n\n\n”;
//printing the values before passing the object cout<<“\n\nValue of objectl before passing”;
s1.print ( );
cout<<“\n\nValue of object2 before passing”;
s2.print( );
//passing object si and s2 s3.pass (s1, s2);
//printing the values after returning to main cout<<“\n\nValue of objectl after passing”;
s1.print () ;
cout<<“\n\nValue of 0bject2 after passing”;
s2.print ( );
return 0;
}
Output;
Example program for PASS BY VALUE
Value of object1 before passing 10
Value of object2 before passing 20
Changed value of object 1 100
Changed value of object 2 200
Value of object 1 after passing 10
Value of object 2 after passing 20

In the above program the objects s1 and s2 are passed to pass( ) method. They are copied to obj 1 and obj2 respectively. The data member num’s value is changed inside the function. But it didn’t affect the s1 and s2 objects data member.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 29.
Explain pass by reference with example.
Answer:
When an object is passed by reference, its memory address is passed to the function. So the called function works directly on the original object used in the function call. So any changes made to the object inside the function definition are reflected in original object.

C++ program to illustrate how the pass by reference method work:
#include<iostream>
using namespace std;
class Sample
{
private:
int num;
public:
void set(int x)
{
num = x;
}
void pass(Sample &objl, Sample &obj2) //objects are passed
{
obj1.num=100; // value of the object is changed inside the function
obj2.num=200; // value of the object is changed inside the function
cout<<“\n\n Changed value of object1″<<obj1.num;
cout<<“\n\n Changed value of objeet2″<<obj2.num;
}
void pfint( )
{
cout<<num;
}
};
int main( )
{ … .
clrscr( );
//object declarations Sample si;
Sample s2;
Sample s3;
//assigning values to the data member of objects si.set(10);
s2.set(20) ;
cout<<“\n\t\t Example program for pass by reference\n\ n\n”;
//printing the values before passing the object
cout<<‘\\n\nValue of objectl before passing”;
s1.print ( ) ;
cout<<“\n\nValue of object2 before passing”;
s2.print( );
//passing object s1 and s2 s3.pass (s1, s2);
//printing the values after returning to main
Cout<<“\n\nValue of object1 after passing”;
s1.print( );
cout<<“\n\nValue of object2 after passing”;
s2.print ( );
return 0;
}
Output:
Example program for PASS BY REFERENCE
Value of object 1 before passing 10
Value of object 2 before passing 20
Changed value of object 1 100
Changed value of object 2 200
Value of object 1 after passing 100
Value of object 2 after passing 200

Question 30.
Explain the parameterized constructors with example.
Answer:
A constructor which can take arguments is called parameterized constructor. This type of constructor helps to create objects with different initial values. This is achieved by passing parameters to the function. To illustrate the Parameterized constructor used for creating objects:
#include<iostream>
using namespace std;
class simple
{
private:
int a,b;
public:
simple(int m,int n)
{
a= m ;
b= n;
cout<<“\n Parameterized Constructor of Class- simple”<<endl;
}
void putdata( )
{
cout<<“\nThe two integers are. . . “<<a<<‘\t'<< b<<endl; cout<<“\n The sum of the variables “<<a<<“+”<<b<<“=” <<a+b;
}
};
int main ( )
{
simple s1(10,20),s2 (30,45);
//Created two objects with different values created cout<<“\n\t\tObject 1\n”;
si.putdata( );
cout<<“\n\t\tObject 2\n”;
s2.putdata( );
return 0;
}
Output:
Parameterized Constructor of class-simple
Parameterized Constructor of class-simple
Object 1
The two integers are .. 10 20
The sum of the variables 10 + 20 = 30
Object 2
The two integers are… 30 45
The sum of the variables 30 + 45 = 75

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 31.
Write the characteristics of constructors.
Answer:

  1. The name of the constructor must be same as that of the class.
  2. No return type can be specified for constructor.
  3. A constructor can have parameter list.
  4. The constructor function can be overloaded.
  5. They cannot be inherited but a derived class can call the base class constructor.
  6. The compiler generates a constructor, in the absence of a user defined constructor.
  7. Compiler generated constructor is public member function.
  8. The constructor is executed automatically when the object is created.
  9. A constructor can be used explicitly to create new object of its class type.

Question 32.
Write the characteristics of destructors.
Answer:

  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 to destroy the object.
  7. They cannot be inherited.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 33.
State the reason for the invalidity of the following code fragment.

(i)

(ii)

Class count

{

int first;

int second;

public;

int first;

};

Class item

{

int prd;

};

item int prdno;

Answer:
(i) Redeclaration of variable first.
(ii) Two or more datatypes in declaration of prdno.

Question 34.
class area
{
int s;
public:
void calc( );
};
Write an outline function definition for calc( ); which finds the area of a square.
Answer:
void area :: calc( )
{
cout<<“Enter the value of s”;
cin>>s;
cout<<“The area of square is”<<s*s
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 35.
Identify the error in the following code fragment
class A
{
float x;
void init( )
{
A a1;
X1.5=1;
void main( )
{A1.init( );}
Answer:
class A
{
float x;
public:
void init( )
{
x=1.5;
} };
int main( )
{
A a1;
a1.init( )
}

Question 36.
What is the size of the objects s1, s2?
Answer:
class sum
{
int n1,n2;
public:
void add( ){int n3=10;nl=n2=10;}
} s1,s2;
S1 8 bytes
S2 8 bytes

Question 37.
(i) Write member function called display with no return. The function should display all the member value of the class objects.
(ii) Try the output of the above coding with the necessary modifications.
Answer:
#include<iostream>
using namespace std;
class compute
{
int n1,n2;
public:
int n;
int add(int a,int b)
{
int c= a+b; return c;
}
int prd(int a,int b)
{
int c=a*b;
return c;
}
void display( )
{
compute c1,c2; .
c1 .n=c1..add(12, 15);
c2.n=c2..add(8, 4);
cout<<“\nSum of object-1” <<c1. n; .
cout<<“\nSum of objeet-2” <<c2.n;
cout<<“\n Sum of the two
objects are”<<c1. n+c2 . n;
c1.n=c1.prd(5, 4);
c2.n=c2.prd(2, 5);
cout<<“\nProduct of object-1” <<c1.n;
cout<<“\nProduct of object-2” <<c2 . n;
cout<<“\nProduct of two . objects are”<<c1.n*c2 .n;
}
};
int main( )
{
compute c;
c.display 0;
return 0;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 38.
#include<iostream>
using namespace std;
class Sample
{
int i ,j;
public:
int k;
Sample( )
{
i=j=k=0;//constructor defined inside the
class
}
};
int main ( )
{
Samples1;
return 0;
}
Answer:
In the above program justify your reason for no output.
There is no cout statement in the above program.

Question 39.
Define a class in general and in C++’s context.
Answer:
The classes are the most important feature of C++ that leads to object oriented programming. Glass is a user defined data type, which holds its own data members and member functions, which can be accessed and used by creating instance of the class.

Question 40.
What is the purpose of a class specifier?
Answer:
The purpose of a class specifier is to identify the access rights for the data and member functions of the class.

Question 41.
Compare a structure and a class in C++ context.
Answer:

  1. Members of a class are private by default and members of struct are public by default.
  2. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public. And when deriving a class, default access specifier is private.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 42.
Compare private and public access specifier.
Answer:
Private: The private member is not accessible from outside the class.
Public: The public members are accessible from outside the class, using objects of class.

Question 43.
What is non-inline member function? Write its syntax.
Answer:
When a member function is defined outside the class just like normal function definition then it is called as outline member function (or) non-inline member function.
Syntax:
return type class name :: function name
(parameter list)
{
Function definition
}

Question 44.
Define a class Employee with the following specification.
Answer:
private members of class employee:
empno – integer
ename – 20 characters
basic-float
netpay, hra, da, – float
calculate( ) – A function to find the basic+hra+da with float return type .
public member functions of class employee:
havedata( ) – A function to accept values for empno, ename, basic, hra, da and call calculate!) to compute netpay
dispdata( ) – A function to display all the data members on the screen
class employee
{
private:
int empno;
char ename[20];
float basic, hra, da, netpay;
float calculate ( ) ;
public:
vpid havedata( );
void dispdata( );
};
float employee :: calculated
{
return basic + hra + da;
}
void employee :: havedata( )
{
cout<<“\n Enter employee number”;
cin>>empno;
cout<<“\n Enter employee name”;
cin>> ename;
cout<<“\n Enter basic”;
cin>> basic; cout<<“\n Enter hra”;
cin>>hra;
cout<<“\n Enter da”;
cin>>da;
netpay = calculated ( );
}
void employee :: dispdata ( )
{
cout<<“\n Employee number”<<empno;
cout<<“\n Employee name”<<ename;
cout<<“\n Basic: “<<basic;
cout<<“\n HRA: “<<hra;
cout<<“\n DA:”<<da;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 45.
Define a class MATH with the following specifications.
Answer:
private members:
num1, num2, result-float
init( ) function to initialize numl, num2 and result to zero
protected members:
add( ) function to add numl and num2 and store the sum in result
diff( ) function to subtract numl from num2 and store the difference in the result.

public members:
getdata( ) function to accept values for numl and num2
menu( ) function to.display menu
(i) Add…
(ii) Subtract…
invoke add( ) when choice is
(i) and invoke prod when choice is
(ii) and also display the result.
#include<iostream>
using namespace std;
class math
{
private:
float num1, num2, result;
int c;
void init( )
{
numl = 0.0;
num2 =0.0;
result =0.0;
}
protected: void add( )
{
result = num1 + num2;
cout<<“\n The sum is:”<<result;
void diff( )
{
result = numl-num2; cout<<“\n The product is:” <<result;
}
public:
void getdata( )
{
init ( )
cout<<“\n Enter numbers:”;
cin>>num1>>num2;
}
void menu( )
{
cout<<“\n1.Add”;
cout<<“\n2.Subtraction”;
cout<<“\n Enter your choice:”;
cin>>c;
if(c==1)
add( );
else
diff( );
}
};
int main( )
{
clrscr 0;
math m1; m1.getdata ( );
m1.menu( );
return 0;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 46.
Create a class called Item with the following specifications.
private members:
code, quantity – Integer data type
price – Float data type
getdata( )-function to accept values for all data members with no return

public members:
tax – float
dispdata( ) member function to display code, quantity, price and tax. The tax is calculated as if the quantity is more than 100 tax is 2500 otherwise 1000.
Answer:
class item
{
private:
int code,quantity;
float price;
void getdata( )
{
cout<<“\n Enter code, quantity, price”;
cin>>code>>quantity>>price;
}
public:
float tax = 0.0;
void putdata( )
{
cout<<“\n code:”<<code;
cput<<“\n Quantity: “<<quantity;
cout<<“\n Price:”<<price;
if(quantity > 100) tax =2500;
else
tax = 1000;
cout<<“\n Tax:”<<tax;
}
};

Question 47.
Write the definition of a class FRAME in C++ with following description.
Private members:
FrameID – Integer data type
Height, Width, Amount – Float data type
SetAmount( ) -Member function to calculate and assign amount as 10*Height*Width
Public members
GetDetail( ) A function to allow user to entervalues of FramelD, Height, Width. This function should also call SetAmount( ) to calculate the amount.
ShowDetail( ) A function to display the values of all data members,
Answer:
class FRAME
{
int Frame ID;
float Height, Width , Amount;
void setAmount( )
{
Amount = 10*Height*Width;
}
Public:
void GetDetail( )
{
cout<<“Enter Frame ID”<<end-1;
cin>>Frame ID;
cout<<“Enter Height”<<endl;
cin>>Height;
cout<<“Enter Widthw<<endl;
cin>>Width; setAmount( );
}
void showDetail( )
{
cout«”Frame ID: “<<FrameID<<endl;
cout<<“Height: w<<Hpight<<endl;
cput<<”Width: “<<Width<<endl;
}
};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 48.
Define a class RESORT in C++ with the following description:
Private Members :
Rno//Data member to store Room No
RName //Data member to store customer name
Charges //Data member to store per day charges
Days //Data member to store number of days of stay
COMPUTE( ) //A function to calculate and return Amount as
//Days*Charges and’ if the value of Days*Charges is more than 5000 then as 1.02*Days*Charges
Public Members:
Getinfo() //A function to enter the content Rno, Name, Charges and Days
Displayinfo( ) //A function to display Rno, RName, Charges, Days and
//Amount (Amount to displayed by calling functionCOMPUTE())
Answer:
class RESORT
{
int Rno, Days;
char RName[20];
float charges float COMPUTE ( )
public:
void Getinfo ( );
void Displayinfo( );
void RESORT :: Getinfo( )
{
cout<<“Room Number:'”;
cin>>Rno; cout<<,‘Name i gets(name);
cout<<”Charges:
cin>>Charges;
cput<<“Pays:w;
cin>>Days;
void RESORT :: Displayinfo( )
{
cout<<endl<<“Details as
follows:”<<endl<<“Ropm No: “<<RNo<<“\n Name : “;
puts(name);
cput<<“Charges: “<<Charges<<“\n Days: “<<Days<<“\n Amount: “<<Compute ( ) <<endl;
}
}
float RESORT : : COMPUTE ( )
{
float amount = Charges * Days;
if (amount > 5000)
amount = 1.02*Days*Charges;
return amount;
}

Question 49.
struct pno
{
int pin; float balance;
}
Create a BankAccount class with the following specifications
Protected members
pho_obj //array of 10 elements
init(pin) // to accept the pin number and initialize it and initialize
// the balance amount is 0
public members
deposit(pin, amount):
Increment the account balance by accepting the amount and pin. Check the pin number for matching. If it matches increment the balance and display the balance else display an appropriate message.

withdraw(self, pin, amount):

Decrement the account balance by accepting the amount and pin. Check the pin number for matching and balance is greater than 1000 and amount is less than the balance. If it matches withdraw the amount and display the balance else display an appropriate message.
Answer:
class BankAccount
{
protected:
char name[15];
int acc_no;
char acc_type;
float bal_amount;
public:
void readData( )
{
cout<<“\nEnter the name: “;
gets(name);
cout<<“\nEnter the account number: “;
cin>>acc_no;
cout<<“\nEnter the account type:
cin>>acc_t ype;
cout<<“\nEnter the amount to deposit:
cin>>bal_amount;
}
void deposit( )
{
float deposit;
cout<<“\nEnter your account number:
cin>>acc_no;
cout<<“\nEnter the amount to deposit: “;
cin>>deposit;
bal_amount=bal_amount + deposit;
}
void withdraw( )
{
float w_amount;
cout<<“\nEnter your account number: “;
cin>>acc_no;
cout<<“\nEnter amount to withdraw”;
cin>>w_amount;
if ((bal_amount-*w^amount) <1000)
cout<<“\nWithdraw is not possible”;
else
{
bal_amount=bali_amaunt-w_ amount;
cout<<“\nThe balance is”<<bal_ amount-w_amount;
}
}
void display( )
{
cout<<“\nName of the depositor :”<<name;
cout<<”\nAccount Number: “<<acc_ no;
cout<<“\nAcCount Type:”<<acc_ type;
cout<<“\nThe balance amount is”<<bal_amount;
}
};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 50.
Define a class Hotel in C++ with the following description:
Private Members:
Rno //Data member to store Room No
Name //Data member to store customer name
Charges //Data member to store per day charges
Days //Data member to store number of days of stay
Calculate( ) //A function to calculate and return Amount as
//Days*Charges and if the value of Days*Charges is more than 12000 then as 1.2*Days*Charges

Public Members:
Hote{ } //to initialize the class members
Getinfo( ) //A function to enter the content Rno, Name, Charges//and Days
Showinfo( ) //A function to display Rno, RName, Charges, Days and
//Amount (Amount to displayed by calling function CALCULATE( ))
Answer:
class Hotel
{
int Rno, NOD;
char Name[30] float charges;
float calculate ( )
{
float temp = NOD*Charges;
if(temp>12000)
return (1.2*temp);
return temp;
}
public:
void Getinfo( )
{
cout<<“Enter the Room number:”<<endl;
cin>>Rno;
cout<<“Enter the customer .name:” <<endl;
gets(Name);
cout<<“Enter the Room charges per day”;<<endl;
cin>>charges;
cout<<“Enter number of days
stayed by customer”;<<endl;
cin>>NOD;
}
void Showinfo( )
{
cout<<“Room Number: “<<Rno<<endl ;
cout<<“Customer
Name:”<<puts (Name) ;
cout<<“Charges per . day: “<<charges<<endl;
cout<<“Number of days stayed by customer: “<<NOD;
cout<<“Total charges of customers: “<<calculate ( )
}
};

Question 51.
Define a class Exam in C++ with the following description:
Private Members:
Rollno – Integer data type
Cname – 25 characters
Mark – Integer data type

public:
Exam(int,char[ ],int) //to initialize the object
~Exam( ) // display message “Result will be intimated shortly”
void Display( ) // to display all the details if the mark is
// above 60 other wise display “Result Withheld”
Answer:
Class Exam
{
int Rolino;
char Cname[25];
int mark;
public:
Exam( )
{
Rollno=0;
strcpy(Cname,” “) ;
mark=0; .
}
~Exam( )
{
cout<<“Result will be intimated shortly”;
}
void Display( )
if(marks>60)
{
cout<<“Roll No:”<<Rollno;
cout<<“Name: “<<Cname;
cout<<“Marks: “<<marks;
}
else
{
cout<<“Result Withheld”;
}
};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 52.
Define a class Student in C++ with the following specification:
Private Members:
A data member Rno(Registration Number) type long
A data member Cname of type string
A data member Agg_marks (Aggregate Marks) of type float
A data member Grade of type char
A member function setGrade ( ) to find the grade as per the aggregate marks obtained by the student. Equivalent aggregate marks range and the respective grade as shown below.

Aggregate Marks

 Grade

>=90  A
Less than 90 and >=75  B
Less than 75 and >=50  C
Less than 50  D

Public members:
A constructor to assign default values to data members:
A copy constructor to store the value in another object
Rno=0,Cname=”N.A” Agg_marks=0.0
A function Getdata ( ) to allow users to enter values for Rno.Cname, Agg_marks and call
functionsetGrade ( ) to find the grade.
A function dispResult( ) to allow user to view the content of all the data members.
A destructor to display the message “END”
Answer:
class student
{
long Rno;
char CName[20];
float Agg-Marks;
char Grade;
void setGrade( )
{
If (Agg_Marks>=90)
Grade = ‘A’;
else if (Agg_Marks<9.0 && Agg_Marks>=75)
Grade = ‘B’;
else if(Agg_Marks<75 && Agg_Marks>=50)
Grade = ‘C’;
else
Grade = ‘D’;
}
public:
candidate( )
{
Rno- 0;
Strcpy(CName , “N.A”);
Agg-Marks =0.0;
void Getdata( )
{
cout<<“Enter Register No”;
cih>>RNO;
cout<<“Enter CName”;
cin>>CName;
cout<<“A§gregate Marks”;
cin>>Agg_Marks;
setGrade( );
}
void dispResult( )
{
cout<<“Registration No”<<Rno;
cout<<“Name”«cname;
cout<<“Aggregate. Marks”<<Agg_Marks;
}
~student ( )
{
cout<<“END”;
}
};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 53.
What are called members?
Answer:
Class comprises of members. Members are 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. Member functions are called as methods and data members are called as attributes.

Question 54.
Differentiate structure and class though both are user defined data type.
Answer:

Structure

 Class

In C++, a structure Can be referred to as an user defined data type possessing its own operations.  In C++, a class can be defined as a collection of related variables and functions encapsulated in a single structure.
Generally used for smaller amounts of data.  Generally used for large amounts of data.
The member variable of structure cannot be initialized directly.  The member variable of class can be initialised directly.

Question 55.
What is the difference between the class and object in terms of oop?
Answer:

class

 Object

A template or blueprint with which objects are Created is known as class.  An instance of a class is known as object.
It is declared by using class keyword.  It is invoked by new keyword.
The formation of a class doesn’t allocate memory. Creation of object consumes memory.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 56.
Why it is considered as a good practice to define a constructor though compiler can automatically generate a constructor?
Answer:

  1. When an object of the class is created, a compiler automatically generates a constructor if it is not defined.
  2. It is considered that writing constructor for a class is a good practice because constructor takes over very important duty of initialization of an object being created and relieves us from this task.

Question 57.
Write down the importance of destructor.
Answer:

  1. The purpose of the destructor is to free the resources that the object may have acquired during its lifetime.
  2. A destructor function removes the memory of an object which was allocated by the constructor at the time of creating a object.

Question 58.
Rewrite the following program after removing the syntax errors if any and underline the errors:
#include<iostream>
#include<stdio.h>
classmystud
{
intstudid =1001;
char name[20];
public mystud( )
{ }
void register ( )
{
cin>>studid;
gets(name);
}
void display ( )
{
cout<<studid<<“: “<<name<<endl;
}
int main( )
{
mystud MS;
register.MS( );
MS.dispfay( );
}
Answer:
#include<iOstream>
#include<stdio.h>
class mystud
{
int studid;
char name[20];
public:
mystud( )
{
Studid =1001;
}
void register( )
{
cin>>studid;
gets(name);
}
void display( )
{
cout<<studid<<“: “<<namd<<endl;
}
int main( )
{
mystud MS;
MS.register( );
MS.display( ) ;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 59.
Write with example how will you dynamically initialize objects?
Answer:
When the initial values are provided during runtime, then it is called dynamic initialization.
Eg:
int main( )
{
int a;
float b;
cout<<“\n Enter the Roll . number”;
cin>>a;
cout<<“\h Entet the Avetage”;
cin>>b;
x x(a,b); //dynamic initialization
x.disp( );
return 0;

Question 60.
What are advantages of declaring constructors and destructor under public accessibility?
Answer:
The advantages of declaring under public accessibility, so that its object can be created in any function.

Question 61.
Given the following C++ code, answer the questions (i) & (ii)
class TestMeOut
{
public:
~TestMeOut( ) //Function 1
{cout<<“Leaving the examination hall”<<endl;
}
TestMeOut( )//Function 2
{cout<<“Appearingforexamination”<<endl;
}
void MyWork( )//Function 3
{
cout<<“Attempting Questions//<<endl;}
};

(i) In Object Oriented Programming, what is Function 1 referred as and when doesit get invoked / called ?
(ii) In Object Oriented Programming, what is Function 2 referred as and when doesit get invoked / called ?
Answer:
(i) Destructor: It is invoked as soon as the scope of the object of the class TestMeOut gets over.
(ii) Constructor: It is invoked automatically at the time of creation of the object of class TestMeOut.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 62.
Write the output of the following C++ program code :
#include<iostream>
using namespace std;
class Calci
{
char Grade;
int Bonus;
public:
Calci( )
{
Grade=’E’; Bonus=0;}//ascii value of
A=65
void Down(int G)
{
Grade-=G;
}
void Up(intG)
{
Grade+=G;
Bonus++;
}
Answer:
void Show( )
{
cout<<Grade<<“#”<<Bonus<<endl;
}
};
int main( ) ,
{
Calci c;
c.Down(3);
c.Show();
c.Up(7);
c.Show( );
c.Down(2);
c.Show( );
return 0;
}
Output:
B#0
I#1
G#1

Question 63.
Explain nested class with example.
Answer:
When a class is declared with in another class, the inner class is called as Nested class (i.e., the inner class) and the outer class is known as Enclosing class. Nested class can be defined in private as well as in the public section of the Enclosing class.
C++ program to illustrate the nested class:
#inelude<iostream>
using namespace std;
class enclose
{
private:
int X;
class nest
{
private :
int y;
public:
int z;
void prn( )
{
y=3; z=2
cout<<“\n The product of “<<y<< ‘ *’ <<z<<“=”<<y*z<<“\n”;
}
}; //inner class definition over
nest n1;
public:
nest n2;
void square( )
{
n2.prn( ); //inner class member function is called by its object
x=2;
n2.z=4;
cout<<“\n The product of “<<n2 . z <<‘*'<<n2 . z<<=<n2 . z*n2 . z <<“\n”;
cout<<“\n The product of ” <<x<< ‘*’ <<x<<“=”<<x*x;
}
}; //outer class definition over
int main( )
{
enclose e;
e.square ( ); //outer class member function is called
}
Output:
The product of 3*2=6
The product of 4*4=16
The product of 2*2=4
In the above program, the inner class nest is defined inside the outer class enclose. Nest is accessed by enclose by creating an object of nest.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 64.
Mention the differences between constructor and destructor.
Answer:

Constructor

 Destructor

A constructor is called when a new instance of a class is created.  A destructor is called when an existing instance of a class is destroyed.
It is called each time a class is instantiated.  It is called automatically when an object is deleted from the memory.
They can have arguments.  They gannot have arguments.
It allocates memory to a newly created object.  It deallocates memory of an object after its deletion.
There can be multiple constructors inside a class.  There can be only one destructor in a class.
It can be overloaded. The name of the constructor must be same as that of the class.  It cannot be overloaded. The destructor has the same name as that of the class prefixed by the tilde character.

Question 65.
Define a class RESORT with the following description in C++:
Private members:
Rno // Data member to store room number Name //Data member to store user name
Charges //Data member to store per day charge
Days //Data member to store the number of days
Compute ( ) // A function to calculate total amount as Days * Charges and if the
//total amount exceeds 11000 then total amount is 1.02 * Days *Charges

Public member:
getinfo( ) // Function to Read the information like name, room no, charges and days
dispinfo ( ) // Function to display all entered details and total amount calculated // using COMPUTE function
Answer:
Class RESORT
{
int Rno, Days;
char Name[30];
float charges;
float compute ( )
{
float temp = Days * charges;
if(temp >11000) .
return(1.02*temp);
}
Public:
void getinfo( )
{
cout<<“Enter the room number:
cin>>Rno;
cout<<“Enter the customer Name:” gets(Name);
cout<<“Enter the room charges per day:”;
cin>>charges;
cout<<“Enter number of days stayed by customer:”;
cin>>Days;
}
void dispinfo( )
{
cout<<“Room number: “«Rno; cout<<“Customer Name:” ;
puts (Name);
cout<<“Charges per day :” <<Charges;
cout<<“Number of days stayed by customer: “<<Days;
cout<<“Total charges of
customer: “<<compute ( ) ;
}
};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 66.
Write the output of the following:
#include<iostream>
#include<stdio.h>
using namespace std;
class sub
{
int day, subno;
public:
sub(int,int); // prototype
void printsub( )
{
cout<<“subject number :”<<subno; cout<<“Days :”<<day;
}
};
sub::sub(int d=150,intsn=12)
{
cout<<endl<<“Constructing the object” <<endl;
day=d;
sub no=sn;
}
class stud
{
int rno;
float marks;
public:
stud( )
{
cout<<“Constructing the object of students” <<endl;
rno=0;
marks=0.0;
}
void getval( )
{
cout<<“Enter the roll number and the marks secured”;
cin>>rno>>marks;
}
void printdet( )
{cout<<“Roll no : “<<rno<<“Marks :”<<marks<<endl;
}
};
class admission
{
sub obj;
stud objone;
float fees;
public:
admission ( )
{
cout<< “Constructing the object of admission”<<endl;
fees=0.0;
}
void printdet( )
{
objone.printdet( );
obj.printsub();
cout<<“fees :”<<fees<,endl;
}
};
int main( )
{system(“cls”);
admission adm;
cout<<endl<< “Back in main ()”;
return 0;
}
Answer:
Output:
Constructing the object
Constructing the object of students
Constructing the object of admission
Back in main( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 67.
Write the output of the following.
#include<iostream>
#include<stdio.h>
using namespace std;
class P
{
public:
P( )
{
cout<< “\nConstructor of class P”;}
~P( )
{
cout<< “\nDestructor of class P”;}
class Q
{
public:
Q ( )
{
cout<<“\nConstructor of class Q”;
}
~Q( )
{cout<< “\nDestructor of class Q”;
}
};
class R
{
P obj1, obj2;
Q obj3;
public:
R( ) ,
{
cout<<“\nConstructor of class R”;}
~ R ( )
{
cout<< “\nDestructor of class R”;}
};
int main ( )
{
R Ro;
Q oq;
Pop;
return 0;
}
Answer:
Output:
Constructor of class P
Constructor of class P
Constructor of class Q
Constructor of class R
Constructor of class Q
Constructor of Class P
Destructor of class P
Destructor of class Q
Destructor of class R
Destructor of class Q
Destructor of class P
Destructor of class P

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Choose the correct answer:

Question 1.
________ is a way to bind the data and its associated functions together.
(a) Class
(b) Function
(c) Objects
(d) Variables
Answer:
(a) Class

Question 2.
The class body has access specifiers.
(a) two
(b) three
(c) four
(d) five
Answer:
(b) three

Question 3.
_________ is one of the important features of object oriented programming.
(a) Inheritance
(b) Encapsulation
(c) Data hiding
(d) Polymorphism
Answer:
(c) Data hiding

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 4.
The default access specifier for member is:
(a) public
(b) protected
(c) static
(d) private
Answer:
(d) private

Question 5.
Identify the odd:
(a) Public
(b) Protected
(c) Private
(d) Auto
Answer:
(d) Auto

Question 6.
The member functions of a class can be defined in ____ ways.
(a) two
(b) three
(c) four
(d) five
Answer:
(a) two

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 7.
Member functions are called as;
(a) data
(b) variables
(c) objects
(d) methods
Answer:
(d) methods

Question 8.
Data members are also called as:
(a) class
(b) objects
(c) attributes
(d) methods
Answer:
(c) attributes

Question 9.
_________ is a scope resolution operator.
(a) :
(b) ;
(c) .
(d) ::
Answer:
(d) ::

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 10.
Objects can be created in ______ methods.
(a) three
(b) five
(c) six
(d) two
Answer:
(d) two

Question 11.
_______ objects can be used by any function in the program.
(a) Local
(b) Auto
(c) Static
(d) Global
Answer:
(d) Global

Question 12.
________ objects cannot be accessed from outside the function.
(a) Protected
(b) Local
(c) Public
(d) Static
Answer:
(b) Local

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 13.
The members of a class are accessed by using ______ operator.
(a) :
(b) \
(c) ,
(d) .
Answer:
(d) .

Question 14.
An array which contains the class type of elements is called:
(a) array of objects
(b) array of elements
(c) array of classes
(d) array of functions
Answer:
(a) array of objects

Question 15.
Objects can be passed in ______ ways.
(a) three
(b) four
(c) two
(d) five
Answer:
(c) two

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 16.
If there are multiple variables with the same name defined in separate blocks then _________ operator will reveal the hidden file scope variable.
(a) &
(b) =
(C) >
(d) ::
Answer:
(d) ::

Question 17.
In ______ changes made to the object inside the function do not affect the original object.
(a) pass by value
(b) pass by object
(c) pass by reference
(d) pass by function
Answer:
(a) pass by value

Question 18.
In ______ any changes made to the object inside the function definition are reflected in original object.
(a) pass by class
(b) pass by object
(c) pass by reference
(d) pass by value
Answer:
(c) pass by reference

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 19.
When one class become the member of another class then it is called:
(a) Nested function
(b) Nested objects
(c) Nested class
(d) Nested structure
Answer:
(c) Nested class

Question 20.
When an instance of a class comes into scope, a special function called the _______ gets executed.
(a) constructor
(b) nested function
(c) destructor
(d) structure
Answer:
(a) constructor

Question 21.
The constructor function name has the same name as the ______ name.
(a) function
(b) object
(c) class
(d) array
Answer:
(c) class

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 22.
If a class does not contain an user defined constructor compiler automatically generates ______ constructor.
(a) copy
(b) abstract
(c) default
(d) destructor
Answer:
(c) default

Question 23.
A constructor which can take arguments is called _______ constructor.
(a) default
(b) copy
(c) abstract
(d) parameterized
Answer:
(d) parameterized

Question 24.
________ constructor helps to create objects with different initial values.
(a) First
(b) Parameterized
(c) Instance
(d) Copy
Answer:
(b) Parameterized

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 25.
Constructors are advisable to define in __________ section of a class.
(a) private
(b) protected
(c) public
(d) default
Answer:
(c) public

Read the code below and answer the questions 26 and 27.
class simple
{
Private: int x;
public: simple(int y)
{
x = y;
}
~ simple( )
{
}
};

Question 26.
The name of the constructor is:
(a) simple
(b) simple
(c) private
(d) public
Answer:
(a) simple

Question 27.
What type of constructors are used in the above code?
(a) Non – parameterized
(b) Copy
(c) Parameterized
(d) Default
Answer:
(c) Parameterized

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 28.
There are ________ ways to Create an object using parameterized constructor.
(a) three
(b) two
(c) four
(d) five
Answer:
(b) two

Question 29.
An _____ to constructor creates temporary instance in the memory.
(a) implicit call
(b) explicit call
(c) copy
(d) object
Answer:
(b) explicit call

Question 30.
A constructor having a reference to an already existing object of its own class is called:
(a) call by reference
(b) default constructor
(c) copy constructor
(d) abstract
Answer:
(c) copy constructor

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 31.
add(add & a) is a _________ constructor.
(a) copy
(b) abstract
(c) default
(d) parameterized
Answer:
(a) copy

Question 32.
Whieh of the following is not true?
(a) The name of the constructor must be same as that of the class.
(b) No return type can be specified for constructor.
(c) A constructor can have parameter list.
(d) The constructor function cannot be overloaded.
Answer:
(d) The constructor function cannot be overloaded.

Question 33.
When a class object goes out of seope, ______ gets executed.
(a) destructor
(b) constructor
(c) default constructor
(d) copy constructor
Answer:
(a) destructor

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 34.
The destructor is prefixed by:
(a) *
(b) ~
(c) +
(d) –
Answer:
(b) ~

Question 35.
Which of the following are not provided by the compiler by default?
(a) Zero-argument constructor
(b) Destructor
(c) Copy constructor
(d) Copy destructor
Answer:
(c) Copy constructor

Question 36.
A _______ is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.
(a) default constructor
(b) copy constructor
(c) Both (a) and (b)
(d) None of these
Answer:
(a) default constructor

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 37.
How many default constructors per class are possible?
(a) Only one
(b) Two
(c) Three
(d) Uilimited
Answer:
(a) Only one

Question 38.
Which of the following statement is correct about destructors?
(a) A destructor type. has void return
(b) A destructor type. has integer return
(c) A destructor has no return type.
(d) A destructors return type is always same as that of main( ).
Answer:
(c) A destructor has no return type.

Question 39.
Which of the following never requires any argument?
(a) Member function
(b) Friend function
(c) Default constructor
(d) Const function
Answer:
(c) Default constructor

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 40.
Which of the following statements are correct?
(a) Constructor is always called explicitly.
(b) Constructor is called either implicitly or explicitly, where as destructor is always called implicitly.
(c) Destructors is always called explicitly.
(d) Constructor and destructor functions are not ealled at all as they are always inline.
Answer:
(b) Constructor is called either implicitly or explicitly, where as destructor is always called implicitly.

Question 41.
Identify the default constructor?
(a) add( )
(b) add(int s1)
(c) add(int s1, int s2)
(d) add(add & a)
Answer:
(a) add( )

Read the following code and answer the questions 42 & 43.
class simple
{
private: int x;
public: simple(int y)
{
x=y;
}
};
void main ( )
{
Simple s(6) ;
}

Question 42.
How many objects are created?
(a) 0
(b) 7
(c) 1
(d) 6
Answer:
(d) 6

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 43.
What type of constructors are used in the above program?
(a) Parameterized constructor
(b) Copy constructor
(c) Non- parameterized constructor
(d) Default constructor
Answer:
(a) Parameterized constructor

Question 44.
Which of the following two entities can be connected by the dot operator?
(a) A class member and a class object.
(b) A class object and a class.
(c) A class and a member of that class-
(d) A class object and a member of that class.
Answer:
(d) A class object and a member of that class.

Question 45.
Which of the following statements is correct about the constructors and destructors?
(a) Destructors can take arguments but constructors cannot.
(b) Constructors can take arguments but destructors cannot.
(c) Destructors can be overloaded but constructors cannot be overloaded.
(d) Constructors can return a value.
Answer:
(b) Constructors can take arguments but destructors cannot.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 46.
Which of the following access specifiers is used in a class definition by default?
(a) Protected
(b) Public
(c) Private
(d) Friend
Answer:
(c) Private

Question 47.
_______ provides additional benefit to access the child classes.
(a) Default
(b) Break
(c) Protected
(d) Private
Answer:
(c) Protected

Question 48.
Which of the following ean access private data members or member functions of a class?
(a) Any function in the program.
(b) All global functions in the program.
(c) Any member function of that class.
(d) Only public member functions of that class.
Answer:
(c) Any member function of that class.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 49.
Which of the following statements is correct?
(a) Data items in a class must be private.
(b) Both data and functions can be either private or public.
(c) Member functions of a class must be private.
(d) Constructor of a class cannot be private
Answer:
(b) Both data and functions can be either private or public.

Question 50.
Where does the object is created?
(a) Class
(b) Constructor
(c) Destructor
(d) Attributes
Answer:
(a) Class

Question 51.
Match the following:

(i) Member function  (a) attributes
(ii) Data Members  (b) instance of a class
(iii) Object  (c) allocate memory space to object
(iv) Constructor  (d) methods

(a) (i) – (d); (ii) – (a); (iii) – (b); (iv) – (c)
(b) (i) – (a); (ii) – (b); (iii – (c); (iv) – (d)
(c) (i) – (b); (ii) – (a); (iii) – (d); (iv) – (c)
(d) (i) – (c); (ii) – (d); (iii) – (b); (iv) – (a)
Answer:
(a) (i) – (d); (ii) – (a); (iii) – (b); (iv) – (c)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 52.
Match the following:

(i) Test ( )  (a) Copy constructor
(ii) Test(int x int y)  (b) Method
(iii) Void show( )  (c) Default constructor
(iv) Test (test & a)  (d) Parametarized constructor

(a) (i) – (b); (ii) – (c); (iii) – (d); (iv) – (a)
(b) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)
(c) (i) – (b); (ii) – (c); (iii) – (a); (iv) – (d)
(d) (i) – (c); (ii) – (d); (iii) – (b); (iv) – (a)
Answer:
(d) (i) – (c); (ii) – (d); (iii) – (b); (iv) – (a)

Question 53.
Identify the correct statement:
(a) In constructor overloading is not allowed.
(b) It is executed when an object is destroyed.
(c) It allocates memory space to objects.
(d) It cannot have argument.
Answer:
(c) It allocates memory space to objects.

Question 54.
Identify the Incorrect statement:
(a) :: operator will reveal the hidden file scope variable.
(b) A member function can access only the private function.
(c) When a class is declared with in another class, the inner class is called as nested class.
(d) The destructors are prefixed by tilde character
Answer:
(b) A member function can access only the private function.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 55.
Assertion (A):
A constructor having a reference to an already existing object of its own class is called copy constructor.
Reason (R):
The argument should be passed only by reference not by value method.
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(a) Both A and R are true and R is the correct explanation for A.

Question 56.
The variables declared inside the class are known as data members and the functions are known as:
(a) data functions
(b) inline functions
(c) member functions
(d) attributes
Answer:
(c) member functions

Question 57.
Which of the following statements about member functions are True or False?
(i) A member function can call another member function directly with using the dot operator.
(ii) Member function can access the private data of the class.
(a) (i) -True, (ii) – True
(b) (i) – False, (ii) – True
(c) (i) – True, (ii) – False
(d) (i) – False, (ii) – False
Answer:
(b) (i) – False, (ii) – True

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 58.
A member function can call another member function directly, without using the dot operator called as:
(a) sub function
(b) sub member
(c) nesting of member function
(d) sibling of member function
Answer:
(c) nesting of member function

Question 59.
The member function defined within the class behave like:
(a) inline functions
(b) non-inline function
(c) outline function
(d) data function
Answer:
(a) inline functions

Question 60.
Which of the following access specifier
(a) Private
(b) Protected
(c) Public
(d) Global
Answer:
(a) Private

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 61 .
class x
{
int y;
public:
x(int z)(y=z;}
} x1[4];
int main( )
{
x x2(10);
return 0;
}
How many objects are created for the above program?
(a) 10
(b) 14
(c) 5
(d) 2
Answer:
(c) 5

Question 62.
State whether the following statements about the constructor are True or False.
(i) constructors should be declared in the private section.
(ii) constructors are invoked automatically when the objects are created.
(a) True, True
(b) True, False
(c) False, True
(d) False, False
Answer:
(c) False, True

Question 63.
Which of the following constructor is executed for the following prototype?
add displayf add &); // add is a class name
(a) Default constructor
(b) Parameterized constructor
(c) Copy Constructor
(d) Non-Parameterized constructor
Answer:
(c) Copy Constructor

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 14 Classes and Objects

Question 64.
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero- argument constructor?
(a) Compile-time error
(b) Domain error
(c) Runtime error
(d) Runtime exception.
Answer:
(a) Compile-time error

Question 65.
Which of the following Create a temporary instance?
(a) Implicit call to the constructor
(b) Explicit call to the constructor
(c) Implicit call to the destructor
(d) Explicit call to the destructor
Answer:
(b) Explicit call to the constructor

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

TN State Board 11th Computer Science Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 1.
Define procedural programming.
Answer:
Procedural is a list of instructions were given to the computer to do something. Procedural programming aims more at procedures. This emphasis on doing things.

Question 2.
Define class.
Answer:
Class is defined as a template or blueprint_representing a group objects that share common properties and relationship.

Question 3.
Define object.
Answer:
An identifiable entity with, some characteristics and behaviour is called object.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 4.
Define encapsulation.
Answer:
The mechanism by which the data and functions are bound together into a single unit is known as Encapsulation.

Question 5.
What do you mean by modularity?
Answer:
Modularity is designing a system that is divided into a set of functional units (named modules) that can be composed into a larger application.

Question 6.
What is Inheritance?
Answer:
Inheritance is the technique of building new classes (derived class) from an existing Class (base class). The most important advantage of inheritance is code reusability.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 7.
What do you mean by modular programming?
Answer:
Modular programming consist of a list of instructions that instructs the computer todo something. Tins’ Paradigm consists of multiple modules, each module has a set of functions of related types. Data is hidden under the modules. Arrangement of data can be changed only by modifying the module.

Question 8.
Write short note on (i) Class (ii) object.
Answer:
(i) Class:
AClass is a construct in C++ which is used to bind data and its associated function together into a single unit using the encapsulation concept. Class is a user defined data type. Class represents a group of similar objects. It can also be defined as a template or blueprint representing a group of objects that share common properties and relationship.

(ii) Object:
It represents data and its associated function together into a single unit. Objects are the basic unit of OOP. An object is created from a class. They are instances of class also called as class variables. An identifiable entity with some characteristics and behaviour is called object.

Question 9.
Write short note on Data Abstraction.
Answer:
Abstraction shows only the essential features without revealing background details. Classes use the concept of abstraction to define a list of abstract attributes and function which operate on these attributes. They encapsulate all the essential properties of the object that are to be created. The attributes are called data members because they hold information. The functions that operate on these data are called methods or member function.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 10.
Write short note on Encapsulation.
Answer:
The mechanism by which the data and functions are bound together into a single unit is known as Encapsulation. It implements abstraction.

Encapsulation is about binding the data variables and functions together in class. It can also be called data binding. Encapsulation is the most striking feature of a class. The data is accessible only to functions which are wrapped in the class can access it. These functions provide the interface between the object’s data and the program. This encapsulation of data from direct access by the program is called data hiding or information hiding. ‘

Question 11.
Write down the important features of object oriented programming language.
Answer:

  1. Emphasizes on data rather than algorithm.
  2. Data abstraction is introduced in addition to procedural abstraction.
  3. Data and its associated operations are grouped in to single unit.
  4. Programs are designed around the data being operated.
  5. Relationships can be created between similar, yet distinct data types.
    Eg: C++, Java, VB.Net, Python etc.

Question 12.
What do you mean by procedural programming? Write down the important features.
Answer:
Procedural is a list of instructions given to the computer to do something. Procedural programming aims more at procedures. This emphasis on doing things.
Important features of procedural programming:
(i) Programs are organized in the form of subroutines or sub programs.
(ii) All data items are global.
(iii) Suitable for small sized software application.
(iv) Difficult to maintain and enhance the program code as any change in data type needs to be propagated to all subroutines that use the same data type. This is time consuming.
Eg: FORTRAN and COBOL.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 13.
Explain modular programming with important features.
Answer:
Modular programming consist of a list of instructions that instructs the computer to do something. This Paradigm consists of multiple modules, each module has a set of functions of related types. Data is hidden under the modules. Arrangement of data can be changed only by modifying the module.
Important features of Modular programming:
(i) Emphasis on algorithm rather than data.
(ii) Programs are divided into individual modules.
(iii) Each modules are independent of each other and have their own local data.
(iv) Modules can work with its own data as well as with the data passed to it.
Eg: Pascal and C.

Question 14.
Explain object oriented programming in detail.
Answer:
Object Oriented Programming paradigm emphasizes on the data rather than the algorithm. It implements programs using classes and objects.

Class:
A Class is construct in C++, which is used to bind data and its associated function together into a single unit using the encapsulation concept. Class is a user defined data type. Class represents a group of similar objects.
An identifiable entity with some characteristics and behaviour is called object.
Important features of Object oriented programming:

  1. Emphasizes on data rather than algorithm.
  2. Data abstraction is introduced in addition to procedural abs’traction.
  3. Data and its associated operations are grouped into single unit.
  4. Programs are designed around the data being operated.
  5. Relationships can be created between similar, yet distinct data types.
  6. Eg: C++, Java, VB.Net, Python etc.,

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 15.
How is modular programming different from procedural programming paradigm?
Answer:
Procedural programming aims more at procedures. Here the programs are organized in the form of subroutines or sub programs. Modular programming emphasis on algorithm rather than data. Programs are divided into individual molecules.

Question 16.
Differentiate classes and objects.
Answer:

Object

 Class

An instance of a class is known as object.  A template or blueprint with which objects are created is known as class.
Object is invoked by new keyword.  Class is declared by using class keyword.
Creation of object consumes memory.  The formation of a class doesn’t allocate memory.

Question 17.
What is polymorphism?
Answer:
Polymorphism is the ability of a message or function to be displayed in more than one form.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 18.
How encapsulation and abstraction are interrelated?
Answer:
Encapsulation is wrapping data into single unit. Abstraction is hiding unessential parts and showing only essential data.

Question 19.
Write the disadvantages of OOP.
Answer:
Size: Object Oriented Programs are much larger than other programs.
Effort: They require a lot of work to create.
Speed: They are slower than other programs, because of their size.

Question 20.
What is paradigm? Mention the different types of paradigm.
Answer:

  1. Paradigm means organizing principle of a program. It is an approach to programming.
  2. Procedural programming, Modular Programming and Object Oriented Programming are different approaches available for solving problem using computer.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 21.
Write a note on the features of procedural programming.
Answer:

  1. Programs are organized in the form of subroutines or sub programs.
  2. All data items are global.
  3. Suitable for small sized software application.
  4. Difficult to maintain and enhance the program code as any change in data type needs to be propagated to all subroutines that use the same data type. This is time consuming.
    Eg: FORTRAN and COBOL.

Question 22.
List some of the features of modular programming.
Answer:

  1. Emphasis On algorithm rather than data.
  2. Programs are divided into individual modules.
  3. Each modules are independent of each other and have their own local data.
  4. Modules can work with its own data as well as with the data passed to it.
    Eg: Pascal and C.

Question 23.
What do you mean by modularization and software reuse?
Answer:
Modularization:
The program can be decomposed into modules.
Software re-use: A program can be composed from existing and new modules.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 24.
Define information hiding.
Answer:
Encapsulation of data from direct access by the program is called data hiding or information hiding.

Question 25.
Write the differences between Object Oriented Programming and procedural programming.
Answer:

Object Oriented Programming

 Procedural programming

Program is divided into parts called objects. Program is divided into small parts called functions.
Importance is given to the data rather than procedures or functions because it works as a real world.  Importance is not given to data but to functions.
OOP has access specifier named public, private, protected. Procedural programming does not have access specifier.
Objects can move and communicate with each other through member functions. Data can move freely from function to function in the system.
Data cannot move easily from function to function, it can be kept public or private. So we can control the access of data. Function uses Global data for sharing that can be accessed freely from function to function in the system.
OOP provides Data Hiding. So it provides more security. It does not have any proper way for hiding data. So it is less secure.
Overloading is possible in the form of function, overloading and operator overloading. Overloading is not possible.
Example of C++,               JAVA, VB.NET, C#. NET. C, VB, FORTRAN, PASCAL

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 26.
What are the advantages of OOPs?
Answer:
(i) Reusability:
Write once and use it multiple times” it can achieved by using class.

(ii) Redundancy:
Inheritance is the good feature for data redundancy. If a same functionality is needed in multiple class, a common class is written for the same functionality and inherit that class to sub class.

(iii) Easy Maintenance:
It is easy to maintain and modify existing code as new objects can be created with small differences to existing ones.

(iv) Security:
Using data hiding and abstraction only necessary data will be provided thus maintains the security of data.

Question 27.
Write a note on the basic concepts that support OOPs.
Answer:
Main Features of Object Oriented Programming are
(i) Data Abstraction,
(ii) Encapsulation,
(iii) Modularity,
(iv) Inheritance,
(v) Polymorphism.

(i) Data Abstraction:
Abstraction refers to showing only the essential features without revealing background details.

(ii) Encapsulation:
The mechanism by which the data and functions are bound together into a single unit is known as Encapsulation. It implements abstraction.

(iii) Modularity:
Modularity is designing a system that is divided into a set of functional units (named modules) that can be composed into a larger application.

(iv) Inheritance:
Inheritance is the technique of building new classes (derived class) from an existing Class (base class). The most important advantage of inheritance is code reusability.

(v) Polymorphism:
Polymorphism is the ability of a message or function to be displayed in more than one form.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Choose the correct answer:

Question 1.
The ________ Paradigm allows us to organize software as a collection of objects that consists of both data and behaviour.
(a) STACK
(b) SOP
(c) SAP
(d) OOP
Answer:
(d) OOP

Question 2.
__________ means organizing principle of a program.
(a) Functions
(b) Paradigm
(c) Class
(d) Object
Answer:
(b) Paradigm

Question 3.
In __________ programming programs are organized in the form of subroutines or sub programs.
(a) procedural
(b) functional
(c) structural
(d) modular
Answer:
(a) procedural

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 4.
FORTRAN and COBOL are examples of ________ programming.
(a) Structural
(b) Modular
(c) Linear
(d) Procedural
Answer:
(d) Procedural

Question 5
_________ programming consists of multiple modules, each module has a set of functions of related types.
(a) Linear
(b) Non – Linear
(c) Model
(d) Modular
Answer:
(d) Modular

Question 6.
__________ is hidden under modules.
(a) Object
(b) Class
(c) Function
(d) Data
Answer:
(d) Data

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 7.
Pascal and C are examples of
(a) Structural
(b) OOV
(c) Modular
(d) Linear
Answer:
(c) Modular

Question 8.
________ is defined as the template or blueprint representing a group objects that share common properties.
(a) Class
(b) Objects
(c) Program
(d) Algorithm
Answer:
(a) Class

Question 9.
______ represents data and its associated function together into a single unit.
(a) Variable
(b) Expressions
(c) Objects
(d) Constants
Answer:
(c) Objects

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 10.
_____ are the basic unit of OOP.
(a) Class
(b) Objects
(c) Program
(d) Algorithm
Answer:
(b) Objects

Question 11.
Python is an example for _________ programming.
(a) Functional
(b) Structural
(c) SAP
(d) OOP
Answer:
(d) OOP

Question 12.
Basically an object is created from a:
(a) class
(b) functions
(c) structures
(d) statements
Answer:
(a) class

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 13.
In ___________ the program can be decomposed into modules.
(a) sub-programs
(b) modularisation
(c) naturalization
(d) multi-way branching
Answer:
(b) modularisation

Question 14.
A program can be composed from existing and new modules in:
(a) software re-use
(b) existing modules
(c) new modules
(d) redundancy
Answer:
(a) software re-use

Question 15.
The mechanism by which the data and functions are bound together into a single unit is called:
(a) encapsulation
(b) inheritance
(c) polymorphism
(d) data hiding
Answer:
(a) encapsulation

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 16.
Encapsulation is also called as:
(a) data hiding
(b) object hiding
(c) object binding
(d) data binding
Answer:
(d) data binding

Question 17.
__________ shows only the essential features without revealing background details.
(a) Abstraction
(b) Polymorphism
(c) Inheritance
(d) Data binding
Answer:
(a) Abstraction

Question 18.
Attributes are called:
(a) data
(b) objects
(c) variables
(d) data members
Answer:
(d) data members

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 19.
The functions that operate on data are called:
(a) Procedures
(b) Objects
(c) Methods
(d) Structure
Answer:
(c) Methods

Question 20.
Methods are also called as:
(a) friend function
(b) method function
(c) member function
(d) inline function
Answer:
(c) member function

Question 21.
_________ is the technique of building new classes from an existing class.
(a) Polymorphism
(b) Inheritance
(c) Modularity
(d) Encapsulation
Answer:
(b) Inheritance

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 22.
__________ is the ability of a message or a function to be displayed in more than one form.
(a) Polymorphism
(b) Data hiding
(c) Methods
(d) Members
Answer:
(a) Polymorphism

Question 23.
_____ paradigm emphasizes on the data rather than the algorithm.
(a) OOP
(b) SAP
(c) Structural
(d) Functional
Answer:
(a) OOP

Question 24.
Match the following:

(i) Modul arization (a) Represents data and its associated function together
(ii) Class (b) Programs can be decomposed into modules
(iii) Objects (c) Blue print representing group of objects that share common properties
(iv) Paradigm  (d) Organizing principles of a program

(a) (i) – (d); (ii) – (a); (iii) – (c); (iv) – (b)
(b) (i) – (b); (ii) – (c); (iii) – (a); (iv) – (d)
(c) (i) – (b); (ii) – (c); (iii) – (d); (iv) – (a)
(d) (i) – (d); (ii) – (c); (iii) – (b); (iv) – (a)
Answer:
(b) (i) – (b); (ii) – (c); (iii) – (a); (iv) – (d)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 25.
Match the following:

(i) Procedural programming  (a) data binding
(ii) Modular programming  (b) C++,JAVA, VB.Net
(iii) Object oriented programming  (c) Pascal and C
(iv) Encapsulation  (d) FORTRAN and COBOL

(a) (i) – (d); (ii) – (c); (iii) – (b); (iv) – (a);
(b) (i) – (a); (ii) – (b); (iii) – (c); (iv) – (d);
(c) (i) – (b); (ii) – (a); (iii) – (d); (iv) – (c);
(d) (i) – (c); (ii) – (d); (iii) – (b); (iv) – (a);
Answer:
(a) (i) – (d); (ii) – (c); (iii) – (b); (iv) – (a);

Question 26.
The term used to describe a programming approach based on classes and objects is:
(a) OOP
(b) POP
(c) ADT
(d) SOP
Answer:
(a) OOP

Question 27.
The paradigm which aims more at procedures:
(a) Object Oriented Programming
(b) Procedural programming
(c) Modular programming
(d) Structural programming
Answer:
(b) Procedural programming

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 28.
Which of the following is a user defined data type?
(a) class
(b) float
(c) int
(d) object
Answer:
(a) class

Question 29.
The identifiable entity with some characteristics and behaviour is:
(a) class
(b) object
(c) structure
(d) member
Answer:
(b) object

Question 30.
The mechanism by which the data and functions are bound together into a single unit is known as:
(a) Inheritance
(b) Encapsulation
(c) Polymorphism
(d) Abstraction
Answer:
(b) Encapsulation

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 31.
Encapsulation of the data from direct access by the program is called as:
(a) Data hiding
(b) Inheritance
(c) Polymorphism
(d) Abstraction
Answer:
(a) Data hiding

Question 32.
Which of the following concept encapsulate all the essential properties of the object that are to be created?
(a) Class
(b) Encapsulation
(c) Polymorphism
(d) Abstraction
Answer:
(a) Class

Question 33.
Which of the following is the most important advantage of inheritance?
(a) Data hiding
(b) Code reusability
(c) Code modification
(d) Accessibility
Answer:
(b) Code reusability

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 13 Introduction to Object-Oriented Programming Techniques

Question 34.
“Write once and use it multiple time” can be achieved by:
(a) redundancy
(b) reusability
(c) modification
(d) composition
Answer:
(b) reusability

Question 35.
Which of the following supports the transitive nature of data?
(a) Inheritance
(b) Encapsulation
(c) Polymorphism
(d) Abstraction
Answer:
(a) Inheritance

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures

Question 1.
Write the syntax to declare a one-dimensional array with example.
Answer:
Syntax:
<data type><array_name> [<array_ size>];
data_type declares the basic type of the array, which is the type of each element in the array.
array name specifies the name with which the array will be referenced.
array size defines how many elements the array will hold. Size should be specified with square brackets [ ].
Eg: int num[10];

Question 2.
What do you mean by subscript?
Answer:
Each element (Memory box) has a unique index number starting from 0 which is known as “subscript”. The subscript always starts with 0 and it should be an unsigned integer value. Each element of an array is referred by its name with subscript index within the square bracket. For example, num[3] refers to the 4th element in the array.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 3.
Write the formula to allocate memory space for an array.
Answer:
The memory space allocated for an array can be calculated using:
Number of bytes allocated for type of array × Number of elements.

Question 4.
What do you mean by initialization of an array?
Answer:
An array can be initialized at the time of its declaration. Unless an array is initialized, all the array elements contain garbage values.
Syntax:
<datatype> <array_name> [size]
= {value-1, value-2, ………, value-n};
Eg:
int age[5]={19,,21,16,1,50};

Question 5.
How will you accept values to an array during run time?
Answer:
Multiple assignment statements are required to insert values to the cells of the array during runtime. The for loop is ideally suited for iterating through the array elements.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 6.
What do you mean by searching in a one dimensional array?
Answer:
Searching is a process of finding a particular value present in a given set of numbers. The linear search or sequential search compares each element of the list with the value that has to be searched until all the elements in the array have been traversed and compared.

Question 7.
Write the syntax to initialize the character array with example.
Answer:
The character array can be initialized at the time of its declaration. The syntax is shown below:
char array_name [size] = {list of characters separated by comma or a string} ;
Eg:
char country[6]=”INDIA”;
At the end of the string, a null character is automatically added by the compiler.

Question 8.
How will you read a line of text?
Answer:
cin.get( ) is used to read a line of text including blank spaces.
getline( ) is also used to read a line of text from the input stream.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 9.
How will you access array elements?
Answer:
Array elements can be used anywhere in a program as in case of a normal variable. The elements of an array are accessed with the array name followed by the subscript index within the square bracket.
Eg:
cout<<num[3];
In the above statement, num[3] refers to the 4th element of the array and cout statement displays the value of num[3].

Question 10.
What is two dimensional array? Give syntax to declare the two dimensional array.
Answer:
Two-dimensional (2D) arrays are collection of similar elements where the elements are stored in certain number of rows and columns. An example m x n matrix where m denotes the number of rows and n denotes the number of columns is shown in Figure below.

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 1

The array arr can be conceptually viewed in matrix form with 3 rows and columns. Point to be noted here is since the subscript starts with 0 arr [0][0] represents the first element.
The declaration of a 2-D array is
data-type array_name[row-size] [col-size];

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 10.
Write down the bytes that are allocated for each data type.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 2

Question 11.
Write a simple program to access the array elements.
Answer:
#include<iostream>
using namespace std;
int main( )
{
int num[5] = {10, 20, 30, 40, 50};
int t=2;
cout<<num[2] <<endl; //SI cout«num [ 3+1 ] <<endl; // S2
cout<<num[t=t+l] ; // S3
Output:
30
50
40

Question 12.
Write a C++ program to read and write the values from an array.
Answer:
#include<iostream>
using namespace std;
int main( )
{
int age[4];//declaration of array
cout<<“Enter the age of four persons:” <<endl;
for(int i=0; i<4; i++)//loop to

write array elements
cin>> age[i];
cout<<“The ages of four persons are:”;
for(int j=0; j<4; j++)
cout<< age[j]<<endl;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 13.
#include <iostream>
using namespace std;
int main( )
{
int num[10], even=0, odd=0;
for (int i=0; i<10; i++)
{
cout<< “\n Enter Number”<< i+1
cin>>num[i];
if (num[i] %2 = = 0)
++even;
else
++odd;
}
cout<<“\n There are”«even«”Even Numbers”;
cout<<“\n There are”« odd «”Odd Numbers”;
}
Rewrite the above coding with the conditional operator instead of if.
Answer:
#include<iostream>
using namespace std;
int main( )
{
int num[10],even=0,odd=0;
for (int i=0;i<10;i++)
{
cout<<“\n Enter Number*'<<i+1 <<“=”;
cin>>num[i] ;
(num[i]%2 = = 0)? ++even
}
cout<<“\n There are”<<even<< “Even Numbers”;
cout<<“\n There are”<<odd<<“0dd Numbers”;
>
}
Output:
Enter Number 1= 78
Enter Number 2= 51
Enter Number 3= 32
Enter Number 4= 66
Enter Number 5= 41
Enter Number 6= 68
Enter Number 7= 27
Enter Number 8= 65
Enter Number 9= 28
Enter Number 10= 94
There are 6 Even Numbers
There are 4 Odd Numbers

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 14.
Write a C++ program to read the prices of 10 products in an array and then print the sum and average of all the prices and also find the product of the prices.
Answer:
#include<iostream>
using namespace std;
int main( )
{
float price [10] , sum=0, avg=0, prod=1;
for(int i=0; i<10; i++)
{
cout<<“\n Enter the price of item”<<i+1<<“=”;
cin>>price[i];
sum+=price[i];
}
avg=sum/10.0;
cout<<“\n Sum of all prices:”<<sum;
cout<<“\n Average of all prices:” <<avg;
}

Question 15.
Write a C++ program to accept the sales of each day of the month and print the total sales and average sales for each month.
Answer:
#include<iostream>
using namespace std;
int main( )
int days;
float sales [5] , avgSales=0, totalSales=0; .
cout<<“\n Enter No. of days:”;
cin>>days;
for(int i=0; i<days; i++)
{
cout<<“\n Enter sales on day”<<i+1<<“:”;
cin>>sales [i} ;
totalSales+=sales[i];
}
avg=total sales/days;
cout<<“\n Average Sales =” <<avgSales;
return 0;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 16.
Write a note on character array creation in C++.
Answer:
To create any kind of array, the size (length) of the array must be known in advance, so that the memory locations can be allocated according to the size of the array. Once an_array is created, its length is fixed and cannot be changed during run time. This is shown in figure below.

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 3

Syntax:
Array declaration is:
char array_name[size];
In the above declaration, the size of the array must be. an unsigned integer value.
Eg:
char country[6];
The array reserves 6 bytes of memory for storing a sequence of characters. The length of the string cannot be more than 5 characters and one location is’ reserved for the null character at the end.
//Program to demonstrate a character array.
#include<iostream>
using namespace std;
int main( )
{
char country[6];
cout<<“Enter the name of the country:”;
cin>>country;
cout<<“The name of the country is”<<country;
}
Output:
Enter country the name: INDIA
The country name is INDIA

Question 17.
Write a C++ program to demonstrate various methods of initializing the character array.
Answer:
#include<iostream>
using namespace std;
int main( )
{
char arr1[6]=”INDIA”;
char arr2[6]={‘I’,’N’,’D’,’I’, ‘AV\0’f;
char arr3[ ]=”TRICHY”;
char arr4[ ]={‘T’,’R’, ‘I’, ‘C’,’H’, ‘Y’, ‘\0’};
char arr5[8]=”TRICHY”;
cout<<“arrl is :” <<arr1<< “and its size is”
<<sizeof (arr1) <<endl;
cout<<“arr2 is :” <<arr2<< “and its size is”
<<sizeof (arr2)<<endl;
cout<<“arr3 is :” <<arr3<< “and its size is”
<<sizeof (arr3) <<endl;
cout<<“arr4 is: “<<arr4<<” and its size is”
<<sizeof (arr4) <<endl;
cout<<“The elements of arr5″<<endl;
for(int i=0; i<8; i++) cout<<arr5 [i]<<” “;
return 0;
}
Output:
arr1 is :INDIA and its size is 6
arr2 is :INDIA and its size is 6
arr3 is :TRICHY and its size is 7
arr4 is :TRiCHY and its size is7
The elements of arr5 T R I C H Y.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 18.
Write a C++ program to display a line of text using get ( ) function.
Answer:
// str10.cpp
// To read a line of text
#include<iostream>
using namespace std;
int main( )
{
char str[100];
cout<<“Enter a string:”;
cin.get(str,100);
cout<<“You entered: “<<str<<endl;
return 0;
}
Output:
Enter a string: I am a student
You entered: I am a student

Question 19.
Write the ways to initialize the Two-Dimensional array.
Answer:
The array can be initialized in more than one way at the time of 2-D array declaration.
Eg:
int matrix[4][3]={
{10,20,30},// Initializes row 0
{40,50,60},// Initializes row 1
{70,80,90},// Initializes row 2
{100,110,120}// Initializes row 3
};
int matrix[4][3]={10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120};

Question 20.
Write a program to demonstrate array of string using 2d character array.
Answer:
#include<iostream>
using namespace std;
int main ( )
{
// initialize 2d array
char colour [4] [10] = {“Blue”, “Red”,”Orange”,”yellow”};
// printing strings stored in 2d array
for(int i=0; i<4; i++)
cout<<colour [i]<<“\n”;
}
Output:
Blue
Red
Orange
Yellow

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 21.
Write a C++ program to display marks of 5 students using one dimensional array.
Answer:
#include<iostream>
using namespace std;
void display (int m[5]);
int main( )
{
int marks[5]={88,76,90,61,69};
display(marks);
return 0;
}
void display (int m[5])
{
cout<<“\n Display Marks : “<<endl;
for (int i=0; i<5; i++)
{
cout<<“Student”<<i+K<“: “<<m[i]<<endl;
}
}
Output:
Display Marks:
Student 1: 88
Student 2: 76
Student 3: 90
Student 4: 61
Student 5: 69

Question 22.
How will you represent two-dimensional array?
Answer:
The two-dimensional array can be viewed as a matrix. The conceptual view of a 2-D array is shown below:
int A[4] [3] ;

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 4

In the above example, the 2-D array name A has 4 rows and 3 columns. Like one-dimensional, the 2-D array elements are stored in continuous memory.
There are two types of 2-D array memory representations. They are:
(i) Row-Major order
(ii) Column-Major order.
Eg:
int A[4][3]={ .
{ 8,6,5},
{2,1,9},
{3,6,4},
{4,3,2},

Row Major order:
In row-major order, all the elements are stored row by row in continuous memory locations, i.e., all the elements in first row, then in the second row and so on. The memory representation of row major order is as shown below;

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 5

Column-Major order:

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 6

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 23.
Write a C++ program to check the given string is palindrome or not.
Answer:
#include<iostream>
using namespace std;
int main( )
{
int i,j,len,flag =1;
char a [20];
-cout<<“Enter a string:”;
cin>>a;
for(len=0; a[len]!-‘\0’; ++len)
for(!=0, j =len-1; i<leh/2; ++i, –j)
{
if(a[j]!=a[i])
flag=0;
}
if (flag==1) ;
cout<<“\n The String is palindrome”;
else
cout<<“\n The String is not palindrome”;
return 0;

Output:
Enter a string : madam
The String is palindrome

Question 24.
Explain the returning structures from functions with example.
Answer:
A structure can be passed to a function through its object. Passing a structure to a function or passing a structure object to a function is the same because structure object represents the structure. Like a normal variable, structure variable (structure object) can be passed by value or by references / addresses.

Sitnilar to built-in data types, structures also can be returned from a function.
#ihclude<iostream.h>
using namespace std;
struct Employee
{
int Id;
char Name 125];
int Age;
long Salary;
};
Employee Input( );
void main ( )
{
Employee e;
Emp = Input( );
cout<<“The values Entered are” <<endl:
cout<<“\nEmployee Id: “<<e. Id”;
cout<<“\nEmployee :”<<e.Name;
cout<<“\nEmployee Age:”<<e.Age;
cout<<“\nEmployee Salary :”<<e.Salary;
}
Employee Input( )
{
Employee e;
cout<<“\nEnter Employee Id
cin>>e.Id;
cout<<“\nEnter Employee Name :”;
cin>>e.Name;
cout<<“\nEnter Employee Age :”;
cin>>e.Age;
cout<<“\nEnter Employee Salary :”;
cin>>e. Salary;
return;
}
Output:
Enter Employee Id : 10
Enter Employee Name : Ajay
Enter Employee Age : 25
Enter Employee Salary : 15000
Employee Id : 10
Employee Name : Ajay
Employee Age : 25
Employee Salary : 15000

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 25.
Write a program to perform addition of two matrices.
Answer:
#include<iostream>
#include<conio>
using namespace std;
int main ( )
{
int row, col,m1[10][10], m2[10][10],sum[10][10];
cout<<“Enter the number of rows: “;
cin>>row;
cout<<“Enter the number of columns: “;
cin>>col;
cout<<“Enter the elements of first matrix: “<<endl;
for(int i=0; i<row; i++)
for(int j=0; j<col; j++)
cin>>m1 [i] [ j ] ;
cout<<“Enter the elements of second matrix: “<<endl;
for (int i=0; i<row; i++)
for(int j=0; j<col; j++)
cin>>m2[i] [j];
cout<<“Output: “<<endl;
for(int i=0; i<row; i++)
for (int j=0; j<col; j++)
{
sum[i] [j]=ml[i] [j]+m2[i] [j];
cout<<sum [i] [ j ] <<” “;
}
cout<<endl<<endl;
}
getch( );
return 0;
}
Output:
Enter the number of rows : 2
Enter the number of column : 2
Enter the elements of first matrix:1 1 1 1
Enter the elements of second matrix:1 1 1 1
Output:
2 2
2 2

Question 26.
Write a program to accept the marks of 10 students and find the average, maximum and minimum marks.
Answer:
#include<iostream>
using namespace std;
int main( )
{
int mark[10],i,max,min,sum=0;
float avg =0.0;
cout<<“Enter the marks:”;
for(i=0;i<10;i++)
{
cin>>mark[i];
sum += mark[i];
}
avg = sum/10;
max = mark[0] ;
for(i=0; i<10; i++)
{
if(max<mark[i])
max = mark[i];
}
min = mark[0];
for(i=0; i<10; i++)
{
if(min>mark[i] )
min = mark[i];
}
cout<<“The average marks :”<<avg;
cout<<“\n The maximum mark:” <<max;
cout<<“\n The minimum mark:” <<min;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 27.
Write a program to accept rainfall recorded in four metropolitan cities of India and find the city that has the highest and lowest rainfall.
Answer:
#include<iostream>
using namespace std;
int main( )
{
double rainfall[4],sum=0,avg, highest=0,lowest;
int highest_city,lowest_city;
for (int i=0; i<4; i++)
{
cout<<“\n The total rainfall for”<<i+1<<“city:”;
cin>>rainfall [i] ;
while(rainfall[i]< 0)
{
cout<<“\n Error. Enter a positive value:”;
cout<<“\n Enter the total rainfall”<<i+1<<“city:”;
cin>>rainfall [i] ;
}
for (int x=0;x<4;x++)
{
if(highest<rainfall[x];
{
… highest = rainfall[x];
highest_city = x+1;
}
}
lowest = rainfall[0];
for(int y=0; y<4; y++)
{
if(lowest>rainfall[y];
lowest_city = y+1;
}
}
cout<<“\n The city has the highest rainfall is”<<highest_city<<endl;
cout<<“\n The city has the lowest rainfall is”<<lowest_ city<<endl;
return 0;
}

Question 28.
Survey your neighbouring shops and find the price of any particular product of interest and suggest where to buy the product at the lowest cost.
Answer:
You are living in the heart of the city. You are very much fond of ice-creams. There are many ice-cream parlours in
your area. You want quality based product and at the same time it should be pocket-friendly.
You have collected pamphlets from three icecream outlets and the same is given below:

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 7

Suggestions:
(i) If you want to buy cone ice cream you can buy at ABC or MMM outlets.
(ii) Black forest is cheap at ABC ice cream parlour.
(iii) MMM ice cream shop offers the lowest price for the family pack.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 29.
What is Traversal in an Array?
Answer:
Accessing each element of an array at least once to perform any operation is known as “Traversal”.

Question 30.
What is Strings?
Answer:
A string is defined as a sequence of characters where each character may be a letter, number or a symbol. Each element occupies one byte of memory. Every string is terminated by a null (‘\0’, ASCII code 0) character which must be appended at the end of the string.

Question 31.
What is the syntax to declare two – dimensional array.
Answer:
data-type array_name[row-size][col-size];
Eg: int A[5] [5];

Question 32.
Define an Array? What are the types?
Answer:
“An array is a collection of variables of the same type that are referenced by a common name”.
Types of Arrays:

  1. One-dimensional arrays
  2. Two-dimensional arrays
  3. Multi-dimensional arrays

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 33.
Write note on Array of strings.
Answer:
An array of strings is a two-dimensional character array. The size of the first index (rows) denotes the number of strings and the size of the second index (columns) denotes the maximum length of each string. Usually, array of strings are declared in such a way to accommodate the null character at the end of each string. For example, the 2-D array has the declaration:
char N ame[6] [10];
In the above declaration, the 2-D array has two indices which refer to the row size and column size, that is 6 refers to the number of rows and 10 refers to the number of columns.

Question 34.
Write a C++ program to accept and print your name?
Answer:
#include<iostream>
using namespace std;
int main ( )
{
char name[20];
cout<<“Enter your Name:”;
cin>>name;
cout<<“your Name is”<<name;
}
Output:
Enter your Name: Ramu
your Name is Ramu

Question 35.
Write a C++ program to find the difference between two matrix.
Answer:
#include<iostream>
#include<conio.h>
using namespace std;
int main( )
{
int row,col,ml[10][10],m2[10][10], diff[10] [10] ;
cout«”Enter the number of rows:”;
cin>>row;
cout<<“Er,ter the number of columns:”; cin»col;
cout<<“Enter the elements of first matrix:”«endl; for(int i-0;icrow;i++) .
for(int j=0; j<col; j++)
{
cin>>m1 [i] [ j ] ;
}
}
cout<<“Enter the elements of ; second matrix: “<<endl;
for(int i=0; i<row; i++)
for(int j=0; j<col; j++)
{
cin>>m2[i] [ j];
}
}
cout<<“output: “<<endl;
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
diff [ i ] [ j ] = m1 [i][ j] – m2 [i][j];
cout<<diff[i] [j]<< ” “;
}
cout<<endl<<endl;
}
return 0;
}
Output:
Enter the number _ of rows : 2
Enter the number of columns : 2
Enter the elements of first matrix :
3
3
3
3
Enter the elements of second matrix :
1 .
1
1
1
Output:
2 2
2 2

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 36.
How will you pass two dimensional array to a function explain with example.
Answer:
In C++, array can be passed to a function as an argument. To pass an array to a function in C++, the function needs the array name as an argument.
C++ program to display values from two dimensional array:
#include<iostream>
using namespace std;
void display(int n[3][2]);
int main ( )
{
int num[3][2] = {{3,4}, {9,5}, {7,1}};
display(num);
return 0;
}
void display(int n[3][2])
{
cout<<“\n Displaying Values” <<endl;
for (int i=0; i<3; i++)
{
for(int j=0; j<2; j++)
{
cout«n [i] [ j ] <<”
}
cout<<endl<<endl;
}
}
Output:
Displaying Values
3 4
9 5
7 1

Question 37.
Define structure. What is its use?
Answer:
Structure is a user-defined which has the combination of data items with different data types.
Uses:
This allows to group of variables of mixed data types together into a single unit.

Question 38.
To store 100 integer number, Which of the following is good to use? Array or Structure. State the reason.
Answer:
In any situation, when more than one variable is required to represent objects of uniform data-types array can be used. Because it is used to store number of same data type in sequential manner. It provides an easy access to element due to the usage of index number.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 39.
What is the error in the following structure definition?
Answer:
struct employee{inteno; charename[20]; char dept;}
Employee e1,e2;

Incorrect statement

Correct statement

inteno;  intno;
char ename[20]  char name[20];
char dept;  char dept[20]

Question 40.
Write a structure definition for the structure student containing examno, name and an array for storing five subject marks.
Answer:
struct student
{
int examno;
char name[20];
int marks[5];
};

Question 41.
Why for passing a structure to a function, call by reference is advisable to us?
Answer:
Structures are usually passed by reference method because it saves the memory space and executes faster.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 42.
What is the size of the following highlighted variable in terms of byte if it is compiled in dev C++ ?
Answer:
struct A{ float f[3]; char ch[5];
long double d;};
struct B{ A a; int arr[2][3];}b[3]

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 8

Question 43.
Is the following snippet is fully correct. If not identify the error.
struct sum1{int nl,n2;}s1;
struct sum2{int nl,n2}s2;
cin>>s1 .n1>>s1 .n2;
s2=s1;
Answer:
The error statement is s2 = s1;
The object name must be followed with a dot (.) and the member name.

Question 44.
Differentiate array and structure.
Answer:

Array

 Structures

Array is a collection of variables of similar data type.  Structure is a collection of variables of dissimilar data types.
Variables of an array are stored in a contiguous memory location.  The variables in a structure may or may not be stored in a contiguous memory locations.
Array elements are accessed by their index number.  Structure elements are accessed by their names.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 45.
What are the different ways to initialize the structure members?
Answer:
Values can be assigned to structure elements similar to assigning values to variables.
Eg:
balu.rollno= “702016”;
balu.age= 18;
balu.weight- 48.5;
Also, values can be assigned directly as similar to assigning values to Arrays.
balu={702016,18,48.5};

Question 46.
What is wrong with the following C++ declarations?
Answer:
A. struct point ( double x, y)
B. struct point (double x, double y };
C. struct point {double x; double y}
D. struct point {double x; double y;};
E. struct point { double x; double y;}
struct point {double x; double y;}; is the only one syntactically correct.

Question 47.
How will you pass a structure to a function?
Answer:
A structure variable can be passed to a function in a similar way of passing any argument that is of built-in data type.

  1. If the structure itself is an argument, then it is called “call by value”.
  2. If the reference of the structure is passed as an argument then it is called, “call by reference”.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 48.
The following code sums up the total of all students name starting with ‘^S’ and display it. Fill in the blanks with required statements.
Answer:
struct student {int exam no, lang, eng, phy, che, mat, csc, total;char name[15];};
int main( )
{
student s[20];
for(int i=0;i<20;i++)
{
//accept student details
}
for(int i=0;i<20;i++)
{
//check for name starts with letter “S”
// display the detail of the checked name
}
return 0;
}
#include<iostream>
using namespace std;
struct student
{
int examno, lang, eng, phy, che, mat, esc, total;
Char name[15];
};
int main ( )
{
student s [20];
for(int i=0; i<20; i++)
{
cout<<“\n Enter Exam no”;
cin>>examno;
cout<<“Enter Name”
cin>>name;
cout<<“\n Enter language”;
cin>>lang;
cout<<“\n Enter English mark”;
cin>>eng;
cout<<“\n Enter Physics mark”;
cin>>phy;
cout<<“\n Enter Chemistry mark”;
cin>>che;
cout<<“\n Enter Maths mark”;
cin>>mat;
cout<<“\n Enter CSC mark”;
cin»csc; .
}
cout<<“Displaying the information the name starts
Now the elements of the structure student can be accessed as follows.
balu.rollno
balu.age
balu.weight
frank.rollno
frank.age
frank.weight.

Question 49.
Write the syntax and an example for structure.
Answer:
Syntax:
struct structure_name
{
type member_namel;
type member_name2;
} reference_name;
An optional field reference name can be used to declare objects of the structure type directly.
Eg:
struct Student
{
long rollno;
int age;
float weight;
};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 50.
For the following structure definition write the user defined function to accept data through keyboard.
struct date{ int dd,mm,yy};
struct item {int item id; char name[10];float price;
date date_manif;}
Answer:
date readdata(date d)
{
cout<<“Enter date”;
cin>>d.dd;
cout<<“Enter month”;
cin>>d.mm;
cout<<“Enter year”;
cin>>d;yy;
}
item readdata(item i)
{
cout<<“Enter Item code:”;
cin>>i.item_id;
cout<<“Enter Name:”; cin»i.name;
cout<<“Enter Price:”;
cin>>i .price;
cout<<“Enter date of manufacture:”;
cin>>i. date_manif;
}

Question 51.
What is called anonymous structure? Give an example.
Answer:
Anonymous Structure A structure without a name/tag is called anonymous structure.
struct
{
long rollno;
int age;
float weight;
} student;
The student can be referred as reference name to the above structure and the elements can be accessed like student.rollno, student, age and student.weight.

Question 52.
Write a user defined function to return the structure after accepting value through keyboard. The structure definition is as follows:
Answer:
struct ltem{int item no;float price;};
item Input( )
{
item I
cout<<“Enter Item Number”;
cin>>I.itemno;
cout<<“Enter Price”;
cin>>Price;
return;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 53.
Explain array of structures with example.
Answer:
An array of structures is declared in the same way as declaring an array with built-in data types like int or char.
The following program reads the details of 20 students and prints the same.
#include<iostream>
using namespace std;
struct Student
{
int age;
float height,weight; char name[30];
with letters”;<<endl;
for(int i=0; i<=3; i++.)
{
if(s[i].name[0} == ‘S’
{
cout<<s[i] .examno<<endl;
cout<<s [i].name<<endl;
cout<<s [i]. language<<endl;
cout<<s [i].Eng<<endl;
cout<<s [i].Phy<<endl;
cout<<s[i].Che<<endl;
cout<<s [i] .Mat<<endl;
cout<<s [i] .Csc<<endl;
}
}
return 0;
}

Question 54.
What is called nested structure? Give example.
Answer:
The structure declared within another structure is called a nested structure.
Eg:
The following code the struct date of birth can be assigned as one of the elements in the student structure.

Now the student structure will be,
struct Student
{
int age;
float height, weight;
struct dob
{
int date;
char month[4];
int year;
};
};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 55.
Rewrite the following program after removing the syntactical error(s),if any.
Answer:
Underline each correction.
struct movie
{
charm_name[10];
charm_lang[10];
float ticket cost =50;};
Movie;
void main( )
{
gets(m_name);
cin>>mjang;
return 0;
}
struct movie
{
char m_name[10];
char m_lang[50];
float ticket_Cost =50;
}movie;
int main( )
{
gets(movie.m_name);
cin>>movie.m lang;
return 0;
}

Question 56.
What is the difference among the following two programs?
Answer:
(a) #inelude <iostream.h>
struct point { double x; double y;};
int main( ) {
struct point test;
test.x = .25; test.y = .75;
cout<<test.x<<test.y;
return 0;
}

(b) #include <iostream.h>
struct { double x; double y;} Point;
int main(void) {
Point test={.25;. 75};
return 0;
}
The program (b) is the anonymous structure.
The program (b) does not contain a name/tag in the structure.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 57.
How to access members of a structure? Give example.
Answer:
The members of the structure can be accessed directly by using a dot(.)
Eg:
struct Student
{
long rollno;
int age;
float weight;
}balu,frank;
};
void main( )
{
Student std[20];
int i;
Cout<<“Enter the details for 20 students”<<endl;
for(i=0; i<20; i++)
{
cout<<“Enter the details of Student”<<i+1<<endl;
cout<<“Enter the age:”<<endl;
cin>>std[i].age;
cout<<“Enter the. height: “<<endl;
cin>>std[i] .height;
cout<<“Enter the weight: “<<endl;
cin>>std[i] .weight;
}. . .
cout<<“The values entered for Age,.height and weight are”<<endl;
for(i=0; i<20; i++)
cout<<“Student”<<i+l<<“\t”<<std[i] .age<<“\t”<<std[i] . height<< “\t”<<std [i] weight;
}
Output:
Enter the details of 20 students details for students age:
height:
weight:
details for student2 age:
height:
Enter -the weight: 61.5
The values entered for Age, height and weight are Student 1 18 160.5 46.5 Student 2 18 164-5 61.5

Question 58.
Explain call by value with respect to structure.
Answer:
When a structure is passed as argument to a function using call by vatue method, any change made to the contents of the structure variable inside the function to which it is passed do not affect the structure variable used as an argument.
Eg:
#include<iostream>
using namespace std;
struct Employee
{
char.name[50];
int age;
float salary;
};
void printData(Employee);
//Function declaration
int main( )
{
Employee p;
cout<<“Enter Full name:”;
cin>>p.name;
cout<<“Enter age:”;
cin>>p.age;
cout<<“Enter salary:”;
cin>>p. salary;
// Function call with structure variable as an argument printData(p);
return 0;
}
void printData(Employee q)
{
cout<<“\nDi splaying Information.” <<endl;
cout<<“Name: “<< q.name <<endl;
cout<<“Age: “<<q. age<<endl;
cout<<“Salary: “<<q. salary;
}
Output:
Enter Full name: Kumar
Enter age: 55
Enter salary: 34233.4
Displaying Information.
Name: Kumar
Age: 55
Salary: 34233.4
In the above example, a structure named Employee is declared and used. The values that are entered into the structure are name, age and salary of a Employee are displayed using a function named printDataQ. The ^ argument for the above function is the structure Employee. The input ban be received through a function named readData( ).

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 59.
How call by reference is used to pass structure to a function. Give an Example.
Answer:
In this method of passing the structures to functions, the address of a structure variable
/object is passed to the function using address of(&) operator. So any change made to the contents of structure variable inside the function are reflected back to the calling function.
Eg:
#include<iostream>
using namespace std;
struct Employee
{
char name[50];
int age;
float salary;
};
void readData(Employees) ;
void printData(Employee);
int main( )
{
Employee p;
readData(p);
printData (p);
return 0;
}

void readData.(Employee &p)
{
cout<<“Enter Full name:”;
cin.get(p.name, 50) ;
cout<<“Enter age:”;
cin>>p. age;
cout<<“Enter salary:”;
cin>>p.salary;
}
void printData(Employee p)
{
cout<<“\nDisplaying Information. “<<endl;
cout<<“Name: “<<p.name<<endl;
cout<<“Age: “<<:p. age<<endl;
Cout<<“Salafy: “<<p. salary;
}
Output:
Enter Full name: Kumar
Enter age: 55
Enter Salary: 34233.4
Displaying Information.
Name: Kumar
Age: 55
Salary: 34233.4

Question 60.
Write a C++ program to add two distances using the following structure definition.
Answer:
Struct Distance
{
int feet;
float inch;
}
d1 , d2, sum;
PROGRAM:
#include<idstream>
using namespace std;
Struct Distance .
{
int feet;
float inch; .
}
d1, d2, sum;

int main( )
{
cout<<“Enter 1st distance”<<endl;
cout<<“Enter feet:”;
cin>>d1.feet;
cout<<“Enter inch:”
cin>>d1.inch;
cout<<“nEnter information for 2nd distance”<<endl;
Cout<<“Enter feet:”; ‘
cin>>d2. feet;
cout<<“Enter inch:”;
cin>>d2.inCh;
sum.feet = d1.feet + d2.feet;
sum.inch = d1.inch + d2.inch;
//Changing to feet if inch is greater than 12
if(sum.inch>12)
{
++ sum.feet;
sum.inch – = 12;
}
cout<<endl<<“sum of distances-“<<sum. feet<<“feet”<<sum.inch<<“inches”;
return 0;
}
Output:
Enter 1st .distance
Enter feet : 6
Enter inch : 3.4
Enter infdtmatidh for 2nd distance
Enter feet : 5
Enter inch : 10.2
Sum of distances – 12 feet 1.6 inches

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 61.
Write a C++ Program to Add two Complex Numbers by Passing Structure to a Function for the following structure definition,
struct complex
{
float real;
float imag;
};
The prototype of the function is complex add Complex Numbers(complex, complex);
Answer:
#include<iostream>
using namespace std;
typedef struct complex
{
float real;
float, imag;
}
Complex Number;
Complex Number addComplexNumbers(complex, Complex);
int main( )
{
Complex Number n1, n2, temporaryNumber;
char SignofImag;
cout<<“For 1st complex number,”<<endl;
cout<<“Enter real and imaginary parts respectively:”<<endl;
cin>>n1. real>>n2 . imag;
cout<<“For 2nd complex number “<<endl;
cout<<“Enter real and imaginary parts respectively:”<<endl;
cin>>n2 . real>>n2 . imag;
SignofImag =(temporaryNumber. , imag>0) ? ‘+’: ‘-‘;
cout<<“Ehter real and imaginary parts respectively:”<<endl;
cin>>n2 . real>>n2 . imag;
SignofImag =(temporaryNumber. , imag>0) ?
temperaryNumber. imag = (temporaryNurnbet.imag>0)? temporaryNumber .imag: – temporaryNumber.imag; temporaryNumber = addComplexNumbers(n1,n2);
cout<<“Sum = ” <<temporaryNumber. real<<temporatyNumber. imag<<“i”;
return 0;
}
ComplexNumber
addComplexNumbers(complex n1,complex n2)
{
complex temp;
temp.real – n1.real + n2.real;
temp.imag = hi. imag + n2. imag;
return(temp);
}
Output:
For 1st complex number,
Enter real and imaginary parts respectively:
3.4
5.5
For 2nd complex number,
Enter real and imaginary parts, respectively:
– 4.5
– 9.5
sum = -1.1 – 4i

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 62.
Write a C++ Program to declare a structure book containing name and author as character array of 20 elements each and price as integer. Declare an array of book. Accept the name, author, price detail for each book. Define a user defined function to display the book details and calculate the total price. Return total price to the calling function.
Answer:
#inciude<iostream>
using namespace std;
struct Book
{
char bookname [20];
char author[20];
float price;
}b[3] ;
void displaydata(Book);
int main( )
{
for (int i=1; i<-3; i++)
(
cout<<“Enter Book Name :”;
cin>>b [ i ] .bookname;
Gout<<“Enter Author Name :”;
cin>>b[i] .author;
cout<<“Enter Price :”;
cin>>b [i] .price;
}
displaydata (b.[3] ) ;
return 0;
}
void displaydata(Book)
float total=0.0;
cout<<“Displaying Book Details”<<endl;
cout<<“\nS.No\tBook Name\tAuthor Name\tPrice”<<endl;
for(int i=1;i<=3;i++)
{
cout<<i<<“\t”<<b [i] .bookname<<“\t”<<b [i] . author<<“\t”<<b [i] .
price<<endl;
total+=b[i].price;
}
cout<<“\nThe total price =”<<total<<endl;
}
Output:
Enter Book Name :Programming
Enter Author Name :Dromy
Enter Price :150
Enter Book Name:C++programming
Enter Author Name :BjarneStrouStrup
Enter Price :200
Enter Book Name :JavaProgramming
Enter Author Name :James
Enter Price :220
Displaying Book Details

TN State Board 11th Computer Science Important Questions Chapter 12 Arrays and Structures 9

The Total Price = 550

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 63.
Write a C++ program to declare and accept an array of professors. Display the details of the department=”COMP.SCI” and the name of the professors start with ‘A’. The structure “college” should contain the following members.
prof_id as integer
name and Department as character array
Answer:
#include<iostream>
#include<string.h>
using namespace std;
struct college
{
int Prof_Id;
char name[20];
char Department[20];
};
int main( )
{
college c [4] ;
for(int i=0; i<=3; i++)
{
cout<<“Enter Record”<i + 1<<endl;
cout<<“Enter Prof_Id”<<endl ;
cin>>c[i] . Prof_Id;
cout<<“Enter Professor Name” <<endl;
cin>>c [i] .name;
cout<<“Enter Department”<<endl ;
cin>>c[i].Department;
}
cout<<“Displaying the information”<<endl;
for(int i=0; i<=3; i++)
{
if(strcmp (c [i] .Department, “COMP.SCI”)==0)&&
(s[i].name[0]==’A’) | | (s[i]. name[0]==’a’)

Question 64.
Write the output of the following C++ program.
#include<iostream>
#include<stdio>
#include <string>
#include<conio>
using namespace std;
struct books
{
char name[20], author[20];
}
a [50];
int main( )
{
cout<<c[i] .Prof_Id<<endl;
cout<<c[i] .name<<endl;
cout<<c[i] . Department<<endl;
}
}
return 0;
}
Answer:
Output:
Enter Record 1
Enter Prof_Id
1001
Enter Name
Aarthi
Enter Department
COMP.SCI
Enter Record 2
Enter Prof_Id
1002
Enter Name
Sangeetha
Enter Department
Physics
Enter Record 3
Enter Prof_Id
1003
Enter Name Kavitha
Enter Department
Chemistry
Enter Record 4
Enter Prof_Id
1004
Enter Name
Saritha
Enter Department
Physics
Displaying the information
1001
Aarthi
COMP.SCI
clrscr( );
cout<<“Details of Book No” <, 1<, “\n”;
cout<,”————-\n”;
cout<< “Book Name :”<<strcpy(a[0].name,”Programming”)<<endl; ’
cout<< “Book Author :”<<strcpy(a[0].author,”Dromy”)<<endl;
cout<< “\nDetails of Book No”<< 2 << “\n”;
cout<< ” ———–\n”;
cout<< “Book Name :”<<strcpy(a[1].name,”C++programming” )<<endl;
cout<< “Book Author :”<<strcpy(a[1].author,”BjarneStroustrup”)<<endl;
cout<<“\n\n”;
cout<< “==================\n”;
cout<< “S.No\t| Book Name\t|author\n”;
cout<, “=================”;
for (Int i = 0; i < 2; i++)
{
cout<<“\n”<< i + 1<< “\t |” << a[i].riame << “\t |”<< a[i].author;
}
cout<< “\n=======-========”;
return 0;
}
Output:
DETAILS OF BOOK NO 1
Book Name : Programming
Book Author : Dromy

DETAILS OF BOOK NO 2
Book Name : C++ Programming
Book Author : BjarneStroustrup
=======================
S.No | Book Name | author
=======================
1 | Programming | Dromy
2 | C++ Programming | BjarneStroustrup

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 65.
Write the output of the following C++ program.
#include <iostream>
#include <string>
using namespace std; ,
struct student
{
int roll_no;
char name[10];
long phone_number;
};
int main( ){
student p1 = {1,”Brown”, 123443};
student p2, p3;
p2.roll_no = 2;
strcpy(p2.name ,”Sam”);
p2.phone_number = 1234567822;
p3.roll_no = 3; ,
strcpy(p3.name,”Addy”);
p3.phone_number = 1234567844;
eout<< “First Student” <<endl;
cout,<< “roll no :”<< p1.roll_no <<endl;
cout<< “name :”<< pi.name <<endl;
cout<< “phone no :”<< p1.phone_number <<endl;
cout<< “Second Student”<<endl;
cout<< “roll no :”<< p2.roll_no <<endl;
cout<< “name :”<< p2.name <<endl;
cout<< “phone no :”<< p2.phone_number <<endl;
cout<< “Third Student”<<endl;
cout<< “roll no :”<< p3.ro|l_no <<endl;
cout<, “name :”<< p3.name <<endl;
cout<<“phone no;”<< p3.phone_number <<endl;
return 0;
}
Output:
First Student
roll no : 1
name : Brown
phone no : 123443
Second Student
roll no : 2
name : Sam
phone no : 1234567822
Third Student roll no : 3
name : Addy .
phone no : 1234567844

Question 66.
Debug the error in the following program,
#include <is.vream.h>
structPersonRec
{
charlastName[10];
chaefirstName[10];
intage;
}
Person RecPeopleArrayType[10];
voidLoadArray(PeopleRecpeop);
void main( )
{
PersonRecord people;
for (i = 0; i < 10; i++)
{
cout<<people.firstName<<” <<people. lastName
<<setw(10) <<people.age;
}
}
LoadArray(PersonRecpeop)
{
for (int i = 0; i < 10; i++)
{
cout<< “Enter first name:”;
cin<<peop[i].firstName;
cout<< “Enter last name:”;
cin>>peop[i].lastName;
cout<< “Enter age:”;
cin>> people[i].age;}
#include<iostream>
#include<iomanip.h>
using namespace std;
struct_PersonRec
{
char lastName[10];
char firstName [10];
int age;
};
PersonRec PeopleArrayType[10];
void LoadArray(PeopleArrayTypepeop);
int main( )
{
PeopleArrayType people;
for (int i=0;i<10;i++)
{
cout<<people [ i ] .firstName<<‘ ‘<<people(i].lastName <<setw (10) <<people[ i ] . age;
}
}
void LoadArray(PeopleArrayType peop)
{
for (int i=0;i<10;i++)
{
cout<<“Enter first name:”;
cin>>peop[i] .firstName;
cout<<“Enter last name:”;
cin>>peop [i] . lastName;
cout<<“Enter age:”;
cin>>peop[i] .age;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Choose the correct answer:

Question 1.
________ is a collection of variables of the same type that are referenced by a common name.
(a) Structure
(b) Array
(c) Function
(d) Class
Answer:
(b) Array

Question 2.
There are ______ types of arrays used in C++.
(a) three
(b) four
(c) five
(d) six
Answer:
(a) three

Question 3.
Displaying all the elements in an array is an example of:
(a) walk through
(b) traversal
(c) accessing
(d) statements
Answer:
(b) traversal

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 4.
Which of the following correctly declares an array?
(a) int num[5];
(b) int num
(c) num{10};
(d) num num[10];
Answer:
(a) int num[5];

Question 5.
What is the index number of the last element of an with 6 elements?
(a) 6
(b) 5
(c) 0
(d) 1
Answer:
(b) 5

Question 6.
Which of the following gives the memory address of the first element in array?
(a) num[0];
(b) num[l];
(c) num(O);
(d) num( 1);
Answer:
(a) num[0];

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 7.
Which of the following access the seventh element stored in array?
(a) num(7);
(b) num(6);
(c) num[7];
(d) num[6];
Answer:
(d) num[6];

Question 8.
________ is a process of finding a particular value present in a given set of numbers.
(a) Finding
(b) Searching
(c) Traversing
(d) Walkthrough
Answer:
(b) Searching

Question 9.
____ function receives array, size and value to be searched as parameters.
(a) find( )
(b) replace( )
(c) searching( )
(d) search( )
Answer:
(d) search( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 10.
If the searched items are not found it returns:
(a) 0
(b) 1
(c) array index
(d) -1
Answer:
(d) -1

Question 11.
_____ is defined as a sequence of characters.
(a) Characters
(b) Numbers
(c) Arrays
(d) String
Answer:
(d) String

Question 12.
char country[6];
In this array reserves _________ bytes of memory.
(a) 5
(b) 6
(c) 0
(d) none
Answer:
(b) 6

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 13.
In the initialization of the string, if all the characters are not initialized, then the rest of the characters will be filled with:
(a) Zero
(b) Empty
(c) 1
(d) Null
Answer:
(d) Null

Question 14.
________ is used to read a line of text including blank spaces.
(a) cin.get( )
(b) gets( )
(c) read( )
(d) read line( )
Answer:
(a) cin.get( )

Question 15.
In C++, __________ is also used to read a line of text from the input stream.
(a) getsline( )
(b) readline( )
(c) putline( )
(d) getline( )
Answer:
(d) getline( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 16.
________ arrays are collection of similar elements where the elements are stored in certain number of rows and columns.
(a) Single-dimensional
(b) Two-dimensional
(c) Structures
(d) Functions
Answer:
(b) Two-dimensional

Question 17.
Identify the invalid:
(a) int A[3][4];
(b) float x[2][3];
(c) char name[5][20];
(d) int A(3)(4);
Answer:
(d) int A(3)(4);

Question 18.
An array of _______is a two-dimensional character array.
(a) character
(b) strings
(c) number
(d) symbols
Answer:
(b) strings

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 19.
int a[3][2] declares:
(a) 3 rows and 3 columns
(b) 2 rows and 3 columns
(c) 2 columns and 3 rows
(d) 3 rows and 2 columns
Answer:
(d) 3 rows and 2 columns

Question 20.
Determine the number of elements in the following declaration int array[10][12];
(a) 10
(b) 12
(c) 120
(d) 100
Answer:
(c) 120

Question 21.
Structure is declared using the keyword:
(a) str
(b) structure
(c) struct
(d) std
Answer:
(c) struct

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 22.
Objects declared along with structure definition are called _______ objects.
(a) global
(b) local
(c) class
(d) function
Answer:
(a) global

Question 23.
By default all members are ________ in a structure.
(a) private
(b) protected
(c) public
(d) static
Answer:
(c) public

Question 24.
A structure without a name/tag is called ________
(a) anonymous
(c) infinite
(b) finite
(d) empty
Answer:
(a) anonymous

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 25.
The structure declared within another structure is ealled a _______ structure.
(a) looping
(b) nested
(c) iterative
(d) selection
Answer:
(b) nested

Question 26.
Nested structures act as _________ of another structure.
(a) objects
(b) variables
(c) members
(d) classes
Answer:
(c) members

Question 27.
If the structure itself is an argument, then it is called:
(a) call by method
(b) call by value
(c) call by reference
(d) call by obj ect
Answer:
(b) call by value

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 28.
While declaring and initializing values in an array the values should be given within the:
(a) {}
(b) <>
(c) ( )
(d) [ ]
Answer:
(a) {}

Question 29.
By default all members ar ______ in a structure.
(a) public
(b) private
(c) protected
(d) struct
Answer:
(a) public

Question 30.
The array subscripts always commences from:
(a) 1
(b) 0
(c) -1
(d)10
Answer:
(b) 0

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 31.
The second index of the 2D-array refers to:
(a) column
(b) row
(c) length
(d) size
Answer:
(a) column

Question 32.
The header file for setw( ):
(a) iostream
(b) iomanip
(c) stdio
(d) conio
Answer:
(b) iomanip

Question 33.
________ is used between the object name and the member name.
(a) .
(b) ;
(c) :
(d) ,
Answer:
(a) .

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 34.
Matrices can be represented through:
(a) single dimensional array
(b) 2-D array
(c) 3-D array
(d) 4-D array
Answer:
(b) 2-D array

Question 35.
In C++, array subscripts is enclosed within ______ symbol.
(a) [ ]
(b) { }
(c) ( )
(d) < >
Answer:
(a) [ ]

Question 36.
The appropriate declaration statement to initialize the variable ‘name’ with the value ‘computer’ is:
(a) char name = “computer”
(b) char[ ] name = “computer”;
(c) char name[ ] – computer;
(d) char name[ ] – “computer”;
Answer:
(d) char name[ ] – “computer”;

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 37.
Which of the following is an invalid array declaration?
(a) int array[100];
(b) int array[ ];
(c) int array[i]
(d) const int i – 10; int array[i];
Answer:
(b) int array[ ];

Question 38.
How many elements are stored in an array int num[4][2]?
(a) 2
(b) 4
(c) 6
(d) 8
Answer:
(d) 8

Question 39.
Which function returns 0, if the strings are equal?
(a) strcmp( )
(b) strcpy( )
(c) strlen( )
(d) strcat( )
Answer:
(a) strcmp( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 40.
Which of the following is called as literals?
(a) String
(b) Float
(c) Int
(d) Char
Answer:
(a) String

Question 41.
Match the following:

(i) Variable  (a) Sequence of characters
(ii) Array  (b) Read a line of text
(iii) String  (c) Basic building blocks in C++
(iv) Getline( )  (d) Collection of variables of the same type

(a) (i) – (d); (ii) – (a); (iii) – (c); (iv) – (b)
(b) (i) – (a); (ii) – (c); (iii) – (b); (iv) – (d)
(c) (i) – (d); (ii) – (a); (iii) – (b); (iv) – (c)
(d) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)
Answer:
(d) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)

Question 42.
Identify the correct statement:
(a) Array size must be unsigned integer value which is greater than 0.
(b) In arrays, column size is optional but row size is compulsory.
(c) An array of strings is a two-dimensional character array.
(d) Displaying all the elements is an array is an example of‘‘traversal”
Answer:
(b) In arrays, column size is optional but row size is compulsory.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 43.
Identify the correct statement:
(a) If the structure itself is an argument it is called “call by reference”
(b) If the structure is passed as an argument then it is called “call by value”
(c) Structure assignment is possible only if both structure variables / objects are same type
(d) Structure is declared using the keyword “array”
Answer:
(c) Structure assignment is possible only if both structure variables / objects are same type

Question 44.
Assertion (A):
An array is a collection of variables of the same type that are referenced by a common name.
Reason (R):
In an array the values are stored in a fixed number of elements of the same type sequentially in memory.
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(a) Both A and R are true and R is the correct explanation for A.

Question 45.
Which of the following is the collection of variables of the same type that are referenced by a common name?
(a) int
(b) float
(c) Array
(d) class
Answer:
(c) Array

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 46.
Array subscripts is always starts with which number?
(a) -1
(b) 0
(c) 2
(d) 3
Answer:
(b) 0

Question 47.
int age[ ] = {6,90,20,18,2}; How many elements are there in this array? ‘
(a) 2
(b) 5
(c) -6
(d) 4
Answer:
(b) 5

Question 48.
cin>>n[3]; To which element does this statement accepts the value?
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(c) 4

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 49.
By default, the string end with which character?
(a) \o
(b) \t
(c)\n
(d) \b
Answer:
(a) \o

Question 50.
The data elements in the structure are also known as:
(a) objects
(b) members
(c) data
(d) records
Answer:
(b) members

Question 51.
Structure definition is terminated by:
(a) :
(b) }
(c) ;
(d) ::
Answer:
(c) ;

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 52.
What will happen when the structure is declared?
(a) it will not allocate any memory
(b) it will allocate file memory
(c) it will be declared and initialized
(d) it will be only declared
Answer:
(a) it will not allocate any memory

Question 53.
What is the output of this program?
#include<iostream>
#include<string.h>
using namespace std;
int main ( )
{
struct student
{
int n;
char name[10];
};
student s;
s.n – 123;
strcpy(s.name,”Balu”);
cout<<s.n;
cout<<s. name«endl;
return 0;
}
(a) 123Balu
(b) BaluBalu
(c) Balu 123
(d) 123 Balu
Answer:
(a) 123Balu

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 54.
A structure declaration is given below,
struct Time
{
int hours; int minutes;
int seconds;
} t;
Using declaration which of the following refers to seconds.
(a) Time. seconds
(b) Time:: seconds
(c) seconds
(d) t. seconds
Answer:
(d) t. seconds

Question 55.
What will be the output of this program?
#include<iostream>
using namespace std;
struct ShoeType
{
string name;
double price;
};
int main ( )
{
ShoeType shoel,shoe2;
shoe1.name =? “Adidas”;
shoel.price = 9.99;
cout<<shoel. name<<“#”<<shoe1.price<<end1;
shoe2 = shoe1;
shoe2.price = shoe2.price/9;
cout<<shoe2. name<<“#”<<shoe2.price;
return 0;
(a) Adidas #9.99 Adidas #1.11
(b) Adidas # 9.99 Adidas #9.11
(c) Adidas # 9.99 Adidas #11.11
(d) Adidas #9.11 Adidas #11.11
Answer:
(a) Adidas #9.99 Adidas #1.11

Question 56.
Which of the following is a properly defined structure?
(a) struct {intnum;}
(b) struct sum {int num;}
(c) struct sum int sum;
(d) struct sum {int num;};
Answer:
(d) struct sum {int num;};

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 57.
A structure declaration is given below.
struct employee
{
int empno;
char ename[10];
}e [5] ;
Using above declaration which of the following statement is correct.
(a) cout<<e[0].empno<<e[0].ename;
(b) cout<<e[0].empno<<ename;
(c) cout<<e[0]→empno<<e[0]->ename;
(d) cout<<e.empno<<e.ename;
Answer:
(a) cout<<e[0].empno<<e[0].ename;

Question 58.
Which of the following cannot be a structure member?
(a) Another structure
(b) Function
(c) Array
(d) Variable of double data type
Answer:
(b) Function

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 12 Arrays and Structures

Question 59.
When accessing a structure member, the identifier to the left of the dot operator is the name of:
(a) structure variable
(b) structure tag
(c) structure member
(d) structure function
Answer:
(a) structure variable

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 11 Functions

TN State Board 11th Computer Science Important Questions Chapter 11 Functions

Question 1.
Write the types of functions in C++.
Answer:
Functions can be classified into two types,

  1. Pre-defined or Built-in or Library Functions.
  2. User-defined Function.

Question 2.
What is getchar( ) and putchar ( ) function.
Answer:
The predefined function getchar( ) is used to get a single character from keyboard and putchar() function is used to display it.

Question 3.
Differentiate between getchar( ) and gets( ) function.
Answer:

getchar( )

 gets( )

It is used to get single Character from keyboard.  It reads a string from standard input and stores it into the string pointed by the variable.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 4.
What is puts( ) function?
Answer:
puts( ) function prints the string read by gets( ) function in a newline.

Question 5.
Name the character functions in C++.
Answer:

  1. isalnum( )
  2. isalpha( )
  3. isdigit( )
  4. islower( )
  5. isupper( )
  6. toupper( )
  7. tolower( )

Question 6.
Write the syntax for toupper( ) and its uses.
Answer:
toupper( ) is used to convert the given character into its uppercase.
It will return the upper case equivalent of the given character. If the given character itself is in upper case, the output will be the same.
Syntax:
char toupper(char c);
The following statement will assign the character constant ‘K’ to the variable c.
char c = toupper(‘k’);
But, the output of the statement given below will be‘B’itself.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 7.
How will you define a function? Write the syntax.
Answer:
A function must be defined before it is used anywhere in the program. The general syntax of a function definition is:
Return_Data_Type Function_ name(parameter list)
{
Body of the function
}

Question 8.
What do you mean by void data type? Give example.
Answer:
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.
Eg:
void fun(void)
> The above function prototype tells compiler that the function fun( ) neither receives values from calling program nor return a value to the calling program.

Question 9.
Write the methods of calling function.
Answer:
In C++, the arguments can be passed to a function in two ways. The function calling methods can be classified based on the method of passing arguments as based on the method of passing the arguments. The function calling methods can be classified as

  1. Call by Value method,
  2. Call by Reference or Address method.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 10.
What are the advantages of inline functions.
Answer:
The advantages of inline functions:

  1. Inline functions execute faster but requires more memory space.
  2. Reduce the complexity of using STACKS.

Question 11.
Write the return type for the following function prototype.
Answer:

Function Prototype

 Return type

int sum(int, float)  int
float area(float, float)  float
char result( )  char
double factfint( )  double

Question 12.
What is recursion?
Answer:
A function that calls itself is known as recursive function. This technique is known as recursion.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 13.
Write the types of scopes in C++.
Answer:
Scope refers to the accessibility of a variable. There are four types of scopes in C++. They are: Local scope, Function scope, File scope and Class scope.

Question 14.
How will you reveal the hidden scope of a variable?
Answer:
The scope operator reveals the hidden scope of a variable. The scope resolution operator (::) is used to access a Global variable when there is a Local variable with same name.

Question 15.
Give the reason to need for functions in C++.
Answer:
To reduce size and complexity of the program functions are used. The programmers can make use of sub programs either writing their own functions or calling them from standard library.
Divide and Conquer

  1. Complicated programs can be. divided into manageable sub programs called functions.
  2. A programmer can focus on developing, debugging and testing individual functions.
  3. Many programmers can work on different functions simultaneously.

Reusability:

  1. Few lines of code may be repeatedly used in different contexts. Duplicationof the same code can be eliminated by using functions which improves the maintenance and reduce program size.
  2. Some functions can be called multiple times with different inputs.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 16.
Write the standard input/output function in C++.
Answer:
The header file stido.h defines the standard I/O predefined functions getchar( ), putchar( ), gets( ), puts( ) and etc.,
The predefined function getchar( ) is used to get a single character from keyboard and putchar( ) function is used to display it.
C++ code to accept a character and displays it:
#include
#include
using namespace std;
int main( )
{
cout<<“\n Type a Character :”;
char ch = getchar();
cout<<“\n The entered Character is:”;
putchar(ch);
return 0;
}
Output:
Type a Character : T
The entered Character is: T
gets( ) function reads a string from standard input and stores it into the string pointed by the variable. puts() function prints the string read by gets() function in a newline.
C++ code to accepts and display a string:
#include
#include
using namespace std; .
int main( )
{
char str[50];
cout<<“Enter a string :”;
gets(str);
cout<<“You entered:”
puts(str);
return (0) ;
}
Output:
Enter a string : Computer Science
You entered: Computer Science

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 17.
What is the use of sqrt( ) function?
Answer:
The sqrt( ) function returns the square root of the given value of the argument. It takes a single non-negative argument. If a, negative value is passed as an argument to sqrt( ) function, a domain error occurs.
.#include
#include using namespace std;
int main( )
{ .
double x = 625, result;
result = sqrt(x);
cout<<“sqrt (“<<x<<“) =”<<result;
return 0;
}
Output:
sqrt(625) = 25

Question 18.
Write short notes on constant Arguments.
Answer:
The constant variable can be declared using const keyword. The const keyword makes variable value stable. The constant variable should be initialized while declaring. The const modifier enables to assign an initial value to a variable that cannot be changed later inside the body of the function.
Syntax:

(const )
Eg:
(i) int minimumfconst int a=10);
(ii) float area(const float pi=3.14, int r=5);

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 19.
Write short note on inline functions.
Answer:
An inline function looks like normal function in the source file but inserts the function’s code directly into the calling program. To make a function inline, kgyword inline is inserted in the function header.
Syntax:
inline returntype
functionname(datatype parameternamel, … datatype parameternameN)

Advantages of inline functions:
(i) Inline functions execute faster but requires more memory space.
(ii) Reduce the complexity of using STACKS.

Question 20.
What is return statement? Write the syntax. Give example.
Answer:
The return statement is used to return from a function. It is categorized as a jump statement because it terminates the execution of the function and transfer the control to the called statement. A return may or may not have a value associated with it. If return has a value associated with it, that value becomes the return value for the calling statement. Even for void function return statement without parameter can be used to terminate the function.
Syntax:
return expression/variable;
Example:
return (a+b);
return(a);
return; // to terminate the function

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 21.
Write a program to find the factorial of a Number using Recursion.
Answer:
#include
using namespace std;
int factorial(int); // Function prototype //
int main( )
{
int no;
cout<<“\nEnter a number to find its factorial:”; cin>>no;
cout<<“\nFactorial of Number” <<no<<“=”< 1)
{
return m*factorial(m-1);
}
else
{
return 1;
}
}
Output:
Enter a number to find its factorial: 5
Factorial of Number 5 = 120

Question 22.
Explain the different types of character function in C++.
Answer:
The header file defines various operations on characters. Following are the various character functions available in C++. The header file ctype.h is to be included to use these functions in a program.
isalnum( )
It is used to check whether a character is alphanumeric or not. This function returns non-zero value if c is a digit or a letter, else it returns 0.
Syntax:
int isalnum (char c)
Eg:
int r = isalnum(‘5’);
cout< But the statements given below assign 0 to the variable n, since the given character is neither an alphabet nor a digit,
char c = ‘$’
int n = isalnum (c);
cout<<c; .
Output:
0
isalpha( )
The isalpha( ) function is used to check whether the given character is an alphabet or not.
Syntax:
int isalpha(char c);
It will return 1 if the given character is an alphabet, and 0 otherwise 0. The following statement assigns 0 to the variable n, since the given character is not an alphabet,
int n = isalpha(‘3’);
The statement given below displays 1, since the given character is an alphabet.
cout< isdigit( )
It is used to check whether a given character is a digit or not. This function will return 1 if the given character is a digit, and 0 otherwise.

Syntax:
int isdigit(char c);
When the following program is executed, the value of the variable n will be 1,since the given character is not a digit.
islower( )
It is used to check whether a character is in lower case (small letter) or not. This functions will return a non-zero value, if the given character is a lower case alphabet and 0 otherwise.
Syntax:
int islower(char c);
After executing the following statements, the value of the variable n will be 1 since the given character is in lower case.
char ch = ‘n’ ;
int n = islower(ch);
The statement given below will assign 0 to the variable n, since the given character is an uppercase alphabet.
int n = islower(‘P’);
isupper( )
It is used to check the given character is uppercase. This function will return 1 if true otherwise 0. For the following examples value 1 will be assigned to n and 0 for m.
int n=isupper(‘A’);
int m=isupper(‘a’);
toupper( )
It is used to convert the given character into its uppercase. This function will return the upper case equivalent of the given character. If the given character itself is in upper case, the output will be the same.

Syntax:
char toupper(char c) ;
The following statement will assign the character constant ‘K’ to the variable c.
char c = toupper(‘k’);
The output of the statement given below will be ‘B’ itself.
cout< tolower( )
It is used to convert the given character into its lowercase. This function will return the lower case equivalent of the given character. If the given character itself is in lower case, the output will be the same.

Syntax:
char tolower(char c);
The following statement will assign the character constant ‘k’ to the variable c.
char c = tolower(‘K’);
The output of the statement given below will be ‘b’ itself. ,
cout<

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 23.
Explain the various string manipulation in C++.
Answer:
The library string.h (also referred as cstring) has several common functions for dealing with strings stored in arrays of characters. The string.h header file is t& be included before using any string function.
strcpy( )
The strcpy( ) function takes two arguments: target and source. It copies the character string pointed by the source to the memory location pointed by the target. The null terminating character (\0) is also copied.

strlen( )
The strlen( ) takes a null terminated byte string source as its argument and returns its length. The length does not include the null(\0) character.

strcmp( )
The strcmp( ) function takes two arguments: string 1 and string2. It compares the contents of string 1 and string2 lexicographically.

The strcmp( ) function returns a:
(i) Positive value if the first differing character in string 1 is greater than the corresponding character in string2. (ASCII values are compared)
(ii) Negative value if the first differing character in string 1 is less than the corresponding character in string2.
(iii) 0 if string 1 and string2 are equal.

strcat( )
The strcat( ) function takes two arguments: target and source. This function appends copy of the character string pointed by the source to the end of string pointed by the target.

strupr ()
The strupr( ) function is used to convert the given string into Uppercase letters.

strlwr( )
The strlwr( ) function is used to convert the given string into Lowercase letters.

Question 24.
Explain the basic mathematical functions in C++.
Answer:
The mathematical functions are defined in math.h header file which includes basic mathematical functions.

cos( ) function
The cos( ) function takes a single argument in radians. The cos() function returns the value in the range of [- 1,1]. The returned value is either in double, float or long double.

sqrt( ) function
The sqrt( ) function returns the square root of the given value of the argument. The sqrt( ) function takes a single non-negative argument. If a negative value is passed as an argument to sqrt( ) function, a domain error occurs.

sin( ) function
The sin( ) function takes a single argument in radians. The sin( ) function returns the value in the range of [-1, 1]. The returned value is either in double, float or long double.

pow( ) function
The pow( ) function returns base raised to the power of exponent. If any argument passed to pow( ) is long double, the return type is promoted to long double. If not, the return type is double. The pow( ) function takes two arguments:
(i) base – the base value
(ii) exponent – exponent of the base.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 25.
Explain call by reference or address method with example.
Answer:
Call by reference, copies the address of the actual argument into the formal parameter. Since the address of the argument is passed, any change made in the formal parameter will be reflected back in the actual parameter.
#include
using namespace std;
void display(int &x) //passing address of a//
{
x=x*x;
cout<<“\n\nThe Value inside display function (n1 x n1)
: “< }
int main( )
{
int n1;
cout<<“\nEnter the Value for N1:”; cin>>n1;
cout<<“\nThe Value of N1 is inside main function Before passing:”<<n1; .
display(n1);
cout<<“\nThe Value of N1 is inside main function After passing (n1 × n1) :”<< n1;
return(0);
}
Output:
Enter the Value for N1 :45
The Value of N1 is inside main function Before passing : 45
The Value inside display function (n1 × n1) : 2025
The Value of N1 is inside main function After passing (n1 × n1) : 2025

Question 26.
Explain the different forms of user-defined function declaration with example.
Answer:
A Function without return value and without parameter:

The following program is an example for a function with no return and no arguments
passed.

The name of the function is display( ), its return data type is void and it does not have any argument.
#include
using namespace std;,
void display( )
{
cout<<“First C++ Program with
Function”;
}
int main( )
{
display( ); // Function calling statement//
return (0);
Output:
First C++ Program with Function
A Function with return value and without parameter:
The name of the function is display( ), its return type is int and it does not have any argument. The return statement returns a value to the calling function and transfers the program control back to the calling statement.
#include
using namespace std;
int display( )
{
int a,b,s;
cout<<“Enter 2 numbers:”; cin>>a>>b;
s=a+b;
return s;
}
int main ( )
{
int m=display( );
cout<<“\nThe Sum=”<<m; return(0);
}
Output:
Enter 2 numbers: 10 30
The Sum=40.
A Function without return value and with parameter:
The name of the function is display( ), its return type is void and it has two parameters or arguments x and y to receive two values.
The return statement returns the control back to the calling statement.
#include
using namespace std;
void display(int x,int y)
{
int s=x+y;
cout<<“The Sum of Passed Values:”<<s;
}
int main( )
{
int a,b;
cout<<“\nEnter the First Number:”; cin>>a;
cout<<“\nEnter the Second Number:”; cin>>b;
display(a,b);
return (0);
}
Output:
Enter the First Number :50
Enter the Second Number :45
The Sum of Passed Values: 95
A Function with return value and with parameter:
The name of the function is display( ), its return type is int and it has two parameters or arguments x and y to receive two values. The return statement returns the control back to the calling statement.
#include
using namespace std;
int display(int x, int y)
{
int s=x+y;
return s;
}
int main( )
{
int a,b;
cout<<“\nEnter the First Number:”; cin>>a;
cout<<“\nEnter the Second Number:”; cin>>b;
int s=display(a,b);
cout<<“\nExample: Function with
Return Value and with Arguments”;
cout<<“\nThe Sum of Passed Values :”<<s;
return (0);
}
Output:
Enter the First Number :45
Enter the Second Number :67
Example: Function with Return Value and with Arguments
The Sum of Passed Values: 112

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Write C++ program to solve the following problems:

Question 27.
Program that reads two strings and appends the first string to the second.
Answer:
For example, if the first string is entered as Tamil and second string as nadu, the program should print Tamilnadu. Use string library header.
#include
#include
using namespace std;
int main ( )
{
char stringl[50]= “Tamil”;
char string2[50]= “nadu”;
strcat(stringl, string2);
cout<<stringl;
return 0;
}
Output:
Tamilnadu

Question 28.
Program that reads a string and converts it to uppercase. Include required header files.
Answer:
#include
#include
#include
using namespace; std;
int main( )
{
char str1[50];
cout<<“\nType any string in lower case:”;
gets(strl);
cout<<“\n Converted the Source string”<<str1< return 0;
}
Output:
Type any string in lower case : computer science
Converted the Source string Computer science into upper Case is COMPUTER SCIENCE

Question 29.
Program that checks whether a given character is an alphabet or not. If it is an alphabet, whether it is lowercase character or uppercase character? Include required, header files.
Answer:
#include
#include
using namespace std;
int main( )
{
char c;
cout<<“Enter a character”; cin>>n;
if((c>=’a’&&c<=’z’)\\ (c>=”A”&&c<=’z’))
{
if(isupper (c) )
cout<<“The given character is in uppercase”;
else
cout<<“The given character is in lowercase”;
}
else
{
eout<<“The given character is
}
return 0;.
}
Output:
Enter a character: B
The given character is in uppercase.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 30.
Program that checks whether the given character is alphanumeric or a digit. Add appropriate header file.
Answer:
#include
#include
#include
using namespace std;
int main( )
{
char ch;
int r;
cout<<“\n Type a Character:”;
ch = getchar( );
r = isalnum(ch);
cout<<“\nThe Return Value of isalnum(ch) is :”<<r;
}
Output-1:
Type a Character :A
The Return Value of isalnum(ch) is :1
Output-2:
Type a Character 😕
The Return Value of isalnum(ch) is : 0

Question 31.
Write a function called zero_small ( ) that has two integer arguments being passed by reference and sets smaller of the two numbers to 0. Write the main program to access this function.
Answer:
#include
using namespace std;
void zero-small(int &, int&)
int main( )
{
int x,y;
cout<<“Enter first number:”; cin>>x;
cout<<“Enter second number:”; cin>>y;
zero-small(x, y);
cout<<“first number is:”<<x;
cout<<”\n second number is:”<<y;
return 0;
}
void zero-small(int&a, int&b)
if(a<b)
a=0;
else
b=0;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 32.
Write definition for a function sumseries ( ) in C++ with two arguments/ parameters – double x and int n. The function should return a value of type double and it should perform sum of the following series:
x-x2 /3! + x3 / 5! – x4 / 7! + x5 / 9! -… upto n terms.
Answer:
#include
#include
#include using namespace std;
double sumseries(int xl, int nl);
int main( )
(
int x;
int n;
cout<<“Enter the value of X and N”; , cin>>x>>n.;
cout<<“\nThe sum of the series = ” < return 0;
}
double sumseries(int x1, int n1)
{
double sum=0;
int c=0
for(int i=1; i<=(2*n1); i=i+2)
{
int f=1;
for(int j=1; j<=i; j++)
{
f=f*j;
}
c=c+1;
if (c%2==1)
{
sum=sum+pow(x1,c)/f;
}
else
{
sum=sum-pow(x1, c) / f
}
}
return sum;
}

Question 33.
Program that invokes a function calc ( ) which intakes two intergers and an arithmetic operator and prints the corresponding result.
Answer:
#include
using namespace std;
int calc(int a,int b);
int main( )
{
int n1, n2, sum;
cout<<“Enter first number:”; cin>>n1;
cout<<“Enter second number:”; cin>>n2;
sum=calc(n1,n2);
cout<<“The sum of two numbers is:”<<sum<<endl;
return 0;
}
int calc (int a, int b)
{
return (a+b);
}
Output:
Enter first number: 10
Enter second number: 20
The sum of two numbers is: 30

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 34.
Define Functions.
Answer:
(i) A large program can typically be split into small sub-programs (blocks) called as functions where each sub-program can perform some specific functionality.
(ii) Functions reduce the size and complexity of a program, makes it easier to understand, test and check for errors.

Question 35.
Write about strlen( ) function.
Answer:

  1. The strlen( ) takes a null terminated byte string source as its argument and returns its length
  2. The length does not include the null(\0) character.

Question 36.
What are the importance of void data type?
Answer:
Void type has two important purposes

  1. To indicate the function dues not ret s„
  2. To declare a generic pointer.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 37.
What is Parameter and list its types?
Answer:
Arguments or parameters are the means to pass values from the calling function to the called function.

  1. The variables used in the function definition as parameters are known as formal parameters.
  2. The constants, variables or expressions used in the function call are known as actual parameters.

Question 38.
Write a note on Local Scope.
Answer:

  1. A local variable is defined within a block. A block of code begins and ends with curly braces { }.
  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 local variable is created upon entry into its block and destroyed upon exit

Question 39.
What is Built-in functions ?
Answer:
C++ provides a rich collection of functions ready to be used for various tasks. The tasks to be performed by each of these are already written, debugged and compiled. Their definitions alone are grouped and stored in files called header files. Such ready-to- use sub programs are called pre-defined functions or built-in functions.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 40.
What is the difference between isupper( ) and toupper( ) functions?
Answer:

isupper( )

 toupper( )

It is used to check the given character is uppercase.  It is used to convert the given character into its uppercase.
It will return 1 if true otherwise 0.  It will return the Uppercase equivalent of the given character.
Eg: int n=isupper(‘A’); The value 1 will be assigned to n  Eg: char c=toupper (‘k’). The character constant ‘k’ is assigned to the variable c.

Question 41.
Write about strcmp( ) function.
Answer:
The strcmp( ) function takes two arguments: string 1 and string2. It compares the contents of string 1 and string2.
The strcmp( ) function returns:
(i) Positive value if the first differing character in string 1 is greater than the corresponding character in string2. (ASCII values are compared)
(ii) Negative value if the first differing character in string 1 is less than the corresponding character in string2.
(iii) 0 if string1 and string2 are equal.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 42.
Write short note on pow( ) function in C++.
Answer:
The pow( ) function returns base raised to the power of exponent. If any argument passed to pow( ) is long double, the return type is promoted to long double. If not, the return type is double. The pow( ) function takes two arguments:
(i) base – the base value
(ii) exponent – exponent of the base
Eg:
cout< Output: 16

Question 43.
What are the information the prototype provides to the compiler?
Answer:

TN State Board 11th Computer Science Important Questions Chapter 11 Functions 1

The prototype above provides the following information to the compiler:
(i) The return value of the function is of type long.
(ii) fact is the name of the function.
(iii) The function is called with two arguments:
(a) The first argument is of int data type.
(b) The second argument is of double data type.
Eg:
int display(int , int) // function prototype//

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 44.
What is default arguments ? Give example.
Answer:
In C++, default values can be assigned to the formal parameters of a function prototype. The Default arguments allows to omit some arguments when calling the function.
When calling a function,
(i) For any missing arguments, compiler uses the values in default arguments for the called function.
(ii) The default value is given in the form of variable initialization.
Eg: void default value (int n1=10, n2=100);
(iii) The default arguments facilitate the function call statement with partial or no arguments.
Eg: defaultvalue(x,y);
defaultvalue(200,150);
defaultvalue(150);
defaultvalue(x, 150);
(iv) The default values can be included in the function prototype from right to left, i.e., cannot have a default value for an argument in between the argument list.
Eg: void defaultvalue(int n1=10, n2);
//invalid prototype.
void defaultvalue(int n1, n2 = 10);
//valid prototype.

Question 45.
Explain Call by value method with suitable example.
Answer:
In call by value, the value of an actual parameter is copied into the formal parameter of the function. Changes made to formal parameter within the function will have no effect on the actual parameter.
#include
using namespace std;
void display(int x)
{
int a=x*x;
cout<<“\n\nThe Value inside display function (a*a):”<<a;
}
int main( )
{
int a;
cout<<“\nExample : Function call by value:”;
cout<<“\n\nEnter the Value for A:”; cin>>a; .
display(a);
cout<<“\n\nThe Value inside main function”<<a;
return (0);
}
Output:
Example : Function call by value
Enter the Value for A : 5
The Value inside display function(a*a) : 25
The Value inside main function 5

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 46.
What is Recursion? Write a program to find GCD using recursion.
Answer:
A function that calls itself is known as recursive function. And, this technique is known as recursion.
#include
using namespace std;
int gcd(int x,int y) ;
int main( )
{
int a,b;
cout<<“Enter two numbers:”; cin>>a>>b;
cout<<“\n The GCD of “<<a<<“and”<<b<<“is”< return (0);
}
int gcd(int x,int y)
{
int z=x%y;
if(z==0)
return(y);
else :
return (gcd(y,z));
}

Question 47.
What are the different forms of function return? Explain with example.
Answer:
The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point.

The return statement:
It is used to return from a function. It is categorized as a jump statement because it terminates the execution of the function and transfers the control to the called statement. A return may or may not have a value associated with it.

Syntax:
return expression/variable;
Example : return(a+b); return( (a);
return; // to terminate the function

The Returning values:
The functions that return no value is declared as void. The data type of a function is treated as int, if no data type is explicitly mentioned.
Eg:
int add (int,int);
add (int,int);
In both prototypes, the return value is int, because by default the return value of a function in C++ is of type int.

Function Prototype

 Return type

int sum(int, float)  int
float area(float, float)  float
char result( )  char
double fact(int n)  double

Returning Non-integer values:A string can also be returned to a calling statement.

#include
#include
using namespace std;
char *display( )
{
return(“chennai”);
}
int main ( )
{
char s[50];
strcpy(s,display ( )) ;
cout<<“\nExample:Function with Non Integer Return”<<s;
return (0);
}
Output :
Example: Function with Non Integer Return Chennai
The Returning by reference:
#include
using namespace std;
int main( )
{
int n1=150;
int &n1ref=n1;
cout<<“\n The Value of N1 = ” <<nl<<” and nlReference =” <<nlref;
n1ref++;
co.ut<<“\nAfter. nl increased the Value of N1= “<<n1;
cout<<“and n1Reference =” <<nlref;
return (0);
}
Output:
The Value of N1 = 150 and n1Reference = 150
After n1 increased the Value of N1 = 151 and n1Reference = 151

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 48.
Explain scope of variable with example. Scope refers to the accessibility of a variable.
Answer:
Local scope, Function scope, File scope and Class scope are the four types of scopes in C++.

Local Scope:
(i) A local variable is defined within a block. A block of code begins and ends with curly braces { }.
(ii) The scope of a local variable is the block in which it is defined.
(iii) A local variable cannot be accessed from outside the block of its declaration.
(iv) A local variable is created upon entry into its block and destroyed upon exit.

Function Scope:
(i) The scope of variables declared within a function is extended to the function block and all sub-blocks therein.
(ii) The life time of a function scope variable, is the life time of the function block. The scope of formal parameters is function scope.

File Scope:
(i) A variable declared above all blocks and functions (including main ( ) ) has the scope of a file. The life time of a file scope variable is the life time of a program.
(ii) The file scope variable is also called as global variable.

Class Scope:
(i) A class is a new way of creating and implementing a user defined data type. Classes provide a method for packing data of different types together.
(ii) Data members are the data variables that represent the features or properties of a class.

class student

{

private:

intt mark1, mark2, total;

};

The class student contains mark 1, mark 2 and total are data variables. Its scope is within the class student only.

Example
#include
using namespace std;
int i=0; //file scope
void func( )
{
cout<<i; int main ( ) { int flag=1, a=100;//function scope while (flag) { int x=200;//local scope if(a>x)
{
– –
– –
}
else
{
– – –
– – – –
}
}
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 49.
Write a program to accept any integer number and reverse it.
Answer:
#include
using namespace std;
int main ( )
}
long int num, sum;
int digit;
cout<<“Enter an Integer Number:”; cin>>num;
if(num<0)
{
cout<<“Enter a positive Integer “<<endl; return -1; } sum=0; while (num>0)
{
digit = num%10;
sum=(sum*10)+digit;
num=num/10;
}
cout<<“Reverse number is:”<<endl;
return 0;
}
Output:
Enter an Integer Number: 15389
Reverse number is : 98351

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Choose the correct answer:

Question 1.
_________ reduce the size and complexity of a program.
(a) Functions
(b) Pointers
(c) Structures
(d) Objects
Answer:
(a) Functions

Question 2
_______ functions are default functions.
(a) Built-in
(b) User-defined ( )
(c) Add 0
(d) Multiply ( )
Answer:
(a) Built-in

Question 3.
________ functions are created by users.
(a) Void( )
(b) Main( )
(c) String( )
(d) User-defined
Answer:
(d) User-defined

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 4.
Functions can be classified into _______ types.
(a) three
(b) two
(c) five
(d) four
Answer:
(b) two

Question 5.
A header file can be identified by their file extension:
(a) .f
(b) .c
(c) .d
(d) .h
Answer:
(d) .h

Question 6
________ is used to get a single character from keyboard.
(a) putchar( )
(b) put( )
(c) getchar( )
(d) gets( )
Answer:
(c) getchar( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 7.
_______ displays a single character.
(a) putchar( )
(b) gets( )
(c) write( )
(d) writechar( )
Answer:
(a) putchar( )

Question 8.
_______ reads a string from standard input.
(a) input( )
(b) gets( )
(c) getchar( )
(d) getch( )
Answer:
(b) gets( )

Question 9.
_______ function used to print the string.
(a) write( )
(b) puts( )
(c) putin( )
(d) put( )
Answer:
(b) puts( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 10.
_____ defines various operations on characters.
(a) ctype.h
(b) chtype.h
(c) chartype.h
(d) ctype.c
Answer:
(a) ctype.h

Question 11.
What will be the output for the given statement?
char c=’$’;
int n = isalnum (c);
cout<<c;
(a) 1
(b) null
(c) 0
(d) c
Answer:
(c) 0

Question 12.
The function is used to check whether the given character is an alphabet or not.
(a) isalphabet( )
(b) isalnum( )
(c) isalpha( )
(d) isdigit( )
Answer:
(c) isalpha( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 13.
What is the value of n?
int n = isalpha(‘3’)
(a) 1
(b) 3
(c) n
(d) 0
Answer:
(d) 0

Question 14.
What is the value of n?
int n = isalpha(‘a’)
(a) n
(b) a
(c) 1
(d) 0
Answer:
(c) 1

Question 15.
_________ is used to check whether a given character is a digit or not.
(a) isalpha( )
(b) isnum( )
(c) isdigit( )
(d) isalnum( )
Answer:
(c) isdigit( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 16.
______ is used to check whether a given character is in lower case or not.
(a) islower( )
(b) lower( )
(c) loweris( )
(d) tolower( )
Answer:
(a) islower( )

Question 17.
What will be the value of n?
int n = islower(‘P’); ……….
(a) P
(b) p
(c) 1
(d) 0
Answer:
(d) 0

Question 18.
______ is used to check the given character is uppercase.
(a) upper( )
(b) isupper( )
(c) uppercase( )
(d) toupper( )
Answer:
(b) isupper( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 19.
int n=isupper(‘A’);
The value of n is:
(a) A
(b) a
(c) 1
(d) 0
Answer:
(c) 1

Question 20.
int m=isupper (‘a’);
The value of m is:
(a) 0
(b) m
(c) a
(d) 1
Answer:
(a) 0

Question 21.
________ used to convert the given character into its uppercase.
(a) upper( )
(b) lower( )
(c) toupper( )
(d) upppercase( )
Answer:
(c) toupper( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 22.
char c=toupper(‘k’);
The value of c is:
(a) K
(b) k
(c) 0
(d) C
Answer:
(a) K

Question 23.
cout<<toupper(‘B’);
The output of the statement will be:
(a) 0
(b) 1
(c) b
(d) B
Answer:
(d) B

Question 24.
__________ is used to convert the given character into its lowercase.
(a) lower( )
(b) lowercase( )
(c) tolower( )
(d) islower( )
Answer:
(c) tolower( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 25.
char c=tolower(‘K’);
The value of c is:
(a) c
(b) K
(c) k
(d) 1
Answer:
(c) k

Question 26.
cout<<tolower(‘b’); The output of the above statement is:
(a) B
(b) 0
(c) b
(d) 1
Answer:
(c) b

Question 27.
_______ header file to be included before using string function.
(a) strings.h
(b) string.h
(c) source.h
(d) string
Answer:
(b) string.h

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 28.
The strcpy( ) function takes arguments.
(a) one
(b) two
(c) three
(d) four
Answer:
(b) two

Question 29.
______ terminating character is copied in strcpy( ).
(a) ‘\a’
(b) ‘\\’
(c) ‘\b’
(d) ‘\0’
Answer:
(d) ‘\0’

Question 30.
_________ copies the character string pointed by the source to the memory location pointed by the target.
(a) strcpy( )
(b) strlen( )
(c) strcmp( )
(d) stracat( )
Answer:
(a) strcpy( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 31.
________ takes a null terminated byte string source as its argument and return its length.
(a) strlen( )
(b) length( )
(c) strlength( )
(d) stringcmp( )
Answer:
(a) strlen( )

Question 32.
_______ function used to compare two strings.
(a) compare( )
(b) stringcmp( )
(c) strcmp( )
(d) strcat( )
Answer:
(c) strcmp( )

Question 33.
If string 1 is greater than the corresponding character in string2 strcmp function returns ________ value.
(a) 0
(b) null
(c) negative
(d) positive
Answer:
(d) positive

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 34.
If string 1 is less than the corresponding character in string2 strcmp function returns _____ value.
(a) 0
(b) null
(c) negative
(d) positive
Answer:
(c) negative

Question 35.
_________ function appends copy of the character string pointed by the source to the end of string pointed by the target.
(a) strcat( )
(b) strcpy( )
(c) stringcat( )
(d) stringcopy( )
Answer:
(a) strcat( )

Question 36.
________ is used to convert the given string into uppercase letter.
(a) strupr( )
(b) toupper( )
(c) isupper( )
(d) stringupper( )
Answer:
(a) strupr( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 37.
_______ is used to convert the given string into lowercase letters.
(a) lower( )
(b) islower( )
(c) tolower( )
(d) strlower( )
Answer:
(d) strlower( )

Question 38.
Mathematical function includes header file.
(a) maths.h
(b) math.h
(c) math
(d) mathematical.h
Answer:
(b) math.h

Question 39.
The function that returns square root of the given argument is:
(a) sum( )
(b) squareroot( )
(c) square( )
(d) sqrt( )
Answer:
(d) sqrt( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 40.
______ function returns base raised to the power of exponent.
(a) power( )
(b) pow
(c) pow( )
(d) power
Answer:
(c) pow( )

Question 41.
_______ are the means to pass values from the calling function to the called function.
(a) Class
(b) Objects
(c) Functions
(d) Parameters
Answer:
(d) Parameters

Question 42.
The variables used in the function definition as parameters are known as parameters.
(a) actual
(b) informal
(c) default
(d) formal
Answer:
(d) formal

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 43.
The constants, variables or expressions used in the function call are known as ________ parameters.
(a) null
(b) actual
(c) formal
(d) copy
Answer:
(b) actual

Question 44.
The constant variable can be declared using _____ keyword.
(a) constant
(b) const
(c) void
(d) int
Answer:
(b) const

Question 45.
The ______ modifier enables to assign an initial value and cannot be changed later inside the body of the function.
(a) int
(b) signed
(c) unsigned
(d) const
Answer:
(d) const

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 46.
In C++, the arguments can be passed to function in _____ ways.
(a) one
(b) two
(c) three
(d) four
Answer:
(b) two

Question 47.
In _____ changes made to formal parameter will have no effect on the actual parameter.
(a) call by value method
(b) call by reference method
(c) function method
(d) structure method
Answer:
(a) call by value method

Question 48.
In _______ method changes made in the formal parameter will be reflected in the actual parameter.
(a) call by value
(b) call by reference
(c) arrays
(d) structure
Answer:
(b) call by reference

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 49.
______ functions execute faster but requires more memory space.
(a) String
(b) Math
(c) Iostream
(d) Inline
Answer:
(d) Inline

Question 50.
The ________ statement returns the control back to the calling statement.
(a) return
(b) call
(c) continue
(d) break
Answer:
(a) return

Question 51.
A function that calls itself is known as _______ function.
(a) inline
(b) string
(c) void
(d) recursive
Answer:
(d) recursive

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 52.
There are ________ types of scopes in C++.
(a) two
(b) three
(c) four
(d) five
Answer:
(c) four

Question 53.
A variable that is declared inside a block is called ________ variable.
(a) local
(b) global
(c) functions
(d) class
Answer:
(a) local

Question 54.
A variable that is declared inside a class is called ______ variable.
(a) object
(b) function
(c) private
(d) class
Answer:
(d) class

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 55.
A variable that is declared outside all functions called _______ variables.
(a) local
(b) global
(c) private
(d) protected
Answer:
(b) global

Question 56.
A variable declared inside a function is called _______ variables.
(a) private
(b) protected
(c) public
(d) function
Answer:
(d) function

Question 57.
Match the following:

(i) getchar( )  (a) math.h
(ii) strcpy( )  (b) ctype.h
(iii) isalpha( )  (c) stdio.h
(iv) sin( )  (d) string.h

(a) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)
(b) (i) – (d); (ii) – (a); (iii) – (b); (iv) – (c)
(c) (i) – (a); (ii) – (b); (iii) – (d); (iv) -(c)
(d) (i) – (d); (ii) – (c); (iii) – (a); (iv – (b)
Answer:
(a) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 58.
Choose the correct statement:
(a) The pow( ) function returns the square root of the given value.
(b) The strupr( ) used to convert the string into uppercase letters.
(c) isdigit( ) check the given character is an alphabet or not.
(d) strcmp( ) finds the length of the string.
Answer:
(b) The strupr( ) used to convert the string into uppercase letters.

Question 59.
Choose the incorrect statement:
(a) The strlwr( ) function is used to convert the given string into lowercase letters.
(b) The strcmp( ) function compares the contents of the two strings.
(c) toupper( ) is used to check the given character is uppercase.
(d) puts( ) prints the string read by gets( ) function.
Answer:
(c) toupper( ) is used to check the given character is uppercase.

Question 60.
Assertion (A):
setw inserts a new line and flushes the buffer.
Reason (R):
The field width determine the minimum number of character to be written j in output.
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(d) A is false, but R is true.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 61.
Choose the odd one out:
(a) endl
(b) setfill( )
(c) setprecision( )
(d) Const
Answer:
(d) Const

Question 62.
Which of the following header file defines the standard I/O predefined functions ?
(a) stdio.li
(b) math.h
(c) string.h
(d) ctype.h
Answer:
(a) stdio.li

Question 63.
Which function is used to check whether a character is alphanumeric or not. (a) isalpha( ) (b) isdigit( ) (c) isalnum( )
(d) islower( )
Answer:
(c) isalnum( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 64.
Which function begins the program execution?
(a) isalpha( )
(b) isdigit( )
(c) main( )
(d) islower
Answer:
(c) main( )

Question 65.
Which of the following function is with a return value and without any argument ?
(a) x=display(int, int)
(b) x=display(.)
(c) y=display(float)
(d) display(int)
Answer:
(b) x=display(.)

Question 66.
Which is return data type of the function prototype of add(int, int); ?
(a) int
(b) float
(c) char
(d) double
Answer:
(a) int

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 67.
Which of the following is the scope operator?
(a) >
(b) &
(c) %
(d) ^
Answer:
(d) ^

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 10 Flow of Control

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control

Question 1.
What is control flow?
Answer:
The flow of control jumps from one part of the code to another segment of code. This is called as “control flow.”

Question 2.
How many kinds of statements are used in C++?
Answer:
There are two kinds of statements used in C++.

  1. Null statement
  2. Compound statement

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 3.
What do you mean by sequential statement?
Answer:

  1. The sequential statement are the statements, that are executed one after another only once from tqp to bottom.
  2. They always end with a semicolon (;).

Question 4.
Write the general Syntax of the if statement.
Answer:
if (expression)
true-block;
statement-x;

Question 5.
Write the three forms of nested if.
Answer:

  1. If nested inside if part
  2. If nested inside else part
  3. If nested inside both if part and else part.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 6.
Write the Syntax of the conditional operator.
Answer:
The syntax of the conditional operator is: expression 1? expression 2 : expression 3

Question 7.
What is iteration statement?
Answer:

  1. An iteration (or looping) is a sequence of one or more statements that are repeatedly executed until a condition is satisfied.
  2. These statements are also called as control flow statements.

Question 8.
What are the types of iteration statements?
Answer:
C++ supports three types of iteration statements. They are:

  1. for statement
  2. while statement
  3. do-while statement.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 9.
What are the four elements of a loop?
Answer:
Every loop has four elements that are used for different purposes. These elements are

  1. Initialization expression
  2. Test expression
  3. Update expression
  4. The body of the loop.

Question 10.
State reason to prefer prefix operator over postfix.
Answer:
The update expression contains increment/ decrement operator (++ or – -). In this part, always prefer prefix increment/decrement operator over postfix when to be used alone. The reason behind this is that when used alone, prefix operators are executed faster than postfix.

Question 11.
What is jump statement? Write the types of Jump statements are used to interrupt the normal flow of program.
Answer:
Types of Jump Statements are:

  1. goto statement
  2. break statement
  3. continue statement.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 12.
What is goto statement? Write the Syntax.
Answer:
The goto statement is a control statement which is used to transfer the control from one place to another place without any condition in a program.
The syntax of the goto statement is;

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 1

Question 13.
When will the while loop be infinite? Give example.
Answer:
A while loop may be infinite loop when no update statement inside the body of the loop. Eg:
int main( )
{
int i = 0;
while(i<=10)
cout<<“The value of i is”
<<i; → [This statement is infinitely displaying because no update statement inside body of the loop]
i++; → [This is not part of the loop statement because of missing curly braces]
return 0;
}

Question 14.
What is the use of update expression?
Answer:
Update expression is used to change the value of the loop variable. This statement is executed at the end of the loop after the body of the loop is executed.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 15.
Write short note on iteration statement.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 2

The iteration statement is a set of statement that are repetitively executed if the condition is true. As soon as the condition becomes false, the repetition stops. This is also known as looping statement or iteration statement.
The set of statements that are executed again and again is called the body of the loop. The condition on which the execution or exit from the loop is called exit-condition or test- condition.

Question 16.
What do you mean by If-else-if ladder?
Answer:
The if-else ladder is a multi-path decision making statement.
The syntax of if-else ladder:
if(expression 1)
{
Statement-1
}
else
if (expression 2)
{
Statement-2
}
else
if (expression 3)
{
Statement-3
}
else
{
Statement-4
}

When expression becomes true, the statement associated with block is executed and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 3

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 17.
Write a program to find your grade using if-else ladder?
Answer:
#include
using namespace std;
int main( )
{
int marks;
cout<<“Enter the Marks ; cin>>marks;
if(marks >= 60)
cout<<“Your grade is 1st class !!” <<endl; else if(marks >= 50 && marks < 60)
cout<<“your grade is 2nd class ! ! ” <<endl; else if(marks >= 40 && marks < 50)
cout<<“your grade is 3rd class !!” <<endl;
else
cout<<“You are fail !!”<<endl;
return 0;
}
Output:
Enter the Marks :60
Your grade is 1st class ! !

Question 18.
List down the rules for the switch statement?
Answer:

  1. The expression provided in the switch should result in a constant value otherwise it would not be valid.
  2. Duplicate case values are not allowed.
  3. The default statement is optional.
  4. The break statement is used inside the switch to terminate a statement sequence.
  5. The break statement is optional. If omitted, execution will continue on into the next case.
  6. Nesting of switch statements is also allowed.

Question 19.
Explain how conditional operator works with example?
Answer:
(i) The conditional operator (or Ternary operator) is an alternative for ‘if else statement’.
(ii) The conditional operator consists of two symbols (?:). It takes three arguments.
The syntax of the conditional operator is: expression 1 ? expression 2 : expression 3

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 4

Eg:
#include
using namespace std;
int main( )
{
int a, b, largest;
cout<<“\n Enter any two numbers:” ; cin>> a >> b;
largest = (a>b)? a : b;
cout<< “\n Largest number :”<< largest;
return 0;
}
Output:
Enter any two numbers: 12 98
Largest number : 98

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 20.
Write some important points about switch statement.
Answer:

  1. A switch statement can only work for quality of comparisons.
  2. No two case labels in the same switch can have identical values.
  3. If character constants are used in the switch statement, they are automatically converted to their equivalent ASCII codes.
  4. The switch statement is more efficient choice than if in a situation that supports the nature of the switch operation.
    The switch statement is more efficient than if-else statement.

Question 21.
Write the while loop syntax and the control flow.
Answer:
(i) A while loop is a control flow statement that allows the loop statements to be executed as long as the condition is true.
(ii) The while loop is an entry-controlled loop because the test-expression is evaluated before entering into a loop.
The while loop syntax is:
while(Test expression)
{
Body of the loop;
}
Statement-x;
The control flow and flow chart of the while loop is shown below.

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 5

while loop control flow and while loop flowchart.

Question 22.
What do you mean by empty loop?
Answer:
Empty loop means a loop has no statement in its body is called an empty loop. Following for loop is an empty loop:
for (i+0; i<=5; +=i)(;) → the body of for loop contains a null statement.
In the above statement, the for loop contains a null statement, it is an empty loop.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 23.
What do you mean by nested switch? Write the Syntax.
Answer:
(i) When a switch is a part of the statement sequence of another switch, then it is called as nested switch statement.
(ii) The inner switch and the outer switch constant may or may not be the same.
The syntax of the nested switch statement is:
switch(expression)
{
case constant 1:
statement(s);
break;
switch(expression)
{
case constant 1:
statement (s);
break;
case constant 2:
statement(s);
break;
.
.
.
default :
statement(s);
}
case constant 2:
statement(s);
break; .
default :
statement (s);
}

Question 24.
How will you give multiple initialization and multiple update expressions in for loop?
Answer:
(i) Multiple statements can be used in the initialization and update expressions of for loop.
(ii) These multiple initialization and multiple update expressions are separated by commas.
Eg:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 6

Output:
The value of i is 0 The value of j is 10
The value of i is 1 The value of j is 9
The value of i is 2 The value of j is 8
The value of i is 3 The value of j is 7
The value of i is 4 The value of j is 6

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 25.
Write a short note on break with and show the working of break with different looping statements.
Answer:
A break statement is a jump statement which terminates the execution of loop and the control is transferred to resume normal execution after the body of the loop. The following Figure, shows the working of break statement with looping statements:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 7

Question 26.
What is continue statement? Give the work flow of a continue statement in different statements.
Answer:
The continue statement works quite similar to the break statement. Instead of terminating the loop (break statement), continue statement forces the loop to continue or execute the next iteration.
The following Figure describes the working flow of the continue statement:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 8

Question 27.
Write a C++ program to get the following output: 1 2 3 4 5 7 8 9 10
Answer:
#include
using namespace std;
int main ( )
for(int i = 1; i<= 10; i++)
{
if (i == 6) continue; else
cout«i« ” “;
}
return 0;
}
Output:
1 2 3 4 5 7 8 9 10

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 28.
Differentiate break and continue statement?
Answer:

Break

 Continue

Break is used to terminate the execution of the loop. Continue is not used to terminate the execution of loop.
It breaks the iteration. It skips the iteration.
When this statement is executed, control will come out from the loop and executes the statement immediately after loop. When this statement is executed, it will not come out of the loop but moves/jumps to the next iteration of loop.
Break is used with loops as well as switch case. Continue is only used in loops, it is not used in switch case.

Question 29.
What will be output for the given code below?
Answer:
#include
using namespace std;
int main( )
{
int count=0; do
{
cout<<“count:”<<count<<endl; count ++; if(count>5)
{
break;
}
}while(count<20);
return 0;
}
Output:
count : 0
count : 1
count : 2

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 30.
Write a C++ program to display number from 10 to 1 using do-while loop.
Answer:
#include
using namespace std;
int main( )
{
int n = 10;
do
{
cout<<n<<“,”; n–; }while(n > 0);
}
Output;
10, 9, 8, 7, 6, 5, 4, 3, 2, 1

Question 31.
What do you mean by the body of the loop?
Answer:
The body of the loop:

  1. A statement or set of statements forms a body of the loop that are executed repetitively.
  2. In an entry-controlled loop, first the test- expression is evaluated and if it is non-zero, the body of the loop is executed otherwise the loop is terminated,
  3. In an exit-controlled loop, the body of the loop is executed first then the test- expression is evaluated.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 32.
Explain if and if-else statement with suitable example.
Answer:
if statement:
The if statement evaluates a condition, if the condition is true then a true-block (a statement or set of statements) is executed, otherwise the true-block is skipped. The general syntax of the if statement is:
if (expression)
true-block;
statement-x;

In the above syntax, if is a keyword that should contain expression or condition which is enclosed within parentheses. If the expression is true (non-zero) then the true-block is executed and followed by statement-x are also executed, otherwise, the control passes to statement-x. The true-block may consists of a single statement, a compound statement or empty statement. The control flow of if statement and the corresponding flow chart is shown below.

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 9

C++ Program to check whether a person is eligible to vote using if statement.
#include
using namespace std;
int main( )
{

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 10

}
Output:
Enter your age: 23
You are eligible for voting….
This statement is always executed.

if-else statement:
In the above example of if, allows to execute a set of statement if a condition evaluates to true. What if there is another course of action to be followed if the condition evaluates to false. There is another form of if that allows for this kind of either or condition by providing an else clause. The syntax of the if-else statement is given below:
if(expression)
{
True-block;
}
else
{
False-block;
}
Statement-x
In if-else statement, first the expression or condition is evaluated either True of false.
If the result is true, then the statements inside true-block is executed and false-block is skipped. If the result is false, then the statement inside the false-block is executed i.e., the true-block is skipped.

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 21

 

C++ program to find whether the given number is even number or odd number using if-else statement.
#include
using namespace std;
int main( )
{
int num, rem;
cout<<“\n Enter a number:”; cin>>num;
rem = num%2;
if(rem==0)
cout<<“\n The given number”<<num<“is Even”;
else
cout<<“\n The given number”<<num<<“is Odd”;
return 0;
}

Output:
Enter number: 10
The given number 10 is Even
In the above program, the remainder of the given number is stored in rem. If the value of rem is zero, the given number is inferred as an even number otherwise, it is inferred as on odd number.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 33.
Give the key difference between if-eise and switch.
Answer:
“if-else” and “switch” both are selection statements. The selection statements, transfer the flow of the program to the particular block of statements based upon whether the condition is “true” or “false”. However, there are some differences in their operations. These are given below:
Key Differences Between if-else and switch:

if else

switch

Expression inside if statement decide whether to execute the statements inside if block or under else block. expression inside switch statement decide which case to execute.
An if else statement uses multiple statements for multiple choices. switch statement uses single expression for multiple choices.
If esle statement checks for equality as well as for logical expression.  switch checks only for equality.
The if statement evaluates integer, character, pointer or floating point type or Boolean type. switch statement evaluates only character or a integer data type.
Sequence of execution is like either statement under if block will execute or statements under else block statement will execute. The expression in switch statement decide which case to execute and if do not apply a break statement after each case it will execute till the end of switch statement.
If expression inside if turn out to be false, statement inside else block will be executed.  If expression inside switch statement turn out to be false then default statements are executed.
It is difficult to edit if else statements as it is tedious to trace where the correction is required. It is easy to edit switch statements as they are easy to trace.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 34.
What do you mean by nested if statement? Explain with suitable example.
Answer:
An if statement contains another if statement is called nested if. The nested can have one of the following three forms.
(i) If nested inside if part
(ii) If nested inside else part
(iii) If nested inside both if part and else part The syntax of the nested if:
If nested inside if part
if (expression-1)
{
if (expression)
{
True_Part_Statements;
}
else
{
False_Part_Statements;
}
}
else .
body of else part;
If nested inside else part
if(expression-1)
{
body of true part;
}
else
{
if(expression}
{
True_Part_Statements;
}
else
{
False_Part_Statements ;
}
}
If nested inside both if part and else part
if (expression)
{
if (expression)
{
True_Part_Statements;
}
else
{
False_ Part_Statements;
}
}
else
{
if (expression)
{
True_Part_Statements;
}
else
{
False_Part_Statements;
}
}
In the first syntax of the nested if mentioned above the expression-1 is evaluated and the expression result is false then control passes to statement-m. Otherwise, expression-2 is evaluated, if the condition is true, then Nested- True-block is executed, next statement-n is also executed. Otherwise Nested-False-Block, statement-n and statement-m are executed.

The working procedure of the above said if..else structures are given as flowchart below:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 11

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 12

C++ program to calculate commission according to grade using nested if statement
#include
using namespace std;
int main ( )
{
int sales, commission;
char grade;
cout<<”\n Enter Sales amount:”; cin>>sales;
cout<<”\n Enter Grade:”; cin>>grade;
if (sales > 5000)
commission = sales*0 . 10;
cout<<”\n Commission:”<<commission;
}
else
{
commission = sales * 0.05;
cout<<”\n Cornmission:”<< commission;
}
cout<<”\n Good Job . . . . . .“;
return 0;
}
Output:
Enter Sales amount: 6000
Enter Grade: A
Commission: 600
Good Job . . . . . .

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 35.
Write a C++ program to demonstrate switch statement.
Answer:
#include
using namespace std;
int main ( )
{
char grade;
cout<<“\n Enter Grade: “; cin>>grade;
switch(grade)
{
case ‘A’ : cout<< “\n
Excellent…”;
break;
case ‘B’ :
case ‘C’ : cout<< “\n Welldone . . . .”;
break;
case ‘D’ : cout<< “\n You passed . . . .”;
break;
case ‘ E’ : cout<< “\n Better try again . . . .”;
break;
default : cout<<“\n Invalid Grade . . . .”;
}
cout<< “\n Your grade is ” << grade;
return 0;
}
Output:
Enter Grade: C
Welldone . . .
Your grade is C

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 36.
Explain in detail the parts of a loop.
Answer:
Every loop has four elements that are used for different purposes. These elements are:

  1. Initialization expression
  2. Test expression
  3. Update expression
  4. The body of the loop

Initialization expression(s):
The control variable(s) must be initialized before the control enters into loop. The initialization of the control variable takes place under the initialization expressions. The initialization expression is executed only once in the beginning of the loop.

Test Expression:
The test expression is an expression or condition whose value decides whether the loop-body will be execute or not. If the expression evaluates to true (i.e., 1), the body of the loop executed, otherwise the loop is terminated. In an entry-controlled loop, the test-expression is evaluated before entering into a loop whereas in an exit-controlled loop, the test-expression is evaluated before exit from the loop.

Update expression:
It is used to change the value of the loop variable. This statement is executed at the end of the loop after the body of the loop is executed.

The body of the loop:
A statement or set of statements forms a body of the loop that are executed repetitively. In an entry-controlled loop, first the test-expression is evaluated and if it is non-zero, the body of the loop is executed otherwise the loop is terminated. In an exit-controlled loop, the body of the loop is executed first then the test-expression is evaluated. If the test-expression is true the body of the loop is repeated otherwise loop is terminated.

Question 37.
Explain the for loop with suitable example.
Answer:
The for loop is the easiest looping statement which allows code to be executed repeatedly. It contains three different statements (initialization, condition or test-expression and update expression(s)) separated by semicolon.
The general syntax is:
for(initialization (s); test- expression; update expression(s))
{.
Statement 1;
Statement 2;
……….
}
Statement – x;

The initialization part is used to initialize variables or declare variable which are executed only once, then the control passes to test-expression. After evaluation of test- expression, if the result is false, the control transferred to statement-x. If the result is true, the body of the for loop is executed, next the control is transferred to update expression. After evaluation of update expression part, the control is transferred to the test-expression part. Next the steps 3 to 5 is repeated. The workflow of for loop and flow chart are shown below.

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 13

C++ program to display numbers from 0 to 9 using for loop.
#include
using namespace std;
int main( )
{
int i;
for(i=0;i<10;i++)
cout<<“value of i :”<<i<<endl;
return 0;
}
Output:
value of i : 0
value of i : 1
value of i : 2
value of i : 3
value of i : 4
value of i : 5
value of i : 6
value of i : 7
value of i : 8
value of i : 9

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 38.
Explain the do-while loop with suitable example.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 14

The do-while loop is an exit-controlled loop. In do-while loop, the condition is evaluated at the bottom of the loop after executing the body of the loop. This means that the body of the loop is executed at least once, even when the condition evaluates false during the first iteration.
The do-while loop syntax is:
do
{
Body of the loop;
} while(condition);
C++ program to display number from 10 to 1 using do-while loop
#include
using namespace std;
int main( )
{
int n = 10; do
{
cout<<n<<“, “; n–; } while(n>0) ;
}
Output:
10, 9, 8, 7, 6, 5, 4, 3, 2, 1

In the above program, the integer variable n is initialized to 10. Next the value of n is displayed as 10 and n is decremented by 1. Now, the condition is evaluated, since 9 > 0, again 9 is displayed and n is decremented to 8. This continues, until n becomes equal to 0, at which point, the condition n > 0 will evaluate to false and the do-while loop terminates.

Question 39.
Explain the while loop variation.
Answer:
A while loop may contain several variations. It can be an empty loop or an infinite loop. An empty while loop does not have any statement inside the body of the loop except null statement i.e., just a semicolon.
Eg:
int main ( )
{
int i=0;
while (++i<10000)
→ [This is an empty loop because the while loop does not contain ‘ any statement]
return 0;
}
}
In the above code, the loop is a time delay loop. A time delay loop is useful for pausing the program for some time.
A while loop may be infinite loop when no update statement inside the body of the loop.
Eg:
int main( )
{

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 15

}

Similarly, there is another variation of while is also shown below:

int main( )
{
int i=1;
while(++i < 10)
cout<<“The value of i is”<<i;
return 0;
}
In the above statement while (++i < 10), first increment the value of i, then the value of i is compared with 10.
int main( )
{
int i=1;
while(i++ < 10)
cout<<“The value of i is”<<i;
return 0;
}
In the above statement while (i++ < 10), first the value of i is compared with 10 and then the incrementation of i takes place. When the control reaches cout<< “The value of i is”<

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 40.
Write C++ program to solve the following problems.
Answer:
1. Temperature – conversion program that gives the user the option of converting Fahrenheit to Celsius or Celsius to Fahrenheit and depending upon user’s choice.
#include
using namespace std;
int main( )
{
int res;
double – temp;
cout<,”\n Type 1 to convert fahrenheit to Celsius”
<<“\n Type 2 to convert Celsius to fahrenheit:; cin>>res;
if(res=1)
{
cout<<“Enter temperature in fahrenheit:”; cin>>temp;
cout<<“In Celsius”<<5.0/9.0* (temp-32.0);
}
else
{
cout<<“Enter temperature in Celsius:”; cin>>temp;
cout<<“In fahrenheit”<<9.0/5.0* temp +32.0;
}
cout<<endl;
return 0;
}
Output:
Type 1: to convert fahrenheit to Celsius
Type 2: to covert Celsius to fahrenheit :1 .
Enter temperature in fahrenheit : 120
In Celsius 48.8889

Question 41.
The program requires the user to enter two numbers and an operator. It then carries out the specified arithmetical operation: addition, subtraction, multiplication or division of the two numbers. Finally, it displays the result.
Answer:
#include
using namespace std;
int main( )
{
char option;
float num1, num2;
cout<<“enter operator either+(or)-(or)* (or)1:”; cin>>option;
cout<<“enter first operand:”; cin>>num1;
cout<<“\n enter second operand:”; cin>>num2;
switch(option)
{
case’+’
cout<<num1+num2;
break;
case’-‘
cout<<num1-num2;
break;
case’*’ ,
cout<<num*num;’
break;
case’/’
cout<<numl/num2;
break;
default:
cout<<“error! Operator is not correct”;
break;
}
return 0;
}
Output:
Enter operator either +(or) – (or) * (or) / : +
Enter first operand: 2
Enter second operand:3
5

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 42.
Program to input a character and to print whether a given character is an alphabet, digit or any other character.
Answer:
#include
using namespace std;
int main( )
}
char ch;
cout<<“Enter any character”; cin>>ch;
//Alphabet checking condition
if((ch>=’a’ && ch<=’z’) || (ch>=’A’ && ch<= ‘Z’))
{
cout<<ch<<“is an Alphabet”; } else if(ch>=’0′ && ch<=’9′)
{
cout<<ch<<“is a Digit”;
}
else
{
cout<<ch<<“is a special character”;
}
return 0;
}
Output:
Enter any character :8
8 is a Digit

Question 43.
Program to print whether a given character is an uppercase or a lowercase character or a digit or any other character, use ASCII codes for it. The ASCII codes are as given below:
Answer:

Characters

 ASCII Range

‘0’ – ‘9’  48 – 57
‘A’ – ‘Z’  65 – 90
‘a’ – ‘z’  97 – 122
Other characters  0 – 255 excluding the above mentioned codes.

#include
using namespace std;
int main( )
{
char ch;
cout<<“Enter any character:”; cin>>ch;
if(ch>=65 && ch<=90)
cout<<endl<<ch<<“uppercase character”; else if(ch>=48 && ch<=57)
cout<<endl<<ch<< “a digit”; else if(ch>=97 && ch<=22)
cout<<endl«ch<<” lowercase character”;
else
cout<<endl<<ch<<“a special character”;
return 0;
}
Output:
Enter any character: D
Uppercase character

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 44.
Program to calculate the factorial of an integer.
Answer:
#include
using namespace std;
int main( )
{
unsigned int n;
unsigned long factorial =1;
cout<<“enter a integer:”; cin>>n;
for (int i-;i<=n;++i)
{
factorial *=i;
cout<<“factorial of “<<n<<“=”<<factorial;
return 0;
}
Output:
Enter a integer:2
Factorial of 12=479001600

Question 45.
Program that print 1 2 4 8 16 32 64 128.
Answer:
#include
using namespace std;
int main ( )
{
int j;
for(i=i; i<128; i*=2)
cout<<i<<“ “;
return 0;
)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 46.
Program to generate divisors of an integer.
Answer:
#include
using namespace std;
int main( )
(
long int n, j;
cout<<”Enter the number:”; cin>>n;
cout<<endl<<”Divisor of”<> “are”;
for(i = i; i<=n;++i)
{
if (n%i==0)
cout<<” d “<<j;
)
return 0;
Output:
Enter the number : 6
Divisors of 6 are 1 2 3 6

Question 47.
Program to print fibonacci series i.e., 0 1 1 2 3 5 8 ….
Answer:
#include
using namespace std;
int main( )
mt n1=0, n2=1, n3, i, number;
count<<”enter the number of elements :“; cin>>number;
for (i=0; i<number; i++)
{
n3=n1+n2;
cout<<n3<<” “;
n1=n2;
n2=n3;
}
return 0;
}
Output:
Enter the number of elements:10
0 1 1 2 3 5 13 21 34

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 48.
Programs to produces the following design using nested loops.

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 16

Answer:
(a)
#include
using namespace std;
int main( )
{
char S[ ] = “ABCDEF”
for(int i=0;s[i];++i)
{
for(int j=0;j<=i;++j;
{
cout<<S[j]<<” “;
}
cout<<endl;
}
return 0;
}
Output:
A
A B
A B C
A B C D
A B C D E
A B C D E F

(b)
#include
using namespace std;
int main( )
{
int rows;
for (int i=1; i<=5; ++i) { for (int j =5; j>=i; –j)
{
cout<<j<<” “;
}
cout<<“\n”;
}
return 0;
}
Output:
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5

(c)
#include
using namespace std;
int main( )
{
for (int i=4; i>=1; –i)
{
for (int k=0; k<4-i; ++k)
cout<<” “;
for(int j=i; j<2*i-1; ++j)
{
cout<<“#”;
}
for(j=0;j<i-l;++j) cout«”#”; cout«”\n”;
}
return 0;
}
Output:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 22

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 49.
Program to check whether square root of a number is prime or not.
Answer:
#include
#include using namespace std;
int main( )
{
int x, y=1, z, i;
cout<<“Enter a Number ; cin>>x;
z=sqrt(x);
cout<<“\nSquare Root is : “«z;
if(z==1)
{
cout<<“\nThe Number is Not Prime”;
}
else
{
for(i=2; i<z; i++)
{
if(z%i == 0)
{
y = 0;
break;
}
}
if(y == 1)
{
cout<<“\n”<<z<<“is a Prime Number”;
}
else
{
cout<<“\n”<<z<< “is Not a Prime Number”; } } return 0; } Output: Enter a Number: 16 Square Root is: 4 4 is Not a Prime Number.

Question 50.
What is a null statement and compound statement?
Answer:
The “null or empty statement” is a statement containing only a semicolon. It takes the flowing form: ; // it is a null statement Compound (Block) statement: C++ allows a group of statements enclosed by pair of braces { }. This group of statements is called as a compound statement or a block. The general format of compound statement is: { statement1; statement2; statement3; } For example { int x, y; x = 10; y = x + 10; }

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 51.
What is selection statement? Write it’s types?
Answer:
The selection statement means the statement (s) are executed depending upon a condition. If a condition is true, a true block (a set of statements) is executed otherwise a false block is executed. The types of selection statement are:

  1. if statement
  2. if-else statement
  3. Nested if statement
  4. Switch statement

Question 52.
Correct the following code segment:
Answer:
if(x=1) p=100;
else P=10;
if (x==1) p=100;
else p-10;

Question 53.
What will be the output of the following code: int year; cin>>year;
if (year % 100==0) ,
if (year% 400==0)
cout<<“Leap”;
else
cout<<“Not Leap year”;

If the input given is (i) 2000 (ii) 2003 (iii) 2010?
Answer:
(i) I/p: 2000
O/p: Leap

(ii) I/p: 2003
O/p: No output

(iii) I/p: 2010
O/p: No output

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 54.
What is the output of the following code?
for(int i=2; i<=10; i+=2)
cout<<i;
output:
Answer:
246810

Question 55.
Write a for loop that displays the number from 21 to 30.
Answer:
for(int i=21; i<=30; i++)
cout<<i;

Question 56.
Write a while loop that displays numbers 2, 4 ,6, 8 ……20.
Answer:
int i=2;
while(i<=20)
{
cout<<i<<“, i+=2 }

Question 57.
Compare an if and a? : operator
Answer:
The conditional operator is an expression rather than a statement. There are few places the conditional operator can be used where an if/else cannot be used.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 58.
Convert the following if-else to a single conditional statement:
Answer:
if (x>=10)
a=m +5;
else
a=m;
a=(x>=10) ?m+5:m;

Question 59.
Rewrite the following code so that it is functional:
v=5 .
do;
{
Total+=v;
Cout<<total;
while v<=10
int v=5, total=0;
do
{
total += v;
cout<<total;
v=v+1;
while(v<=10);

Question 60.
Write a C++ program to print multiplication table of a given number.
Answer:
#include
using namespace std;
int main( )
{
int num;
cout<<“Enter number to find multiplication table”; cin>>num;
for(int a=1; a<=10; a++)
{
cout<<num<< ” + ” <<a<< ” = ” <<num*a<<endl;
}
return 0;
}
Output:
Enter number to find multiplication table 3
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30
Press any key to continue

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 61.
Write the syntax and purpose of switch statement.
Answer:
Purpose: It provides an easy way to dispatch execution to different parts of code based on the value of the expression.
The syntax of the switch statement is;
switch(expression)
{
case constant 1:
statement(s);
break;
case constant 2:
statement(s)
break;
default
statement(s);
}

Question 62.
Write a short program to print following series:
(a) 1 4 7 10……40
#include
using namespace std;
int main( )
{
for(i=1;i<=40;i+=3)
cout<< i << ”
}
cout<<endl;
return 0;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 63.
Explain control statement with suitable example.
Answer:
Control statements are statements that alter the sequence of flow of instructions.
Selection statement:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 17

In a program, statements may be executed sequentially, selectively or iteratively. Every programming languages provides statements to support sequence, selection (branching) and iteration.

If the Statements are executed sequentially, the flow is called as sequential flow. In some situations, if the statements alter the flow of execution like branching, iteration, jumping and function calls, this flow is called as control flow.
Sequence statement:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 18

The sequential statement are the statements, that are executed one after another only once from top to bottom: These statements do not alter the flow of execution. These statements are called as sequential flow statements. They always end with a semicolon (;).

The selection statement means the statement (s) are executed depending upon a condition. If a condition is true, a true block (a set of statements) is executed otherwise a false block is executed. This statement is also called decision statement or selection statement because it helps in making decision about which set of statements are to be executed.

Iteration statement:

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 19

The iteration statement is a set of statement that are repetitively executed depends upon a conditions. If a condition evaluates to true, the set of statements (true block) is executed again and again. As soon as the condition becomes false, the repetition stops. This is also known as looping statement or iteration statement. The set of statements that are executed again and again is called the body of the loop.The condition on which the execution or exit from the loop is called exit-condition or test- condition.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 64.
What is entry control loop? Explain any one of the entry loop with suitable example.
Answer:
The loop which has a condition check at the entrance of the loop, the loop executes only and only if the condition is satisfied and is called as entry control loop.
Eg: (i) while loop (ii) for loop

while loop:
A while loop is a control flow statement that allows the loop statements to be executed as long as the condition is true. The while loop is an entry-controlled loop because the test-expression is evaluated before the entering into a loop.
The while loop syntax is:
while(Test expression)
{
Body of the loop;
}
Statement-x;
The control flow and flow chart of the while loop is shown below.

TN State Board 11th Computer Science Important Questions Chapter 10 Flow of Control 20

In while loop, the test expression is evaluated and if the test expression result is true, then the body of the loop is executed and again the control is transferred to the while loop. When the test expression result is false the control is transferred to statement-x.
#include
using namespace std;
int main( )
{
int i=i,sum=0;
while (i<=10)
{
sum=sum+i;
i++;
}
cout<<“The sum of 1 to 10 is”<<sum;
return 0;
}
Output:
The sum of 1 to 10 is 55

In the above program, the integer variable i is initialized to 1 and the variable sum to 0. The while loop checks the condition, i < 10, if the condition is true, the value of i, which is added to sum and i is incremented by 1. Again, the condition i < 10 is checked. Since 2 < 10, 2 is added to the earlier value of sum. This continues until i becomes 11. At this point in time, 11 < 10 evaluates to false and the while loop terminates. After the loop termination, the value of sum is displayed.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 65.
Write a program to find the LCM and GDC of two numbers.
Answer:
#include
using namespace std;
int main( )
{
int a, b, x, y, t, gcd, 1 cm;
cout<<“Enter two Integers\n”; cin>>x>>y;
a=x; ‘
b=y;
while(b!=0)
{
t=b;
b=a%b;
a=t;
}
gcd=a;
1 cm=(x*y)/gcd
cout<<“Greatest common divisor of”<<x<< ” and “<<y<<” = ” <<gcd;
cout<<“Least common multiple of “<<x<<” and “<<y<<” >> ” << 1 cm;
return 0;
}
Output:
Enter two Integers
15
33
Greatest common divisor of 15 and 33=3
Least common multiple of 15 and 33=165

Question 66.
Write program to find the sum of following series:
(i) \(x-\frac{x^{2}}{2 !}+\frac{x^{3}}{3 !}-\frac{x^{4}}{4 !}+\frac{x^{5}}{5 !}-\frac{x^{6}}{6 !}\)

(ii) \(x+\frac{x^{2}}{2}+\frac{x^{3}}{3}+\ldots .+\frac{x^{n}}{n}\)
Answer:
#include
#include using namespace std;
int main( )
{
int i,n,f=1;
float x, sum=0;
cout<<“\n Enter the value of x and n\n”; cin>>x>>n;
for(i=1;i<=n;i++)
{
f=f*i;
if (i%2==0)
{
sum -= pow (x, i) /f; }
else
{
sum += pow(x,i)/f;
}
}
cout<<“\n sum = “<<sum<<endl;
return 0;
}
Output:
Enter the. value of x and n : 2
6
sum = 0.844444

(ii)
#include .
#include using namespace std;
int main ( )
{
int i,n;
float x, sum=0;
cout<<“\n Enter the value of x and n:\n”; cin>>x>>n;
for (i=i;i<=n;i++)
{
sum+= pow(x,i)/i:
}
cout<<“\n Sum is =” <<sum<<endl;
return 0;
}
Output:
Enter the value of x and n:
2
6
sum is = 27.7333

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 67.
Write a program to find sum of the series S = 1 + x + x2+ +xn
Answer:
#include
#include using namespace std;
int main( )
{
long i, n, x, sum=1;
cout<<“\n Enter the value of x and n”; cin>>x>>n;
for(i=1;i<=n;i++)
{
sum += pow(x,i)
}
cout<<“\n sum”<<sum;
return 0;
}
Output:
Enter the value of x and n:
5
2
sum 31

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Choose the correct answer:

Question 1.
There are _________ kinds of statements used in C++.
(a) two
(b) three
(c) four
(d) five
Answer:
(a) two

Question 2.
A group of statements that are enclosed by pair of braces { } are called _______ statement.
(a) compound
(b) single
(c) null
(d) selection
Answer:
(a) compound

Question 3.
_________ statements are statements that alter the sequence of flow of instructions.
(a) Sequential
(b) Control
(c) Iteration
(d) Selection
Answer:
(b) Control

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 4.
_________ statement are the statements, that are executed one after another only once from top to bottom.
(a) Control
(b) Compound
(c) Sequential
(d) Empty
Answer:
(c) Sequential

Question 5.
The sequential flow statements ended with a
(a) .
(b) ;
(c) :
(d) ,
Answer:
(b) ;

Question 6.
_________ statement are executed depends upon a condition.
(a) Iteration
(b) Selection
(c) Null
(d) Sequential
Answer:
(b) Selection

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 7.
The ________ statement is a set of statement are repetitively executed depends upon a Condition. .
(a) control
(b) null
(c) selection
(d) iteration
Answer:
(d) iteration

Question 8.
Iteration statement are also known as _________ statement.
(a) branching
(b) looping
(c) control
(d) empty
Answer:
(b) looping

Question 9.
The if statement that contains another if statement is called ______ statement.
(a) while
(b) for
(c) do
(d) nested statement.
Answer:
(d) nested statement

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 10.
__________ is a multi – path decision making statement.
(a) if statement
(b) if-else statement
(c) switch statement
(d) if-else-if ladder
Answer:
(d) if-else-if ladder

Question 11.
The __________ operator is an alternate for ‘if else statement’.
(a) conditional
(b) assignment
(c) logical
(d) arithmetic
Answer:
(a) conditional

Question 12.
Conditional operator takes __________ arguments.
(a) two
(b) four
(c) five
(d) three
Answer:
(d) three

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 13.
The conditional operate consists of ________ symbols.
(a) one
(b) two
(c) three
(d) five
Answer:
(b) two

Question 14.
________ is a conditional operator.
(a) ::
(b) ;
(c) ?
(d) ?:
Answer:
(d) ?:

Question 15.
________ statement is a multi-way branch statement.
(a) nested if
(b) switch
(c) if-else-if ladder
(d) if-else
Answer:
(b) switch

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 16.
__________ statement reduce the length of code and takes less memory space.
(a) Iteration
(b) Empty
(c) Selection
(d) Sequential
Answer:
(a) Iteration

Question 17.
C++ supports _______ types of iteration statements.
(a) three
(b) four
(c) two
(d) six
Answer:
(a) three

Question 18.
Every loop has elements.
(a) five
(b) six
(c) three
(d) four
Answer:
(d) four

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 19.
In _______ the control variables is initialized.
(a) initialization
(b) test expression
(c) update expression
(d) body of the loop
Answer:
(a) initialization

Question 20.
________ decides whether the loop-body will be execute or not.
(a) Assignment expression
(b) Test expression
(c) Update expression
(d) Initialization expression
Answer:
(b) Test expression

Question 21.
__________ expression change the value of the loop variables.
(a) Update
(b) Change
(c) Initialization
(d) Test
Answer:
(a) Update

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 22.
The ________ loop is the easiest looping statement which allows code to be executed repeatedly.
(a) while
(b) do-while
(c) for
(d) switch
Answer:
(c) for

Question 23.
for loop contains __________ different statements.
(a) six
(b) five
(c) four
(d) three
Answer:
(d) three

Question 24.
Initialization, condition and update expression are separated by:
(a) :
(b) ,
(c) ;
(d) .
Answer:
(c) ;

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 25.
The multiple initialization and multiple update expressions are separated by:
(a) commas
(b) full stop
(c) semicolon
(d) colon
Answer:
(a) commas

Question 26.
_______ is an entry check loop.
(a) while
(b) do-while
(c) switch
(d) if
Answer:
(a) while

Question 27.
The __________ loop is an exit-controlled loop.
(a) for
(b) if
(c) do-while
(d) while
Answer:
(c) do-while

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 28.
______ are used to interrupt the normal flow of program.
(a) Selection statement
(b) Sequential statement
(c) Control statement
(d) Jump statement
Answer:
(d) Jump statement

Question 29.
There are _________ types of jump statement.
(a) four
(b) ffye
(c) three
(d) two
Answer:
(c) three

Question 30.
The ________ statement is a control statement used to transfer the control without any condition.
(a) goto
(b) break
(c) continue
(d) switch
Answer:
(a) goto

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 31.
for (i = 1; i < 30; i++) how many times the loop will be executed:
(a) 1
(b) 29
(c) 30
(d) 31
Answer:
(b) 29

Question 32.
if(a>b);
cout<<“greater”;
else
cout<<“lesser”;
What will be the error if thrown by the compiler from above statement:
(a) misplaced if
(b) misplaced else
(c) misplaced if.. .else
(d) misplaced else…if
Answer:
(b) misplaced else

Question 33. __________ is used to terminate a statement sequence.
(a) case
(b) colon (:)
(c) break
(d) continue
Answer:
(c) break

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 34.
Identify the incorrect statement in switch case.
(a) Duplicate case values are not allowed
(b) The default statement is not optional
(c) The break statement is optional
(d) Nesting of switch statements is also allowed
Answer:
(b) The default statement is not optional

Question 35.
________ loop is used in the above program.
(a) while
(b) for
(c) do-while
(d) switch
Answer:
(c) do-while

Question 36.
An empty while loop does not have any statement inside the body of loop except:
(a) colon
(b) commas
(c) braces
(d) semicolon
Answer:
(d) semicolon

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 37.
In _________ loop the condition is evaluated at the bottom of the loop,
(a) for
(b) while
(c) switch
(d) do-while
Answer:
(d) do-while

Question 38.
________ statement forces the loop to continue or execute the next iteration.
(a) break
(b) continue
(c) goto
(d) default
Answer:
(b) continue

Question 39.
________ statement terminates the execution of the loop and resume normal execution after the body of the loop.
(a) if
(b) switch
(c) break
(d) continue
Answer:
(c) break

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 40.
Identify the invalid one:
(a) if (a > b)
(b) if (a<= b)
(c) if (a= =b)
(d) if a > b
Answer:
(d) if a > b

Question 41.
Every action in the switch statement should be terminated with a ________ statement.
(a) case
(b) colon
(c) break
(d) continue
Answer:
(c) break

Question 42.
An _____ loop will be formed if a test – expression is absent in a for loop.
(a) finite
(b) infinite
(c) empty
(d) continue
Answer:
(b) infinite

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 43.
When a loop has no statement in its body is called an:
(a) while loop
(b) empty loop
(c) finite loop
(d) infinite loop
Answer:
(b) empty loop

Question 44.
In __________ loop the body of the loop is executed at least once even when the condition is false during first iteration.
(a) do-while
(b) for
(c) while
(d) switch
Answer:
(a) do-while

Question 45.
Give the output cout<<5+10:
(a) 5+10
(b) 510
(c) 15
(d) 50
Answer:
(c) 15

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 46.
The loops are enclosed within:
(a) [ ]
(b) { }
(c) <>
(d) ##
Answer:
(b) { }

Question 47.
From the given code below answer the questions from 47 to 50.
#include
using namespace std,
int main ( )
{
int num = 2
do
cout<<num*num;
num +=1;
}
while(num<6);
}
The control variable used in the program is:
(a) num
(b) +=1
(c) \t
(d) none
Answer:
(a) num

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 48.
The test expression in the program is:
(a) num
(b) num*num
(c) (num<6)
(d) +=1
Answer:
(c) (num<6)

Question 49.
How many times the loop will be executed?
(a) 2
(b) 4
(c) 5
(d) 3
Answer:
(b) 4

Question 50.
Match the following:

(i) Null  (a) ?:
(ii) if else  (b) Goto
(iii) While loop  (c) Empty
(iv) Jump  (d) Entry check

(a) (i) – (d); (ii) – (c); (iii) – (b); (iv) – (a)
(b) (i) – (b); (ii) – (a); (iii) – (d); (iv) – (c)
(c) (i) – (a); (ii) – (b); (iii) – (c); (iv) – (d)
(d) (i) – (c); (ii) – (a); (iii) – (d); (iv) – (b)
Answer:
(d) (i) – (c); (ii) – (a); (iii) – (d); (iv) – (b)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 51.
Identify the correct statement:
(a) C++ allows a group of statements enclosed by pair Of [ ]
(b) The null statement is a statement containing a set of code.
(c) The sequential statement are the statement that are executed one after another only once from top to bottom.
(d) The iteration statement is a set of statement are not repetitively executed.
Answer:
(c) The sequential statement are the statement that are executed one after another only once from top to bottom.

Question 52.
Identify the correct statement:
(a) A loop which contains another loop is called as nested loop.
(b) In do-while loop, the condition is evaluated at the top of the loop.
(c) Every loop has four elements that are used for different purpose.
(d) A switch statement can, only work for quality of comparisons.
Answer:
(b) In do-while loop, the condition is evaluated at the top of the loop.

Question 53.
Choose the odd one out:
(a) for
(b) while
(c) do-while
(d) if-else
Answer:
(d) if-else

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 54.
Assertion (A):
The iteration statement is a set of statement are repetitively executed depends upon a condition.
Reason (R):
If a condition evaluates to true, the set of statements is executed again and again.
(a) Both A and R are true, and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(a) Both A and R are true, and R is the correct explanation for A.

Question 55.
What is the alternate name of null statement?
(a) No statement
(b) Empty statement
(c) Void statement
(d) Zero statement
Answer:
(b) Empty statement

Question 56.
In C++, the group of statement should enclosed within:
(a) { }
(b) [ ]
(c) ( )
(d) <>
Answer:
(a) { }

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 57.
The set of statements that are executed again and again in iteration is called as:
(a) condition
(b) loop
(c) statement
(d) body of loop
Answer:
(d) body of loop

Question 58.
The multi way branching statement:
(a) if
(b) if…else
(c) switch
(d) for
Answer:
(c) switch

Question 59.
How many types of iteration statements?
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(b) 3

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 60.
How many times the following loop will execute? for (int i = 0;i < 10;i++)
(a) 0
(b) 10
(c) 9
(d) 11
Answer:
(b) 10

Question 61.
Which of the following is the exit control loop?
(a) for
(b) while
(c) do…while
(d) if…else
Answer:
(c) do…while

Question 62.
Identify the odd one from the keywords of jump statements:
(a) break
(b) switch
(c) goto
(d) continue
Answer:
(b) switch

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 10 Flow of Control

Question 63.
Which of the following is the exit control loop?
(a) do-while
(b) for
(c) while
(d) if-else
Answer:
(a) do-while

Question 64.
A loop that contains another loop inside its body:
(a) Nested loop
(b) Inner loop
(c) Inline loop
(d) Nesting of loop
Answer:
(a) Nested loop

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 9 Introduction to C++

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++

Question 1.
What is character set?
Answer:
Character set is a set of characters which are allowed to write a C++ program. C++ accepts the following characters.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 1

Question 2.
What are identifiers? List the classification of C++operators.
Answer:
C++ Operators are classified as:
(i) Arithmetic Operators
(ii) Relational Operators
(iii) Logical Operators

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 3.
What are constants? List the types of constants in C++.
Answer:
Literals are data items whose values do not change during the execution of a program.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 2

Question 4.
What do you mean by Boolean literals?
Answer:
Boolean literals are used to represent one of the Boolean values(True or false). True has value 1 and false has value 0.

Question 5.
How the operators are classified on the basis of the number of operands.
Answer:

Operators  Operands

 Example

Unary operators  Require only one operands  x++
Binary operators  Require two operands  c = a + b
Ternary operators  Require three operands  max = (num 1 > num 2)? num1 : num2

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 6.
List the charactreristics of C++ operators.
Answer:
(i) Airthmetic Operators
(ii) Relational Operators
(iii) Logical Operators
(iv) Bitwise Operators
(v) Assignment Operators
(vi) Conditional Operator
(vii) Other Operators

Question 7.
What is get from operator?
Answer:
C++ provides the operator >> to get input. It extracts the value through the keyboard and assigns it to the variable on its right; hence, it is called as “Stream extraction” or “get from”

Question 8.
What is put to operator?
Answer:
C++ provides << operator to perform output operation. The operator « is called the “Stream insertion” or “put to” operator.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 9.
What are the two fundamental elements?
Answer:
Every programming language has two fundamental elements, viz., data types and variables.

Question 10.
What is fundamental data type?
Answer:
C++ provides a predefined set of data types for handling the data items. Such data types are known as fundamental or built-in data types.

Question 11.
What is user-defined data type?
Answer:
Apart from the built-in data types, a programmer can also create his own data types called as User-defined data types.

Question 12.
Write the categories of C++.
Answer:
In C++, the data types are classified as three main categories. They are:
(i) Fundamental data types
(ii) User-defined data types and
(iii) Derived data types.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 13.
Write the memory allocation for char data types.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 3

Question 14.
Write the memory allocation for floating point data types.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 4

Question 15.
What do you mean by number suffixes in C++?
Answer:
Suffix can be used to assign the same value as a different type. For example, To store 45 in an int, long, unsigned int and unsigned long int, suffix letter L or U (either case) is used with 45 i.e., 45L or 45U. This type of declaration instructs the compiler to store the given values as long and unsigned. ‘F’ can be used for floating point values.
Eg: 3.14F.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 16.
Give the values associated with a symbolic variable.
Answer:
There are two values associated with a symbolic variable; they are R-value and L-value.
(i) R-value is data stored in a memory location.
(ii) L-value is the memory address in which the R-value is stored.

Question 17.
What do you mean by initialization?
Answer:
Assigning an initial value to a variable during its declaration is called as “Initialization”.
Eg:
int num =100;
float pi = 3.14;
double price = 231.45;

Question 18.
Name the members of iomanip header file.
Answer:
The members of iomanip header file are setw, setfill, setprecision and setf manipulators.

Question 19.
List down the commonly used manipulators.
Answer:
The commonly used manipulators are: endl, setw, setfill, setprecision and setf.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 20.
What is the use of setfill ( )?
Answer:
setfill argument is used for filling the empty fields.
Syntax: setfill (character);
Eg: cout<< “\n H.R.A:” << setw(10) << setfill (0) << hra;

Question 21.
Name the types of conversion provided in C++.
Answer:
(i) Implicit type conversion
(ii) Explicit type conversion

Question 22.
What do you mean by type promotion?
Answer:
If the type of the operands differ, the compiler converts one of them to match with the other, using the rule that the “smaller” type is converted to the “wider” type, which is called as “Type Promotion”.

Question 23.
What is automatic conversion?
Answer:
An Implicit type conversion is performed by the compiler automatically. So, implicit conversion is also called as “Automatic conversion”.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 24.
What is type casting?
Answer: C++ allows explicit conversion of variables or expressions from one data type to another specific data type by the programmer. It is called as “type casting”. Syntax: (type-name) expression;

Question 25.
List the benefits of C++.
Answer:
(i) C++ is a highly portable language and is often the language of choice for multi-device, multi-platform app development.
(ii) It is an object-oriented programming language and includes classes, inheritance, polymorphism, data abstraction and encapsulation.
(iii) It has a rich function library.
(iv) It allows exception handling, inheritance and function overloading which are not possible in C.
(v) It is a powerful, efficient and fast language. It finds a wide range of applications – from GUI applications to 3D graphics for games to real-time mathematical simulations.

Question 26.
Write down the rules for naming an identifier.
Answer:
(i) The first character of an identifier must be an alphabet or an underscore (_ ).
(ii) Only alphabets, digits and underscore are permitted. Other special characters are not allowed as part of an identifier.
(iii) C++ is case sensitive as it treats upper and lower-case characters differently.
(iv) Reserved words or keywords cannot be used as an identifier name.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 27.
Write short notes on string literals.
Answer:
(i) Sequence of characters enclosed within double quotes are called as String literals.
(ii) By default, string literals are auto-matically added with a special character ‘\0’ (Null) at the end.
(iii) Therefore, the string “welcome” will actually be represented as “welcome\0” in memory and the size of this string is not 7 but 8 characters i.e., inclusive of the last character \0. Valid string Literals : “A”, “Welcome” “1234”. Invalid String Literals : ‘Welcome’, ‘1234’.

Question 28.
What do you mean by Bitwise one’s complirhent operator?
Answer:
The bitwise One’s compliment operator -(Tilde), inverts all the bits in a binary pattern, i.e., all 1 ’s become 0 and all 0’s become 1. This is an unary operator. Eg: If a =15;
Equivalent binary values of a is 0000 1111

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 5

Question 29.
Write down the other operands in C++.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 6

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 30.
What do you mean by cascading of I/O operators?
Answer: The multiple use of input aryl output operators such as >> and << in a single statement is known as cascading of I/O operators.
Cascading cout: int Num=20;
cout<<“A=”<<Num; Cascading cin: Eg: cout>>”Enter two numberr
cin>>a>>b;

Question 31.
What is use of using namespace?
Answer:
(i) The line using namespace std; tells the compiler to use standard namespace.
(ii) Namespace collects identifiers used for class, object and variables.
(iii) They provide a method of preventing name conflicts in large projects.

Question 32.
What is a variable? Write the syntax.
Answer:
The variables are the named memory locations to hold values of specific data types.
Syntax: ;

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 33.
Give short notes on data type modifiers in C++.
Answer:
(i) Modifiers are used to modify the storing capacity of a fundamental data type except void type.
(ii) Every fundamental data type has a fixed range of values to store data items in memory.
(iii) For example, int data type can store only two bytes of data.
(iv) Modifiers can be used to modify (expand or reduce) the memory allocation of any fundamental data type. They are also called as Qualifiers.
There are four modifiers used in C++. They are:
(i) signed (ii) unsigned (iii) long (iv) short
These four modifiers can be used with any fundamental data type.

Question 34.
Write the memory allocation for integer data types.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 7

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 8

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 35.
Show the difference between Turbo C++ and Dev C++ for allocation of memory for the data types.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 9

Question 36.
Write short notes on Junk or Garbage values.
Answer:
If you declare a variable without any initial value, the memory space allocated to that variable will be occupied with some unknown value. These unknown values are called as “Junk” or “Garbage” values.
#include
using namespace std;
int main( )
{
int num1, num2, sum;
cout<<num1<<end1;
cout<<num2<,end1;
cout< }
In the above program, some unknown values will be occupied in memory that is allocated for the variables num1 and num2; and the statement court<

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 37.
Explain dynamic initialization with example.
Answer:
A variable can be initialized during the execution of a program. It is known as “Dynamic initialization”.
Eg:
int num1, num2, sum;
sum = num1 + num2;
C++ program to illustrate dynamic initialization:
#include
using namespace std;
int main( )
{
int num1, num2;
cout<<“\n Enter number 1:” ; cin>> numl;
cout<<“\n’Enter number 2:” ; cin>> num2;
int sum = num1 + num2;
// Dynamic initialization cout<<“\n Average:” << sum /2;
}
Output:
Enter number 1: 78
Enter number 2: 65
Average: 71

Question 38.
What is the use of endl? Give example.
Answer:
endl – Inserts a new line and flushes the buffer (Flush means – clean)
‘\n’ – Inserts only a new line.
cout<<“\n The value of num =” «num;
cout<<“The value of num =” << num<<end;
Both these statements display the same output.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 39.
Write short note on setprecision( ).
Answer:
setprecision( ) is used to display numbers with fractions in specific number of digits.
Syntax:
setprecision (number of digits);
Eg:
#include
#include
using namespace std;
int main( )
{
float hra = 1200.123;
cout< }
setprecision can also be used to set the number of decimal places to be displayed. To do this task, an ios flag is set within setf( ) manipulator. This may be used in two forms:
(i) fixed and
(ii) scientific.

Question 40.
What is an expression? Name the types of ’ expressions used in C++.
Answer:
(i) An expression is a combination of operators, constants and variables arranged as per the rules of C++.
(ii) It may also include function calls which return values. (Functions will be learnt in upcoming chapters).
In C++, there are seven types of expressions, and they are:
(i) Constant Expression
(ii) Integer Expression
(iii) Floating Expression
(iv) Relational Expression
(v) Logical Expression
(vi) Bitwise Expression
(vii) Pointer Expression

Question 41.
Write a note on Implicit type conversion. Give example.
Answer:
(i) An Implicit type conversion is performed by the compiler automatically.
(ii) So, implicit conversion is also called as ~ “Automatic conversion”.
Eg:
#include
using namespace std;
int main ( )
{
int a=6;
float b=3.14;
cout<<a+b;
}

In the above program, operand a is an int type and b is a float type. During the execution of the program, int is converted into a float, because a float is wider than int.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 42.
How the explicit conversion takes place? Give example.
Syntax:
(type-name) expression;
Where type-name is a valid C++ data type to which the conversion is to be performed.
Eg:
#include
using namespace std;
int main( )
{
float varf=78.685;
cout<<(int) varf;
}
In the above program, variable varf is declared as a float with an initial value 78.685. The value of varf is explicitly converted to an int type in cout statement. Thus, the final output will be 78.

Question 43.
What happens when you convert
(i) double to float,
(ii) float to int,
(iii) long to short.
Answer:
(i) Double to float:
Loss of precision. If the original value is out of range for the target type, the result becomes undefined.

(ii) Float to int:
Loss of fractional part. If original value may be out of range for target type, the result becomes undefined.

(iii) Long to short:
Loss of data.

Question 44.
Explain the Escape sequences (or) non- graphical characters in C++.
Answer:
(i) C++ allows certain non-printable characters represented as character constants. Non-printable characters are also called as non-graphical characters.
(ii) Non-printable characters cannot be typed directly from a keyboard during the execution of a program in C++, Eg: backspace, tabs etc.,

Escape sequence  Non graphical character
\a  Audible or alert bell
\b  Backspace
\f  Form feed
\n  Newline or linefeed
\r  Carriage return
\t  Horizontal tab
\v  Vertical tab
\\  Backslash
\’  Single quote
\”   Double quote
\?  Question Mark
\On  Octal number
\xHn  Hexadecimal number
\0  Null

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 45.
Name the familiar C++ compilers with IDE.
Answer:
Dey C++
Geany
Code: :blocks
Code Lite
Net Beans
Digital Mars
Sky IDE
Eclipse

Question 46.
Write the syntax to declare more than one variable.
Answer:
More than one variable of the same type can be declared as a single statement using a comma separating the individual variables.
Syntax:
, , , ………., ;
Eg:int num1, num2, sum;

Question 47.
Identify the Identifiers it is valid or invalid, if invalid give reason.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 10

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 48.
Explain the types of constants in detail.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 2

Numeric Constants:
Numeric constants are further classified as
(i) Integer Constants (or) Fixed point constants.
(ii) Real constants (or) Floating point constants.

(i) Integer Constants (or) Fixed point constants:
Integers are whole numbers without any fractions. An integer constant must have at least one digit without a decimal point. In C++, there are three types of integer constants:
(a) Decimal,
(b) Octal,
(c) Hexadecimal.

(a) Decimal:
Any sequence of one or more digits (0 …. 9).

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 11

(b) Octal:
Any sequence of one or more octal values (0 …. 7) that begins with 0 is considered as an Octal constant.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 12

(c) Hexadecimal:
Any sequence of one or more Hexadecimal values (0 …. 9, A …. F) that starts with Ox or OX is considered as an Hexadecimal constant.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 13

The suffix L or l and U or u added with any constant forces that to be represented as a long or unsigned constant respectively.

(ii) Real Constants (or) Floating point constants:
It is a numeric constant having a fractional component. These constants may be written in fractional form or in exponent form. Fractional form of a real constant is a signed or unsigned sequence of digits including a decimal point between the digits. It must have at least one digit before and after a decimal point. It may have prefix with + or – sign. A real constant without any sign will be considered as positive.

Exponent form of real constants consists of two parts:
(1) Mantissa and
(2) Exponent.

The mantissa must be either an integer or a real constant. The mantissa followed by a letter E or e and the exponent. The exponent should also be an integer.
For example, 58000000.00 may be written as 0.58 × 108 or 0.58E8.

Mantissa (Before E)

 Exponent (After E)

0.58

 8

Eg:
5.864 E1 → 5.864 × 101 → 58.64
5864 E-2 → 5864 × 10-2 → 58.64
0.5864 E2 → 0.5864 × 102 → 58.64

Boolean Literals:
Boolean literals are used to represent one of the Boolean values(TrUe or false). Internally true has value 1 and false has value 0.

Character constant:
A character constant is any valid single character enclosed within single quote. A character constant in C++ must contain one character and must be enclosed within a single quote.
Valid character constants : ‘A’,‘2′, $’
Invalid character constants : “A”
The value of a single character constant has an equivalent ASCII value.
Eg: the value of ‘A’ is 65.
String Literals:
Sequence of characters enclosed within double quotes are called as String literals. By default, string literals are automatically added with a special character ‘\0’ (Null) at the end. Therefore, the string “welcome” will actually be represented as “welcome\0” in memory and the size of this string is not 7 but 8 characters i.e., inclusive of the last character \0.
Valid String Literals: “A”, “Welcome” “1234”.
Invalid String Literals: ‘Welcome’, ‘1234’.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 49.
List down the order of precedence in C++.
Answer:
Operators are executed in the order of precedence. The operands and the operators are grouped in a specific logical way for evaluation. This logical grouping is called as an Association.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 14

Question 50.
What are punctuators? List down the punctuators use in C++.
Answer:
Punctuators are symbols, which are used as delimiters, while constructing a C++ program. They are also called as “Separators”. The following punctuators are used in C++;

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 15

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 16

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 51.
Explain the basic elements of C++.
Answer:
1. // C++ program to print a string
(i) It is a comment statement.
(ii) Any statement that begins with // are considered as comments.
(iii) Compiler simply ignores the comment statement.
(iv) If we need to write multiple lines of comments, we can use /* */.

2. # include
(i) All C++ programs begin with include statements starting with a # (hash / pound).
(ii) The symbol # is a directive for the preprocessor i.e., these statements are processed before . the compilation process begins.
(iii) #include statement tells the compiler’s preprocessor to include the header file “iostream” in the program.
(iv) iostream header file contains the definition of its member objects cin and cout.
(v) If iostream is not included in program, an error message will occur on cin and cout.

3. using namespace std;
(i) The line using namespace std; tells the compiler to use standard namespace.
(ii) Namespace collects identifiers used for class, object and variables.
(iii) They provide a method of preventing name conflicts in large projects.
(iv) It is a new concept introduced by the ANSI C++ standards committee.

4. int main ( )
(i) C++ program is a collection of functions and every program must have a main function.
(ii) The main( ) function is the starting point where all C++ programs begin their execution.
(iii) The executable statements should be inside the main( ) function.TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 17

The statements between the turly braces (Line number 5 to 8) are executable statements.

Question 52.
Explain the important steps for creating and executing a C++ program.
Answer:
The following four steps are followed for creating and executing a C++ program.
(i) Creating Source code: Creating includes typing and editing the valid C++ code as per the rules followed by the C++ Compiler.
(ii) Saving source code with extension .cpp: After typing, the source code should be saved with the extension .cpp
(iii) Compilation: This is an important step in constructing a program. In compilation, compiler links the library files with the source code and verifies each and every line of code.
(iv) Execution: This is the final step of construction of a C++ Program. In this stage, the object file becomes an executable file with extension .exe.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 18

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 53.
Explain the various formatting options available ¡n C++.
Answer:
The commonly used manipulators are endl, setw, setfill, setprecision and setf.
(i) endl – Inserts a new line and flushes the buffer (Flush means – clean)
(ii) ‘\n’ – Inserts only a new line.
(iii) setw ( ): setw manipulator sets the width of the field assigned for the output. The field width determines the minimum number of characters to be written in output.
Syntax:
setw(number of characters)
(iv) setfill ( ):This manipulator is usually used after setw. If the presented value does not entirely fil! the given width, then the specified character in the setfihl argument is used for filling the empty fields.
Syntax:
setfill (character);
Eg:
cout<<”\n H.R..A :“<<setw(10)
< (v) setprecision ( ):This is used to display numbers with fractions in specific number of digits.
Syntax: setprecision (number of digits);

Question 54.
Explain the different types of expression used in C++ with example.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 19

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 20

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 55.
Explain the types of conversion in detail.
Answer:
The process of converting one fundamental type into another is called as “Type Conversion”. C++ provides two types of conversions.
(i) Implicit type conversion
(ii) Explicit type conversion.

(i) Implicit type conversion:
This conversion is performed by the compiler automatically. So, implicit conversion is also called as “Automatic conversion”.
If the type of the operands differ, the compiler converts “smaller” type to “wider” type which is called “type promotion”.
Eg:
#include
using namespace std;
int main( )
{
int a=6;
float b=3.14;
cout<< a+b;
}
In the above program, operand a is an int type and b is a float type. During the execution of the program, int is converted into a float, because a float is wider than int.

(ii) Explicit type conversion:
It is used to convert from one data type to another specific data type by the programmer. It is called as “type casting”.
Syntax:
(type-name) expression;
Where type-name is a valid C++ data type to which the conversion is to be performed.
Eg:
#include
using namespace std;
int main( )
{
float varf=78.685;
cout<<(int) varf;
In the above program, variable varf is declared as a float with an initial value 78.685. The value of varf is explicitly converted to an mt type in cout statement. Thus, the final output will be 78.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 56.
Write C++ programs to interchange the values of two variables.
(i) Using with third variable
(ii) Using without third variable
Answer:
(i) Using with third variable.
#include
using namespace std;
int main ( )
int a,b,temp;
cout<<“\n Enter 1st number:”; cin>>a;
cout<<“\n Enter 2nd number:”; cin>>b;
cout<<“Before swapping: First number: “<<a<<“Second number :”<<b;
temp a;
a = b;
b = temp;
cout<<“\n After swapping:
First number: “<<a<<“Second number: “<<b;
return 0;
}
Output:
Enter 1st number : 20
Enter 2nd number: 50
Before swapping:
First number : 20
second number: 50
After swapping:
First number : 50
second number: 20

(ii) Using without third variable:
#inciude
using namespace std;
int, main ( )
{
int a,b;
cout<<“\n Enter two numbers:”; cin>>a>>b; .
a = a+b; .
b = a-b;
a = a-b;
cout<<“\n After swapping numbers
are:”;
cout<<a<<” “<<b;
return 0;
}
Output:
Enter 1st number : 90
Enter. 2nd number: 100
Before swapping: First number: 90
second number: 100
After, swapping: First number:100
second number: 90

Question 57.
Write C++ program to do the following:
(i) To find the perimeter and area of a quadrant.
(ii) To find the area of triangle.
(iii) To convert the temperature from Celsius to Fahrenheit.
Answer:
(i) Perimeter = 0.57πr + 2r
Area = πr2 ÷ 4
Program:
#include
using namespace std;
int main( )
{
float Peri, Area, r;
eout<<“Enter the value of r:”; cin>>r;
Peri = 0.5*3.14*r+2*r;
Area = 3.14*r*r/4;
cout<<“The perimeter of a , quadrant: “<<peri;
cout<<“\n The area of a quadrant: “<<area; return 0;
}
Output:
Enter the value of r: 7
The perimeter of a quadrant: 24.99
The area of a quadrant: 38.465

(ii) (area – sqrt(s*(s-a)*(s-b)*(s-c))
Where s= (a+b+c)/2
Program:
#include
#include
using namespace std;
int main( )
{
float a,b, c, s, area;
cout<<“Enter three sides of a triangle:”; cin>>a>>b>>c;
s=(a+b+c)/2
area = sqrt(s*((s-a)*(s-b)*(s-c));
cout<<“Area of triangle is:”<<area;
return 0;
}
Output:
Enter three sides of a triangle:5 8 10
Area of triangle is 19.81

(iii) Program:
#include
using namespace std;
int main( )
{
float f,c;
cout<<“Enter the temperature in celsius\n”; cin>>c;
f = (9.a/5.0)*c+32
cout<<c<<“centigrade is equal to”<<f<<“fahrenheit”;
return 0;
}
Output:
Enter the temperature in celsius 36 36 centigrade is equal to 96.8 Fahrenheit

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 58.
Write a C++ to find the total and percentage of marks you secured Irani 10th Standard Public Exam. Display all the marks one-by- one along with total and percentage. Apply formatting functions.
Answer:
#include
#include
using namespacestd;
int main( )
{
int m1, m2, m3, m4, m5, tot;
float per;
char name[30]; .
cout<<“\n Enter Name:”;
cin»name;
cout<<“\n Enter Tamil Mark:”; cin>>m1;
cout<<“\n Enter English Mark:”; cin>>m2;
cout<<“\n Enter Maths Mark:”; cin>>m3;
cout<<“\n Enter Science Mark:”; cin>>m4;
cout<<“\n Enter Social science Mark:”; cin>>m5;
Tot = m1 + m2 + m3 + m4 + m5;
Per = tot/5;
cout< setw(10)<< name<<endl:
cout< setw (10) <<ml«endl ;
cout«setw (25)<<“English:”
setw (10)<<m2<<endl;
cout< setw(10)<<m3< cout<<setw(25)<<“Science:”
setw(10)<<m4<<endl;
cout< setw (10)<<m5< cout«setw (25)<<“Total: ”
setw (10) <<tot<<endl;
cout< setw(10)<<per<<endl;
}
Output:
Enter Name : Kavitha
Enter Tamil Mark : 90
Enter English Mark : 86
Enter Maths Mark : 100
Enter Science Mark : 91
Enter Social science Mark: 87
Name : Kavitha
Tamil : 90
English : 86
Maths : 100
Science : 91
Social science : 87
Total : 454
Percentage : 90.8

Question 59.
What is meant by literals? How many types of integer literals available in C++?
Answer:
Literals are data items whose values do not change during the execution of a program.
There are three types of integer literals available in C++.
(i) Decimal
(ii) Octal
(iii) Hexadecimal.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 60.
What kind of constants are following?
(i) 26
(ii) 015
(iii) OxF
(iv) 014.9
Answer:
(i) 26 = Integer constant
(ii) 015 = Octal constant
(iii) OxF = Hexadecimal constant
(iv) 014.9 = Decimal constant

Question 61.
What is character constant in C++?
Answer:
Any valid single character enclosed within single quotes is called a character constant. In C++, a character constant must contain one character and must be enclosed within a single quote.
Valid character constants: ‘A’, ‘2’, *$’
Invalid character constants : “A”

Question 62.
How are non-graphic characters represented in C++?
Answer:
The non-graphical characters are represented are using escape sequences. An escape sequence is represented by a backslash followed by one or two characters.
Eg: \a, \b, \f, \0, \On

Question 63.
Write the following real constants into exponent form:
(i) 32.179
(ii) 8.124
(iii) 0.00007
Answer:
(i) 32.179 = 0.32179 × 102 = 0.32179E2
(ii) 8.124 = 0.8124 × 101 = 0.8124E1
(iii) 0.00007 = 0.7 × 10-4 = 0.7E – 4

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 64.
Write the following real constants into fractional form:
(i) 0.23E4
(ii) 0.517E – 3
(iii) 0.5E – 5
Answer:
(i) 0.23E4 = 0.23 × 104 = 2300.0
(ii) 0.517E – 3 = 0.517 × 10-3 = 0.000517
(iii) 0.5E – 5 = 0.5 × 10-5 = 0.000005

Question 65.
What is the significance of null (\0) character in a string?
Answer:
By default, string literals are automatically added with a special character ‘\0’ (Null) at the end.

Question 66.
What is use of operators?
Answer:
The symbols which are used to do mathematical or logical operations are called as “Operators”; The data items or values that the operators act upon are called as “Operands”.

Question 67.
What are binary operators? Give examples arithmetic binary operators.
Answer:
Operators that required two operands are called binary operators.
Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 21

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 68.
What does the modulus operator % do?
Answer:
Modulus operator is used to find the remainder of a division.
Eg: 10%3 = 1 (remainder of the division)

Question 69.
What will be the result of 8.5 % 2?
Answer:
0.

Question 70.
Assume that R starts with value 35. What will be the value of S from the following expression? S – (R- -)+(++R)
Answer:
R = 35
S = 35+36
S = 71

Question 71.
What will be the value of j = – k + 2k. if k is 20 initially ?
Answer:
k = 20, –k = k – 1 = 20 – 1 = 19
j = –k+2k, Now k = 19
= 19 + 2*19
= 19 + 38
= -57

Question 72.
What will be the value of p = p * ++j where j is 22 and p = 3 initially?
Answer:
p = p*++j
p = 3*23
p = 69

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 73.
Give that i = 8, j = 10, k = 8, What will be result of the following expressions?
(i) i < k
(ii) i < j
(iii) i > = k
(iv) i = = j
(v) j I = k
Answer:
(i) i < k = 0
(ii) i < j = 1
(iii) i >= k = 1
(iv) i = = j = 0
(v) j! = k = 1
[Hint ∵ 0 (false) 1 (true)]

Question 74.
What will be the order of evaluation for the following expressions?
(i) i + 3 >= j – 9
(ii) a +10 < p – 3 + 2q
Answer:
(i) Step 1: i + 3
Step 2: j – 9
Step 3: i + 3 >= j – 9

(ii) Step 1: 2q
Step 2: a+10
Step 3: p – 3
Step 4: a + 10 < p – 3 + 2q

Question 75.
Write an expression involving a logical operator to test, if marks are 75 and grade is ‘A’.
Answer:
((Mark >= 75) &&(grade = = ‘A’))

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 76.
What do you mean by fundamental data types?
Answer:
The predefined data types available with C++ are called the Fundamental (atomic) data types. There are five fundamental data types in C++: char, int, float, double and void.

Question 77.
The data type char is used to represent characters, then why is it often termed as an integer type?
Answer:
(i) All the characters are represented in memory by the associated as ASCII codes. So character data type is often said to be an integer type.
(ii) If a variable is declared as char, C++ allows storing either a character or an integer value.

Question 78.
What is the advantage of floating point numbers over integers?
Answer:
(i) They can represent values between the integers.
(ii) They can represent a much greater range of values.

Question 79.
The data type double is another floating point type. Then why is it treated as a distinct data type?
Answer:
The double data type is for double precision floating point numbers, (precision means significant numbers after decimal point). The double is also used for handling floating point numbers. But, this type occupies double the space than float type. This means, more fractions can be accommodated in double than in float type. The double is larger and slower than type float. The double is used in a similar way as that of float data type.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 80.
What is the use of void data type?
Answer:
The literal meaning for void is ‘empty space’.
(i) In C++, the void data type specifies an empty set of values.
(ii) It is used as a return type for functions that do not return any value.

Question 81.
What is meant by type conversion?
Answer:
The process of converting one fundamental type into another is called as “Type Conversion”.

Question 82.
How implicit conversion different from explicit conversion?
Answer:
Implicit type conversion is a conversion performed by the compiler automatically, where as explicit conversion is done by programmer.

Question 83.
What is difference between endl and \n?
Answer:
endl – Inserts a new line and flushes the buffer.
\n – Inserts only a new line.

Question 84.
What is the use of references?
Answer:
A reference provides an alias for a previously defined variable. Declaration of a reference consists of base type and an & (ampersand) symbol; reference variable name is assigned value of a previously declared variable.
Syntax: <& reference_variable> =

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 85.
What is the use of setprecision ( ) ?
Answer:
It is used to display numbers with fractions in specific number of digits.
Syntax: setprecision (number of digits);

Question 86.
What is meant by a token? Name the token available in C++.
Answer:
The smallest individual unit in a program is known as a token or a lexical unit. The tokens are available in C++ are:
(i) Keywords
(ii) Literals
(iii) Punctuators
(iv) Identifiers
(v) Operators.

Question 87.
What are keywords? Can keywords be used as identifiers?
Answer:
Keywords are the reserved words which convey specific meaning to the C++ compiler. No, keywords cannot be used as identifiers.

Question 88.
The following constants are of which type?
(i) 39
(ii) 032
(iii) OXCAFE
(iv) 04.14
Answer:
(i) 39 = Integer
(ii) 032 = Octal
(iii) OXCAFE – Hexadecimal
(iv) 04.14 = Decimal

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 89.
Write the following real constants into the exponent form:
(i) 23.197
(ii) 7.214
(iii) 0.00005
(iv) 0.319
Answer:
(i) 23.197 = 0.23197 × 102 = 0.23197E2
(ii) 7.214 = 0.7214 × 101 = 0.7214E1
(iii) 0.00005 = 0.5 × 104 = 0.5E – 4
(iv) 0.319 – 0.0319 × 101 = 0.0319E1.

Question 90.
Assume n = 10; what will be result of n>>2;?
Answer:
The equivalent binary value of 10 is (00001010)2

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 22

n>>2 = (00000010)2 = (2)10

Question 6.
Match the following:

A

 B

(i) Modulus  (a) Tokens
(ii) Separators  (b) Remainder of a division
(iii) Stream extraction  (c) Punctuators
(iv) Lexical units  (d) get form

Answer:
(i) – (b)
(ii) – (c)
(iii) – (d)
(iv) – (a)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 91.
Describe the differences between keywords and identifiers?
Answer:

Keywords

 Identifiers

Keywords are the reserved words which convey specific meaning to the C++ complier.  Identifiers are the user – defined names given to different parts,vof the C++ program.
They are essential elements to construct C++ program.  These are the fundamental building blocks of a program.
Eg: Auto, break, class etc.,  Eg: total- sales

Question 92.
Is C++ case sensitive? What is meant by the term “case sensitive”?
Answer:
Yes, C++ is a case sensitive. So all the keywords must be in lower case. It treats upper and lower case characters differently. Eg: int, break, auto etc.

Question 93.
Differentiate “=” and “== “.
Answer:

=

 ==

It is an assignment operator. It is an equal to operator.
It is used to assign the value of variable or expression which is on the left hand side of an assignment statement. It is used to compare value of both left and right operands.
Eg: A = 32 Eg: a = = b

Question 94.
Assume a = 10, b = 15; What will be the value of a^b?
Answer:
a = 10 binary equivalent = (00001010)2
b = 15 binary equivalent = (00001111)2

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 23

(a^b) = (00000101)2 = (5)10

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 95.
What is the difference between “Run time error” and “Syntax error”?
Answer:

Runtime Error

Syntax Error

A mntime error is that occurs during the execution of a program. It occurs because of some illegal operation that take place. Syntax error occurs when grammatical values of C++ are violated.
Eg: If a program tries to Open a file which does not exit, it results in a run time error Eg: cout<< “welcome to programming in C++”. As per grammatical rules of C++, every executable statement should terminate with a semicolon, but this statement does not end with a semicolon. So, C++ will throw an error.

Question 96.
What are the differences between “Logical error” and “Syntax error”?
Answer:

Logical error

Syntax error

A Program has not produced expected result even though the program is grammatically correct. Syntax errors occur when grammatical rules of C++ are violated.
It may be happened by wrong use of variable / operator / order of execution etc.,  Eg: If you type as follows, C++ will throw an error. cout<< “Welcome to Programming in C++”.
This means, program is grammatically correct, but it contains some logical error. So, Semantic error is also called as “Logic Error”. As per grammatical rules of C++, every executable statement should terminate with a semicolon. But, this statement does not end with a semicolon.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 97.
Write about Binary Operators used in C++.
Answer:
(i) Arithmetic operators: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 24

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 25

The above mentioned arithmetic operators are binary operators which requires minimum of two operands.

(ii) Relational Operators:
• Relational operators are used to determine the relationship between its operands.
• When the relational operators are applied on two operands, the result will be a Boolean value
i. e., 1 or 0 to represents True or False respectively. C++ provides six relational operators.
They are,

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 26

• In the above examples, the operand a is compared with b and depending on the relation, the result will be either 1 or 0. i.e., 1 for true, 0 for false.
• All six relational operators are binary operators.

(iii) Logical Operators:
• A logical operator is used to evaluate logical and relational expressions.
• The logical operators act upon the operands that are themselves called as logical expressions. C++ provides three logical operators.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 27

(iv) Bitwise Operators:
Bitwise operators work on each bit of data and perform bit-by-bit operation. In C++, there are,.three kinds of bitwise operators, which are:
(a) Logical bitwise operators
(b) Bitwise shift operators
(c) One’s compliment operators

(a) Logical bitwise operators:

&  Bitwise AND  (Binary AND)
1  Bitwise OR  (Binary OR)
A  Bitwise Exclusive OR  (Binary XOR)

• Bitwise AND (&) will return 1 (True) if both the operands are having the value 1 (True); Otherwise, it will return 0 (False)
• Bitwise OR (|) will return 1 (True) if any one of the operands is having a value 1 (True); It returns 0 (False) if both the operands are having the value 0 (False)
• Bitwise XOR (^) will return 1 (True) if only one of the operand is having a value 1 (True).If both are True or both are False, it will return 0 (False).
Truth table for bitwise operators (AND, OR, XOR)

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 28

Eg:
If a = 65, b = 15
Equivalent binary values of 65 = 0100 0001; 15 = 0000 1111

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 29

(b) The Bitwise shift operators:
There ate two bitwise shift operators in C++, Shift left (<<) and Shift right (>>).
• Shift left (<<) – The value of the left operand is moved to left by the number of bits specified by the right operand. Right operand should be an unsigned integer. • Shift right (>>) – The value of the left operand is moved to right by the number of bits specified by the right operand. Right operand should be an unsigned integer.
Eg:
If a = 15; Equivalent binary value of a is 0000 1111

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 30

(v) Assignment Operators:
• Assignment operator is used to assign a value to a variable which is on the left hand side of an assignment statement.
• = (equal to) is commonly used as the assignment operator in all computer programming languages.
• This operator copies the value at the right side of the operator to the left side variable. It is also a binary operator.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 31

C++ uses different types of assignment operators. They are called as Shorthand assignment operators.

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 32

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 33

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 98.
What are the types of Errors?
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 34

Question 99.
Assume a=15, b=20; What will be the result of the following operations?
(a) a&b,
(b) a | b,
(c) a^b,
(d) a>>3,
(e) (~b)
The binary equivalent of 15 is 00001111
The binary equivalent of 20 is 00010100
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 35

a&b = (00000100)2 = (4)10
a|b = (00011111)2 = (31)10
a^b = (00011011)2 = (27)10
a>>3 = (00000001)2 = (1)10
(~b) = (11101011)2 = (-21)10

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 100.
Write a short note on const keyword with an example.
Answer:
const is the keyword used to declare a constant, const keyword modifies / restricts the accessibility of a variable. So, it is known as Access modifier.
Eg:
int num =100;

Question 101.
What is the use of setw( ) format manipulator?
Answer:
setw manipulator sets the width of the field assigned for the output. The field width determines the minimum number of characters to be written in output.
Syntax: setw(number of characters)

Question 102.
Why is char often treated as integer data type?
Answer:
Character data type is often said to be an integer type, since all the characters are represented in memory by their associated ASCII Codes. If a variable is declared as char, C++ allows storing either a character or an integer value.

Question 103.
What is a reference variable? What is its use?
Answer:
A reference provides an alias for a previously defined variable. Declaration of a reference consists of base type and an & (ampersand) symbol; reference variable name is assigned the value of a previously declared variable.
Syntax:
<& reference_variable> =

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 104.
Consider the following C++ statement. Are they equivalent?
Answer:
char ch = 67;
char ch = ‘C’;
Yes, they are equivalent.

Question 105.
What is the difference between 56L and 56?
Answer:
56L instructs the compiler to store the given value as long and unsigned int.
56 stores the value in an int.

Question 106.
Determine which of the following are valid constant? And specify their type.
(i) 0.5
(ii) ‘Name’
(iii) ‘\t’
(iv) 27,822
Answer:

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 36

Question 107.
Suppose x and y are two double type variable that you want add as integer and assign to an integer variable. Construct a C++ statement for the doing so.
Answer:
double x,y;
int z = (int)x + int(y)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 108.
What will be the result of following if num = 6 initially.
(a) cout << num;
(b) cout <<(num==5); Output: (a) 6 (b) 0

Question 109.
Which of the following two statements are valid? Why? Also write their result.
Answer:
int a;
(i) a = 3,014;
(ii) a=(3,014);
(i) a = 3,014; Invalid
(ii) a = (3,014); Valid.

Question 110.
What are arithmetic operators in C++? Differentiate unary and binary arithmetic operators. Give example for each of them.
Answer:
Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

TN State Board 11th Computer Science Important Questions Chapter 9 Introduction to C++ 37

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

The above mentioned arithmetic operators are binary operators which requires minimum of two operands.

Question 111.
Evaluate x+= x + ++x; Let x=5;
Answer:
++x =x+1 =5+1=6 x =6 x+ = 6+6 x+=12 x =x+12 =6+12=18 x = 18

Question 112.
How relational operators and logical operators related to one another?
Answer:
Relational operators are used to determine the relationship between its operands and produce the Boolean result. Logical operators are used to combine the results of two or more comparison expressions that use relational operators. Logical operators don’t compare values they combine Boolean values and produce a Boolean result. Logical operators are: && (and), ||(or), !(not)

Question 113.
Evaluate the following C++ expressions where x, y, z are integers and m, n are floating point numbers. The value of x = 5, y = 4 and m=2.5;
(i) n = x + y / x;
(ii) z = m * x + y;
(iii)z= (x++) * m+x;
Answer:
(i) n = x+y/x; N = 5+4/5 N = 5+0 (the / symbol gives only the quotient) N = 5
(ii) z = m*x+y = 2.5*5+4 = 12.5+4 = 16.5 Z = 16 (z is declared as integer data type it ignores the fractional part)
(iii) z = (x++)*m+x; = 5 * 2.5+5 = 12.5+5 = 17.5 Z 17 (z is declared as integer data type it takes the integer part and ignores the fractional part).

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Choose the correct answer:

Question 1.
C++ was developed by:
(a) Charles Babbage
(b) Bjame Stroustrup
(c) Bill Gates
(d) Sundar Pichai
Answer:
(b) Bjame Stroustrup

Question 2.
C++ was developed in the year:
(a) 1960
(b) 1979
(c) 1985
(d) 1963
Answer:
(b) 1979

Question 3.
C++ supports both:
(a) procedural language
(b) object oriented programming
(c) both (a) and (b)
(d) none
Answer:
(c) both (a) and (b)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 4.
The name C++ was coined by:
(a) Rick Maseitti
(b) Charles Babbage
(c) Bill Gates
(d) Dennis Ritchie
Answer:
(a) Rick Maseitti

Question 5.
C++ was developed in Laboratory.
(a) T laboratory
(b) AT laboratory
(c) AT & T Bell laboratory
(d) None of the above
Answer:
(c) AT & T Bell laboratory

Question 6.
In ______ the name was change as C++ by Rick Maseitti.
(a) 1983
(b) 1966
(c) 1989
(d) 1994
Answer:
(a) 1983

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 7.
The latest standard version published in December 2017 as:
(a) ISO/ICE 14882:2017
(b) ISO/ICE 14883:2017
(c) ISO/ICE 14885:2017
(d) ICE/ISO 14882:2017
Answer:
(a) ISO/ICE 14882:2017

Question 8.
The first standardized version was published in the year:
(a) 1999
(b) 1986
(c) 1970
(d) 1998
Answer:
(d) 1998

Question 9.
_________ is a set of characters which are allowed to write a C++ program.
(a) character set
(b) number set
(c) symbols
(d) special characters
Answer:
(a) character set

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 10.
The smallest individual unit in a program is known as:
(a) character set
(b) symbols
(c) token
(d) keywords
Answer:
(c) token

Question 11.
_________ is also called as token.
(a) Logical element
(b) Lexical unit
(c) Logical units
(d) symbols
Answer:
(b) Lexical unit

Question 12.
__________ are the reserved works which convey specific meaning to the C++ compiler.
(a) Tokens
(b) Identifiers
(c) Constants
(d) Keywords
Answer:
(d) Keywords

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 13.
C++is:
(a) package
(b) software
(c) case sensitive
(d) non-case sensitive
Answer:
(c) case sensitive

Question 14.
Identify the invalid variable name:
(a) Num
(b) Num2
(c) _add
(d) 2 myfile
Answer:
(d) 2 myfile

Question 15.
__________ are data items whose values do not change during the execution of program.
(a) Literals
(b) This
(c) Identifiers
(d) Special characters
Answer:
(a) Literals

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 16.
Literals are also called as:
(a) identifiers
(b) character set
(c) constants
(d) string
Answer:
(c) constants

Question 17.
______ are whole numbers without any fraction.
(a) String
(b) Integers
(c) Decimal
(d) Keywords
Answer:
(b) Integers

Question 18.
In C++ there are _____ types of integer constants.
(a) two
(b) four
(c) five
(d) three
Answer:
(d) three

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 19.
Identify the Invalid decimal:
(a) 725
(b) -2T
(c) 4.56
(d) 7,500
Answer:
(d) 7,500

Question 20.
Any sequence of one or more octal values that begins with 0 is considered as an ________ constant.
(a) decimal
(b) octal
(c) binary
(d) hexadecimal
Answer:
(b) octal

Question 21.
Identify the invalid octal constant:
(a) 012
(b) -027
(c) +0231
(d) 0158
Answer:
(d) 0158

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 22.
Any sequence of one or more values that starts with ox or OX is considered as:
(a) octal
(b) binary
(c) hexadecimal
(d) decimal
Answer:
(c) hexadecimal

Question 23.
The suffix ________ added with any constant forces that to be represented as long constant.
(a) L or l
(b) I or i
(c) O or o
(d) X or x
Answer:
(a) L or l

Question 24.
The suffix _____ added with any constant forces that to be represented as unsigned constant respectively.
(a) U or u
(b) L or l
(c) O or o
(d) I or i
Answer:
(a) U or u

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 25.
Exponent form of real constant consists of a parts.
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(b) 2

Question 26.
Identify the invalid character constants:
(a) ‘A’
(b) ‘2’
(c) ‘$’
(d) “A”
Answer:
(d) “A”

Question 27.
ASCII was first developed and published in:
(a) 1964
(b) 1963
(c) 1965
(d) 1970
Answer:
(b) 1963

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 28.
An escape sequence is represented by __________ followed by one or two characters.
(a) double quotes
(b) single quote
(c) backslash
(d) forward slash
Answer:
(c) backslash

Question 29.
\t is a:
(a) vertical tab
(b) backslash
(c) backspace
(d) horizontal tab
Answer:
(d) horizontal tab

Question 30.
\r is a:
(a) alert bell
(b) form feed
(c) carriage return
(d) backslash
Answer:
(c) carriage return

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 31.
\n is a:
(a) new line
(b) carriage return
(c) form feed
(d) horizontal tab
Answer:
(a) new line

Question 32.
String literals are automatically added with a special character _________ at the end.
(a) ‘\0’
(b) ‘\n’
(c) ‘\f
(d) ‘\v’
Answer:
(a) ‘\0’

Question 33.
Identify the valid string literals:
(a) ‘welcome’
(b) ‘A’
(c) ‘1234’
(d) “welcome”
Answer:
(d) “welcome”

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 34.
The symbols which are used to do some mathematical or logical operations are called as:
(a) operands
(b) operators
(c) constants
(d) identifiers
Answer:
(b) operators

Question 35.
The data items or values that the operators act upon are called as:
(a) operands
(b) literals
(c) operators
(d) identifiers
Answer:
(a) operands

Question 36.
Unary operator requires operand.
(a) one
(b) two
(c) three
(d) four
Answer:
(a) one

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 37.
Binary operator requires ______ operand.
(a) one
(b) two
(c) three
(d) four
Answer:
(b) two

Question 38.
Ternary operator requires _______ operand.
(a) one
(b) two
(c) three
(d) four
Answer:
(c) three

Question 39.
If N1 = 10 and N2 = 20. Find the value of S where S = N1+++++N2. –
(a) 30
(b) 29
(c) 32
(d) 31
Answer:
(d) 31\

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 40.
In C++ there are _______ types of bitwise operators.
(a) 2
(b) 4
(c) 5
(d) 3
Answer:
(d) 3

Question 41.
There are ________ bitwise shift operators in C++.
(a) 2
(b) 3
(c) 4
(d) 6
Answer:
(a) 2

Question 42.
_______ operator is used to assign a value to a variable.
(a) Bitwise
(b) Logical
(c) Assignment
(d) Arithmetic
Answer:
(c) Assignment

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 43.
In C++ conditional operator is also called as operator.
(a) Unary
(b) Binary
(c) Ternary
(d) Logical
Answer:
(c) Ternary

Question 44.
_______ is a conditional operator.
(a) : :
(b) *
(c) &
(d) ?:
Answer:
(d) ?:

Question 45.
_________ is a address of operator.
(a) →
(b) &
(c) →*
(d) *
Answer:
(b) &

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 46.
______ is used for multiplication as well as for pointer to a variable.
(a) ::
(b) *
(c) &
(d) ?:
Answer:
(b) *

Question 47.
_______ are also called as separators.
(a) Punctuators
(b) Strings
(c) Constants
(d) Identifiers
Answer:
(a) Punctuators

Question 48.
______ are symbols, which are used as delimiters, while constructing a C++ program.
(a) Logical operators
(b) Binary operators
(c) Punctuators
(d) Arithmetic operators
Answer:
(c) Punctuators

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 49.
C++ provides the ________ operator to get input.
(a) >>
(b) <<
(c) >
(d) <
Answer:
(a) >>

Question 50.
The >> operator called as:
(a) Stream extraction
(b) Stream insertion
(c) Input operator
(d) Output operator
Answer:
(a) Stream extraction

Question 51.
Stream extraction operator is also called as _______ operator.
(a) put to
(b) get form
(c) set form
(d) set into
Answer:
(b) get form

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 52.
C++ provides __________ operator to perform in output operation.
(a) << (b) >>
(c) < (d) >
Answer:
(a) <<

Question 53.
The operator << is called the ______ operator.
(a) Stream insertion
(b) Stream extraction
(c) Expression
(d) Ternary
Answer:
(a) Stream insertion

Question 54.
// are considered as ________ statements.
(a) comment
(b) executable
(c) printable
(d) preprocessor
Answer:
(a) comment

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 55.
The symbol _________ is a directive for the preprocessor.
(a) $
(b) &
(c) ::
(d) #
Answer:
(d) #

Question 56.
______ provide a method of preventing name conflicts in large projects.
(a) iostream
(b) name space
(c) main ( )
(d) int
Answer:
(b) name space

Question 57.
The executable statements should be inside the _________ function.
(a) namespace
(b) size of
(c) int ( )
(d) main ( )
Answer:
(d) main ( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 58.
The object file has an extension:
(a) .ojb
(b) .ocb
(c) .obj
(d) .obf
Answer:
(c) .obj

Question 59.
______ makes it easy to create, compile and execute a C++ program.
(a) GUI
(b) Command prompt
(c) Operating system
(d) IDE
Answer:
(d) IDE

Question 60.
To create a source file ______ is used.
(a) Ctrl + N
(b) Ctrl + P
(c) Shift + N
(d) Shift + ctrl + N
Answer:
(a) Ctrl + N

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 61.
______ occur when grammatical rules of C++ are violated.
(a) Syntax errors
(b) Semantic errors
(c) Run-time errors
(d) Logical errors
Answer:
(a) Syntax errors

Question 62.
_________ error occurs when the program is grammatically correct, but it contains some logical error.
(a) Lexical
(b) Syntax
(c) Semantic
(d) Run-time
Answer:
(c) Semantic

Question 63. Every programming language has __________ fundamental elements.
(a) 3
(b) 2
(c) 4
(d) 5
Answer:
(b) 2

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 64.
In a programming language, fields are referred as:
(a) data
(b) records
(c) objects
(d) variables
Answer:
(d) variables

Question 65.
Values are referred to as:
(a) objects
(b) classes
(c) data
(d) variables
Answer:
(c) data

Question 66.
In C++ the data types are classified as __________ main categories.
(a) four
(b) three
(c) six
(d) five
Answer:
(b) three

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 67.
The _________ are the named memory locations to hold values of specific data types.
(a) objects
(b) functions
(c) variables
(d) class
Answer:
(c) variables

Question 68.
________ data types are predefined data types available with C++.
(a) basic
(b) fundamental
(c) derived
(d) user – defined
Answer:
(b) fundamental

Question 69.
There are _________ fundamentals data types in C++.
(a) three
(b) four
(c) five
(d) six
Answer:
(c) five

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 70.
The literal meaning for void is:
(a) half space
(b) empty space
(c) no space
(d) none of these
Answer:
(b) empty space

Question 71.
int data type has ____ bytes.
(a) 1
(b) 2
(c) 3
(d) 8
Answer:
(b) 2

Question 72.
double data type has _______ bytes.
(a) 1
(b) 2
(c) 4
(d) 8
Answer:
(d) 8

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 73.
char data type has _______ bytes.
(a) 1
(b) 2
(c) 5
(d) 8
Answer: (a) 1

Question 74.
float data type has ____ bytes.
(a) 4
(b) 3
(c) 2
(d) 8
Answer:
(a) 4

Question 75.
__________ can be used to modify the memory allocation of any fundamental data type.
(a) variables
(b) modifiers
(c) data type
(d) objects
Answer:
(b) modifiers

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 76.
Modifiers are also called as:
(a) qualifiers
(b) variables
(c) constants
(d) functions
Answer:
(a) qualifiers

Question 77.
There are ________ modifiers used in C++.
(a) three
(b) six
(c) four
(d) five
Answer:
(c) four

Question 78.
short int has the value range from:
(a) -32,768 to 32,767
(b) 32,767 to -32,768
(c) -32,678 to 33,676
(d) 32,678 to 33,676
Answer:
(a) -32,768 to 32,767

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 79.
long double has __________ bytes space in memory.
(a) 5
(b) 11
(c) 10
(d) 12
Answer:
(c) 10

Question 80.
1 byte = ______ bits.
(a) 4
(b) 2
(c) 6
(d) 8
Answer:
(d) 8

Question 81.
char data type has ________ byte.
(a) 2
(b) 1
(c) 3
(d) 4
Answer:
(b) 1

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 82.
__________ are user-defined names assigned to specific memory locations in which the values are stored.
(a) Variables
(b) Int
(c) Float
(d) Void
Answer:
(a) Variables

Question 83.
There are _____ values associated with a symbolic variable.
(a) one
(b) two
(c) three
(d) four
Answer:
(b) two

Question 84.
Declaration of more than one variable in a single statement is separated by using:
(a) :
(b) ,
(c) ;
(d) .
Answer:
(b) ,

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 85.
Assigning an initial value to a variable during its declaration is called as:
(a) execution
(b) declaration
(c) initialization
(d) compilation
Answer:
(c) initialization

Question 86.
A variable that can be initialized during the execution of a program is called:
(a) dynamic initialization
(b) static initialization
(c) compilation
(d) initialization
Answer:
(a) dynamic initialization

Question 87. _________ manipulator is a member of iostream header file.
(a) endl
(b) setw
(c) setprecision
(d) setf
Answer:
(a) endl

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 88.
__________ manipulator sets the width of the field.
(a) setw ( )
(b) set precision ( )
(c) setfill ( )
(d) setf ( )
Answer:
(a) setw ( )

Question 89.
________ is a combination of operators, constants and variables arranged as per the rules of C++.
(a) Expression
(b) Constant
(c) Keywords
(d) Identifiers types of expressions
Answer:
(a) Expression

Question 90.
There are _______ available in C++.
(a) three
(b) four
(c) six
(d) seven
Answer:
(d) seven

Question 91.
The process of converting one fundamental type into another is called as:
(a) type conversion
(b) float conversion
(c) compilation
(d) execution
Answer:
(a) type conversion

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 92.
C++ provides ______ types of conversion.
(a) two
(b) three
(c) six
(d) seven
Answer:
(a) two

Question 93.

(i) Arithmetic operation  (a) a*=5
(ii) Relational operation  (b) a+b
(iii) Unary operation  (c) a<=b
(iv) Assignment operation  (d) ++a

(a) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)
(b) (i) – (a); (ii) – (d); (iii) – (b); (iv) – (c)
(c) (i) – (b); (ii) – (c); (iii) – (d); (iv) – (a)
(d) (i) – (d); (ii) – (b); (iii) – (a); (iv) – (c)
Answer:
(c) (i) – (b); (ii) – (c); (iii) – (d); (iv) – (a)

Question 94.
Match the following:

(i) Address of  (a) ::
(ii) Indirection component selector  (b) *
(iii) Scope resolution  (c) &
(iv) Dereference  (d) →

(a) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)
(b) (i) – (d); (ii) – (c); (iii) – (b); (iv) – (a)
(c) (i) – (b); (ii) – (a); (iii) – (d); (iv) – (c)
(d) (i) – (d); (ii) – (c); (iii) – (a); (iv) – (b)
Answer:
(a) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 95.
Identify the correct statement:
(a) cin>x;
(b) cin>>x>>;
(c) cin>>x>>y;
(d) cin>>x<>x>>y;
Answer:
(c) cin>>x>>y;

Question 96.
Identify the incorrect statement:
(a) The operator « is called the “stream insertion” or “put to” operator
(b) Semantic error is also called as “Logic error”
(c) In C++ the source code should be saved with the extension .c
(d) Compilation translates the source code into machine readable object file with an extension.obj
Answer:
(c) In C++ the source code should be saved with the extension .c

Question 97.
Choose the odd man out:
(a) getch
(b) endl
(c) setw
(d) setf
Answer:
(a) getch

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 98.
Assertion (A):
Process of converting one fundamental type into another is called as “Type conversion”.
Reason (R):
An expression is a combination of operators, Constants and Variable.
(a) Both A and R are true and RJs the correct explanation for A. extension .obj
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(b) Both A and R are true, but R is not the correct explanation for A.

Question 99.
Who developed C++?
(a) Charles Babbage
(b) Bjame Stroustrup
(c) Bill Gates
(d) Sundar Pichai
Answer:
(b) Bjame Stroustrup

Question 100.
What was the original
(a) CPP
(b) Advanced C
(c) C with Classes
(d) Class with C
Answer:
(c) C with Classes

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 101.
Who coined C++?
(a) Rick Mascitti
(b) Rick Bjrane
(c) Bill Gates
(d) Dennis Ritchie
Answer:
(a) Rick Mascitti

Question 102.
The smallest individual unit in a program is:
(a) Program
(b) Algorithm
(c) Flowchart
(d) Tokens
Answer:
(d) Tokens

Question 103.
Which of the following operator is extraction operator of C++?
(a) >>
(b) <<
(c) <>
(d) ^^
Answer:
(a) >>

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 104.
Which of the following statements is not true?
(a) Keywords are the reserved words convey specific meaning to the C++ compiler.
(b) Reserved words or keywords can be used as an identifier name.
(c) An integer constant must have at least one digit without a decimal point.
(d) Exponent form of real constants consists of two parts.
Answer:
(b) Reserved words or keywords can be used as an identifier name.

Question 105.
Which of the following is a valid string literal?
(a) ‘A’
(b) ‘Welcome’
(c) 1232
(d) “1232”
Answer:
(d) “1232”

Question 106.
A program written in high level language is called as:
(a) Object code
(b) Source code
(c) Executable code
(d) All the above
Answer:
(b) Source code

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 107.
Assume a = 5, b = 6; what will be result of a&b?
(a) 4
(b) 5
(c) 1
(d) 0
Answer:
(a) 4

Question 108.
Which of the following is called as compile time operators?
(a) sizeof
(b) pointer
(c) virtual
(d) this
Answer:
(a) sizeof

Question 109.
How many categories of data types available in C++?
(a) 5
(b) 4
(c) 3
(d) 2
Answer:
(c) 3

Question 110.
Which of the following data types is not a fundamental type?
(a) designed
(b) int
(c) float
(d) char
Answer:
(a) designed

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 111.
What will be the result of following statement?
charch=‘B’;
cout<<(int) ch;
(a) B
(b) b
(c) 65
(d) 66
Answer:
(d) 66

Question 112.
Which of the character is used as suffix to indicate a floating point value?
(a) F
(b)C
(c) L
(d) D
Answer:
(a) F

Question 113.
How many bytes of memory allocates for the following variable declaration if you are using Dev C++? short int x;
(a) 2
(b) 4
(c) 6
(d) 8
Answer:
(a) 2

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 114.
What is the output of the following snippet?
char ch = ‘A’;
ch = ch + 1;
(a) B
(b) A1
(c) F
(d) 1A
Answer:
(a) B

Question 115.
Which of the following is not a data type modifier?
(a) signed
(b) int
(c) belong
(d) short
Answer:
(b) int

Question 116.
Which of the following operator returns the size of the data type?
(a) sizeof ( )
(b) int ( )
(c) long ( )
(d) double ( )
Answer:
(a) sizeof ( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 9 Introduction to C++

Question 117.
Which operator to be used to access reference of a variable?
(a) $
(b) #
(c) &
(d) \
Answer:
(c) &

Question 118.
This can be used as alternate to endl command:
(a) \t
(b) \b
(c) \0
(d) \n
Answer:
(d) \n

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion

TN State Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion

Question 1.
Define iteration.
Answer:
In iteration, the loop body is repeatedly executed as long as the loop condition is true. Each time the loop body is executed, the variables are updated. However, there is also a property of the variables which remains unchanged by the execution of the loop body.

Question 2.
Define Recursion.
Answer:
Recursion is an algorithm design technique, closely related to induction. It is similar to iteration, but more powerful. Using recursion, a problem can be solved with a given input, by solving the instances of the problem with a part of the input.

Question 3.
What is Base case.
Answer:
The problem size is small enough to be solved directly. Output the solution. There must be at least one base case.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 4.
Define recursive call.
Answer:
To solve a problem recursively, the solver reduces the problem to sub-problems and calls another instance of the solver, known as sub-solver, to solve the sub-problem. The input size to a sub-problem is smaller than the input size to the original problem. When the solver calls a sub-solver, it is known as recursive call.

Question 5.
Give the difference between Recursion and Iteration.
Answer:

Recursion

 Iteration

The statement in a body of function calls the function itself.  Allows the set of instructions to be executed repeatedly.
It is always applied to functions.  It is applied to iteration statements or “loops”.
It reduces the size of the code.  It makes the code longer.

Question 6.
If we execute the following assignment with, (p, c = 10, 9) after the assignment (u, v) = (11, 10) discover an invariant. What is the value of p – c before and after?
Answer:
— before : p, c = 10, 9
p, c := p + 1, c + 1
— after: p, c = 11, 10
before: p – c = 10 – 9 = 1
after: p – c = 11 – 10 = 1
We find that p – c = 1 is an invariant.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 7.
Show that p – c is an invariant of the assignment.
Answer:
p, c := p + 1, c + 1
Let P(p, c) = p – c. Then
P (p, c) [p, c := p + 1, c + 1]
= p – c [p, c := p + 1, c + 1]
= (p + 1) – (c + 1)
= p – c
= p(P, c)
Since (p – c) [p, c := p + 1, c + 1] = p – c, p – c is an invariant of the assignment p, c := p + 1, c+ 1.

Question 8.
There are 6 equally spaced trees and 6 sparrows sitting on these trees, one sparrow on each tree. If a sparrow flies from one tree to another, then at the same time another sparrow flies from its tree to some other tree the same distance away, but in the opposite direction. It is possible for all the sparrows to gather on one tree?
Answer:
Let us index the trees from 1 to 6. The index of a sparrow is, the index of the tree it is currently sitting on. A pair of sparrows flying can be modeled as an iterative step of a loop. When a sparrow at tree i flies to tree i + d, another sparrow at tree j flies to tree j – d. Thus, after each iterative step, the sum S of the indices of the sparrows remains invariant. Moreover, a loop invariant is true at the start and at the end of the loop.

At the start of the loop, the value of the invariant is or White White. It is illustrated in Figure and annotated in the algorithm below.

S = 1 + 2 + 3 + 4 + 5 + 6 = 21

When the loop ends, the loop invariant has the same value. However, when the loop ends, if all the sparrows were on the same tree, say k, then S = 6k.

S = 21,  loop invariant at the start of the loop
S = 6k,  loop invariant at end of the loop
6k = 21,  loop invariant has the same value at the start and the end 21 is a multiple of 6

It is not possible. 21 is not a multiple of 6. The desired final values of the sparrow indices is not possible with the loop invariant. Therefore, all the sparrows cannot gather on one tree.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 9.
You are given a jar full of two kinds of marbles, white and black, and asked to play this game. Randomly select two marbles from the jar. If they are the same color, throw them out, but put another black marble in (you may assume that you have an endless supply of spare marbles). If they are different colors, place the white one back into the jar and throw the black one away. If you knew the original numbers of white and black marbles, what is the color of the last marble in the jar?
Answer:

TN State Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion 3

The number of white and black marbles in the jar can be represented by two variables w and b. In each iterative step, b and w change depending on the colors of the two marbles taken out: Black Black, Black White or White White. It is illustrated in Figure and annotated in the algorithm below.

1 while at least two marbles in jar
2 b, w
3 take out any two marbles
4 case both are black– BB
5 throw away both the marbles
6 put a black marble back
7 — b = b’1-, w = w’, b+w = b’+w’1- 8 case both are white-W W
9 throw away both the marbles
10 put a black marble back
11 b = b’1+, w = w’2-, b+w = b’+w’1-
12 else –BW
13 throw away the black one
14 put the white one back
15 — b = b’1-, w = w’, b+w = b’+w’1-

For each case, how b, w and b+w change is shown in the algorithm, where b’ and w’ are values of the variables before taking out two marbles. Notice the way w changes. Either it does not change, or decreases by 2. This means that the parity of w, whether it is odd or even, does not change. The parity of w is invariant.

Suppose, at the start of the game, w is even. When the games ends, w is still even. Moreover, only one marble is left, w + b = 1.

1  w + b = 1  end of the loop
2  w = 0 or w = 1  from 1
3  w is even  loop invariant
4  w = 0  from 2, 3
5  b = 1  from 1, 4

Last marble must be black. Similarly, if at the start of the game, there is an odd number of whites, the last marble must be white.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 10.
Explain in detail the Recursion problem solving technique.
Answer:
To solve a problem recursively, the solver reduces the problem to sub-problems, and calls another instance of the solver, known as sub-solver, to solve the sub-problem. The input size to a sub-problem is smaller than the input size to the original problem. When the solver calls a sub-solver, it is known as recursive call.

The magic of recursion allows the solver to assume that the sub¬solver (recursive call) outputs the solution to the sub-problem. Then, from the solution to the sub-problem, the solver constructs the solution to the given problem.

As the sub-solvers go on reducing the problem into sub-problems of smaller sizes, eventually the sub-problem becomes small enough to be solved directly, without recursion. Therefore, a recursive solver has two cases:
(i) Base case:
The problem size is small enough to be solved directly. Output the solution. There must be at least one base case.

(ii) Recursion step:
The problem size is not small enough. Deconstruct the problem into a sub-problem, strictly smaller in size than the given problem. Call a sub solver to solve the sub-problem. Assume that the sub-solver outputs the solution to the sub-problem. Construct the solution to the given problem.
This outline of recursive problem solving technique is shown below.
solver (input)
if input is small enough
construct solution
else
find sub_problems of reduced input solutions to sub_problems = solver
for each sub_problem construct solution to the problem from solutions to the sub_problems

Whenever a problem is solved using recursion, these two cases have to be ensured. In the recursion step, the size of the input to the recursive call is strictly smaller than the size of the given input and there is at least one base case.

Question 11.
What is an invariant?
Answer:
An invariant is a condition that can be relied upon to be true during execution of a program or during some portion of it. It is a logical assertion that is held to always be true during a certain phase of execution.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 12.
Define a loop invariant.
Answer:
A loop invariant is a condition that is necessarily true immediately before and immediately after each iteration of a loop.

Question 13.
Does testing the loop condition affect the loop invariant? Why?
Answer:
No. It does not affect the loop invariant.

  1. at the start of the loop (just before the loop)
  2. at the start of each iteration (before loop body)
  3. at the end of each iteration (after loop body)
  4. at the end of the loop (just after the loop)

Question 14.
What is the relationship between loop invariant, loop condition and the input – output recursively?
Answer:
(i) Establish the loop invariant at the start of the loop.
(ii) The loop body should so update the variables as to progress toward the end and maintain the loop invariant, at the same time.
(iii) When the loop ends, the termination condition and the loop invariant should establish the input-output relation.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 15.
What is recursive problem solving?
Answer:
Each solver should test the size of the input. If the size is small enough, the solver should output the solution to the problem directly. If the size is not small enough, the solver should reduce the size of the input and call a sub-solver to solve the problem with the reduced input.

Question 16.
Define factorial of a natural number recursively.
Answer:
The factorial of a natural number defined recursively as the base case can be taken as the factorial of the number 0 or 1, both of which are 1. The factorial of some number n is that number multiplied by the factorial of (n -1).

Question 17.
There are 7 tumblers on a table, all standing upside down. You are allowed to turn any 2 tumblers simultaneously in one move. Is it possible to reach a situation when all the tumblers are right side up? (Hint: The parity ‘of the number of upside down tumblers is invariant.)Answer:
(i) u is the number of tumblers upside down 3 cases.
(ii) 1 turn two tumblers the right way up (w: = u + 2)
(iii) 2 turn two tumblers the wrong way up (u: = u- 2)
(iv) 3 turn one the right way up and the other the wrong way up (u: = u + 1 – 1)
Answer:
The invariant of these assignments.
(i) Parity is a Boolean value (true or false)
(ii) True if (0, 2, 4, 6 ….)
(iii) False if (1, 3, 5, 7….)
(iv) Notation even u
(v) Invariant of u: – u + 2
(vi) Invariant of u: = u – 2
(vii) Even u is an invariant of the problem-
(viii) No matter how many times we turn over pairs of tumbler, the value is even. So It is not possible to reach the situation when all the tumblers are right side up.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 18.
A knockout tournament is a series of games. Two players compete in each game; the loser is knocked out (i.e. does not play any more), the winner carries on. The winner of the tournament is the player that is left after all other players have been knocked out. Suppose there are 1234 players in a tournament. How many games are played before the tournament winner is decided?
Answer:
Let p be no. of players
Let g be no. of games
initially p = 1234, g = 0
p, g: = p-l,g + l
p + g is invariant
finally p = 1, g = 1233.

Question 19.
King Vikramaditya has two magic swords. With one, he can cut off 19 heads of a dragon, but after that the dragon grows 13 heads. With the other sword, he can cut off 7 heads, but 22 new heads grow. If all heads are cut off, the dragon dies. If the dragon has originally 1000 heads, can it ever die? (Hint:The number of heads mod 3 is invariant.)
Answer:
Sword 1 cuts 19 heads but grows 13 new heads.
So (19 -13) = 6 = 0 (mod 3)
Sword 2 cuts 7 heads but grows 22 new heads.
So (22 – 7) = 15 = 0 (mod 3)
We note (19 – 13) = (22 – 7) = 0 (mod 3)
The magic swords can never change the number of heads of the dragon mod 3.
Since we start at 1000 = 1 (mod 3) we can never get to 0. The dragon lives.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 20.
Assume an 8 × 8 chessboard with the usual coloring. “Recoloring” operation changes the color of all squares of a row or a column. You can recolor re-peatedly. The goal is to attain just one black square. Show that you cannot achieve the goal. (Hint: If a row or column has b black squares, it changes by (|8 – b) – b|).
Answer:
We start with a normal coloured chess board with number of black squares B = 32 and number of white squares W = 32.
So W – B = 0 which is divisible by 4 and W + B = 64 W – B = 0 mod 4.
Whenever we change the colours of a row or column, we change the colour of 8 squares. Let this row (or column) have W white squares + b black squares w + b = 8 squares. If this operation B increases by 2n, then W decreases by 2n so that W + B = 64 but B – W will change by 4n and if will remain divisible by 4.
W – B = 0 mod 4.
After every operation ‘B – W mod 4” can have no other values.
But the required state has 63 white squares and 1 black square, so it requires.
W – B = 63 – 1 = 62 = 2 mod 4. which is impossible.

Question 21.
Power can also be defined recursively as

TN State Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion 4

Construct a recursive algorithm using this definition. How many multiplications are needed to calculate a 10?
Answer:
power (a, n)
— inputs : n is an integer; n > 0
–outputs: an
if n = 0–base case
1
else if n is odd then
a × power (a, n – 1)
else
power (a, n/2) × power (a, n/2)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 22.
A single-square-covered board is a board of 2n × 2n squares in which one square is covered with a single square tile. Show that it is possible to cover this board with triominoes without overlap.
Answer:
The size of the problem is n (board of size 2n × 2n). We can solve the problem by recursion. The base case is n = 1. It is a 2 × 2 single-covered board. We can cover it with one triominoe and solve the problem. In the recursion step, divide the single-covered board of size 2n × 2n into 4 sub-boards, each of size 2n – 1 × 2n – 1, by drawing horizontal and vertical lines through the centre of the board. Place atriominoe at the centre of the entire board so as to not cover the single- covered sub-board, as shown in the left-most board of figure. Now, we have four single-covered boards, each of size 2n – 1 × 2n – 1.

TN State Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion 5

TN State Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion 6

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Choose the correct answer:

Question 1.
In _________ the loop body is repeatedly executed as long as the loop condition is true.
(a) iteration
(b) recursion
(c) function
(d) statement
Answer:
(a) iteration

Question 2.
________ is a method call to the same method.
(a) Algorithm
(b) Recursion
(c) Function
(d) Loop
Answer:
(b) Recursion

Question 3.
Who coined the phrase “structured programming”?
(a) Charles Babbage
(b) Douglas Engelbart
(c) George Boole
(d) Dijkstra
Answer:
(d) Dijkstra

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 4.
Suppose u, v = 20, 15 before the assignment what are the values of u and v after the assignment statement, u, v := u + 5, v – 5
(a) u, v = 10, 25
(b) u, v = 20, 10
(c) u, v = 25, 10
(d) u, v = 25, 5
Answer:
(c) u, v = 25, 10

Question 5.
The loop invariant is true in ______ crucial points in a loop.
(a) two
(b) three
(c) four
(d) five
Answer:
(c) four

Question 6.
There must be atleast _____ base case.
(a) one
(b) two
(c) three
(d) four
Answer:
(a) one

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 7.
Who was one of the most influential pioneers of computing science?
(a) E.W. Dijkstra
(b) Douglas Engelbart
(c) George Boole
(d) G Polya
Answer:
(a) E.W. Dijkstra

Question 8.
A loop invariant need not be true:
(a) at the start of the loop.
(b) at the start of each iteration
(c) at the end of each iteration
(d) at the start of the algorithm
Answer:
(d) at the start of the algorithm

Question 9.
We wish to cover a chessboard with dominoes, the number of black squares and the number of white squares covered by dominoes, respectively, placing a domino can be modeled by:
(a) b := b + 2
(b) w := w + 2
(c) b, w := bl+, wl+
(d) b:= w
Answer:
(c) b, w := bl+, wl+

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 10.
If m × a + n × b is an invariant for the assignment a, b : = a + 8, b + 7, the values of m and n are:
(a) m = 8, n = 7
(b) m = 7, n = – 8
(c) m = 7, n = 8
(d) m = 8, n = -7
Answer:
(b) m = 7, n = – 8

Question 11.
Which of the following is not an invariant of the assignment?
m, n := m+2, n+3
(a) m mod 2
(b) n mod 3
(c) 3 × m – 2 × n
(d) 2 × m – 3 × n
Answer:
(c) 3 × m – 2 × n

Question 12.
If Fibonacci number is defined recursively as:

TN State Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion 1

to evaluate F(4), how many times F( ) is applied?
(a) 3
(b) 4
(c) 8
(d) 9
Answer:
(b) 4

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 8 Iteration and Recursion

Question 13.
Using this recursive definition

TN State Board 11th Computer Science Important Questions Chapter 8 Iteration and Recursion 2

how many multiplications are needed to calculate a10?
(a) 11
(b) 10
(c) 9
(d) 8
Answer:
(b) 10

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition

Question 1.
What is Pseudo code?
Answer:
Pseudo code is inbetween English and high level computer languages. In English, the sentences may be long and may not be precise. In computer languages, the syntax has to be followed meticulously. If these two irritants are removed then we have the Pseudo code.

Question 2.
What is flow chart?
Answer:

  1. Flowchart is a diagrammatic notation for representing algorithms.
  2. A flowchart is a collection of boxes containing statements and conditions which are connected by arrows showing the order in which the boxes are to be executed.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 3.
Write the advantages of flow chart.
Answer:

  1. They are precise. They represent our thoughts exactly.
  2. It is easy to understand small flow charts.

Question 4.
Write the disadvantages of flow chart.
Answer:

  1. Flowcharts are less compact than representation of algorithms in programming language or pseudo code.
  2. They obscure the basic hierarchical structure of the algorithms.
  3. Alternative statements and loops are disciplined control flow structures. Flowcharts do not restrict us to disciplined control flow structures.

Question 5.
What are the three important control flow statements.
Answer:
There are three important control flow statements:

  1. Sequential
  2. Alternative
  3. Iterative.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 6.
Define sequential statement.
Answer:
A sequential statement is composed in the sequence are executed one after another, in the same order as they are written in the algorithm, and the control flow is said to be sequential. Let SI and S2 be statements. A sequential statement composed of S1 and S2 is written as

S1
S2

Question 7.
Define compound statement.
Answer:
Statements may be composed of other statements, leading to a hierarchical structure of algorithms. Statements composed of other statements are known as compound statements.

Question 8.
Give the notations for algorithms.
Answer:
We need a notation to represent algorithms. There are mainly three different notations for representing algorithms.

  1. A programming language is a notation for expressing algorithms to be executed by computers.
  2. Pseudo code is a notation similar to programming languages. Algorithms expressed in pseudo-code are not intended to be executed by computers, but for communication among people.
  3. Flowchart is a diagrammatic notation for representing algorithms. They give a visual intuition of the flow of control, when the algorithm is executed.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 9.
Write short notes on variant of alternative statement.
Answer:
Some times we need to execute a statement only if a condition is true and do nothing if the condition is false. This is equivalent to the alternative statement in which the else- clause is empty. This variant of alternative statement is called a conditional statement. If C is a condition and S is a statement, then
if C
S
is a statement, called a conditional statement, that describes the following action:
(i) Test whether C is true or false.
(ii) If C is true then do S; otherwise do nothing.
The conditional control flow, is depicted in the flowchart of Figure

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 8

Question 10.
Explain the process of iterative statement.
Answer:
An iterative process executes the same action repeatedly, subject to a condition C. If C is a condition and S is a statement, then while C
S
is a statement, called an iterative statement, that describes the following action:
(i) Test whether C is true or false.
(ii) If C is true, then do S and go back to step 1; otherwise do nothing.

The iterative statement is commonly known as a loop. These two steps, testing C and executing S, are repeated until C becomes false. When C becomes false, the loop ends and the control flows to the statement next to the iterative statement. The condition C and the statement S are called the loop condition and the loop body, respectively. Testing the loop condition and executing the loop body once is called an iteration. Now C is known as the termination condition.

Iterative control flow is depicted in the flowchart of Figure. Condition C has two outgoing arrows, true and false. The true arrow points to S box. If C is true, S box is executed and control flows back to C box. The false arrow points to the box after the iterative statement (dotted box). If C is false, the loop ends and the control flows to the next box after the loop.

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 9

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 11.
Write an algorithm to compare two numbers and produces the result as
compare(a, b) = {-1 if a < b, 0 if a = b, 1 if a > b}
Answer:
1. case a < b
2. result :=-1
3. case a = b
4. result := 0
5. else– a > b
6. result: = 1

Question 12.
Describe the action of the alternative statement with an example.
Answer:
A condition is a phrase that describes a test of the state. If C is a condition and both S1 and S2 are statements, then
if C
S1
else
S2
is a statement, called an alternative statement, that describes the following action:
(i) Test whether C is true or false.
(ii) If C is true, then do S1; otherwise do S2.

In pseudo code, the two alternatives S1 and S2 are indicated by indenting them from the keywords if and else, respectively. Alternative control flow is depicted in the flowchart of Figure. Condition C has two outgoing arrows, labeled true and false. The true arrow points to the SI box. The false arrow points to S2 box. outgoing arrows of SI and S2 point to the same box, the box after the alternative statement.

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 10

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 13.
Write the specification and algorithm to find minimum of two numbers.
Answer:
The specification of algorithm minimum is
— minimum(a, b)
— input s : a , b
— outputs: result = a↓b
Algorithm minimum can be defined as
1. minimum(a, b)
2. — a, b
3. if a < b
4. result: = a
5. else
6. result = b
7. — result = a↓b

Question 14.
Write the characteristics of algorithm.
Answer:
A well defined algorithm has the five basic characteristic as follows.
(i) Input:
Algorithm starts with procedural steps to accept input data. The algorithm must accept one or more data to be processed.

(ii) Definite:
Each operational step or operation must be definite (i.e.) each and every instruction must clearly specify that what should be done.

(iii) Effective: Each operational step can atleast in principle is carried out by a person using a paper and pencil in a . minimum number of times.

(iv)Terminate:
After some minimum number of operation algorithm must come to an end.

(v) Output:
An algorithm is written to solve the problem, therefore it must produce one or more computed.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 15.
Draw a flow chart to estimate the volume of a box using its length, breadth and height.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 11

Question 16.
The state changes for the goat, grass and wolf problem as solved in Example 6.2 (Textbook Page No. 117) are shown in Figure 7.13. The values of farmer, goat, grass and wolf are denoted by -4tuples such as LLLL. Write a sequence of state changes is possible from LLLL to RRRR. Find it.
Answer:
1. – farmer, goat, grass, wolf = L, L, L, L
2. farmer, goat := R, R
3. — farmer, goat, grass, wolf = R, R, L, L
4. farmer := L
5. farmer, goat, grass, wolf = L, R, L, L
6. farmer, grass := R, R
7. — farmer, goat, grass, wolf = R, R, R, L
8. farmer, goat := L, L
9. — farmer, goat, grass, wolf = L, L, R, L
10. farmer, wolf := R, R
11. — farmer, goat, grass, wolf = R, L, R, R
12. farmer: = L
13. – farmer, goat, grass, wolf = L, L, R, R
14. farmer, goat: = R, R
15. — farmer, goat, grass, wolf = R, R, R, R

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 17.
Draw a flow chart for integer division.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 12

Question 18.
Draw the different types of boxes used in the flow chart. Explain each one of its roles.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 13

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 14

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 19.
On the island of chrome land there are three different types of chameleons: red chameleons, green chameleons and blue chameleons whenever two chameleons of different colours meet they both change color to the third colour. In the end, all should display the same colour.
Answer:
Let us represent the number of chameleons of each type by variables a, b and c, and their initial values by A, B and C, respectively. Let a – b be the input property. The input-output relation is a = b = 0 and c = A+B+C. Let us name the algorithm monochromatize. The algorithm can be specified as
monochromatize(a, b, c)
– inputs: a=A, b=B, c=C, a=b
— outputs: a = b = 0 , c = A+B+C
In each iterative step, two chameleons of the two types (equal in number) meet and change, their colors to the third one. Eg: if A, B, C = 4, 4, 6, then the series of meetings will result in

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 15

In each meeting, a and b each decreases by 1 and c increases by 2. The solution can be expressed as an iterative algorithm. monochromatize(a, b, c)
— inputs: a=A, b=B, c=C, a=b
— outputs: a = b = 0, c = A + B + C
while a > 0
a, b, c:= a – 1; b – 1; c + 2
The algorithm is depicted in the flowchart of Figure.

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 16

Question 20.
Draw a flow chart to eat breakfast.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 17

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 21.
Using function minimum(a, b) define a function minimum 3(a, b, c) to output the minimum of three numbers a, b, and c.
Answer:
The specification of an algorithm minimum is minimum (a, b, c)
— inputs : (a, b, c)
— outputs: a↓b↓c
Algorithm minimum can be defined as
1. minimum (a, b, c)
2. -a, b, c
3. x = a
4. if b < x then
5. x = b
6. else
7. if c < x then
8. x = c
9. x = a↓b↓ c.

Question 22.
Draw a flow chart to read a number between 0 and 3 and write it in words.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 18

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 23.
Distinguish between a condition and a statement.
Answer:

Condition

 Statement

The conditions are specified by a set of conditional statements having the boolean expressions which are evaluated to a boolean value true or false.  A statement is a command given to the computer that instructs the computer to take a specific action. A computer program is made up of a series of statements.

Question 24.
Draw a flowchart for conditional statement.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 19

Question 25.
Both conditional statement and iterative statement have a condition and a statement. How do they differ?
Answer:
The conditional statement is executed only if the condition is true. Otherwise, nothing is done. Whereas the iterative statement repeatedly evaluates a condition and executes a statement as long as the condition is true.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 26.
What is the difference between an algorithm and a program?
Answer:

Algorithm

 Program

An algorithm is a list of steps, typically written in some human language, that explains how to perform a specific task.  A program is a list of instructions that tells a computer exactly what to do from step to step.

Question 27.
Why is function an abstraction?
Answer:
After an algorithmic problem is decomposed into subproblems, we can abstract the j subproblems as functions. A function is like a sub-algorithm. Similar to an algorithm, a j function is specified by the input property and the desired input-output relation.

Question 28.
How do we refine a statement?
Answer:
After decomposing a problem into smaller subproblems, the next step is either to refine the subproblem or to abstract the subproblem.

  1. Each subproblem can be expanded into more detailed steps. Each step can be further expanded to still finer steps, and so on. This is known as refinement.
  2. We can also abstract the subproblem. We specify each subproblem by its input property and the input-output relation, While solving the main problem, we only need to know the specification of the subproblems. We do not need know how the subproblems are solved.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 29.
For the two flowcharts given below. Write the pseudo code.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 20

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 21

(a) start
read a,b,c
if a < b then
(if a < c then
print a
else
print c
)
else
(if b < c then
print b
else
print c)
end.

(b) start
sum = 0
n = 1
while n <= 100 then do
read a
sum = sum + a
n = n + 1
print sum
end.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 30.
If C is false in line 2, trace the control flow in this algorithm.
Answer:
1 S1
2 — C is false
3 if C
4 S2
5 else
6 S3
7 S4
(i) Test the condition C is false.
(ii) If C is false the statement SI, S3, S4 is executed.

Question 31.
What is case analysis?
Answer:
Case analysis splits the problem into an exhaustive set of disjoint cases. For each case, the problem is solved independently. If Cl, C2 and C3 are conditions and S1, S2, S3 and S4 are statements, a 4-case analysis statement has the form,
1. case C1
2. S1
3. case C2
4. S2
5. case C3
6. S3
7. else
8. S4

The conditions C1, C2, and C3 are evaluated in turn. For the first condition that evaluates to true, the corresponding statement is executed, and the case analysis statement ends. If none of the conditions evaluates to true, then the default case S4 is executed.
(i) The cases are exhaustive: at least one of the cases is true. If all conditions are false, the default case is true.
(ii) The cases are disjoint: only one of the cases is true. Though it is possible for more than one condition to be true, the case analysis always executes only one case, the first one that is true. If the three conditions are disjoint, then the four cases are (1) C1, (2) C2, (3) C3, (4) (not C1) and (not C2) and (not C3).

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 32.
Draw a flowchart for -3case analysis using alternative statements.
Answer:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 22

Question 33.
Define a function to double a number in two different ways: (1) n + n, (2) 2 × n.
Answer:
(1) double (n)
— inputs : n
— outputs : n + n
(2) double (n)
— inputs : n
— outputs: 2 × n

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 34.
Exchange the contents: Given two glasses marked A and B. Glass A is full of apple drink and glass B is full of grape drink. Write the specification for exchanging the contents of glasses A and B, and write a sequence of assignments to satisfy the specification.
Answer:
drinks (A, B)
— inputs: A, B where A is Apple drink, B is grape drink
— outputs: A (grape drink), B (apple drink)
such that
t: = A
A : = B
B : = t

Question 35.
Circulate the contents: Write the specification and construct an algorithm to circulate the contents of the variables A, B and C as shown below: The arrows indicate that B gets the value of A, C gets the value of B and A gets the value of C.

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 23

The specification of the algorithm for circulating the contecontents (a, b, c)
— inputs : a = 10, b = 20, C = 30 -outputs : a = 30, b = 10, C = 20 Algorithm for circulating the contents 0 start
1. Read a, b, c
2. temp = b
3. b = a
4. a = c
5. c = temp
6. print a, b, c
7. End

Question 36.
Decanting problem. You are given three bottles of capacities 5, 8 and 3 litres. The 8L bottle is filled with oil, while the other two are empty. Divide the oil in 8L bottle into two equal quantities. Represent the state of the process by appropriate variables. What are the initial and final states of the process? Model the decanting of oil from one bottle to another by assignment. Write a sequence of assignments to achieve the final state.
Answer:
The goal is to construct a statement so as to move from initial state to final state.
Let A = 5 litre, B = 8 litre, C = 3 litre
— outputs: A (grape drink), B (apple drink) such that
1. A, B, C = 0, 8; 0 (initial state)
2. S
3. A, B, C = 4, 4, 0
Now we have to write a sequence of assignment statement to achieve the final statement.
1. –A, B, C = 0, 8, 0 (initial state)
2. –A, B: = 3, 5
(pour 3 litre in the first bottle)
3. –A, B, C = 3, 5, 0
4. B, C: = 3/2
(pour 2 litre from bottle B to C)
5. –A, B, C = 3, 3, 2
6. –A, B := 6, 0
(pour 3 litre from bottle B to A)
7. –A, B, C = 6, 0, 2
8. A, B:= 1, 5
(pour 5 litre from bottle A to B)
9. –A, B, C = 1, 5, 2
10. B, C = 4, 3
(pour 1 litre from bottle B to C)
11. —A, B, C = 1, 4, 3
12. A, C := 4, 4
(pour three litre from bottle C to A)
13. –A, B, C = 4, 4, 0

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 37.
Trace the step-by-step execution of the algorithm for fartorial(4). factorial(n)
Answer:
— inputs : n is an integer, n > 0
— outputs:f = n!
f, i = 1, 1
while i < n
f, i := f × i, i + 1

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 24

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 25

Factorial (4) = 24
(i) Read the value n = 4
(ii) Assign the value of f = 1, i = 1
(iii) Check the condition i < n if it is true the statement f = f * i
i = i + 1 is executed.
(iv) When the condition goes false the control variable i comes out of the loop and print the result.
Output: n = 24

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Choose the correct answer:

Question 1.
Algorithm is made up of:
(a) sequence to print data
(b) selection
(c) repetition
(d) all of above
Answer:
(d) all of above

Question 2.
__________ is a diagrammatic notation for representing algorithms.
(a) Psuedo code
(b) Flow chart
(c) Statement
(d) Diagrams
Answer:
(b) Flow chart

Question 3.
The rectangle shaped symbol is used to show the:
(a) errors
(b) decision
(c) process
(d) input / output
Answer:
(c) process

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 4.
________ is a mix of programming language – like constructs and plain English.
(a) Pseudo code
(b) Algorithm
(c) Flow chart
(d) Program
Answer:
(a) Pseudo code

Question 5.
There are ________ important control flow statements.
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(b) 3

Question 6.
The ________ statements in the sequence are executed one after another.
(a) sequential
(b) alternative
(c) iterative
(d) control
Answer:
(a) sequential

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 7.
The variant of alternative statement is called a _______ statement.
(a) sequential
(b) control
(c) conditional
(d) Iterative
Answer:
(c) conditional

Question 8.
An ________ process executes the same action repeatedly.
(a) iterative
(b) non-iterative
(c) flow charts
(d) pseudo code
Answer:
(a) iterative

Question 9.
The elementary problem – solving techniques is:
(a) composition
(b) iteration
(c) decomposition
(d) refinement
Answer:
(c) decomposition

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 10.
A _______ is like a sub-algorithm.
(a) Function
(b) Arrays
(c) Pseudo code
(d) Structure
Answer:
(a) Function

Question 11.
_________ represents a comparison, that determinates alternative paths to be followed:

(a) TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 2

(b) TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 3

(c) TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 4

(d) TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 5

Answer:

(c) TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 4

Question 12.
Statements composed of other statements are known as _______ statements.
(a) simple
(b) compound
(c) sequential
(d) iterative
Answer:
(b) compound

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 13.
Connector is represented by a:
(a) rectangle
(b) square
(c) oval
(d) small circle
Answer:
(d) small circle

Question 14.
Control flow statements are called:
(a) compound statements
(b) looping statements
(c) branching statements
(d) control statements
Answer:
(a) compound statements

Question 15.
A sub problem can be expanded to finer steps:
(a) Decomposition
(b) Refinement
(c) Abstract
(d) Decompose
Answer:
(b) Refinement

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 16.
Which is used as a function in solving other problems?
(a) Black box
(b) Red box
(c) Square box
(d) Blue box
Answer:
(a) Black box

Question 17.
Identify the incorrect statement:
(a) Pseudo-code is a mix of programming – language like constructs and plain English.
(b) Flowchart is a diagrammatic notation for representing algorithms.
(c) A statement is a phrase that commands the computer to do an action.
(d) A sequential statement is not composed of a sequence of statements.
Answer:
(d) A sequential statement is not composed of a sequence of statements.

Question 18.
Choose the odd from the control flow statements:
(a) Sequential
(b) pseudo-code
(c) Alternative
(d) Iterative
Answer:
(b) pseudo-code

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 19.
Match the following:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 6

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 7

(a) (i) – (a); (ii) – (b); (iii) – (d); (iv) – (c)
(b) (i) – (d); (ii) – (a); (iii) – (b); (iv) – (c)
(c) (i) – (b); (ii) – (c); (iii) – (a); (iv) – (d)
(d) (i) – (b); (ii) – (d); (iii) – (c); (iv) – (a)
Answer:
(b) (i) – (d); (ii) – (a); (iii) – (b); (iv) – (c)

Question 20.
Suppose u, v = 10, 5 before the assignment. What are the values of u and v after the sequence of assignments?
1 u := v
2 v := u
(a) u, v = 5, 5
(b) u, v = 5, 10
(c) u, v = 10, 5
(d) u, v=10,10
Answer:
(a) u, v = 5, 5

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 21.
Which of the following properties is true after the assignment (at line 3?
1– i + j = 0
2 i, j := i + 1, j – 1
3– ?
(a) i + j > 0
(b) i + j < 0
(c) i + j = 0
(d) i = j
Answer:
(c) i + j = 0

Question 22.
If C1 is false and C2 is true, the compound statement:
1 if C1
2 SI
3 else
4 if C2
5 S2
6 else
7 S3
executes
(a) S1
(b) S2
(c) S3
(d) none
Answer:
(b) S2

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 23.
If C is false just before the loop, the control flows through:
1 S1
2 while C
3 S2
4 S3
(a) S1 ; S3
(b) S1 ; S2 ; S3
(c) S1 ; S2 ; S2 ; S3
(d) S1 ; S2 ; S2 ; S2 ; S3
Answer:
(a) S1 ; S3

Question 24.
If C is true, SI is executed in both the flowcharts, but S2 is executed in:

TN State Board 11th Computer Science Important Questions Chapter 7 Composition and Decomposition 1

(a) (1) only
(b) (2) only
(c) both (1) and (2)
(d) neither (1) nor (2)
Answer:
(a) (1) only

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 7 Composition and Decomposition

Question 25.
How many times the loop is iterated?
i := 0
while i ≠ 5
i := i + 1
(a) 4
(b) 5
(c) 6
(d) 0
Answer:
(b) 5

TN Board 11th Computer Science Important Questions

TN Board 11th Computer Science Important Questions Chapter 6 Specification and Abstraction

TN State Board 11th Computer Science Important Questions Chapter 6 Specification and Abstraction

Question 1.
What is a process?
Answer:
A process evolves, which accpmplishes the intended task or solves the given problem.

Question 2.
What are variables?
Answer:
Variables are named boxes for storing data. When we do operations on data, we need to store the results in variables. The data stored in a variable is also known as the value of the variable. We can store a value in a variable or change the value of variable, using an assignment statement.

Question 3.
Define function.
Answer:
A function is like a sub algorithm. It takes an input and produces an output, satisfying a desired input output relation.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 4.
What is meant by composition?
Answer:
An algorithm is composed of assignment and control flow statements. A control flow statement tests a condition of the state and depending on the value of the condition, decides the next statement to be executed.

Question 5.
How will you abstracts the specification of the problem?
Answer:
Specification abstracts a problem by the properties of the inputs and the desired input-output relation. We recognize the properties essential for solving the problem, and ignore the unnecessary details.

Question 6.
Write the specification of an algorithm to find the square root of a number.
Answer:
square_root(n)
— inputs: n is a real number, n ≥ 0.
— outputs : y is a real number such that y2 = n.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 7.
What are the basic building blocks of an algorithm?
Answer:
Algorithms are constructed using basic building blocks such as

  1. Data
  2. Variables
  3. Control flow
  4. Functions.

Question 8.
Write the control flow statements to alter the control flow depending on the state.
Answer:
There are three important control flow statements to alter the control flow depending on the state.

  1. In sequential control flow, a sequence of statements are executed one after another in the same order as they are written.
  2. In alternative control flow, a condition of the state is tested, and if the condition is true, one statement is executed; if the condition is false, an alternative statement is executed.
  3. In iterative control flow, a condition of the state is tested, and if the condition is true, a statement is executed. The two steps of testing the condition and executing the statement are repeated until the condition becomes false.

Question 9.
Write a note on Decomposition.
Answer:
We divide the main algorithm into functions. We construct each function independently of the main algorithm and other functions. Finally, we construct the main algorithm using the functions. When we use the functions, it is enough to know the specification of the function. It is not necessary to know how the function is implemented.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 10.
Write the specification in the initial state, all four variables farmer, goat, grass wolf have the variable L. In the final state all four variables should have the value R.
Answer:
cross_river
— inputs: farmer, goat, grass, wolf = L, L, L, L
— outputs: farmer, goat, grass, wolf = R, R, R, R

Question 11.
Explain the Algorithm Design Techniques.
Answer:
There are a few basic principles and techniques for designing algorithms.
(i) Specification:
The first step in problem solving is to state the problem precisely. A problem is specified in terms of the input given and the output desired. The specification must also state the properties of the given input, and the relation between the input and the output.

(ii) Abstraction:
A problem can involve a lot of details. Several of these details are unnecessary for solving the problem. Only a few details are essential. Ignoring or hiding unnecessary details and modeling an entity only by its essential properties is known as abstraction. For example, when we represent the state of a process, we select only the variables essential to the problem and ignore inessential details.

(iii) Composition:
An algorithm is composed ofassignmentandcontrolflowstatements. A control flow statement tests a condition of the state and depending on the value of the condition, decides the next statement to be executed.

(iv) Decomposition:
We divide the main algorithm into functions. We construct each function independently of the main algorithm and other functions. Finally, we construct the main algorithm using the functions. When we use the functions, it is enough to know the specification of the function. It is not necessary to know how the function is implemented.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 12.
Write the specification of an algorithm to compute the quotient and remainder after dividing an integer A by another integer B.
Answer:
Let A and B be the input variables. We will store the quotient in a variable q and the remainder in a variable r. So q and r are the output variables.
What are the properties of the inputs A and B?
Answer:
(i) A should be an integer. Remainder is meaningful only for integer division and ^
(ii) B should not be 0, since division by 0 is not allowed. We will specify the properties of the inputs as
— inputs: A is an integer and B ≠ 0
What is the desired relation between the inputs A and B, and the outputs q and r?
Answer:
(i) The two outputs q (quotient) and r (remainder) should satisfy the property
A = q × B + r, and
(ii) The remainder r should be less than the divisor B, 0 < r < B
Combining these requirements, we will specify the desired input-output relation as
— outputs: A = q × B + r and 0 < r < B.
The comment that starts with — inputs: actually is the property of the given inputs.
The comment that starts with — outputs: is the desired relation between the inputs and the outputs. The specification of the algorithm is
1. divide (A,B)
2. — inputs: A is an integer and B ≠ 0
3. — outputs : A = q × B + r and 0 < r < B

Question 13.
Define an algorithm.
Answer:
An algorithm is a step by step sequence of statements intended to solve a problem. When executed with input data, it generates a computational process and ends with output data, satisfying the specified relation between the input data and the output data.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 14.
Distinguish between an algorithm and a process.
Answer:

Algorithm

 Process

An algorithm is a sequence of instructions to accomplish a task or solve a problem.  A process evolves, which accomplishes the intended task or solve the given problem.

Question 15.
Initially, farmer, goat, grass, wolf = L, L, L, L and the farmer crosses the river with goat. Model the action with an assignment statement.
Answer:
Farmer, goat: = R, R.

Question 16. Specify a function to find the minimum of two numbers.
Answer:
–min(a, b)
–inputs: a, b
–outputs:result = a↓b

Question 17.
If √2 = 1.414, and the square_root( ) function returns -1.414, does it violate the following specification?
Answer:
– square_root (x) – inputs: x is a real number, x > 0
– outputs: y is a real number such that y2 = x.

There is no real root of negative numbers. This is because there is no negative square number. When we square a positive number, we multiply positive by positive. When we square a negative number, we multiply negative by negative. In both cases the results are positive, i.e., there is no negative square involved. So there can’t “be a square root of negative numbers.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 18.
When do you say that a problem is algorithmic in nature?
Answer:
A problem is algorithmic in nature when its solution involves the construction of an algorithm. Some types of problems can be immediately recognized as algorithmic.

Question 19.
What is the format of the specification of an algorithm?
Answer:
The specification in a standard three part format:

  1. The name of the algorithm and the inputs.
  2. Input: the property of the inputs.
  3. Output: the desired input-output relation.

Question 20.
What is abstraction?
Answer:
Abstraction is the process of ignoring or hiding irrelevant details and modeling a problem only by its essential features. Abstractions are used unconsciously to handle complexity. It is the most effective mental tool used for managing complexity. If we do not abstract a problem adequately, we may deal with unnecessary details and complicate the solution.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 21.
How is state represented in algorithms?
Answer:
State is a basic and important abstraction. Computational processes have state. A computational process starts with an initial state. As actions are performed, its state changes. It ends with a final state. State of a process is abstracted by a set of variables in the algorithm. The state at any point of execution is simply the values of the variables at that point.

Question 22.
What is the form and meaning of assignment statement?
Answer:
Assignment statement is used to store a value in a variable. The variable is written on the left side of the assignment Operator and a value on the right side.
variable := value
When this assignment is executed, the value on the right side is stored in the variable on the left side. The assignment is m := 2
stores value 2 in variable m.

Question 23.
What is the difference between assignment operator and equality operator?
Answer:

Assignment Operator

 Equality Operator

The ‘:=’ is the so – called assignment operator and is used to assign the result of the expression on the right side of the operator to the variable on the left side.  The ‘= =’ is the so – called equality comparison operator and is used to check whether the two expressions on both sides are equal or not. It returns true if they are equal and false if they are not equal.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 24.
Write the specification of an algorithm hypotenuse whose inputs are the lengths of the two shorter sides of a right angled triangle, and the output is the length of the third side.
Answer:
hypotenuse (a,b)
–inputs: (a,b)
–outputs: c where
c = (a2 + b2)1/2

Question 25.
Suppose you want to solve the quadratic equation ax2 + bx + c = 0 by an algorithm.
Answer:
quadratic_solve (a, b, c)
— inputs : ?
– outputs: ?
You intend to use the formula and you are prepared to handle only real number roots. Write a suitable specification.

x = \(\frac{-b \pm \sqrt{b^{2}-4 a c}}{2 a}\)
quadratic – solve (a, b, c)
–inputs: a, b, c are real numbers and a ≠ 0
–outputs: x1, x2 such that
d = (b x b) – (4 x a x c)
x1 = – b + (d)1/2 × a
x2 = – b – (d)1/2 × a

Question 26.
Exchange the contents: Given two glasses marked A and B. Glass A is full of apple drink and glass B is full of grape drink. For exchanging the contents of glasses A and B, represent the state by suitable variables, and write the specification of the algorithm.
Answer:
drinks(A, B)
— inputs: A, B where A and B are not empty
— outputs: B, A such that
t := A
A := B
B := t

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Choose the correct answer:

Question 1.
An _________ is a sequence of instructions to accomplish a task or solve a problem.
(a) algorithm
(b) program
(c) instruction
(d) data
Answer:
(a) algorithm

Question 2.
_________ changes the values of variables and hence the state.
(a) Selection statement
(b) Assignment statement
(c) Control statement
(d) Functions
Answer:
(b) Assignment statement

Question 3.
_________ are named boxes for storing data.
(a) Variables
(b) Process
(c) Functions
(d) Procedure
Answer:
(a) Variables

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 4.
The parts of an algorithm are known as:
(a) procedure
(b) decomposition
(c) abstraction
(d) functions
Answer:
(d) functions

Question 5.
________ indicates that the rest of the line is a comment in C++.
(a) –
(b) – –
(c) / /
(d) – /
Answer:
(c) / /

Question 6.
The specification of an algorithm can be _____ part.
(a) four
(b) three
(c) five
(d) two
Answer:
(b) three

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 7.
Which symbol is used in algorithmic notation to start a comment line?
(a) –
(b) – –
(c) //
(d) *
Answer:
(b) – –

Question 8.
A computation is abstracted by a set of variables in:
(a) State
(b) Function
(c) Abstract
(d) Composition
Answer:
(a) State

Question 9.
Which statement is used to store a value in a variable?
(a) Control
(b) Input
(c) Assignment
(d) Branch
Answer:
(c) Assignment

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 10.
Which is known as assignment operator?
(a) :=
(b) + =
(c) + + =
(d) = =
Answer:
(a) :=

Question 11.
Match the following:

(a) Relation between the input and the output  (i) Decomposition
(b) Ignoring or hiding unnecessary details  (ii) Composition
(c) Assignment and control flow statements  (iii) Abstractions
(d) Functions  (iv) Specification

(a) (iv), (iii), (ii), (i)
(b) (iii), (iv), (i), (ii)
(c) (iv), (ii), (i), (iii)
(d) (iv), (iii), (i), (ii)
Answer:
(a) (iv), (iii), (ii), (i)

Question 12.
Match the following:

(i) Functions  (a) Ignoring or hiding unnecessary details
(ii) Abstraction  (b) Composed of assignment and control flow statements
(iii) Composition  (c) Parts of an algorithm
(iv) Decomposition  (d) Divide the main algorithm into functions

(a) (i) – (d); (ii) – (b); (iii) – (c); (iv) – (a)
(b) (i) – (b); (ii) – (a); (iii) – (c); (iv) – (d)
(c) (i) – (c); (ii) – (a); (iii) – (b); (iv) – (d)
(d) (i) – (a); (ii) – (b); (iii) – (d); (iv) – (c)
Answer:
(c) (i) – (c); (ii) – (a); (iii) – (b); (iv) – (d)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 13.
Assertion (A):
An algorithm is a sequence of instructions to accomplish a task or solve a problem.
Reason (R):
An instruction describes an action.
(a) Both A and R are true, and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(a) Both A and R are true, and R is the correct explanation for A.

Question 14.
Assertion (A):
Specification cannot abstract a problem by the properties of the inputs and the desired input-output relation.
Reason (R):
We can recognize the properties essential for solving the problem and ignore the unnecessary details.
(a) Both A and R are true, and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(d) A is false, but R is true.

Question 15.
Which of the following activities is algorithmic in nature?
(a) Assemble a bicycle
(b) Describe a bicycle
(c) Label the parts of a bicycle
(d) Explain how a bicycle works
Answer:
(a) Assemble a bicycle

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 16.
Which of the following activities is not algorithmic in nature?
(a) Multiply two numbers
(b) Draw a kolam
(c) Walk in the park
(d) Swaping of two numbers
Answer:
(a) Multiply two numbers

Question 17.
Omitting details inessential to the task and representing only the essential features of the task is known as:
(a) specification
(b) abstraction
(c) composition
(d) decomposition
Answer:
(b) abstraction

Question 18.
Stating the input property and the input- output relation a problem is known:
(a) specification
(b) statement
(c) algorithm
(d) definition
Answer:
(a) specification

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 19.
Ensuring the input-output relation is:
(a) the responsibility of the algorithm and the right of the user.
(b) the responsibility of the user and the right of the algorithm.
(c) the responsibility of the algorithm but not the right of the user.
(d) the responsibility of both the user and the algorithm.
Answer:
(a) the responsibility of the algorithm and the right of the user.

Question 20.
If i = 5 before the assignment i := i – 1 after the assignment, the value of i is:
(a) 5
(b) 4
(c) 3
(d) 2
Answer:
(b) 4

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 6 Specification and Abstraction

Question 21.
If 0 < i before the assignment i := i – 1 after the assignment, we can conclude that:
(a) 0 < i
(b) 0 ≤ i
(c) i = 0
(d) 0 ≥ i
Answer:
(b) 0 ≤ i

TN Board 11th Computer Science Important Questions