More questions (classes and pointers)
Interview and Viva questions:
Q.) List out the two uses for the & and * operator and also how they differ.
Q.) List out the important characteristics of OOP.
Q.) Differentiate between a class and an object. Give an example.
Q.) What are pointers?
Q.) What is the relationship between arrays and pointers?
Q.) Should we use reference variables or pointers? Can we use references everywhere instead of pointers?
Q.) Why is it better to pass by reference than by value?
Q.) Differentiate between the use of ‘public’ and ‘private’ in classes.
Q.) Is it that we should always make data private and functions public?
Q.) Explain constructors and destructors in classes and why they are needed.
Q.) How many constructors and destructors can a class have? Can we overload destructors?
Q.) What is a default constructor?
Q.) Which method of accessing arrays is more efficient/ faster? (indexing or pointer accessing).
Q.) When we pass 2-D arrays to a function why do we need to specify the 2nd dimension in the function declaration?
Q.) What is a copy constructor? Should we pass the argument to the copy constructor only by reference? Why?
Q.) Does implicit conversion occur only when the class has a single-argument constructor?
Programs to try out
Q.) Write a program to display the address of an array of integers (the array element values are entered by the user).
Q.)Use pointers to reverse a given array of integers.
Q.)Sort an array in descending order using pointers.
Q.) Write a program to set the value of the entire array to some user-defined value (use an integer array).
Q.) Create a class for complex numbers. It should have two member data (for the real and imaginary parts of a complex number). The class should have functions for calculating the magnitude of the number, displaying the complex number and also for obtaining inputs from the user and setting the values for the real and imaginary parts.
Q.) Create a class called ‘batsman’ which should contain member data for keeping track of his name, highest and lowest score, number of matches etc. There should be a function to obtain these values from the user and another function to display the details.
Q.) Create an employee class which models a real life employee and make use of appropriate class members. Provide parameter and parameter-less constructors for the class. The class should at least consist of the following: employee ID, department, age, salary and experience. Also include a function to calculate bonus for an employee (bonus=10% of salary * experience).
Q.) Create a class called ‘student’. It should have provision for the following:
· Obtaining the name, date of birth and marks in 5 subjects for the student.
· Calculating the current age of the student.
· Calculating the average marks of the student.
Q.) Create a class called ‘time’. This should have 3 member data: hours,minutes and seconds. There should be functions to reset the time, to add user-entered minutes to the time and calculate the new time (for example if the user inputs 70 minutes then the member function should add 1 hour and 10 minutes to the present time). A function should exist to display the current time.
Q.) Write a class to model a 3x3 matrix. This class should have functions to obtain the elements of the matrix, to find the inverse of the matrix and also to find the determinant of the matrix.
Go back to the Contents Page
Copyright © 2005 Sethu Subramanian All rights reserved. Sign my guestbook.