Tuesday, October 2, 2012

TYPE OF DERIVATION THROUGH MULTILEVEL INHERITENCE


TYPE OF DERIVATION THROUGH MULTILEVEL INHERITENCE

#include
#include
#include
class student
{
 protected:
 char name[30];
 char enroll[8];
 public:
 void input()
 {
   cout<<"Enter name of student";
   gets(name);
   cout<<"ENter enroll";
   gets(enroll);
 }
 void output()

   {
    cout<<"Name of student is... "<    cout<<"Enroll of student is... "<   }
};

class course:public student
{
 protected:
 char cours[6];
 public:
  void input()
 {
   student::input();
   cout<<"Enter course of student";
   gets(cours);
 }
 void output()
 {  student::output();
    cout<<"Name of course is... "< }
};

class subject:protected course
{
 protected:
 char sub[20];
 public:
void input()
 {
   course::input();
   cout<<"Enter subject of student";
   gets(sub);
 }
 void output()
 {  course::output();
    cout<<"Name of subject is... "< }
};

class marks:private subject
{
 protected:
 int markss;
 public:
void input()
 {
   subject::input();
   cout<<"Enter marks of student";
   cin>>markss;
 }
 void output()
 {  subject::output();
    cout<<"Marks of subject is... "< }
};


void main()
{
 clrscr();
 marks a;
 a.input();
 a.output();
 getch();
}




BELOW PROGRAM SHOW HOW PUBLIC MEMBER BECOME PRIVATE AND ACCESS BY OTHER DERIVE CLASS

#include
#include
#include
class student
{
 protected:
 char name[30];
 char enroll[8];
 public:
 void input()
 {
   cout<<"Enter name of student";
   gets(name);
   cout<<"ENter enroll";
   gets(enroll);
 }
 void output()

   {
    cout<<"Name of student is... "<
    cout<<"Enroll of student is... "<
   }
};

class course:public student
{
 protected:
 char cours[6];
 public:
  void input()
 {
   student::input();
   cout<<"Enter course of student";
   gets(cours);
 }
 void output()
 {  student::output();
    cout<<"Name of course is... "<
 }
};

class subject:protected course
{
 protected:
 char sub[20];
 public:
void input()
 {
   course::input();
   cout<<"Enter subject of student";
   gets(sub);
 }
 void output()
 {  course::output();
    cout<<"Name of subject is... "<
 }
};

class marks:private subject
{
 protected:
 int markss;
 public:
void input()
 {
   course::input();//here we can acces becouse input of course is protected
   // in subject class
   cout<<"Enter marks of student";
   cin>>markss;
 }
 void output()
 {  subject::output();
    cout<<"Marks of subject is... "<
 }
};

class sports:private marks
{
 protected:
 char sports_name[20];
 public:
void input()
 {
  // subject::input(); // here input function of subject private in marks
   //so it cannot access
   cout<<"Enter fav sports of student";
   gets(sports_name);
 }
 void output()
 {  marks::output();
    cout<<"fav sports of subject is... "<

 }
};


void main()
{
 clrscr();
 sports a;
 a.input();
 a.output();
 getch();
}

Saturday, September 29, 2012

ADDRESS CALCULATION FOR TWO DIMENSIONAL ARRAY


When lower bond is not given.

The computer keeps track of Base (BA), 
the address of the first element A[0][0] of A[M][N], 
and computes address Loc (A[I][J]) of A[M][N] using the formula

Address can be calculated as Column major order:-

Loc (A[I][J] ) = Base (BA) + W [M x J + I ]

Address can be calculated as Row major order:-

Loc (A [I][J]) = Base (BA) + W [N x I + J ]

W denotes the size, i.e; number of bytes per data element of the array A,
 M is total numbers of rows, and N is total number of columns in the array.

When lower bond is given.

Address can be calculated as Row major order:-

Address of A[ I ][ J ]th element = BA + [ N * ( I - LBR) + ( J - LBC) ] * W

Where BA = Base address
W = Number of bytes occupied by each element
N = Number of columns

Address can be calculated as Column major order:-

Address of a[ I ][ J ]th element = BA + [ ( I - LBR) + M * ( J - LBC) ] * N

Where BA = Base address
W = Number of bytes occupied by each element
M = Number of rows

In case of C language 
LBR (Lower bound row) = 0
LBC (Lower bound column) = 0

e.g. Suppose element of array 
A[4][5] occupies 4 bytes, and the address of the 1st element is 49.  Find the address of the element A(4,3) when the storage is row major.


                                                     = BA + [n * (i - LBR) + (j - LBC)] * w
                                                     = 49 + [5 * (4 – 0) + (3 - 0)] * 4
                                                     = 49 + [23] * 4
                                                     = 49 + 92
                                                     = 141