EXERCIES - A SOLUTION

Sample solution to question 6

PUBLISH.H

#if !defined (PUBLICATION_SEEN)  
    #define PUBLICATION_SEEN

class CPublication
{
    protected:
    char m_szTitle [40];
    float m_fPrice;

    public:
    void get (void);
    void put (void);
};

#endif

BOOK.H

#include "publish.h"

class CBook : public CPublication
{
    protected:
    int m_iPageCount;

    public:
    void get (void);
    void put (void);
};

## TAPE.H

#include "publish.h"

class CTape : public CPublication
{
    protected:
    float m_fPlayTime;

    public:
    void get (void);
    void put (void);
};

PUBLISH.CPP

#include <iostream.h>

#include "publish.h"

void CPublication::get (void)
{
    cout << "Enter title ";

    cin >> m_szTitle;

    cout << endl;

    cout << "Enter price ";

    cin >> m_fPrice;

    cout << endl;
}

void CPublication::put (void)
{
    cout << "Title " << m_szTitle << endl;

    cout << "Price " << m_fPrice << endl;
}

BOOK.CPP

#include <iostream.h>

#include "book.h"

void CBook::get (void)
{
    CPublication::get ();

    cout << "Enter number of pages ";

    cin >> m_iPageCount;

    cout << endl;
}

void CBook::put (void)
{
    CPublication::put ();

    cout << "Pages " << m_iPageCount << endl;
}

TAPE.CPP

#include <iostream.h>

#include "tape.h"

void CTape::get (void)
{
    CPublication::get ();

    cout << "Enter play time ";

    cin >> m_fPlayTime;

    cout << endl;
}

void CTape::put (void)
{
    CPublication::put ();

    cout << "Play time " << m_fPlayTime << endl;
}

MAIN.CPP

#include "book.h"

#include "publish.h"

#include "tape.h"

void main ()
{
    CBook aBook;

    CPublication aPublication;

    CTape aTape;

    aBook.get ();

    aBook.put ();

    aPublication.get ();

    aPublication.put ();

    aTape.get ();

    aTape.put ();
}  

Download