Вы находитесь на странице: 1из 26

Branch: Electrical Engg. ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 1 TUTORIAL SHEET NO.

: 1(A)
Q 1. What do you mean by command line arguments? Write a program to calculate factorial of any input number. (RTU-2010,2012) Q 2. What is the use of pointers? Write a C++ program to calculate sum of two numbers using the concept of pointer. (RTU-2010). Q 3.Explain the pointer operators, and how they can be used to access value of any variable. (RTU-2008,2009)

Q 4. What is structure and how it is different from array? Also write a program to create a structure whose representation is shown below : Employee (emp_code,emp_name,emp_dept, date of joining[day,month,year]) Also create instances for this structure to store data of 1000 employees. (RTU-2012) Q 5. Write a program to swap two numbers using the concept of pointers. Q 6. How is do-while statement different from for and while loop statements? Q 7. What is 1-D array? What does array variable store? Explain with example, how elements in array can be accessed? Q 8. What do you mean by variable? List the rules to name the variable. Q 9. Differentiate with the help of example : a. Structure and union b. while and do while c. case and nested if Q 10. Explain difference between singly and doubly linked lists. Q 11. Explain the advantages and disadvantages of linked list over arrays. Q 12. Write a C program to copy first 100 characters of file1.txt to file2.txt. (RTU-2012). Q 13. What is linked list? Insert an element in doubly linked list. Q 14. What are the different types of link list? Explain each type in brief. Q 15. Write a program to delete an element from any given position for double link list. (RTU-2008,2009) (RTU-2010) (RTU-2010) (RTU-2007) (RTU-2008,2009,2011) (RTU-2011) (RTU-2011) (RTU-2011) (RTU-2009,2008)

Prepared by- Er. Anamika Choudhary

Branch: Electrical Engineering ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 1 TUTORIAL SHEET NO.: 1(B)
A. Short Answers Type Questions: Q.1 What is C? Q.2 How do you find out if a linked-list has an end? (i.e. the list is not a cycle) Q.3 What is the difference between realloc() and free()? Q.4 What is function overloading and operator overloading? Q.5 What is the difference between declaration and definition? Q.6 What are the advantages of inheritance? Q.7 What is the difference between an ARRAY and a LIST? Q.8 Name some pure object oriented languages. Q.9 Who is the developer of c language? Q.10 What is linked list? B. Multiple Choice Questions: Q.11 Who is the developer of c : (A) James Gosling (B)Dennis Ritchie Q.12 Q.13

(C) Donald

(D)Linus Torvalds

The minimum number of temporary variables needed to swap the contents of two variables is (A)1 (B)2 (C)3 (D)0 C is often called a (A)Object oriented language (C)Assembly language (B)High level language (D)Machine level language

Q.14 Q.15 Q.16

The loop in which the statements within the loop are executed at least once is called (A)do-while (B)while (C)for (D)goto The control automatically passes to the first statement after the loop in (A)continue statement (B) break statement (C)switch statement A pointer variable can be (A) passed to a function as argument. (C) returned by a function. (D)if statement

(B) changed within function. (D) assigned an integer value.

Q.17 Q.18 Q.19 Q.20

A self contained block of statements that perform a coherent task of some kind is called a (A) Monitor (B) Function (C) Program (D) Structure Recursion is sometimes called (A) Circular definition (B) Complex definition Each C preprocessor directive begins with (A) # (B) include (C) main() main() { long i = 30000; printf(%d, i); } the output is (A) 3000 (B) 30000 (C) Procedure (D) { (D) Union

(C) 0

(D) -1 (C) Bitwise shifting (D) Bitwise complement (D) #include library

Q.21 Q.22

The << operator is used for (A) Right shifting (B) Left shifting

The C language includes the header file standard input & output in (A) stdlib.h library (B) stdio.h library (C) conio.h library

Prepared by- Er. Anamika Choudhary

Q.23 Q.24 Q.25

The machine registers are sometimes called (A) local variables (B) global variables (C) accumulators

(D) static variables

Set of values of the same type, which have a single name followed by an index is called (A) function (B) structure (C) array (D) union What is the output of the following program segment? main() { int i = ++2; printf(%d\n, i); } (A) 3 (B) 2 (C) 0 (D) -1 scanf() can be used for reading (A) double character (B) single character (C) multiple characters (D) no character

