InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What Are Some Of The Things A Programmer Should Be Aware Of When Using The Stl?(many Of These May Not Make Sense Until You Have Actually Tried To Use The Stl.) |
Answer»
In particular:
In particular: |
|
| 2. |
How Do You Use The Stl? |
|
Answer» By including the necessary header files to permit ACCESS to the parts of the STL that you need, by declaring objects of the appropriate container, ITERATOR and function types, and then USING member functions and/or algorithms, as appropriate, to PERFORM whatever tasks your application requires. It is also generally necessary to ensure that whatever objects you plan to put into your container(s) are objects of classes that have a default constructor, a copy constructor, and an overloaded operator=. In addition, if you plan to sort or compare such container objects, the corresponding classes must provide definitions for operator== and operator<. FINALLY, since it is often the case that different containers can be used in the same problem situation, the user needs to be able to make an appropriate choice for each occasion, and this choice will usually be based on performance characteristics. By including the necessary header files to permit access to the parts of the STL that you need, by declaring objects of the appropriate container, iterator and function types, and then using member functions and/or algorithms, as appropriate, to perform whatever tasks your application requires. It is also generally necessary to ensure that whatever objects you plan to put into your container(s) are objects of classes that have a default constructor, a copy constructor, and an overloaded operator=. In addition, if you plan to sort or compare such container objects, the corresponding classes must provide definitions for operator== and operator<. Finally, since it is often the case that different containers can be used in the same problem situation, the user needs to be able to make an appropriate choice for each occasion, and this choice will usually be based on performance characteristics. |
|
| 3. |
What Are Some Other Components Of The Stl? |
|
Answer» Other STL components include function OBJECTS (objects of a class that defines operator()), or allocators (which manage memory allocation and deal location for containers). Function objects are ESSENTIAL for effective use of the STL, but the AVERAGE user will be able to ignore allocators most of the time by simply accepting the DEFAULT allocator for each container USED. Other STL components include function objects (objects of a class that defines operator()), or allocators (which manage memory allocation and deal location for containers). Function objects are essential for effective use of the STL, but the average user will be able to ignore allocators most of the time by simply accepting the default allocator for each container used. |
|
| 4. |
What Are The Major Components Of The Stl? |
|
Answer» The CONTAINERS and container adaptors (both are objects that can hold other objects), the iterators (generalized pointers that point at ITEMS in containers), and the algorithms (that work on containers through iterators) will be the most frequently used COMPONENTS of the STL. The containers and container adaptors (both are objects that can hold other objects), the iterators (generalized pointers that point at items in containers), and the algorithms (that work on containers through iterators) will be the most frequently used components of the STL. |
|
| 5. |
What Is The Design Philosophy Of The Stl? |
|
Answer» The STL exemplifies generic PROGRAMMING RATHER than object-oriented programming, and derives its power and flexibility from the use of templates, rather than inheritance and polymorphism. It also avoids new and delete for memory management in favor of allocators for STORAGE allocation and deal location. The STL also provides performance GUARANTEES, i.e., its specification requires that the containers and algorithms be implemented in such a way that a user can be CONFIDENT of optimal runtime performance independent of the STL implementation being used. The STL exemplifies generic programming rather than object-oriented programming, and derives its power and flexibility from the use of templates, rather than inheritance and polymorphism. It also avoids new and delete for memory management in favor of allocators for storage allocation and deal location. The STL also provides performance guarantees, i.e., its specification requires that the containers and algorithms be implemented in such a way that a user can be confident of optimal runtime performance independent of the STL implementation being used. |
|
| 6. |
Why Should A C++ Programmer Be Interested In The Stl? |
|
Answer» Because the STL embodies the concept of reusable software COMPONENTS, and provides off-the-shelf SOLUTIONS to a wide variety of programming problems. It is also EXTENSIBLE, in the sense that any programmer can write new software (containers and algorithms, for example), that "fit in" to the STL and work with the already-existing parts of the STL, provided the programmer follows the APPROPRIATE design guidelines. Because the STL embodies the concept of reusable software components, and provides off-the-shelf solutions to a wide variety of programming problems. It is also extensible, in the sense that any programmer can write new software (containers and algorithms, for example), that "fit in" to the STL and work with the already-existing parts of the STL, provided the programmer follows the appropriate design guidelines. |
|
| 7. |
Who Developed The Stl? |
|
Answer» The STL was developed at Hewlett Packard by ALEXANDER Stepanov, with major contributions by David Musser and Meng Lee. It was DEEMED by the C++ Standards Committee to be so IMPORTANT to the future of C++ that the approval of the C++ Standard was delayed for several YEARS so that the STL could be incorporated into that Standard. A version of the Standard that incorporated the STL was FIRST approved in the fall of 1998. The STL was developed at Hewlett Packard by Alexander Stepanov, with major contributions by David Musser and Meng Lee. It was deemed by the C++ Standards Committee to be so important to the future of C++ that the approval of the C++ Standard was delayed for several years so that the STL could be incorporated into that Standard. A version of the Standard that incorporated the STL was first approved in the fall of 1998. |
|
| 8. |
What Is The Stl? |
|
Answer» It's a sophisticated and POWERFUL LIBRARY of template classes and template functions that IMPLEMENT many common data structures and algorithms, and forms part of the C++ Standard Library. It's a sophisticated and powerful library of template classes and template functions that implement many common data structures and algorithms, and forms part of the C++ Standard Library. |
|
| 9. |
What Is The Difference Between C++ And Vc++? |
|
Answer» VC++ uses all C++ features. VC++ has GUI and it is user FRIENDLY. It has many PROGRAMMING features like Win32, MFC, ATL, ActiveX, DLLs etc. VC++ uses all C++ features. VC++ has GUI and it is user friendly. It has many programming features like Win32, MFC, ATL, ActiveX, DLLs etc. |
|
| 10. |
Tell Me What Is The Difference Between Thread And Process? |
|
Answer» THREAD is a SMALLEST UNIT of PROCESS. In process have ONE or more thread. Thread is a smallest unit of process. In process have one or more thread. |
|
| 11. |
Write A C++ To Define A Class Box With Length, Breadth And Height As Data Member And Input Value(), Print Value() And Volume() As Member Functions? |
|
Answer»
#include class BOX { private: public: VOID input(); void PRINT(); long volume(long,int,int); }; void BOX::input() { cout<<"input values of l,b,h"<<"n"; cin>>l>>b>>h; } void BOX::print() { out<<"volume="<<"and"; } void BOX::volume() { long volume(long l,int b,int h); { return(l*b*h); } } void main() { set BOX b1; b1.input(); b1.print(); b1.volume(); return; } #include #include class BOX { private: int l,b,h; public: void input(); void print(); long volume(long,int,int); }; void BOX::input() { cout<<"input values of l,b,h"<<"n"; cin>>l>>b>>h; } void BOX::print() { out<<"volume="<<"and"; } void BOX::volume() { long volume(long l,int b,int h); { return(l*b*h); } } void main() { set BOX b1; b1.input(); b1.print(); b1.volume(); return; } |
|
| 12. |
Why & Sign Is Used In Copy Constructor? |
|
Answer» To avoid local copy of object reference (&) is used in copy constructor. Moreover if the & is omitted then copy constructor GOES in infinite loop. eg. if class name is SAMPLE. Copy constructor WITHOUT & Sample :: Sample (Sample s) { //Code goes here } and we create object as FOLLOWS. ; Sample s; Sample S1(s); In this scenario program will go in infinite loop. To avoid local copy of object reference (&) is used in copy constructor. Moreover if the & is omitted then copy constructor goes in infinite loop. eg. if class name is Sample. Copy constructor without & Sample :: Sample (Sample s) { //Code goes here } and we create object as follows. ; Sample s; Sample s1(s); In this scenario program will go in infinite loop. |
|
| 13. |
#define Cube(x) (x*x*x) Main() { Int A,b=3; A=cube(b++); Printf("%d %d",a,b); } What Should Be The Value Of A And B? My Calc A=4 But Syst A=6 How Pls Tell Me If You Know It? |
|
Answer» 27 4 is the OUTPUT. The call to the MACRO sets a = B*b*b with b = 3, 3 CUBED is 27 then b is incremented to 4 after the macro call. 27 4 is the output. The call to the macro sets a = b*b*b with b = 3, 3 cubed is 27 then b is incremented to 4 after the macro call. |
|
| 14. |
Write A C++ Program To Create An Object Of A Class Called Employee Containing The Employee Code Name Designation Basic Salary Hra Da Gross Salary As Data 10 Such Objects "members Process "? |
|
Answer»
#include { int person; float salary; }p; cout<<"enter the person NAME"; cin>>p.person; cout<<"enter the salary"; cin>>p.salary; } void main() { person; GETCH(); } #include #include class person { int person; float salary; }p; cout<<"enter the person name"; cin>>p.person; cout<<"enter the salary"; cin>>p.salary; } void main() { person; getch(); } |
|
| 15. |
Why We Are Using The Fork Command And How It Works? |
|
Answer» In LINUX fork() system call is used to create a child process. The Child process inherits some properties of its parent and OPERATES in a SEPARATE memory space. In linux fork() system call is used to create a child process. The Child process inherits some properties of its parent and operates in a separate memory space. |
|
| 16. |
How To Get The Sum Of Two Integers? |
|
Answer» #include<stdio.h> #include<conio.h> VOID main() { clrscr(); int i,j,sum; SCANF("%d%d",&i,&j); sum=i+j; printf("sum=%d",sum); } #include<stdio.h> #include<conio.h> void main() { clrscr(); int i,j,sum; printf("enter two numbers"); scanf("%d%d",&i,&j); sum=i+j; printf("sum=%d",sum); } |
|
| 17. |
Tell Me About C++? |
|
Answer» C++ is OBJECT oriented programming language.. the main function VALUE should RETURN. c++ is object oriented programming language.. the main function value should return. |
|
| 18. |
What Is The Acronym Of The Term C.o.m.p.u.t.e.r? |
|
Answer» Common operating machine a particular user technical education research. OR
Common operating machine a particular user technical education research. OR |
|
| 19. |
What Is Sorted Linked List? |
|
Answer» Linked list MEANS node which is connected each other with a line. It means that each node is connected with another one. Each node of the list holds the reference of the next node. If we talk about the sorted linked list , it is also a list just like another list. but the DIFFERENCE is only that it HOLD all the nodes in a sequential manner either in ascending ORDER descending order. Linked list means node which is connected each other with a line. It means that each node is connected with another one. Each node of the list holds the reference of the next node. If we talk about the sorted linked list , it is also a list just like another list. but the difference is only that it hold all the nodes in a sequential manner either in ascending order descending order. |
|
| 20. |
Explain Method Overloading? |
|
Answer» METHOD OVERLOADING is to overload methods USING same class NAME by writing different parameters. This is called Method overloading. Method overloading is to overload methods using same class name by writing different parameters. This is called Method overloading. |
|
| 21. |
Write A Program In C/c++ To Implement Reader- Writer Problem? |
|
Answer» Readers-Writers Problem: The readers-writers problem is a classic synchronization Problem in which two Distinct classes of threads exist, reader and writer. Multiple reader threads can be present in the Database simultaneously. However, the writer threads must have exclusive access. That is, no other writer thread, nor any reader thread, May be present in the Database while a given writer thread is present. Note: The reader/writer thread must call start Read()/start Write() to enter the database and it must call end Read()/end Write() to exit the database. Class Database extends Object { Private int numReaders = 0; Private int numWriters = 0; Private Condition Variable OKtoRead = new Condition Variable (); private Condition Variable OKtoWrite = new Condition Variable (); public synchronized void start Read() { while (numWriters > 0) wait(OKtoRead); numReaders++; } public synchronized void end Read() { numReaders--; notify(OKtoWrite); } public synchronized void start Write() { while (numReaders > 0 || numWriters > 0) wait(OKtoWrite); numWriters++; } public synchronized void end Write() { numWriters--; notify(OKtoWrite); NOTIFYALL(OKtoRead); } } class Reader extends Object implements Runnable { private Monitor m = null; public Reader(Monitor m) { this.m = m; new Thread(this).start(); } public void RUN() { //do something; m.startRead(); //do some reading… m.endRead(); // do something else for a long time; } } class Writer extends Object implements Runnable { private Monitor m = null; public Writer(Monitor m) { this.m = m; new Thread(this).start(); } public void run() { //do something; m.startWrite(); //do some writing… m.endWrite(); // do something else for a long time; } } - 2 - wait(Condition Variable cond) { put the calling thread on the “wait set” of cond; release LOCK; Thread.currentThread.suspend(); acquire lock; } notify(Condition Variable cond){ CHOOSE t from wait set of cond; t.resume(); } notifyAll(Condition Variable cond){ for all t in wait set of cond; t.resume() } For the FOLLOWING scenarios, we assume that only one reader thread and one writer thread are running on the processor. Readers-Writers Problem: The readers-writers problem is a classic synchronization Problem in which two Distinct classes of threads exist, reader and writer. Multiple reader threads can be present in the Database simultaneously. However, the writer threads must have exclusive access. That is, no other writer thread, nor any reader thread, May be present in the Database while a given writer thread is present. Note: The reader/writer thread must call start Read()/start Write() to enter the database and it must call end Read()/end Write() to exit the database. Class Database extends Object { Private int numReaders = 0; Private int numWriters = 0; Private Condition Variable OKtoRead = new Condition Variable (); private Condition Variable OKtoWrite = new Condition Variable (); public synchronized void start Read() { while (numWriters > 0) wait(OKtoRead); numReaders++; } public synchronized void end Read() { numReaders--; notify(OKtoWrite); } public synchronized void start Write() { while (numReaders > 0 || numWriters > 0) wait(OKtoWrite); numWriters++; } public synchronized void end Write() { numWriters--; notify(OKtoWrite); notifyAll(OKtoRead); } } class Reader extends Object implements Runnable { private Monitor m = null; public Reader(Monitor m) { this.m = m; new Thread(this).start(); } public void run() { //do something; m.startRead(); //do some reading… m.endRead(); // do something else for a long time; } } class Writer extends Object implements Runnable { private Monitor m = null; public Writer(Monitor m) { this.m = m; new Thread(this).start(); } public void run() { //do something; m.startWrite(); //do some writing… m.endWrite(); // do something else for a long time; } } - 2 - wait(Condition Variable cond) { put the calling thread on the “wait set” of cond; release lock; Thread.currentThread.suspend(); acquire lock; } notify(Condition Variable cond){ choose t from wait set of cond; t.resume(); } notifyAll(Condition Variable cond){ for all t in wait set of cond; t.resume() } For the following scenarios, we assume that only one reader thread and one writer thread are running on the processor. |
|
| 22. |
Write A Program In C++ Returning Starting Locations Of A Sub String Using Pointers? |
|
Answer» #INCLUDE<stdio.h> #include<iostream.h> INT main() { Char* mystrstr(char*,char*); Char str1[20]; Char str2[10]; Cin>>str1>>str2; Cout<<"nstr1 = "<<str1<<" str2 "<<str2 ; Char* c= mystrstr(str1,str2); If(c!=NULL) printf ("nc = %sn",c); Return 0; } Char* mystrstr(char* str1, char* str2) { Char *cp = (char *) str1; Char *s1, *s2; If ( !*str2 ) return ((char *)str1); While (*cp) { s1 = cp; s2 = (char *) str2; While ( *s1 && *s2 && !(*s1-*s2) ) { S1++; S2++; } If (!*s2) { printf ("n STRING foundn"); return (cp); } cp++; } return(NULL); } #include<stdio.h> #include<iostream.h> int main() { Char* mystrstr(char*,char*); Char str1[20]; Char str2[10]; Cout<<"n Enter two stringst"; Cin>>str1>>str2; Cout<<"nstr1 = "<<str1<<" str2 "<<str2 ; Char* c= mystrstr(str1,str2); If(c!=NULL) printf ("nc = %sn",c); Return 0; } Char* mystrstr(char* str1, char* str2) { Char *cp = (char *) str1; Char *s1, *s2; If ( !*str2 ) return ((char *)str1); While (*cp) { s1 = cp; s2 = (char *) str2; While ( *s1 && *s2 && !(*s1-*s2) ) { S1++; S2++; } If (!*s2) { printf ("n string foundn"); return (cp); } cp++; } return(NULL); } |
|