0% found this document useful (0 votes)
3 views

04.Functions-Execrise

This document outlines exercises for the 'C++ Fundamentals' course at Software University, requiring students to submit their solutions in Judge. The exercises include finding the closest point to the center, performing basic arithmetic operations, calculating factorial division, converting numbers to English words, and multiplying the sum of even and odd digits. An additional problem involves handling invalid operation inputs and prompting the user to try again.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

04.Functions-Execrise

This document outlines exercises for the 'C++ Fundamentals' course at Software University, requiring students to submit their solutions in Judge. The exercises include finding the closest point to the center, performing basic arithmetic operations, calculating factorial division, converting numbers to English words, and multiplying the sum of even and odd digits. An additional problem involves handling invalid operation inputs and prompting the user to try again.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercises: Functions

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.

Follow us: Page 1 of 3


5 60.00 6 360.0
2 2 0

4. Print Name of Numbers


Write a program that, given an integer number in the range [0, 9999], prints the name of that number in English.
Simplifications:
 Use lowercase English letters only
 Don’t place "and" (e.g. 957 is nine hundred fifty-seven, NOT nine hundred and fifty-
seven)
 Skip 0 digits, except for the number 0 (e.g. 0 -> zero; 101 -> one hundred one; 1001 -> one
thousand one)
 Don’t print dashes (e.g. print 75 as seventy-five, NOT seventy-five)

Examples
Input Output
0 zero
101 one hundred one
957 nine hundred fifty seven

5. Multiply Evens Sum by Odds


Create a program that reads an integer number and multiplies the sum of all its even digits by the sum of all its
odd digits:

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.

Follow us: Page 2 of 3


Examples
Input Output
2 3 -1
-
12 5 try again
? try again
A try again
5 60
*

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 3

You might also like