Tom Kelliher, CS18
Mar. 15, 1996
Entity:
A living being, object, or abstraction that can be described in terms of certain characteristics, and is similar to, but distinct from, entities of the same type.
Examples:
Entity Set:
A collection of entities of the same type.
Distinguished by attributes.
Relationship:
An association among members of one or more entity sets.
Relationship set:
A set of similar but distinct relationships of the same type.
Note: differs from the example in the text.
Attributes:
Attributes:
Attributes:
Structure is a class with public access:
struct sample { int a; }; int main() { sample s; s.a = 12; return 0; }
Class is a structure with private access:
class sample { int a; }; int main() { sample s; // error message: "member `a' is a private member of class `sample'" s.a = 12; return 0; }
Elements of a class declaration:
Class members have access rights associated:
``Access'' means:
Class declaration:
class Complex { private: double real; double imag; public: // constructor declaration: Complex(double re, double im); // destructor definition: ~Complex() {} // other methods' declarations: void Add(Complex x, Complex y); void Mult(Complex x, Complex y); void Conj(void); };
Method definitions:
Complex::Complex(double re, double im) { real = re; imag = im; } void Complex::Add(Complex x, Complex y) { real = x.real + y.real; } void Complex::Mult(Complex x, Complex y) { real = x.real * y.real - x.imag * y.imag; imag = x.real * y.imag + x.imag * y.real; } void Complex::Conj(void) { imag = -imag; }
Client function:
int main() { Complex x(-1.0, 3.0); Complex y(4.0, 5.0); Complex z(0.0, 0.0); z.Add(x, y); y.Conj(); x.real = 23.0; // access violation return 0; }