Computer Science with C++
Important Questions for Viva
Class XII

1.Define program.
2.Define Programming language.
3.Explain different stages of Programdevelopment.
4.What is algorithm?
5.Classification of languages
6.Importance of main()
7.Difference between C and C++.
8.Features of OOPs
9.Difference between Object OrientedPrograms and Procedure OrientedPrograms.
10.Define Tokens.
11.Define Keywords
12.Identifiers (their characteristics)
13.Operators (Arithmetic, Relational,Logical, Ternary, Scope resolution,sizeof(), increment, decrement,indirection, at address)14.Difference between fundamental datatypes and derived data types
15.Fundamental data types, memorysize, range.
16.Type casting
17.Data type qualifiers – long, short etc.
18.Different types of execution –sequential, selection and iteration.
19.ASCII value
20.Difference between prefix and postfix
21.Difference between global variablesand local variables.
22.Arithmetic assignment operators (+=,-=, *=, /=, %=)
23.Difference between entry-controlledloops and exit-controlled loops
24.Elements control a loop –initialisation expression, testexpression, body of the loop andupdate expression.
25.Nested loop
26.Difference between rvalue and lvalue
27.What is compilation?
28.What is debugging?
29.Different types of errors – compilationerror, run time error and logical error 
30.What is an array?
31.Equation for finding total number of elements in an array (UB – LB + 1).
32.What is a matrix?
33.How can we find the address of anelement in a 2-D array?
34. What is the difference between rowmajor and column major form of anarray?
35.What is a string?
36.What is the importance of ‘\0’in astring?
37.What are the criteria used for matrixaddition and multiplication?
38.What do you mean by diagonalelements of a matrix?
39.What is a symmetric matrix?
40.Which are the important stringhandling functions used in C++?
(strcpy(), strlen(). strcmp(), strcat(),strrev())
41.Character functions used in C++(isalpha(), isdigit(), isalnum(),isupper(), islower(), toupper(),tolower())
42.What do you mean by scope of avariable?
43.What is a function?
44.What is function signature or functionprototype?
45.Difference between calling functionand called function?
46.Difference between actualparameters and formal parameters.
47.Difference between break andcontinue.
48.Importance of exit() function.
49.Difference between call by value andcall by reference method of functioncall.
50.Classification of functions – functionswithout argument and without returnvalue, functions with argument andwithout return value, functionswithout argument and with returnvalue, functions with argument andwith return value
51.Difference between pre-definedfunctions and user-defined functions.
52.What do you mean by pre processor directives?
53.What is a structure?
54.What is self referential structure?
55.Difference between structure andunion.
56.What is type compatibility?
57.What is enumeration?
58.Difference between getch() andgetche() functions.

59.Important storage classes – Auto,Extern, Register, Static etc
60.What is the use of randomizefunction?
61.What are pointers?
62.What is a null pointer?
63.Difference between static memoryallocation and dynamic memoryallocation.
64.What is the importance of new anddelete operators in C++?
65.C++ memory map.
66.What do you mean by garbagevalue?
67.What is the difference between = and==?
68.What is a block or compoundstatement?
69.Define class and object.
70.What is the difference between aclass and a structure?
71.What is modularity?
72.Define abstraction and data hiding.
73.What is inheritance?
74.Different types of inheritance.
75.Advantages of inheritance
76.Define base class, super class,abstract class and derived class.
77.Visibility modes- private, public andprotected.
78.Global and local objects and their scope.
79.Difference between member functions and non-member functions.80.What is polymorphism?
81.What are constructors anddestructors?
82.Features of a constructor.
83.Differences between constructorsand other member functions of aclass.
84.What is function over riding?
85.What is a friend function?
86.Different types of constructors –default, parameterised and copyconstructor.87.What are files?88.Basic operations in a file.
89.File stream classes and their uses –ifstream, ofstream and fstream.
90.Different methods used for opening afile.
91.What is a stream?
92.Different file modes – ios::app, ios::in,ios::out, ios::truncate etc.
93.Difference between seekg() andseekp(), tellg() and tellp().
94.Difference between a text file and abinary file.
95.What is eof().96.What is a friend function?
97.What is function overloading?
98.What is function overriding?
99.What is this pointer?
100.Difference between primitive andnon-primitive data types.
101.Difference between stack and queue.
102.Different searching techniques usedin an array
103.Different sorting methods used in anarray
104.Define data, database, databasemanagement system105.Data redundancy
106.What is domain?
107.What is a relation?
108.Define the terms tuple, degree,cardinality, attributes etc.
109.What is a view?110.Difference between a table and aview.
111.What is a key?
112.Define candidate key, primary key,alternate keys, composite primarykey, foreign key etc.
113.What is the difference between selectand project operations in DBMS?
114.What is the difference between unionand set intersection operations?
115.What is SQL?
116.Different data types used in SQL.
117.Difference between character andvarchar2.
118.What is data dictionary or metadata?
119.Different categories of commands used in SQL-DDL, DML,TCL and DCL.
120.What is a constraint?
121.Different constraints used in SQL –unique, primary key, default, check,not null.
122.Aggregate functions used in SQL.
123.What is pseudo column?
124.Explain the commands – SELECT,INSERT, CREATE, ALTER,UPDATE, DROP, TRUNCATE,DELETE etc.
125.What is a schema?
126.Difference between DROP andDELETE commands in a table.



