Based on Borland's World of C++ Video Course
16/10/95
http://info.cv.nrao.edu/aips++/docs/html/aips++.html
http://osiris.sunderland.ac.uk/sst/casehome.html
WWW course on C++ for C user's
Frank B. Brokken and Karel Kubat (frank@icce.rug.nl, karel@icce.rug.nl)
ICCE, State University of Groningen
Westerhaven 16, 9718 AW Groningen
Netherlands
http://www.icce.rug.nl/docs/cplusplus/cplusplus.html
Pointer to handouts for C++ coureses.
Also other interesting pointers to OO places.
http://www.cs.wustl.edu/~schmidt/C++/index.html
Listing of available C/C++ tutorials and book on C++.
You find here almost everything usefull available on the WWW.
http://vinny.csd.mu.edu/learn.html
Learning C++ page from the C++ Virtual Library.
http://info.desy.de/user/projects/C++/Learning.html
http://dxsting.cern.ch/sting/sting.html
http://www.cygnus.com/~mrs/
http://www.omg.org/
http://cuiwww.unige.ch/ooinfo?info-page
http://www.s2k.com/trans.htm
http://www.telstra.com.au/docs/ose/doc/ose-home.html
http://www.quadralay.com:80/www/CCForum/CCForum.html
http://www.sigs.com/cgi-bin/imagemap/menumap?219,46
http://info.desy.de/user/projects/C++.html
http://www.einet.net/galaxy/Engineering-and-Technology/
Computer-Technology/Object-Oriented-Systems/
ricardo-devis/oo.html
http://rbse.jsc.nasa.gov/virt-lib/soft-eng.html
http://www.rational.com/
Eckel, B. - McGrawHill, 1995
Lippman S., Addison Wesley, 1991
Stroustrup B., Addison Wesley, 1991
Ellis M. Stroustrup B., Addison Wesley, 1990
ftp://research.att.com/dist/stdc++/WP/
Stroustrup B., Addison Wesley, 1994
Coplien J., Addison Wesley, 1992
G.Booch, Addison Wesley, 1994
Rumbaugh J. et al., Prentice Hall, 1992
Ellis J.R., SIGS Books, 1994
Meyer B., Prentice Hall, 1989
// CAR.CPP : basic composition
// From Borland's The World of C++, Lesson 17
// (C) Copyright 1991 by Borland International
class wheel {
int diameter;
public:
wheel(int d) { diameter = d; }
};
class engine {
int horsepower;
public:
engine(int hp) { horsepower = hp; }
};
class car {
wheel lf, rf, lr, rr;
engine e;
int passengers;
public:
car(int dia, int hp, int pas);
};
car::car(int dia, int hp, int pas) :
lf(dia), rf(dia), lr(dia), rr(dia), e(hp) {
passengers = pas;
}
main() {
}
// CAR2.CPP : pseudo constructor calls in the constructor
// initializer list for car.
// From Borland's The World of C++, Lesson 17
// (C) Copyright 1991 by Borland International
class wheel {
int diameter;
public:
wheel(int d) { diameter = d; }
};
class engine {
int horsepower;
public:
engine(int hp) { horsepower = hp; }
};
class car {
wheel lf, rf, lr, rr;
engine e;
int passengers;
public:
car(int dia, int hp, int pas);
};
car::car(int dia, int hp, int pas) :
lf(dia), rf(dia), lr(dia), rr(dia), e(hp),
passengers(pas) {
}
// DOG.CPP
// From Borland's The World of C++, Lesson 18
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class dog {
public:
void speak() { puts("woof!"); }
};
void talk(dog * d) {
d->speak();
}
main() {
dog d;
talk(&d);
}
// PET.CPP
// From Borland's The World of C++, Lesson 18
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class pet {
public:
void speak() {}
};
class dog : public pet {
public:
void speak() { puts("woof!"); }
};
class cat : public pet {
public:
void speak() { puts("murroww!"); }
};
class bird : public pet {
public:
void speak() { puts("cheep!"); }
};
void talk(dog * d) {
d->speak();
}
main() {
dog d;
talk(&d);
}
// PET2.CPP : don't write C++ programs this way!
// From Borland's The World of C++, Lesson 18
// (C) Copyright 1991 by Borland International
#include <stdio.h>
enum pet_type { DOG, CAT, BIRD };
class pet {
pet_type ptype;
public:
pet(pet_type pt) : ptype(pt) {}
void speak() {}
// ask it what type it is:
pet_type type() { return ptype; }
};
class dog : public pet {
public:
dog() : pet(DOG) {}
void speak() { puts("woof!"); }
};
class cat : public pet {
public:
cat() : pet(CAT) {}
void speak() { puts("murroww!"); }
};
class bird : public pet {
public:
bird() : pet(BIRD) {}
void speak() { puts("cheep!"); }
};
void talk(pet * p) {
switch(p->type()) {
case DOG : ((dog*)p)->speak(); break;
case CAT : ((cat*)p)->speak(); break;
case BIRD : ((bird*)p)->speak(); break;
default : puts("oops!"); break;
}
}
main() {
dog d;
cat c;
bird b;
talk(&d);
talk(&c);
talk(&b);
}
// VPET.CPP : pets speak properly with late binding
// From Borland's The World of C++, Lesson 19
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class pet {
public:
// virtual causes late binding:
virtual void speak() {}
virtual void sit() {}
};
// talk uses the common interface to pet:
void talk(pet * p) {
p->speak();
}
class dog : public pet {
public:
void speak() { puts("woof!"); }
};
class cat : public pet {
public:
void speak() { puts("murroww!"); }
};
class bird : public pet {
public:
void speak() { puts("cheep!"); }
};
main() {
dog d;
talk(&d); // This still works...
}
// VPET2.CPP : A menagerie of pets
// From Borland's The World of C++, Lesson 19
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class pet {
public:
virtual void speak() {} // virtual causes late binding
virtual void sit() {}
};
// talk uses the common interface to pet:
void talk(pet * p) {
p->speak();
}
// can also use references:
void talk2(pet& p) {
p.speak();
}
class dog : public pet {
public:
void speak() { puts("woof!"); }
};
class cat : public pet {
public:
void speak() { puts("murroww!"); }
};
class bird : public pet {
public:
void speak() { puts("cheep!"); }
};
main() {
pet* menagerie[] = {
new dog, new cat, new bird
};
const sz =
sizeof(menagerie)/sizeof(menagerie[0]);
for(int i = 0; i < sz; i++) {
talk(menagerie[i]);
talk2(*menagerie[i]);
}
}
// SIZES.CPP : sizes of objects with virtual functions
// From Borland's The World of C++, Lesson 19
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class no_virtual {
int i;
public:
void f();
void g();
};
class simple_base : public no_virtual {};
class one_virtual {
int i;
public:
virtual void f();
void g();
};
class virtual_in_base :
public one_virtual {};
class two_virtuals {
int i;
public:
virtual void f();
virtual void g();
};
class virtual_in_base2 :
public two_virtuals {};
#define SIZE(arg) \
printf("sizeof(" #arg ")= %d\n",sizeof(arg))
main() {
SIZE(no_virtual);
SIZE(simple_base);
SIZE(one_virtual);
SIZE(virtual_in_base);
SIZE(two_virtuals);
SIZE(virtual_in_base2);
void * voidpointer;
SIZE(voidpointer);
}
// VPET2.CPP : A menagerie of pets
// From Borland's The World of C++, Lesson 20
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class pet {
public:
// virtual causes late binding:
virtual void speak() {}
};
class dog : public pet {
public:
void speak() { puts("woof!"); }
};
class cat : public pet {
public:
void speak() { puts("murroww!"); }
};
class bird : public pet {
public:
void speak() { puts("cheep!"); }
};
// talk uses the common interface to pet:
void talk(pet * p) {
p->speak();
}
// can also use references:
void talk2(pet& p) {
p.speak();
}
main() {
pet* menagerie[] = { new dog, new cat, new bird };
const sz = sizeof(menagerie)/sizeof(menagerie[0]);
for(int i = 0; i < sz; i++) {
talk(menagerie[i]);
talk2(*menagerie[i]);
}
}
// VPET3.CPP : pets with an abstract base class
// From Borland's The World of C++, Lesson 20
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class pet {
public:
// pure virtual function:
virtual void speak() = 0;
};
class dog : public pet {
public:
void speak() { puts("woof!"); }
};
class cat : public pet {
public:
void speak() { puts("murroww!"); }
};
class bird : public pet {
public:
void speak() { puts("cheep!"); }
};
// talk uses the common interface to pet:
void talk(pet * p) {
p->speak();
}
// can also use references:
void talk2(pet& p) {
p.speak();
}
main() {
pet* menagerie[] = { new dog, new cat, new bird };
const sz = sizeof(menagerie)/sizeof(menagerie[0]);
for(int i = 0; i < sz; i++) {
talk(menagerie[i]);
talk2(*menagerie[i]);
}
}
// VPET4.CPP : Extending the pet system
// From Borland's The World of C++, Lesson 20
// (C) Copyright 1991 by Borland International
#include <stdio.h>
class pet {
public:
// pure virtual function:
virtual void speak() = 0;
};
class dog : public pet {
public:
void speak() { puts("woof!"); }
};
class cat : public pet {
public:
void speak() { puts("murroww!"); }
};
class bird : public pet {
public:
void speak() { puts("cheep!"); }
};
// Extending the system by adding a new class:
class hamster : public pet {
public:
void speak() { puts("squeak!"); }
};
// talk uses the common interface to pet:
void talk(pet * p) {
p->speak();
}
// can also use references:
void talk2(pet& p) {
p.speak();
}
main() {
pet* menagerie[] = { new dog, new cat, new bird, new hamster };
const sz = sizeof(menagerie)/sizeof(menagerie[0]);
for(int i = 0; i < sz; i++) {
talk(menagerie[i]);
talk2(*menagerie[i]);
}
}
// OP_OVL.CPP : Simple operator overloading in C++
// From Borland's The World of C++, Lesson 20
// (C) Copyright 1991 by Borland International
class point { // a point in 2-D space
int x, y;
public:
point(int X, int Y) { x = X; y = Y; }
point operator=(point rv) {
x = rv.x;
y = rv.y;
return *this; // a copy of this object
}
point operator+(point arg) {
return point(x + arg.x, y + arg.y);
}
};
main() {
point A(9,12), B(47,14), C(0,0);
C = A + B;
}
// MULTIPLE.CPP: simple multiple inheritance
// From Borland's The World of C++, Lesson 21
// (C) Copyright 1991 by Borland International
class storable { // stores itself on disk
public:
storable(char* filename);
virtual void store();
};
class elevator {
int floor_selected;
int floor_number;
public:
elevator(int starting_floor);
void go(int floor);
};
class SElevator // storable elevator
: public storable, public elevator {
public:
SElevator(char * fn, int sfloor) :
storable(fn), elevator(sfloor) {}
// The meaning of store() probably changes:
void store();
};