Skip to main content
Engineering LibreTexts

8.7: Exercises

  • Page ID
    54278
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Below are some quiz questions and project suggestions based on this chapter.

    Quiz Questions

    Below are some quiz questions.

    1. List the six relational operators?
    2. List the three basic logical operators?
    3. For each of the following, answer .true. or .false. .
    logical :: b1 = .true., b2=.false., b3=.true.
    integer :: i=5, j=10
    ( b1 .or. b2 )
    ( b1 .or. b3 )
    ( b1 .and. b2 )
    ( (b1 .or. b2) .and. b3 )
    ( b1 .or. (b2 .and. b3) )
    ( .not. ( i < j ) )
    ( j < i )
    
    1. Write the Fortran IF THEN statements to display the message "Game Over" if the integer variable lives is \(\leq\) to 0. You may assume the variable lives is already declared as an integer and initialized.
    2. Write the Fortran IF THEN statements to check the integer variable num and if the value is < 0, take the absolute value of the number and display the message, "Variable num was made positive". You may assume the variable num is already declared as an integer and initialized.
    3. Write the Fortran statements to compute the formula \(z = \frac{x}{y}\) assuming the values for integer variables \(x\), \(y\), and \(z\) are previously set. However, if \(y = 0\), do not compute the formula, set \(z = 0\), and display an error message, "Z not calculated". You may assume the variables \(x\), \(y\), and \(z\) are already declared as an integers and initialized.
    4. Write the statements required to compute the following formula using real variables \(f\), \(x\), and \(y\). Use a single IF THEN ELSE IF statement. You may assume the values for \(f\), \(x\), and \(y\) have already been declared as real values and initialized.
      \[ f(x) = \begin{cases} x^2 \cdot y & \text{if } x \leq 0.0 \\ x \cdot y & \text{if } x > 0.0 \end{cases} \nonumber \]

    Suggested Projects

    Below are some suggested projects.

    1. Type in the quadratic equation program, compile, and execute the program. Provide input values that will check each of the possible outputs.
    2. Write a Fortran program to prompt for and read the year that a person was born. The year must be between 1900 and 2015 (inclusive). If an invalid entry is read, the program should display the message, "Sorry, that is not a valid year." and re-prompt. If the correct value is not provided after 3 attempts, the program should display the message "Sorry, you're having problems. Program terminated." and terminate. Once a valid year is read, the program should display the year and a message "is a leap year" or "is not a leap year". Include appropriate declarations, prompts, read statements, calculations, and write statements. Test the program on a series of input values and verify that the output is correct.
    3. Type in the grades program, compile, and execute the program. Test the program on a series of input values that will check each grade.
    4. Modify the grades program to handle the following grade assignment
      A A- B+ B B- C+ C C- D F
      \(\geq\)94 93-90 89-87 86-84 83-80 79-77 76-74 73-70 69-60 \(\leq\)59

      Compile, and execute the program. Test the program on a series of input values that will check each grade.
    5. Write a Fortran program to prompt and read the Fahrenheit as an integer, convert to Celsius, and display the result as a real. The formula to convert a Fahrenheit temperature to a Celsius temperature is as follows:\[ \textit{celsius} = \left(\frac{5}{9}\right)\left(\textit{fahrenheit} - 32\right) \nonumber\]The Fahrenheit value must be between -50 and 150 (inclusive). If the Fahrenheit value is out of range, the program should display an error message, "Temperature out of range", and terminate. The calculations must be performed as real. Include program statements, appropriate declarations, prompts, read statements, calculations, and write statements. Test the program on a series of input values.
    6. Write a Fortran program that reads an item cost (real numbers) and amount tendered (real number) and compute the correct change. The correct change should be returned as the number of twenties, tens, fives, ones, quarters, dimes, nickels, and pennies. The main program should ensure that the amount paid exceeds the item cost and, if not, display an appropriate error message. Test the program multiple times using a series of input values.
    7. Write a Fortran to program that reads a number from the user that represents a television channel and then uses a CASE construct to determine the call letters for that station.
      Channel Call Letters Affiliation
      3 KVBC NBC
      5 KVVU FOX
      8 KLAS CBS
      10 KLVX Public
      13 KTNV ABC

      The program should display an appropriate message if an invalid or unassigned channel is entered. Test the program on a series of input values that will show each station.

    This page titled 8.7: Exercises is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?