Q1. What is the difference between call by reference & call by value method in a user defined function in C++? Explain it with suitable example. For - 2 Marks
Ans. Call by value : In this method, actual arguments of a calling function gets duplicated as formal arguments & are made available to the called function. As a result whatever change is made by called function in these arguments, are not reflected back in actual arguments.
Ex. void SWAP(float a, float b)
{ a=a+b;
b=a-b;
a=a-b;
cout<<"\na="<<a<<" and b="<<b;  }
Call by reference : In this function call, the reference of actual arguments are provided to the called function i.e. memory location of actual arguments. As a result, any change made in these arguments by called function is reflected back to the actual arguments.
Ex. void SWAP(float &a, float &b)
{ a=a+b;
b=a-b;
a=a-b; }
In the function’s argument we simply specify ‘&’ operator along with the argument(s) which are being called by reference.
Q.2.Write the names of the header files, which is/are essentially required to execute the following functions:  For - 1 Marks       
   i) isdigit( )                ii) sin( )
Ans. i) ctype.h        ii) math.h
Q .3 . Rewrite the following program after removing all the syntactical errors (if any), underlining each correction. :                    For - 2 Marks
  include<iostream.h>
typedef char[40] string;
void main( )
{  string S=”Australia”;
L=strlen(S);
cout<<”String “<<S<<’ has ’<<L<<”Characters”<<endl; }
Ans.      #include<iostream.h>
            #include<string.h>
typedef char string[40]; 
void main( )
{  string S=”Australia”;
int/long L=strlen(S);
cout<<”String “<<S<<” has”<<L<<”Characters”<<endl; }
Q 4. Give the output of the following program ( Assuming that all required header files are  included in the program )     :               For - 2 Marks
#define i 5
class TEMP
{ static int a;
float b;
public:
TEMP( )
{ b=10; }
void INTEMP( )
{ a++;
b=a+10; }
void OUTTEMP( )
{ cout<<a*i<<"$"<<b-3<<endl; } };
int TEMP::a=2;
void main()
{ TEMP ob[5];
for(int x=1;x<5;x++)
ob[x].INTEMP( );
for(x=1;x<5;x++)
ob[x].OUTTEMP( );} 
Ans. 30$10
30$11
30$12
30$13
Q . 5. Give the output of the following program ( Assuming that all required header files are  included in the program )   :                             For -2 Marks
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void TRANSFER(char *s1,char *s2)
{ int n,j=0;
for(int i=0;*(s1+i)!='\0';i++)
{
n=*(s1+i);
if(n%2==0)
*(s2+j++)=*(s1+i);
} }
void main()
{ char *p="ChaRlesBabBaGe",q[80];
TRANSFER(p,q);
cout<<q<<endl;}
Ans. hRlBbB
Q. 6.Go through the following c++ code, find out the correct possible output(s) from the suggested output options i) to iv). Also write thehighest value which can be assigned to variable G :                              For - 2 Marks
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
int G,H=5;
G=random(H)+30;
for(int i=35;i>G;i--)
cout<<i<<’$’;
cout<<i;
}
1.        35$34$33$32$31$30$
2.        35$34$33$32$31
3.        30$31$32$33$34$35$36
4.        35$34$33$32$31$30
Ans.  Options ii) & iv) will be the correct possible outputs. The highest value of variable G would be 34
Q. 7. What is constructor overloading? Support your answer with example.                             For - 2 Marks
Ans. CONSTRUCTOR OVERLOADING : When more than one constructor appears inside a single class, it is said to be constructor overloading i.e. if we have two or more constructors inside a class, it is said to be an overloaded constructor. For ex.
class ABC
{ private:
int x;
float y;
public:
ABC( )                   //default constructor
{ x=5;
y=0.0; }
ABC(int p, float q) //parameterized constructor
{ x=p;
y=q; }
ABC(ABC &t)      //Copy constructor
{ x=t.p;
y=t.q; }
void INABC( );
void OUTABC( ); };
Here in the above written example, we see three constructors one after another. Since all of them share the same class name and are different in their type and number of arguments, therefore supports overloading mechanism of OOP.
Q. 8 . Answer the questions (i) and (ii) after going through the following class :                             For - 2 Marks
    class BUS
    { private:
     char Pname[30],TicktNo[20];
     float Fare;
      public:
      BUS( )                                                              //function 1
     { strcpy(Pname,”\0”);
        strcpy(TicktNo,”\0”);
        Fare=0; }
      void Details( )                                                   //function 2
      { cout<<Pname<<endl<<TicktNo<<endl<<Fare<<endl; }
       BUS(char * name, char *tno, float N);           //function 3
       BUS(BUS &F);                                              // function 4
     };
1.        In OOP, what is function 3 referred to as? Also define this function.
2.        Define function 4 and write about its purpose?
Ans. i) Function 3  is referred to as parameterized constructor. Its definition is as follows:
                 BUS(char * name, char *tno, float N)
                  { strcpy(Pname,name);
                     strcpy(TicktNo,tno);
                     Fare=N; }
1.        BUS(BUS &F)
                   { strcpy(Pname,F.Pname);
                     strcpy(TicktNo,F.TicktNo);
                     Fare=F.Fare; }
COPY CONSTRUCTOR : It is used to initialize an instance/object  using the values of another instance/object of same class type. It takes the reference to an object of the same class as an argument




1.            What is the difference between interpreters and compilers?

Interpreters read through source code and translate a program, turning the programmer's code, or program instructions, directly into actions. Compilers translate source code into an executable program that can be run at a later time.

2. How do you compile the source code with your compiler?

Every compiler is different. Be sure to check the documentation that came with your compiler.

3. What does the linker do?

The linker's job is to tie together your compiled code with the libraries supplied by your compiler vendor and other sources. The linker lets you build your program in pieces and then link together the pieces into one big program.

4. What are the steps in the development cycle?

Edit source code, compile, link, test, repeat. 
5. What is the difference between the compiler and the preprocessor?

Each time you run your compiler, the preprocessor runs first. It reads through your source code and includes the files you've asked for, and performs other housekeeping chores. The preprocessor is discussed in detail on Day 18, "Object-Oriented Analysis and Design."

