04.Functions-Execrise
04.Functions-Execrise
This document defines the exercises for the "C++ Fundamentals" course @ Software University. Please submit your
solutions (source code) of all below-described problems in Judge.
1. Center Point
You are given the coordinates of two points on a Cartesian coordinate system - X1, Y1, X2, and Y2. Create a method
that prints the point that is closest to the center of the coordinate system (0, 0) in the format (X, Y). If the points are
at the same distance from the center, print only the first one.
Examples
Input Output
2 (-1, 2)
4
-1
2
1 (1, 2)
2
7
6
2. Operations
Write a program that receives two integer numbers and one of the following four instructions (as a single symbol):
+, -, *, / on the next line. The operations are as follows: + is addition, - is subtraction, * is multiplication, and / is
division. Create four functions (for each operation) and call the right one depending on the command.
The function should print:
The calculated number
"Can't divide by zero." - on certain conditions
Examples
Input Output
8 4 2
/
2 3 -1
-
1 2 3
+
3. Factorial Division
Read two integer numbers. Calculate the factorial of each number. Divide the first result by the second and print the
division formatted to the second decimal point.
Examples
Input Output Input Output
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output
0 zero
101 one hundred one
957 nine hundred fifty seven
Examples
Input Output Comments
12345 54 12345 has 2 even digits - 2 and 4. Even digits have a
sum of 6.
Also, it has 3 odd digits - 1, 3, and 5. Odd digits
have a sum of 9.
Multiply 6 by 9 and you get 54.
-12345 54
Additional Problem
Operations* (not included in the homework)
Write a program that receives two integer numbers from the console, then reads one of the following four
instructions (as a single symbol): +, -, *, / and performs the respective operation on the two numbers, with the first
number as a left operand and the second number as a right operand (+ is addition, - is subtraction, * is
multiplication and / is a division).
If the user enters a symbol different than one of the four operations, the program should print try again, and
allow the user to enter the operation again.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.