Professional Documents
Culture Documents
General requirements...........................................................................................................................1
Lab work 1. «Buttons and forms»........................................................................................................1
Lab work 2. «Objects and classes»......................................................................................................3
Lab work 3. «Container»......................................................................................................................4
Lab work 4. Part 1 of 2: «Circles on the form»....................................................................................5
Lab work 4. Part 2 of 2: «MVC»..........................................................................................................6
Lab work 5. «С++ objects life-cycle and virtuality»...........................................................................7
Lab work 6. «Vector object editor»......................................................................................................9
Lab work 7. «Grouping and serialization»...........................................................................................9
Lab work 8. «Object tree and subscription».......................................................................................10
General requirements.
Software requirements:
o code comments, indentation and naming style (PEP 7 or similar) are compulsory;
o console debug output in most methods (L.W. 2,3,5);
Organization requirements:
o code versioning system (git) is compulsory starting with a second lab work; a
history of commits should be presented at lab work defense;
o https://www.youtube.com/watch?v=9XKwTKz3IgU – a lecture about git.
The application should contain no less than 15 various interacting controls (all of different classes).
The student must be able to implement required program changes at once by the teacher’s request of
“Mouse hovering over this object should produce that action on that object” or similar.
Main controls to pay special attention to are the following: a button (title, button press event),
textbox (text, text change event), dropdown combobox (text, list of dropdown elements, selected
element index, selected), static text (text), checkbox (text, check state, check state change event),
radio button (text, check state, check state change event), panel (size), spacer (alignment), list box
and check list box (elements, elements selection event), tabs (active tab, active tab change event)
etc.
The main goal of the first lab work is to learn how to create GUI event-driven applications. The
application to achieve that purpose must be as diverse as possible. The sense, reason and the
meaning of the application are not required. Even more, they interfere and impede the main goal.
Do not try to implement anything useful! Put as many different controls and learn how they interact,
change each other’s properties, call each other’s methods and react on different events.
Lab work may consist of several projects within the same solution. Do not put lots of code into the
same file or implement the task sequentially. I’d be wise to start with definition and implementation
of a simple class, then learn and try to create several instances statically and dynamically, learn to
access its properties and methods. Then declare constructors and destructors and test them. After
that create a descendant class and learn to instantiate it. Learn to declare new methods and redeclare
existing in descendant classes and so on. Do not try to define or redefine here some standard
operators (like ++, <<, >> и т.д.)!
Recommended objects to manipulate: geometric shapes (points, sections, circles and ellipses),
mathematical objects (vectors and matrices) etc.
Not recommended objects to manipulate (as the teacher has little knowledge of this subject area):
Warrior, Weapon, HP, Damage, etc.
Definitions
o classes
o attributes, methods
o descendant classes
o constructors (necessary at least: default without parameters, with parameters, copy
constructor), destructor
o visibility/accessibility modifiers (illustrate private, protected and public)
Implementation
o methods
o inside definition, after definition
o constructors, destructor
Object creation and usage (attribute access, methods invocation)
o statically created objects («MyClass obj;»)
o dynamically created objects («MyClass *obj = new MyClass();»)
o create objects with different constructors (each class must implement 3 constructors:
default, with parameters, copying)
o placing objects into variables of different type (explain how MyBase * obj = new
MyBase() differs from MyBase * obj = new MyDeriv())
o descendant objects creation (illustrate which constructors are invoked)
o object composition: attribute of one class is an object or a pointer to the object of
another class; composed object is created on its parent creation and deleted on its
parent deletion; illustrate the difference between composing another object directly
or a pointer to another object.
Object deconstruction
o for statically created objects
o for dynamically created objects
o of descendant classes objects (illustrate which destructors are invoked)
Lab work requires confident understanding and management of pointers and references. Students
must clearly understand everything the following code does: MyBase * obj = new MyDeriv() (a
pointer variable is created first, a new object is created in the heap later, and its address is put into
the pointer variable).
Lab work requires to implement enough examples to understand the following situations:
an ancestor class has both the constructor and the destructor, a descendant class has neither;
what happens on ancestor object creation, on a descendant object creation?
an ancestor and a descendant classes have both the constructor and the destructor: in which
order are they invoked on ancestor and descendant object creation?
A pointer variable of a base type receives an address of a descendant class object: which
methods are accessible for this variable?
Storage functions
o add an objects
o remove an objects (with object deconstruction and without)
o iterating over objects if applicable (current, next, previous, accessibility checks)
o accessing object by index, if applicable
o iterating over objects to invoke a method on each
Main program should implement the code that randomly:
o creates new objects
o adds new objects to the storage
o performs some simple actions on the objects
o removes objects from the storage
The storage must be implemented as a separate object to be created and manipulated in the main
program. The storage should act (look like) either as an array, or as a list (choose as you prefer).
The storage should be implemented inside either as an array, or as a list (choose as you prefer).
Student must be aware of the difference between two last sentences. Main program should illustrate
storage usage and run a cycle of 100, 1000 and 10000 random actions measuring time. Action
should be selected from the following list: create an object and insert it into a random position;
remove and deconstruct a random object from the storage; select a random object from the storage
and run its method.
For array-looking storages main program should include the code similar to:
// create a storage
MyStorage storage(10);
// add objects
for (int i=0; i<storage.getCount(); i++)
storage.setObject(i, new SomeObject());
// iterate over objects
for (int i=0; i<storage.getCount(); i++)
storage.getObject(i).someMethod();
For list-looking storages main program should include the code similar to:
// create a storage
MyStorage storage();
// add objects
for (int i=0; i<10; i++)
storage.add(new SomeObject());
// iterate over objects
for (storage.first(); !storage.eol(); storage.next())
storage.getObject().someMethod();
The storage should handle random adding, deleting and counting storage object, keeping track of
empty positions in the storage if any, and dynamically resize to fit all necessary objects. If you are
not easy with linked lists, do not use them. If you are not easy with templates, do not use them. STL
containers are not allowed, since the idea of the lab work is more or less to replicate them.
Please, ensure appropriate encapsulation level of CCircle. The CCircle object must be responsible
for drawing its graphical representation on the screen as well as for checking if the coordinates of
the mouse click fall inside it. Hardly for any reason should the coordinates of CCircle be made
public.
Definitions
o redefined methods (implement the code to show when a redefined or inherited
method is invoked);
o virtual and overridden methods including destructors (implement the code to show
when an overridden or base method is invoked);
Implementation
o type checking (check if an object belongs to a certain class, or to a certain class and
all its descendants: “classname” vs. “isA” functionality);
o safe typecasting with dynamic_cast
o safe typecasting with self-implemented “isA” functionality
Passing objects into the functions and returning objects as function results, with lifecycle
control;
Smart pointers unique_ptr and shared_ptr, the way they influence the object lifecycle.
Demonstrate unsafe typecasting and type checking with self-made isA method. Demonstrate
standard language typecasting features (dynamic_cast in c++ or analog in other languages).
To test object passing into the function, the following functions should be implemented:
void func1(Base obj) { ... };
void func2(Base *obj) { ... };
void func3(Base &obj) { ... };
Create a simple Base class and its descendant Desc, implement all three constructors and a
destructor for both of them:
Base() { ... };
Base(Base *obj) { ... };
Base(Base &obj) { ... };
~Base() { ... };
Desc() { ... };
Desc(Desc *obj) { ... };
Desc(Desc &obj) { ... };
~Desc() { ... };
Create Base and Desc instances and pass them into all three functions, explain constructors and
destructors debug output.
To test object returning from the function, the following functions should be implemented:
Base func1() { ... };
Base* func2() { ... };
Base& func3() { ... };
Implement all three functions in two variations: with static and dynamic object instance creation.
Place the result of each function into the local variable and explain constructors and destructors
debug output. Identify evident and possible memory management problems.
In order to learn and illustrate the behavior of smart pointers, create several instances of
unique_ptr and shared_ptr (with and without make_unique and make_shared) and check the
lifecycle.
The storage saving and loading functions should not know any specific object details. All they
should do is invoking save() and load() methods of specific objects to delegate them the writing and
reading from file.
Storage-from-file deserialization is a bit tricky. Each object, evidently, has both save() and load()
virtual functions. However, in order to be able to call load() method, the object has to be created
beforehand! Which class should be instantiated, to call the load() method? It is exactly the problem
the Abstract Factory or Factory Method patterns aim to solve.
The TreeView object should learn to rebuild itself from the current storage contents of specific
objects and groups of objects and groups. That is usually achieved with a recursive function
processNode(TreeNode tn, StorageObject o) with the following typical behavior:
Additionally:
Ensure all application and user interface actions are performed only though commands
(including object creation and deletion, including mouse-invoked commands), with undo
functionality and user-visible history stack.
Implement a property window to check and to change selected objects properties though
introspection and reflection.