Font size
WorksheetsKlase i objekti u programiranju
Total questions: 14
Worksheet time: 35mins
Objasnite razliku između klase i objekta.
Koji su osnovni elementi klase?
Nabrojite nekoliko primjera klasa iz svakodnevnog života. Za primjer, identificirajte neke osnovne elemente te klase i navedite nekoliko primjera odgovarajućih objekata.
Uparite sljedeće funkcije/metode na stringovima s odgovarajućim tipom kojem pripadaju.
Konstruktor klase je metoda čije je ime _______________, a njegova glavna svrha je ____________________________________________________________.
__init__()
postaviti svojstva klase na neku vrijednost.
Objasnite metode __str__() i __repr__().
Objasnite koncept nasljeđivanja klasa.
Napišite zaglavlje klase A koja nasljeđuje postojeću klasu B.
Objekt d tipa datum stvoren je naredbom: d=date(2013,1,2). Što će sljedeće naredbe ispisati? a) print(d.day) b) print(d.month) c) print(d.weekday())
2
1
3
Napišite naredbu koja će ispisati: a) trenutni mjesec b) trenutnu godinu c) ordinalni broj današnjeg datuma u odnosu na 1. siječnja. d) datum koji će biti 100.000 dana nakon 1. siječnja.
date.today().month()
date.today().year()
date.today().toordinal()
date.fromordinal(100000)
Definirajte klasu Krug čija će svojstva biti duljina radijusa.
Create methods circumference() (calculates the circumference of the circle) and area() (calculates the area of the circle). Furthermore, write a program that inputs the length of the radius, creates an object of type Circle, and using the created methods, prints the circumference and area of the circle. Round the result to two decimal places.
Create a method draw(B) that will draw a circle object colored B around the center of the screen. Furthermore, write a main program that will input the radius of the circle and the color and by calling the draw() method, draw the specified circle in the given color.
Define the class Time whose properties will be hours and minutes. In the created class Time, add the method __repr__(self) that will print the time in the format HH:MM. Furthermore, write a program that will input hours and minutes, and using the corresponding class, print the time in the format HH:MM.