6. Why is the function main() special?

main() is called automatically, each time your program is executed.

7. What are the two types of comments, and how do they differ?

C++-style comments are two slashes (//), and they comment out any text until the end of the line. C-style comments come in pairs (/* */), and everything between the matching pairs is commented out. You must be careful to ensure you have matched pairs.

8. Can comments be nested?

Yes, C++-style comments can be nested within C-style comments. You can, in fact, nest C-style comments within C++-style comments, as long as you remember that the C++-style comments end at the end of the line.

9. Can comments be longer than one line?

C-style comments can. If you want to extend C++-style comments to a second line, you must put another set of double slashes (//). 
10. What are the differences between the function prototype and the function defi-nition?

The function prototype declares the function; the definition defines it. The prototype ends with a semicolon; the definition need not. The declaration can include the keyword inline and default values for the parameters; the definition cannot. The declaration need not include names for the parameters; the definition must.

11. Do the names of parameters have to agree in the prototype, definition, and call to the function?

No. All parameters are identified by position, not name.

12. If a function doesn't return a value, how do you declare the function?

Declare the function to return void.

13. If you don't declare a return value, what type of return value is assumed?

Any function that does not explicitly declare a return type returns int.

14. What is a local variable?

A local variable is a variable passed into or declared within a block, typically a function. It is visible only within the block.

15. What is scope?

Scope refers to the visibility and lifetime of local and global variables. Scope is usually established by a set of braces.

16. What is recursion?

Recursion generally refers to the ability of a function to call itself.

17. When should you use global variables?

Global variables are typically used when many functions need access to the same data. Global variables are very rare in C++; once you know how to create static class variables, you will almost never create global variables.

18. What is function overloading?

Function overloading is the ability to write more than one function with the same name, distinguished by the number or type of the parameters.

19. What is polymorphism?

Polymorphism is the ability to treat many objects of differing but related types without regard to their differences. In C++, polymorphism is accomplished by using class derivation and virtual functions. 
20. Is the declaration of a class its interface or its implementation?

The declaration of a class is its interface; it tells clients of the class how to interact with the class. The implementation of the class is the set of member functions stored--usually in a related CPP file.

21. What is the difference between public and private data members?

Public data members can be accessed by clients of the class. Private data members can be accessed only by member functions of the class.

22. Can member functions be private?

Yes. Both member functions and member data can be private.

23. Can member data be public?

Although member data can be public, it is good programming practice to make it private and to provide public accessor functions to the data.

24. Do class declarations end with a semicolon? Do class method definitions?

Declarations end with a semicolon after the closing brace; function definitions do not.

25. What is the difference between the indirection operator and the address of oper-ator?

The indirection operator returns the value at the address stored in a pointer. The address of operator (&) returns the memory address of the variable.

26. What is the difference between a reference and a pointer?

A reference is an alias, and a pointer is a variable that holds an address. References cannot be null and cannot be assigned to.

27. When must you use a pointer rather than a reference?

When you may need to reassign what is pointed to, or when the pointer may be null.

28. What does new return if there is insufficient memory to make your new object?

A null pointer (0).

29. What is a constant reference?

This is a shorthand way of saying "a reference to a constant object."

30. What is the difference between passing by reference and passing a reference?

Passing by reference means not making a local copy. It can be accomplished by passing a reference or by passing a pointer. 
31. When you overload member functions, in what ways must they differ?

Overloaded member functions are functions in a class that share a name but differ in the number or type of their parameters.

32. What is the difference between a declaration and a definition?

A definition sets aside memory, but a declaration does not. Almost all declarations are definitions; the major exceptions are class declarations, function prototypes, and typedef statements.

33. When is the copy constructor called?

Whenever a temporary copy of an object is created. This happens every time an object is passed by value.

34. When is the destructor called?

The destructor is called each time an object is destroyed, either because it goes out of scope or because you call delete on a pointer pointing to it.

35. How does the copy constructor differ from the assignment operator (=)?

The assignment operator acts on an existing object; the copy constructor creates a new one.

36. What is the this pointer?

The this pointer is a hidden parameter in every member function that points to the object itself.

37. How do you differentiate between overloading the prefix and postfix increments?

The prefix operator takes no parameters. The postfix operator takes a single int parameter, which is used as a signal to the compiler that this is the postfix variant.

38. Can you overload the operator+ for short integers?

No, you cannot overload any operator for built-in types.

39. Is it legal in C++ to overload operator++ so that it decrements a value in your class?

It is legal, but it is a bad idea. Operators should be overloaded in a way that is likely to be readily understood by anyone reading your code.

40. What return value must conversion operators have in their declaration?

None. Like constructors and destructors, they have no return values. 

41. What is a v-table?

A v-table, or virtual function table, is a common way for compilers to manage virtual functions in C++. The table keeps a list of the addresses of all the virtual functions and, depending on the runtime type of the object pointed to, invokes the right function.

42. What is a virtual destructor?

A destructor of any class can be declared to be virtual. When the pointer is deleted, the runtime type of the object will be assessed and the correct derived destructor invoked.

43. How do you show the declaration of a virtual constructor?

There are no virtual constructors.

44. How can you create a virtual copy constructor?

By creating a virtual method in your class, which itself calls the copy constructor.

45. How do you invoke a base member function from a derived class in which you've overridden that function? 
Base::FunctionName();

46. How do you invoke a base member function from a derived class in which you have not overridden that function? 
FunctionName();

47. If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?

Yes, the virtuality is inherited and cannot be turned off.

48. What is the protected keyword used for?

protected members are accessible to the member functions of derived objects. 

49. What is a down cast?

A down cast (also called "casting down") is a declaration that a pointer to a base class is to be treated as a pointer to a derived class.

50. What is the v-ptr?

The v-ptr, or virtual-function pointer, is an implementation detail of virtual functions. Each object in a class with virtual functions has a v-ptr, which points to the virtual function table for that class.


51. If a round rectangle has straight edges and rounded corners, your RoundRect class inherits both from Rectangle and from Circle, and they in turn both inherit from Shape, how many Shapes are created when you create a RoundRect?

If neither class inherits using the keyword virtual, two Shapes are created: one for Rectangle and one for Shape. If the keyword virtual is used for both classes, only one shared Shape is created.

52. If Horse and Bird inherit virtual public from Animal, do their constructors initialize the Animal constructor? If Pegasus inherits from both Horse and Bird, how does it initialize Animal's constructor?

Both Horse and Bird initialize their base class, Animal, in their constructors. Pegasus does as well, and when a Pegasus is created, the Horse and Bird initializations of Animal are ignored.

53. Declare a class Vehicle and make it an abstract data type. 
class Vehicle
{
virtual void Move() = 0;
}

54. If a base class is an ADT, and it has three pure virtual functions, how many of these functions must be overridden in its derived classes?

None must be overridden unless you want to make the class non-abstract, in which case all three must be overridden. 

55. Can static member variables be private?

Yes. They are member variables, and their access can be controlled like any other. If they are private, they can be accessed only by using member functions or, more commonly, static member functions.

56. Show the declaration for a static member variable. 
static int itsStatic;

57. Show the declaration for a static function pointer. 
static int SomeFunction();

58. Show the declaration for a pointer to function returning long and taking an integer parameter. 
long (* function)(int);
59. How do you establish an is-a relationship?

With public inheritance.

60. How do you establish a has-a relationship?

With containment; that is, one class has a member that is an object of another type.


61. What is the difference between containment and delegation?

Containment describes the idea of one class having a data member that is an object of another type. Delegation expresses the idea that one class uses another class to accomplish a task or goal. Delegation is usually accomplished by containment.

62. What is the difference between delegation and implemented-in-terms-of?

Delegation expresses the idea that one class uses another class to accomplish a task or goal. Implemented-in-terms-of expresses the idea of inheriting implementation from another class.

63. What is a friend function?

A friend function is a function declared to have access to the protected and private members of your 
class.

64. What is a friend class?

A friend class is a class declared so that all its member functions are friend functions of your class.

65. If Dog is a friend of Boy, is Boy a friend of Dog?

No, friendship is not commutative.

66. If Dog is a friend of Boy, and Terrier derives from Dog, is Terrier a friend of Boy?

No, friendship is not inherited.

67. If Dog is a friend of Boy and Boy is a friend of House, is Dog a friend of House?

No, friendship is not associative.

68. Where must the declaration of a friend function appear?

Anywhere within the class declaration. It makes no difference whether you put the declaration within the public:, protected:, or private: access areas. 
69. What is the insertion operator and what does it do?

The insertion operator (<<) is a member operator of the ostream object and is used for writing to the output device. 70. What is the extraction operator and what does it do? The extraction operator (>>) is a member operator of the istream object and is used for writing to your program's variables.


71. What are the three forms of cin.get() and what are their differences?

The first form of get() is without parameters. This returns the value of the character found, and will return EOF (end of file) if the end of the file is reached.

The second form of cin.get() takes a character reference as its parameter; that character is filled with the next character in the input stream. The return value is an iostream object.

The third form of cin.get() takes an array, a maximum number of characters to get, and a terminating character. This form of get() fills the array with up to one fewer characters than the maximum (appending null) unless it reads the terminating character, in which case it immediately writes a null and leaves the terminating character in the buffer.

72. What is the difference between cin.read() and cin.getline()?

cin.read() is used for reading binary data structures.
getline() is used to read from the istream's buffer.

73. What is the default width for ouputting a long integer using the insertion operator?

Wide enough to display the entire number.

74. What is the return value of the insertion operator?

A reference to an istream object.

75. What parameter does the constructor to an ofstream object take?

The filename to be opened.

76. What does the ios::ate argument do?

ios::ate places you at the end of the file, but you can write data anywhere in the file. 

77. What is an inclusion guard?

Inclusion guards are used to protect a header file from being included into a program more than once.

78. How do you instruct your compiler to print the contents of the intermediate file showing the effects of the preprocessor?

This quiz question must be answered by you, depending on the compiler you are using.

79. What is the difference between #define debug 0 and #undef debug?

#define debug 0 defines the term debug to equal 0 (zero). Everywhere the word debug is found, the character 0 will be substituted. #undef debug removes any definition of debug; when the word debug is found in the file, it will be left unchanged.



80. Name four predefined macros.

__DATE__, __TIME__, __FILE__, __LINE__

81. Why can't you call invariants() as the first line of your constructor?

The job of your constructor is to create the object. The class invariants cannot and should not exist before the object is fully created, so any meaningful use of invariants() will return false until the constructor is finished. 

82. What is the difference between object-oriented programming and procedural programming?

Procedural programming focuses on functions separate from data. Object-oriented programming ties data and functionality together into objects, and focuses on the interaction among the objects.

83. To what does "event-driven" refer?

Event-driven programs are distinguished by the fact that action is taken only in response to some form of (usually external) simulation, such as a user's keyboard or mouse input.

84. What are the stages in the development cycle?

Typically, the development cycle includes analysis, design, coding, testing, programming, and interaction and feedback among these stages.

85. What is a rooted hierarchy?

A rooted hierarchy is one in which all the classes in the program derive directly or indirectly from a single base class.

86. What is a driver program?

A driver program is simply a function that is designed to exercise whatever objects and functions you are currently programming.

87. What is encapsulation?

Encapsulation refers to the (desirable) trait of bringing together in one class all the data and functionality of one discrete entity. 

88. What is the difference between a template and a macro?

Templates are built into the C++ language and are type-safe. Macros are implemented by the preprocessor and are not type-safe.

89. What is the difference between the parameter to a template and the parameter to a function?

The parameter to the template creates an instance of the template for each type. If you create six template instances, six different classes or functions are created. The parameters to the function change the behavior or data of the function, but only one function is created.
90. What is the difference between a type-specific template friend class and a general template friend class?

The general template friend function creates one function for every type of the parameterized class; the type-specific function creates a type-specific instance for each instance of the parameterized class.

91. Is it possible to provide special behavior for one instance of a template but not for other instances?

Yes, create a specialized function for the particular instance. In addition to creating Array
::SomeFunction(), also create Array::SomeFunction() to change the behavior for integer arrays.

92. How many static variables are created if you put one static member into a template class definition?
One for each instance of the class. 

93. What is an exception?

An exception is an object that is created as a result of invoking the keyword throw. It is used to signal an exceptional condition, and is passed up the call stack to the first catch statement that handles its type.

94. What is a try block?

A try block is a set of statements that might generate an exception.

95. What is a catch statement?

A catch statement has a signature of the type of exception it handles. It follows a try block and acts as the receiver of exceptions raised within the try block.

96. What information can an exception contain?

An exception is an object and can contain any information that can be defined within a user-created class.

97. When are exception objects created?

Exception objects are created when you invoke the keyword throw.

98. Should you pass exceptions by value or by reference?

In general, exceptions should be passed by reference. If you don't intend to modify the contents of the exception object, you should pass a const reference.

99. Will a catch statement catch a derived exception if it is looking for the base class?

Yes, if you pass the exception by reference.

100. If there are two catch statements, one for base and one for derived, which should come first?

catch statements are examined in the order they appear in the source code. The first catch statement whose signature matches the exception is used.

101. What does catch(...) mean?

catch(...) will catch any exception of any type.

102. What is a breakpoint?

A breakpoint is a place in the code where the debugger will stop execution. 

103 What is the difference between strcpy() and strncpy()?

strcpy(char* destination, char* source) copies source to destination, and puts a null at the end of destination. destination must be large enough to accommodate source, or strcpy() will simply write past the end of the array. strncpy(char* destination char* source, int howmany) will write howmany bytes of source to destination, but will not put a terminating null.

104. What does ctime() do?

ctime() takes a time_t variable and returns an ASCII string with the current time. The time_t variable is typically filled by passing its address to time().

105. What is the function to call to turn an ASCII string into a long? 
atol()

SOME MORE VIVA QUESTIONS
1.What are classes?
Ø A class is a collection of objects of similar type. Once a class is defined any number of objects can be created of that class.
Ø Examples of classes are class of cars, class of pens, class of birds etc.
What are Instances?
Ø Instances are essentially objects derived out of classes.
Ø When an object is created for a particular class the process is called Instantiation. In general, life time of object is nothing but the time between an object creation, till the object is no longer used and is destructed or freed.

2.What is object orientation?
It is a technique for system modeling. It offers a number of concepts

3.Pointer type: A Pointer is a variable which holds the address of another variable.

4.Const Qualifier: Const qualifier is used to prevent from accidental changes within a program.

5.Differences between Structured Programming and OOP
– In St.P emphasis is on What is happening. In OOP emphasis is on Who is being affected.
– Data move openly around the system. In St.P. In OOP the data and functions that operate on the data are tied together
– In St.P most fns share global data. In OOP data is hidden and cannot be accessed by external functions.
– In St.P, Large programs are divided to smaller programs known as functions, In OOP they are divided into objects.
.
6.Enumerated Data type: It is a user-defined data type.
• The syntax of enum statement is similar to that of struct
• For Ex: enum shape{ circle, square, triangle};

7. New and Delete : (Memory Management Operators)
These are the unary operators to perform dynamic memory allocation and de-allocation
New operator is used to create objects. The General Form is:
Pointer-variable = new data-type; The general form of using delete
delete pointer-variable;
For Ex: delete p;

To free dynamically allocated array
delete [size] pointer-variable 
For Ex: delete [10] p;

For Ex: int *p = new int;

8. Inline Functions:An inline function is a function that is expanded in line when it is invoked

Inline function-header
{
function body
}
Ex: inline int square(int a)
{ 
return a*a 
};

9. Generic Functions
A generic function defines a general set of operations that can be applied to various types of data.. A generic function is created using the keyword template. The general form of template function definition is 
1. Template ret-type func-name(parameter list)
{ //function body }
10. Constructors and Destructors
1. C++ allows automatic initialization of objects when they are created. This is performed through the use of a constructor function.
2. Constructor is a special function that is a member of the class and has the same name as that class.
3. The Constructor is automatically called whenever an object of its associated class is created.
4. A Constructor is declared and defined as follows
Destructors:
1. A destructor as the name implies is a complement of the constructor, used to destroy objects. 
2. It will be invoked implicitly by the compiler upon exit from program or function or block
3. Local objects are destroyed when the block is left. Global objects are destroyed when the program terminates.
4. It is a member function whose name is same as the class name but is preceded by a tilde (~) operator. Ex : ~stack();
5. There are many reasons why a destructor may be needed. Ex: An object may need to deallocate memory that it had previously allocated, or close a file that it had opened.
6. A destructor never takes any argument nor does it return any value
7. It is a good practice to declare destructors 

11. Class is syntactically similar to a struct.
The only difference between them is that by default all members are public in a struct and private in a class.
12. Friend Functions
1. Private members cannot be accessed from outside the class i.e by a non-member function
2. C++ allows a non-member function to access private members of a class by using a friend function.
3. A friend function need not be a member of any class.
4. To make an outside function friendly to a class, include its prototype within the class, preceding it with the keyword friend.


13. Static Data Members(SDM)
1. Preceding a data member’s declaration with the keyword static tells the compiler that only one copy of that variable will exist and that all objects of the class will share that variable.
2. A static data member is initialized to zero when the first object of its class is created. No other initialization is permitted.
3. Declaring a static data member is not defining it (means not allocating storage for it). Remember class is a logical construct that does not have physical reality.
4. Defining a static data member is done outside the class by redeclaring the static variable using the scope resolution operator .
5. SDM are normally used to maintain values common to entire class 
Static Member Functions(SMF)
There are several restrictions placed on Static member functions.
1. A static function can have access to only other static members declared in the same class.
2. Global functions and data may be accessed by SMF.
3. A SMF does not have a this pointer.
4. There cannot be a static version and non-static version of the same function
5. A SMF may not be virtual.
6. They cannot be declared as const or volatile
7. A static member function can be called using the class name as follows Class-name :: function-name;
8. Use is to preinitialize private static data before any object is created

14. This Pointer
When a member function is called, it is automatically passed an implicit argument that is a pointer to the invoking object. This pointer is called this 

15.Operator Overloading
The mechanism of giving additional meaning to an operator is known as operator overloading.
16.INHERITANCE
1. The mechanism of deriving a new class from an old one is called Inheritance.
2. The concept of Inheritance provides the idea of reusability. This is basically done by creating new classes, reusing the properties of the existing ones.
3. A class that is inherited is referred to as base class, and a class that inherits is called the derived class.
4. Different types of Inheritance:

17.Protected Members
When a member of a class is declared as protected, that member is not accessible by other nonmember elements of the program



18.A Virtual function:
It is a member function that is declared within a base class and redefined by a derived class. To create a virtual function, precede the function’s declaration in the base class with the keyword Virtual.

19.. I/O Operations:
C++ uses the concept of stream and stream classes to implement the I/O Operations. A stream acts as an interface between the program and I/O device.

20.What is Polymorphism?
Ø It is generally ability to appear in many forms. In OOP, polymorphism refers to a programming language’s ability to process objects differently depending on their data type or class.
21.What is Abstraction?
The process of picking out (abstracting) common features of objects and procedures. A programmer would use abstraction. Abstraction is one of the most important techniques in software engineering and it is closely related to two other techniques- encapsulation and information hiding. All these three techniques are used to reduce complexity.

Q. 13. Write functions to perform PUSH  & POP operations  in a dynamically allocated stack containing the objects of the following structure:                            For - 4 Marks
   struct NODE
    {  char name[30];
        float fees;
        NODE *next;     };
ANS.:
NODE *top=NULL; //declaring global pointer & initializing  it with NULL
void PUSH( )
{ NODE *p=new NODE; //creating new dynamic list to go on to stack
cout<<”\nEnter Name : “;
gets(p->name);
cout<<”\nEnter Fees : “;
cin>>p->fees;
p->next=NULL:
                   if(top= = NULL)
                   top=p;
                           else
                               { p->next=top;
                                  top=p }
cout<<”\nList inserted on the top of stack successfully…”;
getch( );
}
void POP( )
{ if(top= = NULL)
  cout<<”\nStack Empty”;
 else
  { NODE *temp=top;
     top=top->next;
    delete temp;
    cout<<”\nList deleted from top of stack successfully…”;
    getch( );
   }
}
Q. 14. Consider the class:                             For - 2 Marks
    class QUEUE
    {
     private:
      int data[20],front,rear;
     public:
     QUEUE( )
      { front=rear=-1; }
     void INSQ(int d); //to insert an element into queue
     void DELQ( ); //to delete an element from the queue
     void PRINTQ( ); //to print the current status of queue
      };
Complete the definition of function DELQ( ) of above class.
Ans.:
void QUEUE::DELQ( )
{
if(front<0)
cout<<”\nQueue Empty”;
else
{
cout<<”\n”<<data[front]<<” has been removed from queue”;
for(int i=front;i<rear;i++)
data[i]=data[i+1];
rear--;
  if(rear<0)
  front=-1; }
}
Q. 15. Evaluate the following postfix notation of expression:                             For - 2 Marks
                            30, 6, 4, +, /, 14, +, 4, *
SOL. (by tabular method):
Steps     INPUT     ACTION          STACK
1             30            Push                   #30
2             6              Push                  #30,6
3             4              Push                  #30,6,4
4             +              Pop 4,6 &
                               Push 6+4=10     #30,10
5             /               Pop 10,30 &
                               Push 30/10=3    #3
6            14             Push                  #3,14
7            +               Pop 14,3 &
                               Push 3+14=17   #17
8            4               Push                  # 17,4
9            *               Pop 4,17 &
                               Push 17*4=68    #68
Ans. 68
Q .16. Observe the program segment given below carefully and answer the question that follows :                              For - 1 Marks
class school
{ private :
 char name[25];
int numstu;
public:
  void inschool( );
  void outschool( );
int retnumstu( )
{ return numstu; }
};
void modify(school A)
  { fstream INOUT;
  INOUT.open(“school.dat”,ios::binary|ios::in|ios::ate);
school B;
  int recread=0, found=0;
  while(!found && INOUT.read((char*)&B,sizeof(B))
  { recread++;
if(A.retnumstu( )= = B.retnumstu( ))
  {
    ____________________________//missing statement
                                               
INOUT.write((char*)&A,sizeof(A));
   Found=1;
  }
  else
  INOUT.write((char*)&B,sizeof(B));
   }
   if(!found)
cout<<”\nRecord for modification does not exist”;
INOUT.close( );  

If the function modify( ) is supposed to modify a record in file school.dat with the values of school A passed to its argument, write the appropriate statement for missing statement using seekp( ) or  seekg( ) , whichever needed, in the above code that would write the modified record at its proper place.
Ans. :
INOUT.seekp(-1*sizeof(school),ios::cur);
OR
INOUT.seekg(-1*sizeof(school),ios::cur);
Q. 17. Write a function to count the number of vowels  stored in a text file “STRINGS.TXT”.                             For - 2 Marks
Ans.:
void countvowel( )
{ int c=0;
char ch;
ifstream fin(“STRINGS.TXT”);
while(!fin.eof( ))
{
fin.get(ch);     OR fin>>ch;
if(!fin)
break;
switch(ch)
{
case ‘A’:
case ‘a’:
case ‘E’:
case ‘e’:
case ‘I’:
case ‘i’:
case ‘O’:
case ‘o’:
case ‘U’:
case ‘u’:c++;
}
}
cout<<”\nTotal vowels in the data file is “<<c;fin.close( ); }
Q. 18. Write a function to delete a record on the given model number for a TV from the binary file “TV.DAT” containing the objects of TV (as defined below) :                             For - 4 Marks
class TV
{
long model;
float size;
char brand[30],comp[30];
 public:
long retmodel( )
{ return model; }
void Input( ) {cin>>model>>size; gets(brand); gets(comp); }
void  Output( ) { cout<<model<<size<<brand<<comp<<endl; } };
Ans.:
void DELREC(long m)
{ TV ob;
ifstream fin("TV.DAT",ios::binary);
ofstream fout("temp.dat",ios::app|ios::binary);
int flag=0;
while(!fin.eof()) //for searching record
{ fin.read((char*)&ob,sizeof(TV));
if(!fin)
break;
if(ob.retmodel( )= =m)
{ flag=1;
break; }
}
if(!flag)
{ cout<<"\nRecord does not exist";
getch(); }
else //for deleting record
{ fin.seekg(0);
while(!fin.eof())
{ fin.read((char*)&ob,sizeof(TV));
if(!fin)
break;
if(ob.retmodel( )= =m)
fout.write((char*)&ob,sizeof(ob)); }
remove("TV.DAT");
rename("temp.dat","TV.DAT");
cout<<"\nRECORD DELETED SUCCESSFULLY........";
getch(); }
fin.close();
fout.close();}



Q. 19. What do you understand by Primary Key and Alternate Key. Explain with example.                             For - 4 Marks
Powered By AlbireoAns : PRIMARY KEY : It is a set of one or more attributes that can uniquely identify tuples within the relation.
ALTERNATE KEY : A candidate key that is not the primary key is known as an alternate key.
For ex.
    Relation: Data
EmpNo
Name
Designation
MobileNo
PANCardNo
Salary
BankAccountNo
Here in above table EmpNo, MobileNo, PANCardNo & BankAccountNo are candidate keys. If EmpNo is made the primary key then remaining will automatically become alternate keys.
Q.20. Consider the following table GAMES and PLAYER. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
Table : GAMES

GCODE
GAMENAME
NUMBER
PRZMONEY
SCHDATE

101
Chess
5
25000
23 Jan 2010
102
Badminton
3
38000
12 Nov 2008
103
Carrom
6
18000
18 Mar 2010
105
Table Tennis
3
30000
09 Jan 2009
108
Basketball
5
40000
29 Apr 2009
Table : PLAYER

PCODE
NAME
GCODE
1
Rakesh Srivastava
101
2
Nilesh Mishra
102
3
Vandana
108
4
Ravi Jindal
105
1.                    to display the details of those games which are having prize money less than 30000 and organized before 2009.                             For -1 Marks
Ans. : SELECT * FROM GAMES WHERE PRZMONEY<30000 AND SCHDATE<’01-JAN-2009’ ;>
2.                    to display the name of PLAYERS in reverse alphabetical order.                             For - 1 Marks
Ans. : SELECT NAME FROM PLAYERS ORDER BY NAME DESC;
3.                    to increase the prize money by 1000 for those games which name starts with ‘B’.                             For - 1 Marks
Ans. : UPDATE GAMES SET PRZMONEY=PRZMONEY+1000 WHERE GAMENAME LIKE ‘B%’;
4.                    Insert an additional attribute namely DOB for entering date of birth in table PLAYER.                             For - 1 Marks
Ans. : ALTER TABLE PLAYER ADD(DOB DATE);
5.                    SELECT GAMENAME,NAME FROM GAMES G,PLAYER P WHERE G.GCODE=P.GCODE;                             For - 1 / 2 Marks
Ans. :    
GAMENAME
NAME
Chess
Rakesh Srivastava
Badminton
Niesh Mishra
Basketball
Vandana
Table Tennis 
Ravi Jindal
6.                    SELECT MIN(SCHDATE), MAX(PRZMONEY) FROM GAMES ;                             For - 1 / 2 Marks
Ans. : MIN(SCHDATE)       MAX(PRZMONEY)
           ----------------------      ---------------------------
           12-Nov-2008         40000
7.                    SELECT AVG(PRZMONEY) FROM GAMES WHERE SCHDATE<’01-JAN-2009’;                             For - 1 / 2 Marks
Ans. :             AVG(PRZMONEY)
                       --------------------------
                           38000
8.                    SELECT COUNT(DISTINCT NUMBER) FROM GAMES;                             For - 1 / 2 Marks
Ans. :  COUNT(DISTINCT NUMBER)
           -----------------------------------------
              3
Q. 21. State and verify Absorption law in Boolean algebra.                             For - 2 Marks
Powered By AlbireoAns.: Absorption law states that :
a) x+xy=x                    b) x(x+y)=x
Verification:
x+xy=x
LHS=x+xy     by distributive law
=x(1+y)  since 1+y=1
=x.1       since 1.x=x
=x = RHS, hence verified
OR (using truth table)
x
y
xy
x+xy
0
0
0
0
0
1
0
0
1
0
0
1
1
1
1
1
Here column x and x+xy are identical, hence proved.
Q. 22. Write the SOP form of a Boolean function G, which is represented in a truth table as follows :                             For - 2 Marks
A
B
C
G
0
0
0
1
0
0
1
1
0
1
0
0
0
1
1
0
1
0
0
1
1
0
1
0
1
1
0
0
1
1
1
1
Ans. Add extra column for min term and write min terms for the rows which have output (G) as 1:-
A
B
C
G
Min Term
0
0
0
1
A’B’C’
0
0
1
1
A’B’C
0
1
0
0

0
1
1
0

1
0
0
1
AB’C’
1
0
1
0

1
1
0
0

1
1
1
1
ABC
Now sum all the min terms to get the SOP as:
Therefore SOP of F(A,B,C)= A’B’C’+A’B’C+AB’C’+ABC
Q. 23. Write the equivalent Boolean Expression R for the following circuit diagram :                             For - 1 Marks
Description: http://www.cbseguess.com/papers/cbse_important_questions/xii/2012/computer_science/images/1.jpg
Ans. : (A+B) (A+B’) (A’+B)
Q. 24. If F(P,Q,R,S) = π (0,2,4,5,6,7,8,10,11,12,14) , obtain the simplified form using K-Map.                                  For - 4 Marks
Ans. Draw the 4 variable K-Map, plot & group the 0s starting from bigger to smaller group:
Description: http://www.cbseguess.com/papers/cbse_important_questions/xii/2012/computer_science/images/2.jpg
Reducing:
Octet = M0.M2.M4.M6.M8.M10.M12.M14
          = S
Quad = M4.M5.M6.M7
          = P+Q’
Pair    = M10.M11
          = P’+Q+R’
Therefore POS of F(P,Q,R,S)= S.(P+Q’).(P’+Q+R’)



Q. 25. What is the difference between packet & message switching?                             For - 1 Marks
Ans.: Packet Switching: It refers to protocols in which messages are broken up into small packets before they are sent. Each packet is transmitted individually across the net. Each packet has header information which enables to route the packet to its destination. At the destination the packets are reassembled into the original message.
Message Switching: In this technique, first the source computer transfers data to the buffer of switching office computer. Further it looks for a free link to another switching office, and then the data are transferred to this link.
Q. 26. Expand the following terminologies :                             For - 1 Marks
                        i) PHP                           ii) SMSC
Ans.: i) PHP – Hypertext Preprocessor            ii) SMSC – Short Message Service Center
Q. 27. What is infrared technology?                             For - 1 Marks
Ans.: INFRARED : Infrared technology allows computing devices to communicate via short-range wireless signals. The infrared transmission technology used in computers is similar to that used in consumer product remote control units. This ray transmits digital data bi-directionally through the air and can propagate throughout a room, but will not penetrate walls.
Q. 28. What do you mean by spam?                             For - 1 Marks
Ans.: SPAM :- It refers to electronic junk mail or junk newsgroup postings. Some people define it as any unsolicited e-mail.
Q. 29. What is proprietary software?.                             For - 1 Marks
Ans.: Proprietary software: It refers to any computer software that has restrictions on any combination of the usage, modification, copying or distributing modified versions of the software. Proprietary software usually can be distributed at no cost or for a fee. Proprietary software may also be called closed-source software. In other words it is neither open nor freely available.
Q. 30. What is Web Hosting?                             For - 1 Marks
Ans.: Web hosting: It is a way of hosting web-server application on a computer system through which electronic content on the internet is readily available to any web-browser client.
Q. 31. The Rangoli Creation has set up its new center at Patna for its office & web based activities. It has four blocks of buildings as shown in the diagram below:
Description: http://www.cbseguess.com/papers/cbse_important_questions/xii/2012/computer_science/images/3.jpg
The distance between various blocks are :
Block A to Block B
30 m
Block B to Block C
110 m
Block C to Block D
55 m
Block A to Block D
260 m
Block B to Block D
195 m
Block A to Block C
32 m
Number of computers in each block are :
Block A
25
Block B
55
Block C
125
Block D
15
( A ) . Suggest the cable layout (with diagram) of connections among the blocks & technology.                             For - 1 Marks
Ans. : (Draw any one)
Description: http://www.cbseguess.com/papers/cbse_important_questions/xii/2012/computer_science/images/4.jpg
Description: http://www.cbseguess.com/papers/cbse_important_questions/xii/2012/computer_science/images/5.jpg
( B ) . Suggest the most suitable place to house the server, with a suitable reason.                             For - 1 Marks
Ans.: The most suitable place to house the server would be Block C as it has the maximum number of computers.
( C ) . Suggest the placement of the following devices with reasons :                             For - 1 Marks
         i) Repeater  ii) Switch/Hub
Ans.: i) In layout 1 repeater will be placed between C & B blocks
Description: http://www.cbseguess.com/papers/cbse_important_questions/xii/2012/computer_science/images/6.jpg
OR
In layout 2, repeater will be placed between C & B and between B & D blocks
Description: http://www.cbseguess.com/papers/cbse_important_questions/xii/2012/computer_science/images/7.jpg
ii) Switch/Hub will be placed in all the blocks as they have their own computer networks.
( D ) The organization is planning to link its another office in the city located in the hilly region where cable connection is not feasible. Suggest an economic way to connect it with reasonably high speed. Justify your answer.                             For - 1 Marks
Ans.: Radio Wave would be an economic way to connect it with reasonably high speed. It offers mobility & freedom from land acquisition rights that are required for laying, repairing cables.



Comments

Popular posts from this blog

Viva Questions for IP Class XII