CPE 150 Laboratory 6: Functions I: 1 Calculate Distance

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CPE 150 Laboratory 6: Functions I

Department of Computer Engineering


Yarmouk University
Spring 2020

1 Calculate Distance
This function takes as its parameters four double numbers that represent two points in the plane and
return the distance between them. The distance between two points (x1, y1) and (x2, y2) in the Cartesian
plane:
p
Distance = (x2 − x1 )2 + (y2 − y1 )2

2 Digits Sum
This function takes one integer number as a parameter and returns the sum of its individual digits till the
sum is a single digit.

3 Calculator
This function takes two integers and a character that represents one of the following operation (+, -, *,
/), if the character equals ’+’ the function prints the sum of the two numbers, if the character equals ’-’;
the function prints the difference of the two numbers, etc.

4 Menu
This function displays the following menu at the screen, prompts the user to enter here/his choice, and
returns the choice.

MAIN MENU
———————————–

1- Calculate Distance.
2- Digits Sum.
3- Calculator.

4- Exit.
- Please Enter your choice(1-4).

1
5 Main Function
Write a menu driven program in main.cpp that repeatedly displays the above menu to the user, executes
the corresponding program until the Exit choice is chosen.
The menu should work as follows:

• Choice 1: Prompt the user to enter the coordinates of two points, calculate the distance, and print
it to the screen.
• Choice 2: Prompt the user to enter an integer, calculate the sum and print it to the screen.
• Choice 3: Prompt the user to enter two integers, calculate the result and print it to the screen.

• Choice 4: Exit.

You might also like