ADDITIONAL EXAMPLES FOR EXERCISE FROM THE FIELD "CLASSES AND OBJECTS"


In this section, examples of tasks from the area of ​​classes and objects, with solutions, are given. Try to solve the examples on your own, and use the solution for checking or use it if, after a large number of attempts and a lot of effort, you still fail to solve the task on your own.
​The solution will be displayed by clicking the button next to the assigned task.
The tasks are colored in different colors depending on the difficulty:

Task 1 - Picture frames - objects:

On the table there are picture frames of different dimensions, but they are all rectangular in shape. Based on the entered width and height of the frame in millimeters, the program should determine the area of ​​the frame in square millimeters. Solve the task using objects.


Input:
The user enters the width and height of the frame for 2 images expressed in millimeters.

Output
On the output, show the areas of the frames in square millimeters:
​
Example
Input
456 785
300 400

Output
357960 120000
Ramovi za slike-zadatak

Task 2-Group of workers-objects:

Create a class that describes the worker. Create 2 objects that represent workers, enter the following data: first name, last name, hourly earnings, number of working hours per week. Write a program that, based on their hourly earnings and the number of working hours per week, calculates their weekly earnings.
Grupa radnika-zadatak

Task 3-Car movement-objects:

The car starts moving from rest with a constant acceleration of a(m/s2).
What is its speed after time t(s)5s>t>30s
How far does he travel in this time?
Enter data for two cars. Solve the task using objects

Input
The two lines of standard input respectively contain the acceleration a in m/s2 and the time t in seconds for the first car.
In the next two lines, enter the same data for the second car

Output
Display speeds, as distance traveled, for both objects representing cars

Example
Input
Acceleration of car 1 in [m/s^2]?
2
Time of movement of car 1 in [s]?
20
Acceleration of car 1 in [m/s^2]?
3.5
Time of movement of car 2 in [m/s]?
10.25

Output
Car 1{ v=40m/s, s=400m}
Car 2{ v=35.875m/s, s=183.86m}​
Kretanje tela - zadatak

Task 4-Car Sales:

Write an application that requires the user to enter data for two cars that are shortlisted for eventual purchase at a car dealership, then stores that data in objects and displays it on the screen. Create a class that describes a car with at least 5 attributes.
Razmena cifara - zadatak

Task 5-Volume of Balls

Create two balls, as objects, enter their radii and then calculate the volumes and display the result on the screen.
Sredina intervala - zadatak

Problem 6-Dice:

Create a class that describes the cube. In the main class, create two cube objects, enter the sides and calculate the areas and volumes.
Operacije po modulu - zadatak

Problem 7-Triangles:

Create two objects that represent triangles, enter their side and height and calculate their areas. Display the result on the screen.

​
Rastojanje tačaka - zadatak