• Nie Znaleziono Wyników

Polymorphism, constructor

N/A
N/A
Protected

Academic year: 2021

Share "Polymorphism, constructor"

Copied!
2
0
0

Pełen tekst

(1)

DPOB LI0 Object programming - classes 3

This document contain information about labolatory exercises.

Object programming - classes 3

Subject - Polimorphism, abstract classes, copy constructor, dynamic object creation, initialize data in costructors.

1. Polimorfizm

1. Basing on classes Person, Student and Worker create a program which counts incomes of people from university.

a) Create virtual method f loat income() in class Person and define table which would store Persons.

b) Create global function spending() that will count total income of pe- ople connected to university as sum of incomes of each person.

c) Change table of pointers to the table of objects. Check whatever the polymorphism mechanism works correctly ? Does it work if you delete a word virtual from income method ?

d) Change method income in class Person to pure virtual method. Are you now allowed to create objects of type Person? What will change if you comment definition of method income in class Student?

2. Constructors, copy Constructors

1. Open file heap.cpp

a) Watch how to dynamic create and delete objects in C++.

b) Add to class Heap constructor with two arguments (string, string) that will set field type and name from parent class Container.

c) Using new create in main() new object Heap with a given name ’Dy- namic created Heap’. Invoke method W riteContainerM ethod() on him.

d) Add copy constructor to class Container(const&Container). Check what now happened when you invoke method W riteContainerM ethod()

?. What is the difference when copy constructor is set and when it is commented?

e) Execute a method W riteHeapElements() two times one by another.

f) Define in Heap new arg-constructor with argument type const char∗.

Execute method W riteHeapElements() with string parameter string a what will happened ? How to prevent such beheviour?

3. Do it yourself tasks

1. Create properly working copy constructor for class Heap (pointers should point to new place in memory).

1

(2)

DPOB LI0 Object programming - classes 3

2. Change Heap class so that it could operate on different data types (string, float, double).

2

Cytaty

Powiązane dokumenty

My focus will be on linguistic constructions with the conditional and the partitive as patterns emergent from casual and institutional Finnish interactions,

Voor de kosten analyse van de kranen is de gelimiteerde data gebruikt uit World Cargo News.. Voor de kosten analyse van kade wanden is een promotie werk gevonden dat de vragen van

Przez Wadowice przechodziły wojska konfederackie dowodzone przez Józefa Bierzyńskiego - marszałka sieradzkiego23 oraz Kazimie­ rza Pułaskiego - marszałka

„Wiadomości Bocheńskie : kwartalnik społeczno-kulturalny Stowarzy- szenia Bochniaków i Miłośników Ziemi Bocheńskiej”. 2016: nr

[r]

Przeto członkow ie takiego Z g rom ad zen ia nie mogą żyć dla sprośnego zysku i chciwości, która je st korzen iem w szystkie­ go złego.. W okół czci tego

W  okresie  od  maja  do  listopada  2011  r.  przeprowadzona  została  dodatkowa  kontrola  bezpieczeństwa  fizycznego 

Alarming (divergent from normal) behaviour was assessedusingtheAlarmingBehaviourQuestionnaire (ANZ)byJadwigaKamińska-Reyman (10)