Betygsättarskriptet klart
This commit is contained in:
parent
de2606200a
commit
1a389039f8
35
Labb5/form.txt
Normal file
35
Labb5/form.txt
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
Points Question
|
||||||
|
------ --------
|
||||||
|
1 Question 1
|
||||||
|
2 Question 2
|
||||||
|
1 Question 3
|
||||||
|
1 Question 4
|
||||||
|
0 Question 5
|
||||||
|
1 Question 6
|
||||||
|
0 Question 7
|
||||||
|
1 Question 8
|
||||||
|
1 Question 9
|
||||||
|
2 Question 10
|
||||||
|
1 Question 11
|
||||||
|
1 Question 12
|
||||||
|
5 Question 13
|
||||||
|
1 Question 14
|
||||||
|
1 Question 15
|
||||||
|
2 Question 16
|
||||||
|
1 Question 17
|
||||||
|
1 Question 18
|
||||||
|
1 Question 19
|
||||||
|
4 Question 21
|
||||||
|
1 Question 22
|
||||||
|
1 Question 23
|
||||||
|
1 Question 24
|
||||||
|
0 Question 25
|
||||||
|
1 Question 26
|
||||||
|
1 Question 27
|
||||||
|
1 Question 28
|
||||||
|
4 Question 29
|
||||||
|
4 Question 30
|
||||||
|
1 Question 31
|
||||||
|
4 Question 32
|
||||||
|
1 Question 34
|
||||||
|
1 Question 35
|
57
Labb5/ovning4.sh
Executable file
57
Labb5/ovning4.sh
Executable file
@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Jack-Benny Persson
|
||||||
|
# LX13
|
||||||
|
# Övning 4, labb 5
|
||||||
|
# Grade-calculation script
|
||||||
|
|
||||||
|
# Set some variables
|
||||||
|
G=30
|
||||||
|
VG=48
|
||||||
|
Form=form.txt
|
||||||
|
|
||||||
|
# Check if the file exist and that we can read it
|
||||||
|
if [ ! -r $Form ]; then
|
||||||
|
echo "Can't read $Form" > /dev/stderr
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get all the points
|
||||||
|
Points=( `tail -n +3 $Form | awk '{print $1}'` )
|
||||||
|
|
||||||
|
# Check that we only have int's in our array and print help
|
||||||
|
for l in ${Points[*]}; do
|
||||||
|
if ! [ "$l" -eq "$l" &> /dev/null ]; then
|
||||||
|
cat <<- EOF
|
||||||
|
Something is wrong with the formatting of $Form
|
||||||
|
Correct formatting should look like this:
|
||||||
|
|
||||||
|
Points Question
|
||||||
|
------ --------
|
||||||
|
1 Question 1
|
||||||
|
1 Question 2
|
||||||
|
4 Question 4
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Calculate the points from the form
|
||||||
|
Total=0
|
||||||
|
for i in ${Points[*]}; do
|
||||||
|
Total=$((Total+i))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Print the total points and grade
|
||||||
|
echo "Your total points on the test was: $Total"
|
||||||
|
|
||||||
|
if [ $Total -lt $G ]; then
|
||||||
|
echo "Your grade is: IG"
|
||||||
|
elif [ $Total -ge $VG ]; then
|
||||||
|
echo "Your grade is: VG"
|
||||||
|
else
|
||||||
|
echo "Your grade is G"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
Loading…
x
Reference in New Issue
Block a user