Codes + Flowcharts + Pseudocodes + Output of Questions!

This repository is created to show solutions of Visual Based Programming midterm questions.

You can easily find the explanation of solutions from Documentation and you can find source codes of questions in HW_N folder where N is 3.8, 5.6, 6.16, 6.16, 7.9. Also flowcharts are in the Flowchart folder, pseudocodes are in Pseudocode folder!

To see Visual Based Programming midterm-2 repository: Second Midterm


Question 3.8:

Write an application that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum, product, difference and quotient of the two numbers.

Question 5.6:

(Pythagorean Triples) A right triangle can have sides that are all integers. A set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of the two sides is equal to the square of the hypotenuse. Write a program to find all Pythagorean triples for side1, side2 and hypotenuse, none larger than 30. Use a triple-nested for loop that tries all possibilities. This is an example of “brute force” computing. You will learn in more advanced computer science courses that there are several problems for which there is no other known algorithmic approach.

Question 6.13:

Write an application that simulates coin tossing. Let the program toss the coin each time the user presses the “Toss” button. Count the number of times each side of the coin appears. Display the results. The program should call a separate method Flip that takes no arguments and returns false for tails and true for heads. Note: If the program realistically simulates the coin tossing, each side of the coin should appear approximately half of the time.

Question 6.16:

The greatest common divisor of integers x and y is the largest integer that evenly divides both x and y. Write a recursive method Gcd that returns the greatest common divisor of x and y. The Gcd of x and y is defined recursively as follows: If y is equal to 0, then Gcd( x, y ) is x; otherwise, Gcd( x, y ) is Gcd( y, x % y ), where % is the modulus operator.

Question 7.9:

(Binary Search) Modify the program in Fig. 7.12 to use a recursive method BinarySearch to perform the binary search of the array. The method should receive an integer array and the starting and ending subscript as arguments. If the search key is found, return the array subscript; otherwise, return -1.