Fortran Programming Lab 4 - Area Calculator and Travel Cost, Lab Reports of Computer Science

Instructions for lab 4 in csci260, a fortran programming course. Students are required to write programs using select case statements to calculate the area of different shapes and if statements to determine travel costs based on user input. The steps to create and compile the programs, including editing files, setting up directories, and running scripts.

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-znj
koofers-user-znj 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI260 Lab 4 Spring 2009
Due: 11:59pm. Wednesday, February 4, 2009
Objective: Use SELECT CASE statements to do selective execution of code. Using IF statements to
do selective execution of code. Coding scientific equations - Your program will get
data from the user, perform computations dependent on input values and output
results.
Overview: You will be provided a Fortran shell with comments to lead you through the program’s
development. The equations and process for decision making that you will use are
provided below. You will write the code to prompt the user for the values of those
variables. This prompting process is similar to the process used in lab2.
1. Login to isengard
2. Change your current working directory to your csci260a directory (cd csci260a).
3. Make a lab4 subdirectory and then change directory to your lab4 directory (mkdir lab4 cd
lab4).
4. Copy the files from the /class/csci260a/Assignments/lab4 directory to your lab4 (current)
subdirectory. (cp /class/csci260a/Assignments/lab4/* . )
5. Use cp to copy and rename the first file from lesson1.f95 to mylesson1.f95.
Edit mylesson1.f95
6. Appropriately modify the header information. Complete the program code to:
You will write a program that uses a SELECT CASE statement. Your program will find the area
of either a triangle, circle, square or a rectangle. Before the SELECT CASE statement you will
need to display options to the user, the options will look like:
***** The area calculator, advanced edition *****
1. Find the area of a triangle.
2. Find the area of a circle.
3. Find the area of a square.
4. Find the area of a rectangle.
*****************************************
What option do you wish?
3
Please enter the side of your square.
2.1
The area of your square is : 4.2
The user enters an option that is used to control the SELECT CASE statement. Within the
different parts of the SELECT CASE statement you will get the correct data from the user and
display the results. In the example the user wanted the area of a square, so, the program
only asks for one side of the square.
a. Declare and initialize your variables.
b. Build code to display the menu.
c. Get the menu option from the user
d. Build the SELECT CASE statements with the proper interaction with the user and formulas
inside.
e. Display the proper results within the correct part of the SELECT CASE statement.
pf2

Partial preview of the text

Download Fortran Programming Lab 4 - Area Calculator and Travel Cost and more Lab Reports Computer Science in PDF only on Docsity!

CSCI260 Lab 4 Spring 2009 Due : 11:59pm. Wednesday, February 4, 2009 Objective : Use SELECT CASE statements to do selective execution of code. Using IF statements to do selective execution of code. Coding scientific equations - Your program will get data from the user, perform computations dependent on input values and output results. Overview : You will be provided a Fortran shell with comments to lead you through the program’s development. The equations and process for decision making that you will use are provided below. You will write the code to prompt the user for the values of those variables. This prompting process is similar to the process used in lab2.

  1. Login to isengard
  2. Change your current working directory to your csci260a directory (cd csci260a).
  3. Make a lab4 subdirectory and then change directory to your lab4 directory (mkdir lab4 cd lab4).
  4. Copy the files from the /class/csci260a/Assignments/lab4 directory to your lab4 (current) subdirectory. (cp /class/csci260a/Assignments/lab4/*. )
  5. Use cp to copy and rename the first file from lesson1.f95 to mylesson1.f.

Edit mylesson1.f

  1. Appropriately modify the header information. Complete the program code to: You will write a program that uses a SELECT CASE statement. Your program will find the area of either a triangle, circle, square or a rectangle. Before the SELECT CASE statement you will need to display options to the user, the options will look like: ***** The area calculator, advanced edition *****

1. Find the area of a triangle.

2. Find the area of a circle.

3. Find the area of a square.

4. Find the area of a rectangle.

What option do you wish? 3 Please enter the side of your square.

The area of your square is : 4. The user enters an option that is used to control the SELECT CASE statement. Within the different parts of the SELECT CASE statement you will get the correct data from the user and display the results. In the example the user wanted the area of a square, so, the program only asks for one side of the square.

a. Declare and initialize your variables.

b. Build code to display the menu.

c. Get the menu option from the user

d. Build the SELECT CASE statements with the proper interaction with the user and formulas

inside.

e. Display the proper results within the correct part of the SELECT CASE statement.

CSCI260 Lab 4 Spring 2009

  1. Save and Exit your editor. Then compile your new Fortran program. g95 mylesson1.f If necessary, re-edit mylesson1.f95 to fix any bugs and then re-compile. When it compiles with no errors, test the compiled program using a.out Make sure that the program runs for all possible cases. Lesson 2, Problem solving Use cp to copy and rename the second file from lesson2.f95 to mylesson2.f. The cost for a collage student to travel a given distance, including money for gas, snacks and favorite beverage is as follows. Distance Cost 0 though 100 $20. More than 100 but not more that 500 $80. More than 500 but less that 1000 $150. 1000 or more $340.00 (Motel-6) Write a program where the user enters the expected distance traveled and the program displays the expected cost of the trip. Test using the following values 60, 420, 750, 1200.
  2. Create a script file. script lab4.script Cat your program source code from lesson 1. (to provide a listing of your code) cat mylesson1.f Compile your program again. (to verify no compilation error) g95 mylesson1.f Run your program three times. (Use the following values:: option 1, height = 3.1, base = 4.2 : option 2, radius = 4.5 : option 4, side1 = 7.9, side2 = 12.4 ) a.out Cat your program source code from lesson 2. (to provide a listing of your code) cat mylesson2.f Compile your program again. (to verify no compilation error) g95 mylesson2.f Run your program again. (Use the values provided in lesson 2, you will have to run the program 4 times) a.out Press ctrl-d to stop the scripting process.
  3. Submit your script file for grading. CLsubmit csci260a lab4 lab4.script