repo update
This commit is contained in:
27
Lecture/Week5/Lab5.txt
Normal file
27
Lecture/Week5/Lab5.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
Shape class
|
||||
data:
|
||||
color (required)
|
||||
1st point
|
||||
# points
|
||||
functions:
|
||||
constructor(color)? <- optional
|
||||
shape::shape(...) <- do this in child?
|
||||
copy constructor
|
||||
assignment operator
|
||||
destructor (virtual)
|
||||
draw <- pure virtual
|
||||
Shape::draw(Graphics context gc)
|
||||
gc->setColor(color)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Shape * S1 = new Line(...)
|
||||
Shape * S2 = new Triangle(...)
|
||||
|
||||
S1->draw(...) draw Line
|
||||
S2->draw(...) draw Triangle
|
||||
|
||||
|
||||
Image class
|
||||
28
Lecture/Week5/main.cpp
Normal file
28
Lecture/Week5/main.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
class Pet{
|
||||
public:
|
||||
string name;
|
||||
void set_data(int data){}
|
||||
};
|
||||
|
||||
class Cat: public Pet{
|
||||
public:
|
||||
int fish;
|
||||
void set_data(int data){fish = data;}
|
||||
};
|
||||
|
||||
class Bird: public Pet{
|
||||
public:
|
||||
int seed;
|
||||
void set_data(int data){seed = data;}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
Pet* C1 = new Cat;
|
||||
Pet* C2 = new Cat;
|
||||
C1->name = "Cat1";
|
||||
C1->set_data(1);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user