UNIT I

  1. What is C++?C++ is a general –purpose programming language with a bias towards system programming that - is a better C. - supports data abstraction - supports object-oriented programming

- supports generic programming.

  1. Write the applications of C++? * C++ is a versatile language for handling very large programs.

* C++ is suitable for virtually any programming task including development of editors, compilers, databases, communication system and complex real-life application system. * C++ programs are easily maintainable and expandable.

  1. Write the striking features of object oriented programming
  1. Emphasis is one data rather than procedure.
  2. Programs are divided into what are known as objects
  3. Data structures are designed such that they characterize the objects.
  4. Functions that operate on the data of an object are tied together in the data structure.
  5. Data is hidden and cannot be accessed by external functions
  6. Objects may communicate with each other through functions.
  7. New data and functions can be easily added whenever necessary.
  8. Follows bottom-up approach in program design.
  1. What you mean by program paradigms?

Oject oriented programming is a technique for programming – a paradigm for writing “good” programs for a set of Problems. If the term “object-oriented programming language” means anything. It must mean a programming language that provides mechanisms that supports the object-oriented style of programming well.

  1. What are the characteristics exhibited by procedure-oriented programming
  1. Emphasis is on doing things (algorithms)
  2. Most of the functions share global data.
  3. Large programs are divided into smaller programs known as functions.

4. Data move openly around the system from function to function.

5. Functions transforms data from one form to another.

6. Employs top-down approach in program design.

  1. What you mean by modular programming

A set of related procedures with the data they manipulate is often called a module. The programming paradigm becomes: Decide which module you want: partition the program so that data is hidden within modules. This paradigm is also known as the data hiding principle. Where there is no grouping of procedures with related date, the programming style suffices. Also , the technique for designing “good procedures” are now applied for each procedure in module. The most common example of module is the definition of stack.

  1. What you mean by separate compilation?

