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:
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:
- Green - easy tasks
- Yellow - tasks of medium difficulty
- Red - more difficult tasks
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 |
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.
|
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} |