Wednesday, April 9, 2008

C++ Software Companies Technical Interview Questions - 2

C++ Questions for Top Software Developing Companies with programs and solutions for 2008

1. What do you understand by visibility modes in class derivations? What are these modes?
Ans. The visibility mode determines the availability of the members of a base class to the deriving class (and other classes, functions and the main function) from the derived class. There are three visibility modes:
(i) Public (ii) Private (iii) Protected

2. Define a class Teacher with the following class specification:
private members:
name 20 characters
subject 10 characters
Basic, DA, HRA float
salary float
Calculate( ) function computes the salary and returns it.
salary is sum of Basic, DA and HRA
public members:
ReadData() function accepts the data values and invoke the calculate function.
DisplayData() function prints the data on the screen.

Ans.
class Teacher
{
char name[20];
char subject[10];
float basic,da,hra;
float salary;

float calculate( )
{
return (basic+da+hra);
}

public:
void readdata();
void displaydata();
};

void Teacher::readdata()
{

cout<<"Enter Name:";
gets(name);
cout<<"Enter subject";
gets(subject);
cout<<"Enter Basic,DA,HRA:";
cin>>basic>>da>>hra;
salary=calculate();

}

void Teacher::displaydata()
{
cout<<"\nName:"<cout<<"\nSubject:"<cout<<"\nBasic:"<cout<<"\nSalary:"< }

3. Consider the following declarations and answer the questions given below:
class vehicle
{
int wheels;
protected:
int passanger;

public:
void inputdata(int,int);
void outputdata();

};
class heavy_vehicle:protected vehicle
{
int diesel_petrol;
protected:
int load;
public:
void readdata(int,int);
void writedata();
};

class bus:private heavy_vehicle
{
char make[20];
public:
void fetchdata(char);
void displaydata();
};

(i) Name the base class and derived class of the class heavy_vehicle.
(ii) Name the data member(s) that can be accessed from function displaydata.
(iii) Name the data member(s) that can be accessed by an object of bus class.
(iv) Is the member function outputdata accessible to the objects of heavy_vehicle class?

Ans.
(i) Base class: vehicle
Derived class: bus
(ii) passanger, load, make
(iii) No data members can be accessed by an object of bus class.
(iv) No


No comments: