Assignment - Class XII Computer Science
Inheritance Assignment
Assignment Date – 22-08-15
Submission Date – 25-08-15
class heavyvehicle: protected vehicle
class bus:private heavyvehicle
Assignment Date – 22-08-15
Submission Date – 25-08-15
1.
What is inheritance? Discuss its various forms.
2.
Discuss various reasons that support the concept of inheritance in Object
Oriented Languages.
3.
Answer the questions (i) and (iv) based on the following:
class Student
{
int Rollno;
char SName[20];
float Marks1;
protected:
void Result();
public:
Student();
void Enroll();
void Display();
};
class Teacher
{
long TCode;
char TName[20];
protected:
float Salary;
public:
Teacher ();
void Enter();
void Show();
};
class Course:public Student,private Teacher
{
long CCode[10]
char CourseName[50];
char StartDate[8],EndDate[8];
public:
Course();
void Commence();
void CDetail();
};
(i) Write the names of member functions, which are accessible from
objects of class Course.
(ii) Write the names of all data members, which is/are accessible from
member function Commence of class Course.
(iii) Write the names of all the members, which are accessible from objects
of class Teacher.
(iv) Which type of inheritance is illustrated in the above C++ code?
4. Answer the questions (i) to (iv) based on the following:
4. Answer the questions (i) to (iv) based on the following:
class Toy
{ char Btype[10];
protected:
float Rate;
void CalcRate(float);
public:
Ball();
void BInput();
void BShow();
void TEntry();
void TDisplay();
};
class SoftToys:public Toys
{ char STName[20];
float Weight;
public:
SofToys();
void STEntry();
void STDisplay();
};
class ElectronicToys:public Toys
{ char ETName[20];
char No_of_Batteries;
public:
ElectronicToys();
void ETEntry();
void ETDisplay();
};
(i) Which type of Inheritance is shown in the above example?
(ii) How many bytes will be required by an object of the class SoftToys?
(iii) Write name of all the data members accessible from member functions
of the class SoftToys.
(iv) Write name of all the member functions accessible from an object of
the class ElectronicToys.
5. Answer the questions (i) to (iv) based on the
following:
class customer
{
intcust_no;
char cust_name[20];
protected:
void register ( );
public:
customer ( );
void status ( );
};
class salesman
{
intsalesman_no;
char salesman_name[20];
protected:
float salary;
public:
salesman ( );
void enter ( );
void show ( );
};
class shop : private customer, public salesman
{
char voucher_no[10];
char sales_date[8];
public:
shop ( );
void sales_entry ( );
void sales_detail ( );
};
(i)
Write the names
of data members which are accessible from objects belonging to class customer.
(ii)
Write the names
of all the member function which are accessible from objects belonging to class
salesman.
(iii) Write the names of all the members which are
accessible from member function of class shop.
(iv) How many bytes will be required by an object
belonging to class shop?
6. Consider the following declarations and answer the
questions given below:
class vehicle
class vehicle
{
int wheels;
protected:
int passenger;
public:
void inputdata( int, int);
void outputdata();
};
class heavyvehicle: protected vehicle
{
int dieselpetrol;
protected:
int load;
public:
void readdata( int, int);
void writedata();
};
class bus:private heavyvehicle
{
char marks[20];
public:
void fetchdata(char);
void displaydata();
};
(i)
Name the base class and derived class of the class heavyvehicle.
(ii)
Name the data members that can be accessed from function displaydata()
(iii)
Name the data members that can be accessed by an object of bus class
(iv)
Is the member function outputdata() accessible to the objects of heavyvehicle class.
7. Consider the following
declarations and answer the questions given below:
#include <iostream.h>
class book
{
char title[20];
char author[20];
int noof pages;
public:
void read();
void show();
};
class textbook: private book
{
int noofchapters, noof assignments;
protected:
int standard;
void readtextbook();
void showtextbook();
};
class physicsbook: public textbook
{
char topic[20];
public:
void readphysicsbook();
void showphysicsbook();
};
(i)
Name the members, which can be accessed from the member functions of
class physicsbook.
(ii)
Name the members, which can be accessed by an object of Class textbook.
(iii)
Name the members, which can be accessed by an object of Class
physicsbook.
(iv)
What will be the size of an object (in bytes) of class physicsbook.
8.
Answer the questions(i) to (iv) based on
the following :
class cloth
{
char category[5];
char description[25];
protected:
float price;
public:
void Entercloth( );
void dispcloth( );
};
class Design : protected cloth
{
char design[21];
protected:
float cost_of_cloth;
public:
int design_code;
Design( );
void Enterdesign( );
void dispdesign( );
};
class costing : public cloth
{
float designfee;
float stiching;
float cal_cp( );
protected:
float costprice;
float sellprice;
public:
void Entercost( );
void dispcost( );
costing ( ) { };
};
(i) Write the names
of data members which are accessible from objects belonging to class cloth.
(ii) Write the names
of all the members which are accessible from objects belonging to class Design.
(iii) Write the names
of all the data members which are accessible from member functions of class
costing.
(iv) How many bytes
will be required by an object belonging to class Design?
9.
Answer the questions(i) to (iv) based on
the following :
class Regular
{
char SchoolCode[10];
public:
void InRegular( );
void OutRegular( );
};
class Distance
{
char StudyCentreCode[5];
public:
void InDistance( );
void OutDistance( );
};
class Course : public Regular, private
Distance
char Code[5];
float Fees;
int Duration;
public:
void InCourse( );
void OutCourse( );
};
(i) Which type of
Inheritance is shown in the above example?
(ii) Write names of
all the member functions accessible from Outcourse function of class Course.
(iii) Write name of
all the members accessible through an object of the Class Course.
(iv) Is the function
InRegular( ) accessible inside the function InDistance ( )? Justify your
answer.
10.
Consider the following declarations and
answer the questions given below:
class Animal
{
int leg:
protected:
int tail;
public:
void INPUT (int );
void OUT ( );
};
class wild : private Animal
{
int carniv;
protected:
int teeth;
Public:
void INDATA (int, int )
void OUTDATA( );
};
class pet : public Animal
{
int herbiv;
public:
void Display (void);
};
(i) Name the base
class and derived class of the class wild.
(ii) Name the data
member(s) that can be accessed from function Display ( ).
(iii) Name the member
function(s), which can be accessed from the objects of class pet.
(iv) Is the member
function OUT ( ) accessible by the objects of the class wild?
---------------------------------------------------------------