chapter_4 Module

All of the programming exercises for Chapter 4: Loops and Character Manipulation



Contents


Functions

public function is_alphnum(char)

Test whether an ASCII character is alpha-numeric

Arguments

Type IntentOptional AttributesName
character(len=1), intent(in) :: char

Return Value logical

public function is_alph(char)

Test whether an ASCII character is a letter

Arguments

Type IntentOptional AttributesName
character(len=1), intent(in) :: char

Return Value logical

public function is_num(char)

Test whether an ASCII character is numeric

Arguments

Type IntentOptional AttributesName
character(len=1), intent(in) :: char

Return Value logical

public function is_lower(char)

Test whether an ASCII character is a lowercase letter

Arguments

Type IntentOptional AttributesName
character(len=1), intent(in) :: char

Return Value logical

public function is_upper(char)

Test whether an ASCII character is an uppercase letter

Arguments

Type IntentOptional AttributesName
character(len=1), intent(in) :: char

Return Value logical

public elemental function calc_current_flow(v_D, I_O, T) result(i_D)

Arguments

Type IntentOptional AttributesName
real(kind=real64), intent(in) :: v_D

The voltage across the diode, in volts

real(kind=real64), intent(in) :: I_O

The leakage current of the diode, in amperes

real(kind=real64), intent(in) :: T

Temperature, in kelvins (K)

Return Value real(kind=real64)

The current flow through the diode in amperes

public elemental function to_kelvin(F)

Convert a temperature in Fahrenheit to Kelvin

Arguments

Type IntentOptional AttributesName
real(kind=real64), intent(in) :: F

Return Value real(kind=real64)

public elemental function to_celcius(F)

Convert a temperature from Fahrenheit to celcius

Arguments

Type IntentOptional AttributesName
real(kind=real64), intent(in) :: F

Return Value real(kind=real64)


Subroutines

public subroutine p4_1()

Test if the following equalities are valid statements, and if they are, evaluate them

Arguments

None

public subroutine p4_3()

Write a Fortran program to evaluate the equation y(x) = x^2 - 3x + 2 for all values between -1 and 3, in steps of 0.1.

Arguments

None

public subroutine p4_4()

Write the Fortran statements required to calculate y(t) from the equation:

Read more…

Arguments

None

public subroutine p4_5()

Write a Fortran program to calculate the factorial function. Be sure to handle the special cases of 0! and of illegal input values.

Arguments

None

public subroutine p4_6()

What is the difference in behavior between a cycle statement and an exit statement?

Arguments

None

public subroutine p4_7()

Modify program stats_2 to use the DO WHILE construct instaed of the while construct currently in the program

Read more…

Arguments

None

public subroutine p4_8()

Examine the following DO statements and determine how many times each loop will be exectued.

Read more…

Arguments

None

public subroutine p4_9()

Examine the following loops, determine the value of ires and the number of times each loop executes

Arguments

None

public subroutine p4_10()

Examine the followin while loops and determine the value of ires at the end of each of the loops.

Arguments

None

public subroutine p4_11()

Modify program ball from example 4-7 to read in the acceleration due to gravity at a particular location, and to calculate the maximum range of the ball for that acceleration. After modifying the program, run it with accelerations of -9.8, -9.7, and -9.6m/s2.

Read more…

Arguments

None

public subroutine p4_12()

Modify program ball from Example 4-7 to read in the initial velocity with which the ball is thrown. After modifying the program, run it with initial velocities of 10, 20, and 20 m/sec. What effect does changin the initial velocity have on the range of the ball? What effect does it have on the best angle theta at which to throw the ball?

Arguments

None

public subroutine p4_13()

Arguments

None

public subroutine p4_14()

Write a Fortran program to evaluate the function y(x) = ln(1/1-x) for any user-specified value of x, where ln is the natural logarithm. Write the program with a while loop, so that the program repeats the calculation for each legal value of x entered into the program. When an illegal value of x is entered, terminate the program.

Arguments

None

public subroutine p4_15()

Write a Fortran program to convert all uppercase characters in a user-supplied character string to lowercase, without changing the uppercase and nonalphabetic characters in the string. Assume that your computer uses the ASCII collating sequence.

Arguments

None

public subroutine p4_16()

Calculating Orbits.

Read more…

Arguments

None

public subroutine p4_17()

Write a program caps that reads in a character string, searches for all of the words within the string, and capitalizes the first letter of each word, while shifting the remainder of the word to lowercase. Assume that all nonalphabetic and nonumeric characters can mark the boundaries of a word within the character variable (periods, commas,etc.). Nonalphabetic characters should be left unchanged.

Arguments

None

public subroutine p4_18()

Write a computer program to calculate the current flowing through this diode for all voltages from -1.0V to +0.6 V, in 0.1 V steps. Repeat this process for the following temperatures: 75F, 100F, and 125F

Arguments

None

public subroutine p4_19()

Write a program that promps a user for a binary number, which will be entered as a string of 0s and 1s in a character variable. This program should be able to handle numbers whos binary representation is up to 10 bits, corresponding to values from 0 to 1023.

Arguments

None

public subroutine to_lower(char)

Convert a single character to lowercase

Arguments

Type IntentOptional AttributesName
character(len=1), intent(inout) :: char

public subroutine to_upper(char)

Convert a single character to uppercase

Arguments

Type IntentOptional AttributesName
character(len=1), intent(inout) :: char