The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Write a Bash script to do a binary search. Read student names and grades from a file into an array. Prompt the user for a student name. Find the name in the array and display the grade. If the student does not exist, print a message stating that.
The data in the file is below:
Ann:A
Bob:C
Cindy:B
Dean:F
Emily:A
Frank:C
Ginger:D
Hal:B
Ivy:A
Justin:F
Karen:D
Your Assignment is to write a bash script to do a binary search The details are in theassignment link here are a few hints to help you with this assignment.
To get data from the user, use the read statement like this. It will display the prompt and read the response into the variable answer.
read-p “please enter something” answer
To read data from a file named students.dat and store it into an array named students, you may use a while loop like this:
Count=0
while read students[$Count}
do
(Count ++))
done < student.dat
To separate an array element into name and grade use the following. The quote Marks you see are the grave accent character. It is just above the left tab key on the keyboard.
name= `echo ${students($loc)} | cut -d:f1`
grade= `echo ${students($loc)} |cut -d: f2`
Attachments:
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly