220k views
4 votes
1) Open the terminal and using vi/vim create a new script and name it lab7

2) Insert at the top of your file a comment with your name, class and section number (e.g. \#John Doe, EMT 2390L - ABC123).
3) In this script you will compute the midpoint between 2 points on a plane.
4) Ask the user for the values x2,y2 of point 2 and store them in variables.
5) Using the values of x1,y1,x2,y2 compute the midpoint using the midpoint formulas:
a)x mid =(x1+x2)/2
b)ymid=(y1+y2)/2
6) Display the midpoint results on the screen e.g. (4,5)
i) Remember that the shell only supports integer division. Therefore, to test the script use values that will result in xmid and ymid equal to a whole number
ii)e.g. x1=3,y1=4,x2=5,y2=6 will result in xmid=4 and ymid=5
7) Save the script and make it executable (HINT: use the chmod command with mode 755).
8) Execute the script (HINT: use dot slash ./ combination, followed by your script name) and fix any errors.
Please use Linux and show the script and output.

User Littlefoot
by
7.6k points

1 Answer

4 votes

Final answer:

To create a script in the terminal using vi/vim, ask the user for values of x2 and y2, compute the midpoint using the formulas given, and display the result. Make the script executable and run it from the terminal.

Step-by-step explanation:

To create a script in the terminal, you can use the vi or vim text editor. First, open the terminal and type 'vi lab7' to create a new script named lab7. Press 'i' to enter insert mode and add a comment at the top of the file with your name, class, and section number. For example, '#John Doe, EMT 2390L - ABC123'.

Next, you need to ask the user for the values of x2 and y2 for point 2. You can use the following command in the script to prompt the user for input:

'read -p "Enter x2: " x2; read -p "Enter y2: " y2;'

After obtaining the values of x2 and y2, you can use the midpoint formulas to compute the midpoint. The formulas are:

a) x_mid = (x1 + x2) / 2

b) y_mid = (y1 + y2) / 2

To display the midpoint results on the screen, you can use the 'echo' command with the computed values. For example, 'echo "($x_mid, $y_mid)"'.

To make the script executable, you can use the chmod command with the mode 755. Execute the script using the './lab7' command.

User Cyrill
by
8.0k points