C++ supports C’s notation of separate compilation. This can be used to organize a program into a set of semi-independent fragments. Typically , we place the declarations that specify the interface to a module in a file with a name indicating its intended use. Thus, namespace stack { void push(char); // interface char pop( ); } would be place in a file stack.h , and users will include that file, called a header file.

  1. Write note on Exception handling.When a program is designed as a set of modules, error handling must be considered in right of these modules. Which module is responsible for handling what errors? Often, the module that detects an error doesn’t know what action to take. The recovery action depends on the module that involved the operation rather than on the module that found the error while trying to perform the operation.
  1. Define user-defined types:

C++ attacks this problem by allowing a user to directly define types that behave in the same way as built-in types. Such a type is often called an abstract data type. A more reasonable definition of abstract data type would require a mathematical “abstract “ specification, what are called types here would be concrete examples of such truly abstract entities. The programming paradigm becomes: Decide which types you want: provide a full set of operations for each type.

  1. Drawbacks of pop:* In pop Global data are more vulnerable to an inadvertent change by a function. * In a large program it is very difficult to identify what data is used by which functions. * In case we need to revise an external datastructures, we should also revise all functions that access the data, this provides an opportunity for bugs to creep in. * It does not model real world problems very well because functions are action-oriented and do not really correspond to the elements of the problem.
  1. What are the characteristics incorporated by OOPS, write some languages that support these? Object-Oriented programming incorporates all of object –based programming features along with two additional features, namely, inheritance and dynamic-binding. Object-based features + inheritance + dynamic binding. Object based features * Data encapsulation * Data hiding and access mechanism * Automatic initialization & clear-up of objects

* Operator overloading Languages that supports these features include c++ , smalltalk & object pascal.

  1. Depends upon features classify OOPS.
  1. Object-based programming languages.
  2. Object oriented programming languages.
  1. State the following statements are true or false
  2. In pop all data are shared by all functions.

---false.

(only global data can be shared by all functions)

  1. Inheritance means the ability to reuse the data values of one object by other objects ----True
  2. C++ allows us to create hierarchy-related objects---true d. In C++ , it is very easy to add to the existing structure of an object ---True.
  1. Discuss cascading of I/O operators:The multiple use of <in one statement is called cascading. When cascading an output operator, we should not ensure necessary blank spaces between different items.

a=10; b=15;cout < “A=”<a<”\n” < “B=” <b<”\n”; This is one statement but provides two lines of output. We can also cascade input operator > as Cin> number1>number 2; The values are assigned from left to right.

  1. State whether the following statements are true or

false

  1. In C++ , Identifier name can be start with digit ----false
  2. ::* is used to declare a pointer to a member of a class---true
  3. (type –name) expression is type cast operator format in C++ ----false (It should be type-name (expression)
  1. Discuss automatic conversion in C++.Whenever data types are mixed in an expression, C++ performs the conversions automatically. This process is known as implicit or automatic conversion.

SHORT CHAR Int Unsigned Long int

Unsigned long int Float Double

Long Double

Water fall model of type conversion

  1. Find the errors, if any, in the following C++ statements
  2. enum (green, yellow, red);
  3. const int array-size;
  4. int public =1000;
  5. int* p = new; // allocate memory with new.
  1. Discuss or compare the evolution of software technology. 1,0 MACHINE LANGUAGE ASSEMBLY LANGUAGE PROCEDURE PROGRAMMING OBJECT-ORIENTED PROGRAMMING Layers of software technology.
  2. Write a short note on relationship of data and functions in a procedure- oriented program. GLOBAL DATA GLOBAL DATA FUNCTION – 1 FUNCTION – 2

FUNCTION – 3

LOCAL DATA LOCAL DATA LOCAL DATA In a multi function program, many important data items are placed as global, so that they may accessed by all function. Each function may its own local data.

  1. Draw the program fragments representation:stack.h

stack interface user.c

stack.c

#include “stack.h” #include “stack.h”

use stack

define stack

UNIT II

21. What is meant by pointer to void?

The address that we put in a pointer must be the same type as the pointer. we cant assign the address of the float variable to a pointer to int. But there is an exception to this. There is a sort of general purpose pointer that can point to any data type called a pointer to a void.

E.g. Void *ptr ;

22. What are the uses of pointers?

  • Accessing array elements.
  • Passing arguments to a function when the function needs to modify the original arguments.
  • Passing arrays and string to functions.
  • Obtaining memory from the system.
  • Creating data structure such as linked lists.

23. What is the use of NEW and DELETE operator.

The NEW operator obtains a specified amount of memory from the system and returns a pointer to the memory. The operator is used to crate variables and data structure during program execution. The DELETE operator releases memory obtained by new.

24. Write a note on THIS pointer.

The member functions of every object have access to a sort magic pointer named this, which points to the object itself. Thus any member function can find out the address of the object of which is a member.

25. How serious is the breach of data integrity when friend functions are used?

A friend function must be declared as such within the class whose data it will access. Thus a programmer who does not have access to the source code for the class cannot make a function into a friend.

26. Write a note on friend function.

A friend function can access a class private data, even though it is not a member function of the class. This is useful when one function must have access to two or more unrelated classes and when an overloaded operator must use, on its left side, a value of a class other than one of which it is a member. Friends are also used to facilitate functional notation.

27. Define inline function.

An inline function looks like a normal function in the source file but inserts the function code directly into the calling program. Inline functions execute faster but may require more memory than normal functions unless they are very small.

28. Write a note on automatic variables.

Variables that are defined within a function body are called automatic variables. An automatic variable is not created until the function in which it is defined is called.

29. Define lifetime of a variable.

The time period between the creation and destruction of a variable is called the lifetime of the variable.

30. Define class.

Classes are created using the keyword class. A class declaration defines a new type that links code and data. This new type is then used to declare objects of that class an object is an instance of a class.

31. What are the 3 access specifiers and explain it.

The 3 access specifiers are Public, Private and Protected

  • Private: It accessed only by other members of the class.
  • Public: It allows functions or data to be accessible to other parts of programs.
  • Protected: Access specifier is needed only when inheritance is involved.

32. Define Friend class.

It is possible to grant a non member function access to the private members of a class by using a friend. A friend function has access to all private and protected members of the class for which it is a friend.

33. How friend function can be declared.

To declare a friend function, include its prototype within the class preceding it with the keyword friend.

For eg,

Class myclass

{

int a,b;

public:

friend int sum(my class x);

};

34. What are the situations where inline expansion cannot work?

  • For function returning values, if a loop, a switch or a go to exists.
  • For function not returning values, if a return statements exist.
  • If function contain static variables.
  • If inline function are recursive.

35. How objects can be passed to function.

Objects may be passed to function in just the same way that any other type of variable can. Objects are passed to functions thru the use of standard call by value mechanism.

36. How objects can be returned in C++.

When an object is returned by a function a temporary object is automatically created that holds the return value. It is this object that is actually returned by the function.

37. How pointer can be used to derived type.

In general, a pointer of one type cannot point to an object of a different type.

However there is an important exception to this rule that relates only to derived class.

To begin assume two classes called B & D. that is D is derived from base class B. In this situation, a pointer of type B* may also point to an object of type D.

38. What is static member function and explain its characteristics?

A member function that is declared static has following property,

  • A static function can have access to only other static members declared in the same class.
  • A static member function can be called using the same class name as follows

class_name:: function_name;

39. What is scope resolution operator? Explain how does it work in c++?

The ::operator links a class name with a member name in order to tell the complier what class the member belongs to. It has another use that is it can allow access to a name in an enclosing scope that is hidden by a local declaration of the same name.

Egname.

Eg:

Void f()

{

int I;

I=10;

………..

……..

}

It may do so by preceding the I with the :: as shown here

Void f()

{

int I;

::I=10;

……..

……..

}

40. How the pointer to the objects can be used in c++?

Just as we can have pointers to other types of variables, we can have pointers to objects. When accessing members of a class given a pointer to an object, use the arrow

(->) operator instead of the dot operator.

When pointer is incremented, it points to next element of its type. For eg: an integer pointer will point to next integer, in general, all pointer arithmetic is relative to base type of the pointer.

41. Define class and objects?

Classes are user defined data types and behave like the built in type of a programming languages. the wrapping up of data and functions into a single unit called class.

Objects are the basic run_time entities in an object oriented system. When a program is executed, the objects interact by sending messages to one another.

42. Compare and contrast between structure and class.

The only difference between a class and a structure is that by default all members are public in a struct and private in a class.

Comparisons:-

There is no fundamental reason not to increase the capabilities of a structure. In c structures already provide a means of grouping data. It also allows us to include member functions.

43. List the restrictions that are to be followed while using unions in c++

  • Union cannot inherit any other classes of any type.
  • Union cannot be a base class
  • No static variables can be members of a union
  • A reference member cannot be used
  • A union cannot have as a member any object that overloads = operator
  • No objects can be a member of a union if the object has an explicit constructor on destructor function.

44. Define friend function?

It’s possible to grant a non-member function access to the private members of a class by using the keyword friend. A friend function has access to all private and protected members of the class for which it is a friend.

45. Circumstances in which friend functions are quite valuable.

  • Friends can be useful when you are overloading certain types of operators.
  • Friend functions make the creation of some types of i/o functions easier.
  • Two or more classes may contain members that are interrelated relative to other parts of our program.

46. Uses of inline functions.

Each time a function is called, a significant amount of overhead is generated by calling and return mechanism. Therefore it increases the performance of our program.

47. Static data member:-

A variable with a declaration static, tells the compiler that only one copy of that variable will exist and that all objects of the class will share the variable. No matter how many objects of a class are create. Only one copy of a static data member exists. Thus all objects of that class use that same variable. All static variables are initialized to zero before the first object is created.

48. Restrictions in using static member functions.

  • Static member functions can only directly refer to the other static members of the class.
  • Global data can also be accessed by static member’s functions.
  • Static member functions does not have a this pointer.
  • A static member functions may not be virtual.

49. Characteristics of friend function?

  • It is not in the scope of the class to which it has been declared as friend.
  • Since it is not in the scope of the class. it cannot be called using the object of that class.
  • It cannot be invoked like a normal function without the help of any object
  • Usually it has objects as arguments.
  • It can be declared either in the public or private part of a class without affecting its meaning.

50. Arrays of objects:-

The objects that are created for a class can also be an array of objects.

Eg:-

Class employee

{

char name[10];

float age;

public:

void get(void);

void disp(void);

}ob[10];arrays of objects

accessing:

for(I=1;I<=n;I++)

{

ob[i].get();

ob[i].disp();

}

51.What are the characteristics of member functions?

  • Several different classes can use the same function name.
  • Member functions can access the private data of the class except friend function.
  • A member function can call another member function directly, without using the dot operator.

52. What are the characteristics of Static member variable?

  • It is initialized to zero, when the first object of its class is created. No other initialization is permitted.
  • Only one copy of that member is created for the entire class and is shared by all the objects of that class.
  • It is visible only within the class, but its lifetime is the entire program.

53. What are the properties of Static member functions?

  • A Static function can have access to only other static members declared in the same class.
  • A static member function can be called using the class name instead of its objects.

54. What are the advantages of using inline member functions?

  • The size of the object code is considerably reduced.
  • It increases the execution speed.
  • The inline member functions are compact function calls.

55. What are the dynamic allocation operators?

New

  • The new operator is used to create a heap memory space for an object of a class.

Delete

  • The delete operator is used to destroy the variable space which has been created by using the new operator dynamically.

56. What are the restrictions that have been placed on Static member functions?

  • Static member functions may only directly refer to other static members of the class.
  • A static member function may only directly refer to other static members of the class.
  • There cannot be static and a non-static version of the same function.
  • A static member function may not be virtual.
  • They cannot be declared as const or volatile.

57. What are the two ways to achieve call-by-reference parameter passing?