linux shell scripring help please Procedure Write the following script using you
ID: 3680117 • Letter: L
Question
linux shell scripring help please
Procedure
Write the following script using your Linux virtual machine. You must use vim as the editor.
The first line of your script file should force the use of the bash shell as the command interpreter. Your script file should be properly commented, including your lab section number, your name, and your student ID etc. Note that marks will be deducted for scripts without proper comments.
In this lab, you will create a script called Grades that will calculate and then display letter grade of LinuxTest. Use only integers for grade calculations.
1. Get user inputs of the following grades:
Assignments 40%
Test1 15%
Test2 15%
Final exam 30%
Note: To avoid decimal places in calculations, you may prompt the user to input an integer percentage number for each of the items listed above. You don't have to handle invalid input.
2. Calculate the number grade by adding up the four grades input by user
3. Convert the number grade to letter grade using the table below:
(Hint: use “Multilevel if-then-else” or case statement)
Number Grade Letter Grade
90 - 100 A+
85 - 89 A
80 - 84 A-
77 - 79 B+
73 - 76 B
70 - 72 B-
67 - 69 C+
63 - 66 C
60 - 62 C-
57 - 59 D+
53 - 56 D
50 - 52 D-
0 - 49 F
The screenshot below demonstrates the execution of this script file.
user1@localhost:~$./grades
Enter assignment mark (0 to 40): 25
Enter Test1 mark (0 to 15): 8
Enter Test2 mark (1 to 15): 10
Enter Final Exam mark (1 to 30): 24
Your final grade is C+
user1@localhost:~$
Explanation / Answer
This below Shell Script will read the four subjects marks and sum the all the values together and based on the final value grade will be decided..
See the below shell script for display the final grade of given total marks..
echo "Enter assignment mark (0 to 40):"
read sub1
echo "Enter Test1 mark (0 to 15):"
read sub2
echo "Enter Test2 mark (0 to 15):"
read sub3
echo "Enter Final Exam Mark(1 to 30):"
read final
sum1=`expr $sub1 + $sub2 + $sub3 + $final`
echo "Sum of 4 subjects are: " $sum1
if [ $sum1 -lt 100 -a $sum1 -ge 90 ]
then
echo "A+"
elif[ $sum1 -lt 89 -a $sum1 -ge 85 ]
then
echo "A+"
elif[ $sum1 -lt 84 -a $sum1 -ge 80 ]
then
echo "A-"
elif[ $sum1 -lt 79 -a $sum1 -ge 77 ]
then
echo "B+"
elif[ $sum1 -lt 72 -a $sum1 -ge 70]
then
echo "B"
elif[ $sum1 -lt 69 -a $sum1 -ge 67 ]
then
echo "C+"
elif[ $sum1 -lt 66 -a $sum1 -ge 63 ]
then
echo "C"
elif[ $sum1 -lt 62 -a $sum1 -ge 60]
then
echo "C-"
elif[ $sum1 -lt 59 -a $sum1 -ge 57]
then
echo "D+"
elif[ $sum1 -lt 56 -a $sum1 -ge 53 ]
then
echo "D"
elif[ $sum1 -lt 52 -a $sum1 -ge 50 ]
then
echo "D-"
elif[ $sum1 -lt 49 -a $sum1 -ge 0]
then
echo "F"
fi
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.