Q.26 Q.27

Which amongst the following is not a keyword? (A) external (B) int (C) float

(D) double

TRUE/FALSE :
1.Keywords can be used as variable names. 2.Structure is a user defined data type. 3.Functions cannot be defined outside the class. 4.Functions can be overloaded. 5. Float is a keyword. 6.Array is a homogeneous collection of elements. 7.A variable is called a sequence of bytes. 8.Reference is another name for a variable. 9.A pointer contains the address of another variable. 10. 11. 12. 13. 14. 15. Function cannot return array. Strcat() is a string handling function. strlen() is used to compare two strings. The break statement is used to change the flow of control. * has more priority than +. For loop is an unconditional branch statement. C is case-sensitive language.

16.

Prepared by- Er. Anamika Choudhary

Fill in the blanks : 1. Variables of a class are called ------2. The argument list of function is known as functions ----3. A function can be invoked by -----4. ----- is a variable which holds the address of another variable. 5. A function with no return type is declared as -----6. ----- are class members that are hidden from the outside world 7. Dynamic allocation of memory is done by ------ operator. 8. ----- is an example of a keyword. 9. A sequence of bytes is called -----10. :: is known as ----.

Prepared by- Er. Anamika Choudhary

Branch: Electrical Engg. ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 2 TUTORIAL SHEET NO.: 2(A)

Q 1. What are the features and concept of OOP? Q 2. Explain with an example the concept of class & object. 07,09,10,11)) Q 3. Explain the three visibility mode of a class (public, private, protected). Q 4. What is inheritance ?Discuss single and multiple inheritance. Q 5. What is polymorphism? Explain in detail the compile time polymorphism? Q 6. Explain the meaning of inheritance in terms of OOP with the help of an example. Q 7. What do you understand by reusability of code in C++? Q 8. Explain the various types of inheritance in C++ with the help of real life example. Q 9. Explain the concept dynamic binding. Q 10 What are the main enhancement of C++ over C in data types? Q.11 Explain attributes of a protectedly derived class.

