Make your own free website on Tripod.com
PENGGUMUMAN

                UJIAN 2 akan diadakan pada :
                Tarikh    : 4/3/99
                Masa     : 8.30 mlm - 10.30 mlm
                Tempat  : Bilik Kuliah 3, N24

Lab 3 : 1/3/99
 

Tulis semula aturcara Point, Circle dan Cube. Iaitu dengan menggunakan inheritance dan composition ( 2 FILE yang berlainan )



#ifndef CYLINDR2_H
#define CYLINDR2_H

#include "circle2.h"

class Cylinder : public Circle {
    friend ostream &operator << ( pstream &, const Cylinder &);

public:
    //default constructor
    Cylinder( double h = 0.0, double r =0.0,
                    int x =0, int y=0);

    void setHeight(double);
    double getHeight() const;
    double area() const;
    double volumn() const;

protected
    double height;
};

#endif


#include <iostream.h>
#include <iomanip.h>
#include "cylindr2.h"

Cylinder :: Cylinder(double h, double r, int x, int y)
            : Circle(r, x, y)
{ setHeight( h);}

double Cylinder::getHeight() const { return height;}

double Cylinder::area() const
{
    return 2 *  Circle::area() +
              2 * 3.14159 * radius * height;
}

double Cylinder::volumn() const
    {return Circle:: area() * height;}

ostream &operator << (ostream, const Cylinder &c)
{
    output << static_cast < Circle > (c)
               << "; Height = " << c.height;
    return output;
}


#include <iostream.h>
#include <iomanip.h>
#include "point2.h"
#include "circle2.h"
#include "cylindr2.h"
 
int main(){
Cylinder cyl(5.7, 2.5, 12, 23);
cout << " X coordinate is " <<cyl.getX()
        << " \nY coordinate is " <<cy1.getY()
        << " \n Radius is " << cy1.getRadius()
        << " \n Height is " << cy1.getHeight() << endl;

cy1.setHeight(10);
cy1.setRadius(4.25);
cy1.setPoint(2,2);
cout << "The new location, radius, and height of cy1 are : \n"
        << cy1<< endl;

Point &pRef = cy1;

cout << "\nCylinder printed as a Point is : "
        << pRef << endl;

Circle &CircleRef = cy1;

cout << "Cylinder printed as a Circle is : \n " << circleRef
        << "\nArea : " << circleRef.area() <<endl;

return 0;

}



 

note :

Aturcara ini hendaklah dihantar pada hari Khamis , 4/3/99, penghantaran lewat dari tarikh tersebut tidak akan dilayan.