Language C++
Thank you so much for helping!!!
\fQ5. [Sorting Equations] The program accepts 3 different positive integers as input. First, consider all the permutations of these 3 numbers. For example, if the inputs are 2, 1, 3, then their permutations are 1 2 3, 1 3 2, 2 1 3, 23 1, 3 1 2, 3 2 1 (in an increasing order). In Q5, we define the order of two permutations as follows: . We compare the number in the left-most place first. The permutation with the smaller left- most number is said to be smaller, e.g., 1 3 2 is smaller than 2 1 3. . If the left-most number are the same, compare the next one, e.g., 2 1 3 is smaller than 2 3 1. Then, insert operators '+ or '- between each two numbers to form an equation and print the result of it. For each operation, both + and - should be considered. For example, for the permutation of 1 2 3, we need to consider four cases: 1 + 2 + 3 = 6, 1 +2 -3 = 0, 1 -2 + 3 = 2, and 1 -2 -3 = -4. The output should display all possible equations and their calculation results in an increasing order sorted by the result of the equation. If two equations have the same result, further sort the equations in an increasing order of the permutations. For example, 1 + 2 + 3 = 6 should be output before 1 + 3 + 2 = 6 because permutation 1 2 3 is smaller than 1 3 2 according to the definition above. Notes: There is a space between each number and operator. No validity check is needed for the inputs. Example 1 (Inputs are underlined): Enter three different positive numbers: 2 1 3 1 - 2-3=-4 1 -3-2=-4 2-1-3=-2 2-3-1=-2 1+2-3=0 1- 3 + 2=0 2+1-3=0 2-3+1=0 3-1-2=0 -2- 1 =0 -2+3=2 + 3 -2=2 2=2 2+1 =2 3 =4 1 =4 ++ +1 ANEWNW + +Q4. [Drawing a Tree] Write a program to print the pattern of a simple tree. The tree has three parts, including the treetop. the middle branch and the trunk. After the program starts, the user inputs an integer value (data type: int) 5, representing the treetop's width, i.e., the number of "*"in the last row of the treetop. We assume that S is an odd number and is no smaller than 5. So, the program needs to check the correctness of this input. If it is invalid, the user needs to input another $ value again. The program only needs to check whether 5 is an odd number and is no smaller than 5. There is NO need to consider whether $ is another type of variable, like double, char, etc. When the input S is valid, print the tree according to the following requirements: . The treetop is an isosceles triangle composed of ($/2] + 1 rows, and each row has an increasing odd number of "*" starting from 1. The middle branch is an isosceles trapezoid with the same number of rows as the treetop. Each row of the middle branch has an increasing odd number of "*" starting from 5 - 2. The trunk is a rectangle with the width S - 4 and the height S. There is NO space between two adjacent "*" in each row. After the valid S is provided, the user needs to further input one character (data type: char) D. We assume D is correct, ie., no need to check its correctness. If D is either 'u' or 'U', please print the tree in a normal way. If D is either 'r' or 'R', please print the tree in a reversed way, i.e., from truck to the middle branch to the treetop. The shape of each part in the tree still follows the requirements above.Example 1: Please input the width of the treetop: 3 Invalid input! Please input the width of the treetop: 6 Invalid input! Please input the width of the treetop: 5 Please input the direction: Example 2: Please input the width of the treetop: Please input the direction:Example 3: Please input the width of the treetop: Please input the direction: R