(RTU-2011) (RTU-

(RTU-2010,2011) (RTU-07,08,09,11)

(RTU-2010)

(RTU-2010) (RTU-2012) (RTU-2012)

Q.12 With the help of suitable example the need of data hiding and its implementation in C++.

Prepared by- Er. Anamika Choudhary

Q.13 State the difference between class in C++ and structures in C. Q.14 What do you understand by Data Abstraction and Data Encapsulation.

(RTU-2012) (RTU-2007)

Branch: Electrical Engineering ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 2 TUTORIAL SHEET NO.: 2(B)
Short Answers Type Questions: 1. 2. 3. 4. 5. 6. 7. 8. 9. Define a constructor - What it is and how it might be called (2 methods). You have two pairs: new() and delete() and another pair : alloc() and free(). What is the difference between class and structure? What is encapsulation? What do you mean by inheritance? Describe PRIVATE, PROTECTED and PUBLIC the differences and give examples. What is namespace? What is a COPY CONSTRUCTOR and when is it called? What is virtual class and friend class?

Fill in the blanks: 1.A child class is said to be ---- from the base class. 2.. A constructor that takes no argument is known as ----3.---- gives a new meaning to the existing C++ operators. 4.Memory once allocated is released using ---- operator. 5.Maximum number of arguments that can be passed to destructor function is ---6.----- is the alternate name for a variable. 7.Variables that are alive and active throughout the program are called -------8.main() is an example of -----

Prepared by- Er. Anamika Choudhary

9.A _________ is a special member function used to initialize the data members of a class. 10. The default access for members of a class is _________.

TRUE/FALSE: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. By default the components of a structure are public. The default access level of a class is public. While is an exit controlled loop. For is an entry controlled loop. Do while is an exit controlled loop. The structure elements are stored in the same memory location. In dynamic allocation memory is allocated at runtime. A null pointer does not point to any data object. Global variables are alive and active throughout the program. The class that handles reading from a file is ofstream. .The class that handles writing to a file is ofstream. The increment operator can be applied to a pointer. A variable can be declared static using the keyword static. Initialized arrays do not have their dimensions specified. C++ is an object oriented language. # define directive defines a macro. . Do while is executed once even if the condition is false. Public members are hidden from the outside world. . Dynamic allocation of memory is done by new operator. :: operator can be overloaded. endl is not a manipulator.

Prepared by- Er. Anamika Choudhary

22. 23. 24. 25. 26. 27. 28. 29. 30.

.A static function can access only static members. Class can be defined within a function. Enum is a user defined data type. Abstract class is not used to create objects. A base class can be publicly or privately inherited. . The private members cannot be inherited. A class can have multiple constructors. Data items in a class may be public Class members are public by default

Multiple Choice Questions :

Q.1 The address of a variable temp of type float is (A) *temp (B) &temp (C) float& temp (D) float temp&

Q.2 What is the output of the following code char symbol[3]={a,b,c}; for (int index=0; index<3; index++) cout << symbol [index]; (A) a b c (B) abc (C) abc (D) abc

Q.3 The process of building new classes from existing one is called ______. (A) Polymorphism (B) Structure (C) Inheritance (D) Cascading

Q.4 If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access (A) protected and public data only in C and B. (C) private data in A and B. (B) protected and public data only in C. (D) protected data in A and B.

Q.5 If the variable count exceeds 100, a single statement that prints Too many is (A) if (count<100) cout << Too many; (C) if (count>100) cout << Too many; (B) if (count>100) cout >> Too many; (D) None of these.

Prepared by- Er. Anamika Choudhary

Q.6 Usually a pure virtual function (A) has complete function body. (C) will be called only to delete an object. Q.7 To perform stream I/O with disk files in C++, you should (A) open and close files as in procedural languages. (C) use C language library functions to read and write data. Q.8 Overloading the function operator (A) requires a class with an overloaded operator. operator. (C) allows you to create objects that act syntactically like functions. (D) usually make use of a constructor that takes arguments. Q.9 In C++, the range of signed integer type variable is ________ (A) 0 to 216 (B) 2 to 2 1 15 15 (C) 2 to 2 1 7 7 (D) 8 0 to 2 (B) requires a class with an overloaded [ ] (B) use classes derived from ios. (D) include the IOSTREAM.H header file. (B) will never be called. (D) is defined only in derived class.

Q.10 If x = 5, y = 2 then x y equals________.(where is a bitwise XOR operator) (A) 00000111 Q.11 If an array is declared as int a[4] = {3, 0, 1, 2}, then values assigned to a[0] & a[4] will be ________ (A) 3, 2 (B) 0, 2 (C) 3, 0 (D) 0, 4 (B) 10000010 (C) 10100000 (D) 11001000

Q.12 Mechanism of deriving a class from another derived class is known as____ (A) Polymorphism Passing Q.13 RunTime Polymorphism is achieved by ______ (A) friend function (B) virtual function (C) operator overloading (D) function overloading (B) Single Inheritance (C) Multilevel Inheritance (D) Message

Q.14 A function call mechanism that passes arguments to a function by passing a copy of the values of the arguments is __________ (A) call by name (B) call by value (C) call by reference (D) call by value result

Q.15 In C++, dynamic memory allocation is accomplished with the operator ____ (A) new (B) this (C) malloc( ) (D) delete

Prepared by- Er. Anamika Choudhary

Branch: Electrical Engg. ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 3 TUTORIAL SHEET NO.: 3(A)
Q 1. Explain inline function ?Write a program that depicts the example of inline function. (RTU-2009) Q 2. How does inline function differ from general functions and macro with suitable example? Q 3. What are constructors? Explain with suitable examples. Q 4. What do you mean by Dynamic Binding and Data Hiding in C++. Q 5 What are destructors? Explain with examples. Q 6. Make difference between constructor and destructor. Q 7. Explain friend function with example. Q 8. Write a C++ program to overload the unary ++ operator. Q 9. What is function overloading? Explain with example. (RTU-07,08,10,12) (RTU-07,10,11) (RTU-2007) (RTU-2009) (RTU-2008,2009) (RTU-2008,2009,2011) (RTU-2007) (RTU-2009) (RTU-07,08,10)

Q 10. Explain operator overloading? Write a program to overload any binary operator.

Q 11. Write a program that determines the sum of 2 rational numbers using operator overloading. Q.12 What are the main enhancements in C++ over C in data types ? (RTU-2010,11)

Q.13 State and explain those operators that are available in C++ but was not present in C. (RTU-2012) Q.14 Write a macro to find largest of two numbers. [use c++]. (RTU-2011)

Prepared by- Er. Anamika Choudhary

Branch: Electrical Engineering ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 3 TUTORIAL SHEET NO.: 3(B) Short Answers Type Questions:
1. Does c++ support multilevel and multiple inheritance? 2. What is friend function? 3. What is abstraction? 4. What are virtual functions? 5. What is a scope resolution operator? 6. A scope resolution operator (::), can be used to define the member functions of a class outside the class. 7. What do you mean by pure virtual functions? 8. Why are arrays usually processed with for loop? 9. How do you link a C++ program to C functions? 10. What are the differences between a C++ structure and C++ class? Fill in the blanks: 11. When the same function is used for multiple operations it is known as -----12. -----is an instance of a class. 13. ---- is a data hiding principle. 14. ---- binds data and associated functions together. 15. The operator & when placed before a variable returns ----16. ---- is an exit control loop. 17. The function inside a class is known as ----18. The ----- pointer stores the address of the object currently invoking a member function. 19. Function overloading is an example of -----20. ------ is an entry controlled loop. 21. ----- function takes objects as arguments. 22. ---- are the access levels of a class. 23. A pointer that does not point to any data object is -----24. In a class all members are ----- by default.

Prepared by- Er. Anamika Choudhary

25. In ----- all data elements are stored in the same memory location.

Multiple Choice Questions:


1. If we create a file by ifstream, then the default mode of the file is _________ (A) ios :: out 2. (A) (B) (C) (D) 2. (A) (B) 3. (A) 4. (A) (B) (C) (D) 5. (A) (B) (C) (D) 6. (B) ios :: in (C)ios :: app (D) ios :: binary

A variable defined within a block is visible from the point of definition onward in the program. from the point of definition onward in the function. from the point of definition onward in the block. throughout the function. The break statement causes an exit from the innermost loop only. from all loops & switches. (C) only from the innermost switch. (D) from the innermost loop or switch.

Which of the following cannot be legitimately passed to a function A constant. (B) A variable. (C) A structure (D) A header file.

A property which is not true for classes is that they are removed from memory when not in use. permit data to be hidden from other classes. bring together all aspects of an entity in one place. Can closely model objects in the real world. You can read input that consists of multiple lines of text using the normal cout << combination. the cin.get( ) function with one argument. the cin.get( ) function with two arguments. the cin.get( ) function with three arguments. The keyword friend does not appear in

Prepared by- Er. Anamika Choudhary

(A) (B) (C) (D) 7. (A) (B) 8. (A) (B) (C) (D) 9. (A) (B) (C) (D) 10. (A) (B) (C) (D) 11.

the class allowing access to another class. the class desiring access to another class. the private section of a class. the public section of a class. The process of building new classes from existing one is called Structure. (B) Inheritance. Polymorphism. (D) Template. If you wanted to sort many large objects or structures, it would be most efficient to place them in an array & sort the array. place pointers to them in an array & sort the array. place them in a linked list and sort the linked list. place references to them in an array and sort the array. Which statement gets affected when i++ is changed to ++i? i = 20; i++; for (i = 0; i<20; i++) { } a = i++; while (i++ = 20) cout <<i; A friend function to a class, C cannot access private data members and member functions. public data members and member functions. protected data members and member functions. the data members of the derived class of C. The operator that cannot be overloaded is ++ (B) :: (C) ( ) (D) ~

(A)

Prepared by- Er. Anamika Choudhary

TRUE/FALSE: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. # define directive defines a macro. Do while is executed once even if the condition is false. Public members are hidden from the outside world. Friend functions have access only to public members of the class. A function designed as public can be accessible by non-members of a class. Friendship is commutative. new and delete are operators. new operator be overloaded ? We can implement generic classes using templates Using operator overloading we can invent new operators. Inheritance helps in making a general class into a more specific class. A base class is never used to create objects. Classes can be inherited privately.

Prepared by- Er. Anamika Choudhary

Branch: Electrical Engg. ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 4 TUTORIAL SHEET NO.: 4(A)
Q 1. Explain the concept and need of inheritance. Q 2. Explain difference between base class and derived class with suitable example. Q 3. What is single inheritance? Differentiate between single and multilevel inheritance. Q 4. What is multiple inheritance ? Explain with suitable example. Q 5. Explain multilevel inheritance by program. Q 6.How is the ambiguity resolved in case of multiple inheritance ? Q 7.What are virtual functions? Explain with suitable example. 07,08,09,11) Q 8. Explain runtime polymorphism and implement it with the help of example. Q.9 What is the difference between virtual function and pure virtual function? Q.10 What is the use of virtual base class. Q.11 Write a simple C++ program which will show the concept of pointers to object. Q.12 What is abstract class? How can you make a class abstract. Q.13 State the difference between static and virtual function. (RTU-2010) (RTU-2010) (RTU-2007) (RTU-2010,11) (RTU-2012) (RTU-2012) (RTU(RTU-2010,11) (RTU-2007,10) (RTU-2008,09) (RTU-2009)

Prepared by- Er. Anamika Choudhary

Q.14 Explain the difference between compile time and run time polymorphism.

(RTU-2012)

Branch: Electrical Engineering ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 4 TUTORIAL SHEET NO.: 4(B) Short Answers Type Questions:
1. What is the Standard Template Library (STL)? 2. Describe run-time type identification. 3. Differentiate between a template class and class template. 4. Define namespace. 5. What is an Iterator class ? 6. What is a Null object? 7. What do you mean by binding of data and functions? 8. What is the difference between an object and a class? 9. What is a class?

Fill in the blanks :


1. The constructor and destructor of a class are called __________. 2.Two or more functions may have the same name, as long as their _________ are different. 3.A constructor with default arguments for all its parameters is called a ________ constructor. 4.Static member functions can access only the _________ data members of a class. 5.The two types of polymorphism is : _____________ & ____________. 6.A file stream is an extension of a ______ stream. 7.The Standard Template Library(STL) is a library of ________ templates. 8.Run time polymorphism is________ than the compile time polymorphism. 9.With private inheritance, public and protected members of the base class become _______ members of the derived class.

Prepared by- Er. Anamika Choudhary

Multiple Choice Questions :


Q 1. Which of the statements is true in a protected derivation of a derived class from a base class? (A) Private members of the base class become protected members of the derived class (B) Protected members of the base class become public members of the derived class (C) Public members of the base class become protected members of the derived class (D) Protected derivation does not affect private and protected members of the derived class. Q 2. Which of the following statements is NOT valid about operator overloading? (A) Only existing operators can be overloaded. (B) Overloaded operator must have at least one operand of its class type. (C) The overloaded operators follow the syntax rules of the original operator. (D) none of the above. Q 3. Exception handling is targeted at (A) Run-time error (B) Compile time error (C) Logical error (D) All of the above. (B) only derived class object (D) None of the above (B) only one parameter (D) only parameters of the derived type (D) any number (B) creates a variable called new (D) tells how much memory is available Q 4. A pointer to the base class can hold address of (A) only base class object (C) base class object as well as derived class object Q 5. Function templates can accept (A) any type of parameters (C) only parameters of the basic type Q 6. How many constructors can a class have? (A) 0 Q 7. The new operator (A) returns a pointer to the variable (C) obtains memory for a new variable Q 8. Consider the following statements: int x = 22,y=15; x = (x>y) ? (x+y) : (x-y); What will be the value of x after executing these statements? (A) 22 (B) 37 (C) 7 (D) Error. Cannot be executed (B) a problem in the operating system (D) a run-time error Q 9. An exception is caused by (A) a hardware problem (C) a syntax error Q 10. A template class (A) is designed to be stored in different containers (B) works with different data types (C) generates objects which must be identical (B) 1 (C) 2

Prepared by- Er. Anamika Choudhary

(D) generates classes with different numbers of member functions. Q 11. Which of the following is the valid class declaration header for the derived class d with base classes b1 and b2? (A) class d : public b1, public b2 (C) class d : public b1, b2 Q 12. A library function exit() causes an exit from (A) the loop in which it occurs (C) the function in which it occurs (A) friend function (A) for the object. these. Q 15. An array element is accessed using (A) a FIFO approach both classes contain a virtual member function abc(), then the statement p->abc(); will cause the version of abc() in the __________class to be executed. (A) Base Class error Q 17. A pure virtual function is a virtual function that (A) has no body Q 18. A static function (A) should be called when an object is destroyed. (B) is closely connected with and individual object of a class. (C) can be called using the class name and function name. (D) is used when a dummy object must be created. Q 19. We can output text to an object of class ostream using the insertion operator<< because (A) the ostream class is a stream (C) we are actually outputting to cout. TRUE/FALSE: 1. A function template defines a parameterized nonmember function, which enables a program to call the same function with different types of arguments. 2. Destructors can be overloaded. 3. Static data members cannot be private. (B) the insertion operator works with all classes. (D) the insertion operator is overloaded in ostream (B) returns nothing (C) is used in base class (D) both (A) and (C) (B) Derived class (C) Produces compile time error (D) produces runtime (B) an index number (C) the operator (D) a member name Q 16. If there is a pointer p to object of a base class and it contains the address of an object of a derived class and (B) virtual function (B) for the pointer. (B) the block in which it occurs (D) the program in which it occurs (C) operator overloading (D) function overloading (C) both for the object and the pointer. (D) none of (B) class d : class b1, class b2 (D) class d : b1, b2

Q 13. RunTime polymorphism is achieved by ___________ Q 14. Declaration of a pointer reserves memory space

Prepared by- Er. Anamika Choudhary

4. Static member functions can use this pointer. 5. One cannot use enumerations in a class. 6. One cannot create an object of a virtual class.

7. The push operation inserts an element at the end of a stack. 8. It is not necessary for each node in a linked list to have a self-referential pointer. 9. In physical memory, the nodes in a linked list may be scattered around.

10. When the head pointer points to NULL, it signifies an empty list. 11. Linked list are not superior to STL vectors. 12. Deleting a node in a linked list is a simple matter of using the delete operator to free the node s memory. 13. A class that builds a linked list should destroy the list in the class destructor. 14. Once an exception has been throw, it is not possible for the program to jump back to the throw point.

Prepared by- Er. Anamika Choudhary

Branch: Electrical Engg. ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 5 TUTORIAL SHEET NO.: 5(A)
Q 1. What do you mean by formatted and unformatted data? Q 2. Which are different types of file opening modes? List their names with meaning. Q 3.What do you mean by file? Explain hierarchy of file stream class in C++. Q 4. What is template? Explain it with program. Q 5. Write a program to open a file in input and output mode. Accept data and write to the file. Display the content of the file. Q 6. Write a program that copies the data of one file into another file. Q 7. There are 100 records present in a file. Now write a program to read these records arrange them in ascending order and write them in target file. Q 8. Distinguish between overloading functions and templates. Q 9. What is STL? How is it different from C++ standard library. Q 10 Write a program which will explain the concept of template in C++. Q.11 Write short notes on File Access permission in C++. Q.12 What are the input and output flags. Discuss formatting operations. (RTU-2012) (RTU-2010) (RTU-2012) (RTU-2012,2010) (RTU-2010) (RTU-2009) (RTU-2010) (RTU-2011) (RTU-2010,2009,07)

Q.13 Write a C++ program to read a file and find out total number of characters, total number of line, total number of words and total no. of spaces from a given file. (RTU-2010)

Prepared by- Er. Anamika Choudhary

Q.14 Explain various functions for manipulation of file pointers and functions put(), get(), read() and write(). (RTU-2011)

Branch: Electrical Engineering ( II Year / III SEM ) 3EE2: COMPUTER PROGRAMMING-I UNIT 5 TUTORIAL SHEET NO.:5 (B) Short Answers Type Questions:
1. What is a template? 2. What is a container class? What are the types of container classes? 3. What is polymorphism? 4. What is an accessor? 5. The default member and base-class access specifier are different. 6. How many ways are there to initialize an int with a constant? 7. What is a default constructor? 8. When is a template a better solution than a base class? 9. What is an explicit constructor? 10. Difference between template and class. Fill in the blanks : 1. Member functions of a class are normally made ________ and data members of a class are normally made ________. 2. A _______ is a set of instance or values. 3. A _______ is a linear list in which additions and deletions take place at different ends. 4. C++ programming language was designed and developed by __________ at _________. 5. C++ is a ___________programming language with __________ extensions. 6. A variable definition defines a _________ of the variable and reserves ______ for it. 7. In C++ a keyword cannot be used as ________. 8. Literals are always ________. 9. In C++, _____ operator has the lowest precedence.

Prepared by- Er. Anamika Choudhary

10. Name mangling is done by the _________. 11. Pointers are ________ that contain the addresses of other variables and ________. 12. A program can use the address of any variable in an expression, except variables declared with the _______ storage class. 13. One cannot perform pointer arithmetic on a ______pointer without _____. TRUE/FALSE: 1. In C++, only one catch block can handle all the exceptions. 2. It is not possible to throw an exception. 3. There can be only one catch block in a program 4. When an exception if throw, but not caught, the program ignorers the error. 5. A class object passed to a function template must overload any operators used on the class object by the template. 6. In the function template definition it is not necessary to use each type parameter declared in the template prefix. 7. 8. It is possible to overload a function template and an ordinary (non-template) function. A class template may not be used as a base class.

9. When declaring an iterator from the STL, the compiler automatically creates the right kind, depending upon the container it is used with. 10. ios stream is derived from iostream. 11. eof() function returns zero value if the eofbit is set.

Multiple Choice Questions: 1.A struct is the same as a class except that (A) there are no member functions. (B) all members are public. (C) cannot be used in inheritance hierarchy. (D) it does have a this pointer.

Prepared by- Er. Anamika Choudhary

2.Pure virtual functions (A) have to be redefined in the inherited class. (B) cannot have public access specification. (C) are mandatory for a virtual class. (D) None of the above. 2.Additional information sent when an exception is thrown may be placed in (A) the throw keyword. (B) the function that caused the error. (C) the catch block. (D) an object of the exception class. 3.Use of virtual functions implies (A) overloading. (B) overriding. (B) static binding. (D) dynamic binding. 4. this pointer (A) implicitly points to an object. (B) can be explicitly used in a class. (C) can be used to return an object. (D) All of the above. 5. Within a switch statement (A) Continue can be used but Break cannot be used (B) Continue cannot be used but Break can be used (C) Both Continue and Break can be used (D) Neither Continue nor Break can be used 6. Data members which are static (A) cannot be assigned a value

Prepared by- Er. Anamika Choudhary

(B) can only be used in static functions (C) cannot be defined in a Union (D) can be accessed outside the class 7. Which of the following is false for cin? (A) It represents standard input. (B) It is an object of istream class. (C) It is a class of which stream is an object. (D) Using cin the data can be read from users terminal. 8. It is possible to declare as a friend (A) a member function (B) a global function (B) a class (D) all of the above 9. In multiple inheritance (A) the base classes must have only default constructors (B) cannot have virtual functions (C) can include virtual classes (D) None of the above. 10. Declaration of a pointer reserves memory space (A) for the object. (B) for the pointer. (C) both for the object and the pointer. (D) none of these. 11. for (; ;) (A) means the test which is done using some expression is always true (B) is not valid (C) will loop forever

Prepared by- Er. Anamika Choudhary

(D) should be written as for( ) 12. The operator << when overloaded in a class (A) must be a member function (B) must be a non member function (B) can be both (A) & (B) above (D) cannot be overloaded 13. A virtual class is the same as (A) an abstract class (B) a class with a virtual function (B) a base class (D) none of the above. 14. Identify the operator that is NOT used with pointers (A) -> (B) & (B) * (D) >> 15. Consider the following statements char *ptr; ptr = hello; cout << *ptr; What will be printed? (A) first letter (C) entire string (B) it is a syntax error (D) last letter 16. In which case is it mandatory to provide a destructor in a class? (A) Almost in every class (B) Class for which two or more than two objects will be created (C) Class for which copy constructor is defined (D) Class whose objects will be created dynamically 17. The members of a class, by default, are (A) Public (B) private Q 19 A template stores (A) styles, macros (B) Auto Text entires, Customized word command Settings (C) protected (D) mandatory to specify

Prepared by- Er. Anamika Choudhary

(C) graphics, text

(D) All of the above

Prepared by- Er. Anamika Choudhary

Вам также может понравиться