Write four functions. The first two functions will translate the parameter passe
ID: 3645137 • Letter: W
Question
Write four functions.The first two functions will translate the parameter passed
to it into integers in the range 0-9.
- The first function will translate the letters 'A'-'J'
to the range 0-9.
- The second will translate the integer values 1-10 into
the range 0-9.
The third and fourth functions will be boolean functions
that test to see if the values passed into them are in a
specific range.
- The third function will be passed a character and will
produce true if it is in the range 'A'-'J'.
- The fourth function will be passed an integer and will
produce true if it is in the range 1-10.
Have your program read in a character and an integer.
Then print the translated results in the range of 0-9 or
print a message indicating that they are not in their
expected ranges.
Ex 1:
----
Enter a char: B
Enter an int: 12
'B' translates to 1.
12 is out of input range.
Ex 2:
----
Enter a char: Z
Enter an int: 5
'Z' is out of input range.
5 translates to 4.
Explanation / Answer
A function is similar to a subroutine (Gosub) except that it can accept parameters (inputs) from its caller. In addition, a function may optionally return a value to its caller. Consider the following simple function that accepts two numbers and returns their sum: Add(x, y) { return x + y ; "Return" expects an expression. } The nextfile statement presented in section The nextfile Statement, is a gawk-specific extension. It is not available in other implementations of awk. This section shows two versions of a nextfile function that you can use to simulate gawk's nextfile statement if you cannot use gawk. Here is a first attempt at writing a nextfile function. # nextfile -- skip remaining records in current file # this should be read in before the "main" awk program function nextfile() { _abandon_ = FILENAME; next } _abandon_ == FILENAME { next } This file should be included before the main program, because it supplies a rule that must be executed first. This rule compares the current data file's name (which is always in the FILENAME variable) to a private variable named _abandon_. If the file name matches, then the action part of the rule executes a next statement, to go on to the next record. (The use of `_' in the variable name is a convention. It is discussed more fully in section
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.