mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.1 KiB
109 lines
3.1 KiB
2 years ago
|
## grades
|
||
|
|
||
|
### Instructions
|
||
|
|
||
|
Create a script `grades.sh` which will ask the user for a specific number of students in order to evaluate them. After the number is set, the script will ask you to introduce the "names" and "grades" of the persons you wish to evaluate.
|
||
|
|
||
|
The grades will have a range between 0 and 100 and will be numeric values only.
|
||
|
|
||
|
According to each student grade you will have to return the following:
|
||
|
|
||
|
- If the student grade is anything lower than 50 you will return the string "<name>: You had a poor performance!":
|
||
|
|
||
|
```console
|
||
|
$ ./grades.sh 1
|
||
|
Student Name #1: Sara
|
||
|
Student Grade #1: 34
|
||
|
Sara: You had a poor performance!
|
||
|
```
|
||
|
|
||
|
- If the student grade is anything equal or greater than 50 you will return the string "<name>: You need a bit more effort!":
|
||
|
|
||
|
```console
|
||
|
$ ./grades.sh 1
|
||
|
Student Name #1: Sara
|
||
|
Student Grade #1: 51
|
||
|
Sara: You need a bit more effort!
|
||
|
```
|
||
|
|
||
|
- If the student grade is anything equal or greater than 70 you will return the string "<name>: You did a good job!":
|
||
|
|
||
|
```console
|
||
|
$ ./grades.sh 1
|
||
|
Student Name #1: Sara
|
||
|
Student Grade #1: 75
|
||
|
Sara: You did a good job!
|
||
|
```
|
||
|
|
||
|
- If the student grade is anything equal or greater than 90 you will return the string "<name>: You did an excellent job!":
|
||
|
|
||
|
```console
|
||
|
$ ./grades.sh 1
|
||
|
Student Name #1: Sara
|
||
|
Student Grade #1: 90
|
||
|
Sara: You did an excellent job!
|
||
|
```
|
||
|
|
||
|
### Error handling
|
||
|
|
||
|
All errors will print a specific message on **stderr** (ending with a newline) and returns a specific non-zero value:
|
||
|
|
||
|
- Wrong number of arguments: `"Error: expect 2 arguments"`, exit with `1`.
|
||
|
|
||
|
- If the student grade is not a number or is greater than 100: `Error: The grade "grade" is not a valid input. Only numerical grades between 0 and 100 are accepted.`, exit with `1`.
|
||
|
|
||
|
```console
|
||
|
$ ./grades.sh 3
|
||
|
./grades.sh 2
|
||
|
Student Name #1: Sara
|
||
|
Student Grade #1: 101
|
||
|
Error: The grade '101' is not a valid input. Only numerical grades between 0 and 100 are accepted.
|
||
|
$
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
|
|
||
|
```console
|
||
|
$ ./grades.sh 4
|
||
|
Student Name #1: Sara # introduced by the user
|
||
|
Student Grade #1: 34 # introduced by the user
|
||
|
Student Name #2: Norman
|
||
|
Student Grade #2: 56
|
||
|
Student Name #3: James
|
||
|
Student Grade #3: 78
|
||
|
Student Name #4: Albert
|
||
|
Student Grade #4: 90
|
||
|
Sara: You had a poor performance!
|
||
|
Norman: You need a bit more effort!
|
||
|
James: You did a good job!
|
||
|
Albert: You did an excellent job!
|
||
|
```
|
||
|
|
||
|
### Hints
|
||
|
|
||
|
In bash, you can use the `read` command to read input from the user and store it in a variable like so:
|
||
|
|
||
|
`read var_name`
|
||
|
|
||
|
You can also use the "-p" option to specify a prompt that will be displayed to the user before reading the input.
|
||
|
|
||
|
Use loops to go through each student. For example the for loop is very helpful.
|
||
|
|
||
|
```console
|
||
|
for element in sequence
|
||
|
do
|
||
|
# commands to be executed
|
||
|
done
|
||
|
```
|
||
|
|
||
|
You can use an array to store multiple pieces of data. To create an array, you can use the `declare` command with the "-a" option:
|
||
|
|
||
|
`declare -a name_array`
|
||
|
|
||
|
To add elements to the array, you can use the += operator:
|
||
|
|
||
|
`name_array+=("Adding this to the array")`
|
||
|
|
||
|
> You have to use Man or Google to know more about commands flags, in order to solve this exercise!
|
||
|
> Google and Man will be your friends!
|