1 case studies and review lecture #14 note: cis 601 notes were originally developed by h. zhu for...
Post on 19-Dec-2015
212 views
TRANSCRIPT
![Page 1: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/1.jpg)
1
Case Studies and Review
Lecture #14
Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised by M. Deek.
![Page 2: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/2.jpg)
2
Case1: Vehicle Management system(P197)
Specifications A tracking program for company vehicles; Identifying how and when vehicles are checked out
for usage by employees. Cargo transportation, business trip, loaner cars, … Record ID number, date checked out, driver name,
mileage, type of usage, and contents. Company use: each trip is recorded including date, time,
miles driven, fuel cost, and the purpose of the trip. Personal use: the insurance information should be
recorded. Carrying passengers: list of passengers; Carrying cargo, an inventory of the vehicle contents
![Page 3: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/3.jpg)
3
Analysis By Vehicle Usage
Vehicle
PersonalVehicle
Company Vehicle
Insurance Info
Triplog
![Page 4: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/4.jpg)
4
Classify By Vehicle Contents
Vehicle
CargoVehicle
Passenger Vehicle
TripLog
Insurance Info
CompanyVehicle
PersonalVehicle
![Page 5: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/5.jpg)
5
Vehicle classtypedef unsigned long ulong;class Vehicle {public: enum VehicleEnum { personal, company }; Vehicle( ulong idNum, VehicleEnum vtype ); Vehicle & Input(); void SetOdometer( ulong odom ); friend ostream & operator <<( ostream & os,const Vehicle & v );private: ulong id; // vehicle ID FString driver; // name of driver ulong odometer; // total mileage Date chkDate; // date checked out VehicleEnum vehicleType;};
![Page 6: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/6.jpg)
6
CompanyVehicle class
class CompanyVehicle :public Vehicle {public: CompanyVehicle( ulong idNum ); CompanyVehicle & Input(); friend ostream & operator <<( ostream & os, const CompanyVehicle & cv );private: TripLog tripRecord; // a single trip record};
![Page 7: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/7.jpg)
7
PersonalVehicle class
class PersonalVehicle :public Vehicle {
public:
PersonalVehicle( ulong id );
PersonalVehicle & Input();
friend ostream & operator <<( ostream & os, const PersonalVehicle & pv );
private:
InsuranceInfo insurance;
};
![Page 8: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/8.jpg)
8
InsuranceInfo class
class InsuranceInfo {
public:
InsuranceInfo & Input();
friend ostream & operator <<(ostream & os,
const InsuranceInfo & I );
private:
FString company; // name of insurance company
FString policyNumber;
};
![Page 9: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/9.jpg)
9
TripLog Classclass TripLog {public: TripLog(); TripLog & Input(); void SetMiles( unsigned m ); void SetFuelCost( float f ); friend ostream & operator <<( ostream & os, const TripLog & tLog );private: Date tDate; // date trip taken Time tTime; // time trip taken unsigned miles; // miles driven FString purpose; // why the trip was taken float fuelCost; // cost of fuel, in dollars};
![Page 10: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/10.jpg)
10
Date class
class Date {public:Date( unsigned dy, unsigned mn, unsigned yr ); Date & Input(); friend ostream & operator <<( ostream & os, const Date & dType );private: unsigned year; // 0 - 2100 unsigned month; // 1 - 12 unsigned day; // 1 - 31 void SetDay( unsigned dy ); void SetMonth( unsigned mn ); void SetYear( unsigned yr );};
![Page 11: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/11.jpg)
11
Time class
class Time {public:// Time(){hour =0; minute=0;}; Time( unsigned hr, unsigned mn ); Time & Input(); friend ostream & operator <<( ostream & os, const Time & tm );private: unsigned hour; // 0 - 23 unsigned minute; // 0 - 59 void SetHour( unsigned hr ); void SetMinute( unsigned mn );};
![Page 12: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/12.jpg)
12
Implementation:Date
Date::Date( unsigned dy = 0, unsigned mn = 0, unsigned yr = 0 )
{ SetDay( dy );
SetMonth( mn );
SetYear( yr );
}
![Page 13: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/13.jpg)
13
DateDate & Date::Input()
{ char temp[80];
char ch;
cout << "(mm/dd/yy format): ";
cin.getline( temp, '\n' );
istrstream input( temp, 80 );
input >> dec;
unsigned n;
input >> n;
SetMonth( n );
input.get( ch );
input >> n;
SetDay( n );
input.get( ch );
input >> n;
SetYear( n );
return *this;
}
![Page 14: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/14.jpg)
14
Date
void Date::SetDay( unsigned d )
{ day = d;}
void Date::SetMonth( unsigned m )
{ month = m;}
void Date::SetYear( unsigned y )
{ year = y; }
ostream & operator <<( ostream & os, const Date & D )
{
os << D.month << "-" << D.day << "-" << D.year;
return os;
}
![Page 15: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/15.jpg)
15
Time
Time::Time( unsigned hr = 0, unsigned mn = 0 )
{
SetHour( hr );
SetMinute( mn );
}
![Page 16: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/16.jpg)
16
TimeTime & Time::Input(){ char temp[80]; char ch; cout << "(hh:mm format): "; cin.getline( temp, '\n' ); istrstream input( temp, 80 ); input >> dec;
// Force decimal input format, to allow the // user to type leading zeros in numbers.
unsigned n;
input >> n;
SetHour( n );
input.get( ch );
input >> n;
SetMinute( n );
return *this;
}
![Page 17: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/17.jpg)
17
Timevoid Time::SetHour( unsigned h ){ hour = h;}void Time::SetMinute( unsigned m ){ minute = m;}ostream & operator <<( ostream & os, const Time & T ){ os << T.hour << ":" << T.minute; return os;}
![Page 18: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/18.jpg)
18
InsuranceInfoInsuranceInfo & InsuranceInfo::Input()
{ cout << "Insurance Information:" << '\n' << "Insurance company: ";
company.GetLine( cin );
cout << "Policy Number: ";
policyNumber.GetLine( cin );
return *this;
}
ostream & operator <<( ostream & os, const InsuranceInfo & I )
{ os << "Insurance Information............." << '\n'
<< " Insurance company: " << I.company << '\n'
<< " Policy number: " << I.policyNumber << endl;
return os;
}
![Page 19: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/19.jpg)
19
TripLog
TripLog::TripLog() :purpose(),tDate(0,1,1),tTime(0,0)
{
miles = 0;
fuelCost = 0.0;
}
![Page 20: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/20.jpg)
20
TripLog
TripLog & TripLog::Input(){ cout << "Entering the trip log." << '\n' << " Date of trip "; tDate.Input(); cout << " Time "; tTime.Input(); cout << " Miles driven: ";
unsigned n; cin >> n; SetMiles( n ); cin.ignore( 255, '\n' ); cout << " Purpose: "; purpose.GetLine( cin );
cout << " Fuel cost: ";
float f;
cin >> f;
SetFuelCost( f );
cin.ignore( 255, '\n' );
return *this;
}
![Page 21: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/21.jpg)
21
TripLog
void TripLog::SetMiles( unsigned m ){ miles = m;}void TripLog::SetFuelCost( float f ){ fuelCost = f;}ostream & operator <<( ostream & os, const TripLog & T ){ os << "Trip Log...................." << '\n' << " Date: " << T.tDate << '\n' << " Time: " << T.tTime << '\n' << " Miles: " << T.miles << '\n' << " Purpose: " << T.purpose << '\n' << " Fuel cost: " << T.fuelCost << endl; return os;}
![Page 22: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/22.jpg)
22
Vehicle
Vehicle::Vehicle( ulong idVal, VehicleEnum vType )
:id(idVal), vehicleType(vType),chkDate(0,1,1)
{
SetOdometer( 0 );
}
![Page 23: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/23.jpg)
23
VehicleVehicle & Vehicle::Input()
{ cout << "Driver name [last,first]: ";
driver.GetLine( cin );
cout << " Odometer reading: ";
long n;
cin >> n;
SetOdometer( n );
cin.ignore( 255, '\n' );
cout << " Date checked out ";
chkDate.Input();
return *this;
}
![Page 24: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/24.jpg)
24
Vehicle
void Vehicle::SetOdometer( ulong od )
{ odometer = od;}
ostream & operator <<( ostream & os, const Vehicle & V )
{ const char * vstring[] = { "personal","company" };
os << " ID: " << V.id << '\n'
<< " Usage: " << vstring[V.vehicleType] << '\n'
<< " Driver: " << V.driver << '\n'
<< " Odometer: " << V.odometer << '\n'
<< " Date out: " << V.chkDate << endl;
return os;
}
![Page 25: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/25.jpg)
25
CompanyVehicle
CompanyVehicle::CompanyVehicle( ulong idVal ) :Vehicle(idVal, company) { }CompanyVehicle & CompanyVehicle::Input(){ Vehicle::Input(); tripRecord.Input(); return *this;}ostream & operator <<( ostream & os, const CompanyVehicle & V ){ os << "Vehicle ....................." << '\n' << Vehicle( V ) << V.tripRecord << endl; return os;}
![Page 26: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/26.jpg)
26
PersonalVehicle
PersonalVehicle::PersonalVehicle( ulong idVal ) :Vehicle( idVal, personal ) { }PersonalVehicle & PersonalVehicle::Input(){ Vehicle::Input(); insurance.Input(); return *this;}ostream & operator <<( ostream & os, const PersonalVehicle & V ){ os << "Vehicle ...................." << '\n' << Vehicle( V ) // display base object << V.insurance << endl; return os;}
![Page 27: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/27.jpg)
27
Main program#include "Vehicle.h"#include <fstream.h>ofstream ofile("vehicle.out", ios::app );void Slicer( const Vehicle & V ){ cout << V << endl;}void Create_PersonalVehicle( ulong id ){ PersonalVehicle V(id); V.Input(); Slicer( V ); // demonstrate object slicing ofile << V << endl;}void Create_CompanyVehicle( ulong id ){ CompanyVehicle V(id); V.Input(); ofile << V << endl;}
![Page 28: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/28.jpg)
28
Main programvoid Create_Vehicle(){ int usage; ulong id; cout << "Vehicle ID: "; cin >> id; cout << "Type of Usage (1)personal, (2)company:"; cin >> usage; cin.ignore( 255, '\n' ); if( usage == 1 ) Create_PersonalVehicle( id ); else if( usage == 2 ) Create_CompanyVehicle( id );}int main(){ Create_Vehicle(); return 0;}//cis601source/ch6/vehicle/main.cpp
![Page 29: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/29.jpg)
29
![Page 30: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/30.jpg)
30
![Page 31: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/31.jpg)
31
![Page 32: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/32.jpg)
32
![Page 33: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/33.jpg)
33
Case2: Shape
Specification: Design a program that supports the
drawing, moving, computing the area and the perimeter of shapes such as circle, rectangle, triangle, etc.
![Page 34: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/34.jpg)
34
Class HierarchyShape
interior_color, shadowmove(), draw(), paint(), area(),
perimeter(), color()
Trianglevertices
height(), base()
Rectangleupper_left, lower_right
width(), length()
Square
Circle
A
![Page 35: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/35.jpg)
35
Circle
Shape
Point
Circle 1
1
![Page 36: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/36.jpg)
36
Circle Object creation interaction diagram
Circle Shape PointCircle(x,y,r)
Shape(color)
Point(x,y)
Process initialization list: initialize base class
Process initialization list: initialize center
Complete initializationConstructor’s body
![Page 37: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/37.jpg)
37
Rectangle and Square
Shape
Point
1
1Circle
Rectangle
Square
2 1
![Page 38: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/38.jpg)
38
Square Object Creation interaction diagram
Square Rectangle ShapeSquare(x1,y1,x2,y2,color)
Rectangle()
Process initialization list: initialize shape segment
Process initialization list: initialize upper_left
Complete initialization Constructor’s body
Point
Constructor’s body
Shape(color)
Point(x1,y1)
Point(x2,y2)Process initialization list: initialize lower_right
Call base class constructor
![Page 39: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/39.jpg)
39
Class Shape
typedef bool Boolean ;
enum Color{RED, BLUE, GREEN, WHITE, BLACK, YELLOW} ;
class Shape
{
private:
Color interior ;
Shape( const Shape & ) ;
Shape & operator =( const Shape & ) ;
protected:
inline Boolean change_color( Color new_color ) ;
![Page 40: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/40.jpg)
40
Class Shape
public:
inline Shape( Color interior_color ) ;
virtual ~Shape() { } ; // do-nothing
inline Color color( void ) const ;
virtual Boolean draw( void ) const = 0 ;
virtual Boolean paint( Color new_color ) = 0 ;
virtual Boolean move( Coordinate x , Coordinate y ) = 0 ;
virtual float area( void ) const = 0 ;
virtual float perimeter( void ) const = 0 ;
} ;
![Page 41: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/41.jpg)
41
Class Shape
inline Shape:: Shape( Color color ): interior ( color ) {};
inline Color Shape:: color( void ) const
{ return( interior ) ;}
inline Boolean Shape:: change_color( Color new_color )
{ Boolean accepted = true ;
if( interior != new_color )
{ interior = new_color ; }
else
{ accepted = false ; }
return( accepted ) ;
};
![Page 42: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/42.jpg)
42
Class Circle
typedef short Radius ;
const double PI = acos( -1.0 ) ;
class Circle: public Shape
{ private:
Point center ; // center coordinate
Radius r ;
Boolean erase( void ) const ;
Circle( const Circle & ) ;
Circle & operator = ( const Circle & ) ;
![Page 43: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/43.jpg)
43
Class Circlepublic:
Circle( Coordinate x, Coordinate y, Radius new_radius, Color interior_color);
~Circle( ) ;
inline Radius radius( void ) const ;
inline virtual Boolean draw( void ) const ;
virtual Boolean paint( Color new_color ) ;
virtual Boolean move( Coordinate x , Coordinate y ) ;
virtual float area( void ) const ;
virtual float perimeter( void ) const ;
} ;
inline Radius Circle:: radius( void ) const
{ return( r ) ;}
![Page 44: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/44.jpg)
44
Class Rectangle
class Rectangle: public Shape{ private:
Point upper_left , lower_right ; Boolean erase( void ) const ;Rectangle( const Rectangle & ) ;Rectangle & operator = ( const Rectangle & ) ;
public:Rectangle( Coordinate x1, Coordinate y1, Coordinate
x2, Coordinate y2, Color interior_color ) ; virtual ~Rectangle( ) ;virtual Boolean draw( void ) const ;virtual Boolean paint( Color new_color ) ;virtual Boolean move( Coordinate x , Coordinate y ) ;virtual float area( void ) const ;virtual float perimeter( void ) const ;
} ;
![Page 45: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/45.jpg)
45
Class Square
typedef unsigned short Length ;
class Square: public Rectangle
{ private:
Square( const Square & ) ;
Square & operator = ( const Square & ) ;
public:
Square( Coordinate x1, Coordinate y1, Length side,
Color interior_color ) ;
virtual ~Square( ) { } ;
virtual Boolean draw( void ) const ;
virtual Boolean paint( Color new_color ) ;
} ;
![Page 46: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/46.jpg)
46
class Point
typedef float Coordinate ;class Point{ private:
Coordinate x , y ;public:
inline Point() ; // default constructorinline Point( Coordinate new_x, Coordinate
new_y ) ;inline Coordinate x_coordinate( void ) const ;inline Coordinate y_coordinate( void ) const ;
} ;
![Page 47: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/47.jpg)
47
Main()
#define MAX_NUM_SHAPES 3int main( int , char ** ) ;Shape * make_shape( int i ) ;void delete_shape ( Shape *current ) ;Boolean process_shape( ostream &output_stream, Shape
*current ) ;int main( int , char ** ){ Shape *list[MAX_NUM_SHAPES] ;
int i ;for( i = 0 ; i < MAX_NUM_SHAPES ; i++ ){ list[i] = make_shape( i ) ; }
![Page 48: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/48.jpg)
48
Main()
for( i = 0 ; i < MAX_NUM_SHAPES ; i++ ){ cout << "\n ** Shape No. " << i ;
process_shape( cout, list[i] ) ;}cout << endl ;for( i = 0 ; i < MAX_NUM_SHAPES ; i++ ){ cout << "\n ** Destroying Shape No. " << i ;
delete_shape( list[i] ) ;}return( 0 ) ;
}
![Page 49: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/49.jpg)
49
process_shape(…)Boolean process_shape( ostream &output_stream, Shape *current ){ Boolean status ;
status = current->draw() ;if( !status ){output_stream << "\n\t Draw Tests ............. Failed " ; }status = current->paint( YELLOW ) ;if( !status ){output_stream << "\n\t Paint Tests ............. Failed " ; }status = current->move( 1 , 1 ) ;if( !status ){output_stream << "\n\t Move Tests .............. Failed " ;}output_stream << "\n\t Area of Shape:" << current->area() ;output_stream << "\n\t Perimeter of Shape:" << current->perimeter() ;return( status ) ;
}
![Page 50: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/50.jpg)
50
make_shape(…)Shape * make_shape( int i )
{ Shape *current ;
if( i == 0 )
{ current = new Circle( 1 , 3 , 4 , RED ) ; }
else if( i == 1 )
{current = new Rectangle( 8, 5, 12, -2, GREEN ) ; }
else
{current = new Square( -6 , 3 , 3 , BLUE ) ;}
return( current ) ;
}
void delete_shape ( Shape *current )
{ delete current ;}//uo/draw/testshape.dsw
//draw/wzd.dsw
![Page 51: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/51.jpg)
51
![Page 52: 1 Case Studies and Review Lecture #14 Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised](https://reader036.vdocuments.us/reader036/viewer/2022081603/56649d405503460f94a19fb5/html5/thumbnails/52.jpg)
52