• Nie Znaleziono Wyników

Introduction to C++. Object paradigms.

N/A
N/A
Protected

Academic year: 2021

Share "Introduction to C++. Object paradigms."

Copied!
2
0
0

Pełen tekst

(1)

DPOB LI0

Object oriented programming classes 1

This document presents information about tasks solved at laboratories.

Object oriented programming classes 1

Topic : Differences between C/C++, object paradigms, objects, encapsulation.

1. Programs in C/C++

Create new file with extension .c and write a program which print

0

Hello world

0

on screen. Compile it with gcc and g + + compiler.

2. Differences between C and C++

Short introduction about both programming languages using a file stos.cpp as an example (stos is a polish word meaning the same as pile in english).

3. Object paradigm

1. Compile and run the file stos.cpp.

2. Can we access all methods and variables in structure Stos ? 3. Change the structure into a class. Correct compilation errors.

4. Data class handling - encapsulation

1. Divide Class members into private (variables: n, dane) and public (me- thods: push, pop, empty) and run the program.

2. Add a method, which return present number of elements in the pile (me- thod should be named: getLiczbaElementow() ).

5. Initialize and finalize objects

1. Define no-arg constructor (constructor which takes no arguments), which would assign 0 to the attribute n, which store information about pre- sent number of elements in the pile, and after that it would print sign

”Mostrar-se!” on screen.

2. Define destructor, which would print on screen sign ”Desaparecer!”.

3. Make changes to the program, which let us observe when the constructor() and desctructor() are invoked.

1

(2)

DPOB LI0

Object oriented programming classes 1

6. Do it yourself

1. Define class Data. Attributes of this class should store information about day, month, year.

Data should have following methods:

— set(int d, int m, int r) - setting values of the day, month and year;

— print() - printing data on screen;

— no-arg constructor - which sets current date (find a proper function on the web);

— constructor with arguments - which set to data values passed in argu- ments;

2. Class Data should not have any other methods than those mention above.

Attributes day, month and year should be private.

3. Create an exemplary program exploiting class Data.

2

Cytaty

Powiązane dokumenty

38 Zainteresowania gnozą są tu niewątpliwe. Mistyczno-epifanieczne poznanie bytu chyba również. Warto zwrócić uwagę na poznanie i samopoznanie w horyzoncie biblijno-mitycznym,

To consider this problem more generally (since one benefit of rational ap- proximation appears to be the approximation to functions in an unbounded interval, which usual

Wychowawca staje więc wobec wychowanka jako osoby, spotyka się z wychowankiem w jego niepowtarzalnym fakcie „bycia osobą”, stąd też realizacja wychowania jest

1f the flow at least in the neighborhood of the impacting bottom approaches a limiting condition quickly enough, the linearized theory can be used to find the total impulse which

System szkolenia załóg okrętów Marynarki Wojennej RP musi uwzględniać zarówno specyfikę reżimu prawnego akwenów morskich, jak i rolę zadań wykonywanych przez siły morskie w

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

(1 point) The sides of a rectangle has been measured to be 40cm and 50cm correct to the nearest 10cmA. The lower bound for the area of the rectangle is (select all

In particular, Bell and Watson [BeW] obtained criteria for the existence and non-existence of means on given continua.. A result of the present paper generalizes their