Lab#6

Lab 6 Description

The first script will ask for three user inputs composing of the name, course code for  a class and then a a number grade. The scripting will output the name, the course code and the corresponding letter grade. The second script will take a integer entered by the user and then accumulate the numbers. All the numbers will then be added and yield a output.

Script 1 Code

lab6 script 1

Script 1 Output Testing

lab6 script 1 output

In the scripting echo is used to display a output message to user to ask for input while the read command with a variable is used to receive the input from the user. After receiving the the three inputs in order to give the appropriate letter grade for the number grade conditional statements must be used. In the following scripting the if, if else, and else conditional statements are used in order to equate the the number to the letter grade. This is done where to output the letter grade of A the if statement is written where is variable grade is less than equal to 100 and greater or equal to 93 then output the statement yielding letter grade A. The -a in the if statement is the boolean operator for the AND operator seen in other programming languages which is usually represented by &. This same formula for the following grades of A-, B+, B-, C+, C, D, and F is used with the relational operators of -le and -ge or less than equal and greater than equal to get the equated letter grade for number grade. As shown in the output the scripting code works as it should in displaying the appropriate output.

Script 2 Code

 

lab6 script 2

Script 2 Output Testing

lab6 script 2 output

In the scripting to accumulate and then sum the accumulated numbers entered by the user two variables are created where the variable number is the one used for storing user entered number where again echo is used to display a message asking for the number entry. While read number is used for reading the input entered by user and storing it there. To accumulate the numbers up to the number entered by the user a single for statement is used where the third variable i is set to start at 0 and with i=i+1 it will add up the numbers until i is less the number entered by the user. So as seen in the output if the user entered 5 the for statement will generate the numbers 0, 1, 2, 3, 4 and then 5. Once the accumulated numbers are generated using the second variable sum it will store the total by adding the generated numbers using the equation sum=sum+i where it will take the numbers which is i and add it to sum which initially starts at 0 but changes with each i added and continually add until the last i variable number is used. After that the output for sum will be displayed outside the for loop. In the above testing of the script the number first entered is 5 where the sum given is 15. Then it is tested again with the number 25.

Leave a Reply

Your email address will not be published. Required fields are marked *