Final Projects CIS121 For both projects you are to write a bash script they will be executed on the server by calling the file name. For example if you have a file named calculator, on the server it...

Need help with assignment attached below


Final Projects CIS121 For both projects you are to write a bash script they will be executed on the server by calling the file name. For example if you have a file named calculator, on the server it will run by writing ./calculator. Find the vowels project In this project you will write a script that will get the contents of a file (the file will be hard coded in the script) and counts the number of characters (spaces count as a character) the script will also count all the vowels (a, e, i, o, and u but not y). When done the script will output the total number of characters and total number of vowels, on the second line it will show the individual count for each a, e, i, o and u. The file has been provided to use with this assignment it is the only file you are to use (the file is named sampletext.txt). For example, if you have the following line of text I love Linux The output from the script will be: The total number of characters is 12 with 5 vowels. The breakdown of vowels (a,e,i,o,u) is 0 a's, 1 e's, 2 i's, 1 o's and 1 u's NOTE: I would use the above text "I love Linux" as a test file to make sure your script is working correctly What to do 1. You will need to put the contents of a file into a variable and make sure all the characters are lowercase. You can use the cat and tr commands to help do that. 2. You will need to write a loop that will go through every character in the file. We have/will covered/cover loops but for the substring part you will need the following code while (( i++ < ${#mystring} )); do char=$(expr substr "$mystring" $i 1) …more code here… done you will need to get the contents of the file into a variable named mystring. ${#mystring} is the number of characters in the mystring variable. the char is the variable what will contain each character. $mystring is the variable that contains the text. $i is the incrementor from the loop. 3. you will need to write an if, elif statement to help decide if the character being passed is a vowel and, if so,count that vowel. the if, elif statement will be in the loop. important note: when write the if or elif statement make sure have a space on after the first bracket and before the last you will get errors. see example if [ "$var" = "scott" ]; then whole number calculator in this project you are to write a script that will ask the user for a whole number, and then ask the user for another whole number and then ask the user to select an operation (a add, s subtract, d divide, m multiply). the script will check if a whole number was entered or a non-number (like a letter) (we will not check for floats or doubles like 3.2 linux doesn't do well with those). we will check that the user entered the correct letter for the operator (operator will be set to lowercase so if user enters "a" it will be changed to "a" in the script you can use the tr command for this it is in your book). a = add s = subtract m = multiply d = divide if the user does not enter a whole number for the first or second number an error message will appear. you must enter two whole numbers if the user does not enter a correct operator an error message will appear you must the correct operator a or m or d or s after an error message appears the script will stop using the exit command once the user enters all the required information correctly the script will output the answer as shown for all options. the sum of the two numbers is (answer here) the product of the two numbers is (answer here) the difference of the two numbers is (answer here) you cannot divide by zero (this will display if they attempt to divide by zero) the quotient is (part of answer here) with a whole number remainder of (answer her). because we will not be able to do decimals, we will give the whole number and the whole number remainder. for example, if the number are 5 and 3 then the output would be 1 (how many times 3 goes into five) and 2 (the whole number remainder, use modules for this). we do not have to worry about if the numbers are reversed 3 and 5. what to do write the echo and read statements that get the required input from the user check that the numbers are a number (remember we are not checking for decimals). exit script if not correct check that they selected the correct operator (make sure to convert to lower case). exit script if not correct if all information is correct, then do calculation and output answer. you can use if/elif statements to determine the operator entered and call the appropriate function. you must write functions that: check the number check the operator do each calculation so a function to add, subtract, multiply and divide. hint: i used grep and regular expressions to do the error checking. important note: when write the if or elif statement make sure have a space on after the first bracket and before the last you will get errors. see example if [ "$var" = "scott" ]; then find the vowels project what to do whole number calculator what to do ${#mystring}="" ));="" do="" char="$(expr" substr="" "$mystring"="" $i="" 1)="" …more="" code="" here…="" done="" you="" will="" need="" to="" get="" the="" contents="" of="" the="" file="" into="" a="" variable="" named="" mystring.="" ${#mystring}="" is="" the="" number="" of="" characters="" in="" the="" mystring="" variable.="" the="" char="" is="" the="" variable="" what="" will="" contain="" each="" character.="" $mystring="" is="" the="" variable="" that="" contains="" the="" text.="" $i="" is="" the="" incrementor="" from="" the="" loop.="" 3.="" you="" will="" need="" to="" write="" an="" if,="" elif="" statement="" to="" help="" decide="" if="" the="" character="" being="" passed="" is="" a="" vowel="" and,="" if="" so,count="" that="" vowel.="" the="" if,="" elif="" statement="" will="" be="" in="" the="" loop.="" important="" note:="" when="" write="" the="" if="" or="" elif="" statement="" make="" sure="" have="" a="" space="" on="" after="" the="" first="" bracket="" and="" before="" the="" last="" you="" will="" get="" errors.="" see="" example="" if="" [="" "$var"="scott" ];="" then="" whole="" number="" calculator="" in="" this="" project="" you="" are="" to="" write="" a="" script="" that="" will="" ask="" the="" user="" for="" a="" whole="" number,="" and="" then="" ask="" the="" user="" for="" another="" whole="" number="" and="" then="" ask="" the="" user="" to="" select="" an="" operation="" (a="" add,="" s="" subtract,="" d="" divide,="" m="" multiply).="" the="" script="" will="" check="" if="" a="" whole="" number="" was="" entered="" or="" a="" non-number="" (like="" a="" letter)="" (we="" will="" not="" check="" for="" floats="" or="" doubles="" like="" 3.2="" linux="" doesn't="" do="" well="" with="" those).="" we="" will="" check="" that="" the="" user="" entered="" the="" correct="" letter="" for="" the="" operator="" (operator="" will="" be="" set="" to="" lowercase="" so="" if="" user="" enters="" "a"="" it="" will="" be="" changed="" to="" "a"="" in="" the="" script="" you="" can="" use="" the="" tr="" command="" for="" this="" it="" is="" in="" your="" book).="" a="add" s="subtract" m="multiply" d="divide" if="" the="" user="" does="" not="" enter="" a="" whole="" number="" for="" the="" first="" or="" second="" number="" an="" error="" message="" will="" appear.="" you="" must="" enter="" two="" whole="" numbers="" if="" the="" user="" does="" not="" enter="" a="" correct="" operator="" an="" error="" message="" will="" appear="" you="" must="" the="" correct="" operator="" a="" or="" m="" or="" d="" or="" s="" after="" an="" error="" message="" appears="" the="" script="" will="" stop="" using="" the="" exit="" command="" once="" the="" user="" enters="" all="" the="" required="" information="" correctly="" the="" script="" will="" output="" the="" answer="" as="" shown="" for="" all="" options.="" the="" sum="" of="" the="" two="" numbers="" is="" (answer="" here)="" the="" product="" of="" the="" two="" numbers="" is="" (answer="" here)="" the="" difference="" of="" the="" two="" numbers="" is="" (answer="" here)="" you="" cannot="" divide="" by="" zero="" (this="" will="" display="" if="" they="" attempt="" to="" divide="" by="" zero)="" the="" quotient="" is="" (part="" of="" answer="" here)="" with="" a="" whole="" number="" remainder="" of="" (answer="" her).="" because="" we="" will="" not="" be="" able="" to="" do="" decimals,="" we="" will="" give="" the="" whole="" number="" and="" the="" whole="" number="" remainder.="" for="" example,="" if="" the="" number="" are="" 5="" and="" 3="" then="" the="" output="" would="" be="" 1="" (how="" many="" times="" 3="" goes="" into="" five)="" and="" 2="" (the="" whole="" number="" remainder,="" use="" modules="" for="" this).="" we="" do="" not="" have="" to="" worry="" about="" if="" the="" numbers="" are="" reversed="" 3="" and="" 5.="" what="" to="" do="" write="" the="" echo="" and="" read="" statements="" that="" get="" the="" required="" input="" from="" the="" user="" check="" that="" the="" numbers="" are="" a="" number="" (remember="" we="" are="" not="" checking="" for="" decimals).="" exit="" script="" if="" not="" correct="" check="" that="" they="" selected="" the="" correct="" operator="" (make="" sure="" to="" convert="" to="" lower="" case).="" exit="" script="" if="" not="" correct="" if="" all="" information="" is="" correct,="" then="" do="" calculation="" and="" output="" answer.="" you="" can="" use="" if/elif="" statements="" to="" determine="" the="" operator="" entered="" and="" call="" the="" appropriate="" function.="" you="" must="" write="" functions="" that:="" check="" the="" number="" check="" the="" operator="" do="" each="" calculation="" so="" a="" function="" to="" add,="" subtract,="" multiply="" and="" divide.="" hint:="" i="" used="" grep="" and="" regular="" expressions="" to="" do="" the="" error="" checking.="" important="" note:="" when="" write="" the="" if="" or="" elif="" statement="" make="" sure="" have="" a="" space="" on="" after="" the="" first="" bracket="" and="" before="" the="" last="" you="" will="" get="" errors.="" see="" example="" if="" [="" "$var"="scott" ];="" then="" find="" the="" vowels="" project="" what="" to="" do="" whole="" number="" calculator="" what="" to="">
Apr 28, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here