Question
lab software
using
cygwin
part1
1 of 1 1. Write a shell program name it lab4q1.sh to compare the two strings: a. Read the first string. b. Read the second

part2
Write a shell program lab3.sh that will take 5 times input number from the user. After each input taken, you need to calculat
1 of 1 1. Write a shell program name it "lab4q1.sh" to compare the two strings: a. Read the first string. b. Read the second string. c. If the strings are empty print "String Empty" and exit using the statement exit 1. d. Compare the two strings using the if and print longer string. e. If the size of both strings is same, then print that two strings are equal (use printf), otherwise, print two strings are not equal (use printf), and exit with exit 0.
Write a shell program lab3.sh that will take 5 times input number from the user. After each input taken, you need to calculate sum and the average of the inputs number and display them. If the user enters -1, you need to quit the program. Ex: After 5 Numbers entered: Enter a number: 10 Total: 10 Average: 10 Enter a number: 15 Total: 25 Average: 12 Enter a number: 20 Total: 45 Average: 15 Enter a number: 25 Total: 70 Average: 17 Enter a number: 30 Total: 100 Average: 20 After -1 is ente red: Enter a number: 10 Total: 10 Average: 10 Enter a number: 20 Total: 30 Average: 15 Enter a number: 30 Total: 60 Average: 20 number: -1 Enter a Bye!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part 1 Answer:

read string_1 #reading first of string

read string_2 #reading second string

if [ -z "$string_1" ] && [ -z "$string_2" ] #checking whether strings are empty or not

then

printf "String Empty\n"

exit 1 # exiting with 1 if stringa s are empty

fi

if [ ${#string_1} -ge ${#string_2} ] #checking the equality of string

then

if [ ${#string_1} -eq ${#string_2} ] # checking two string are equal or not

then

printf "Two Strings are equal\n"

exit 0

fi

printf $string_1

printf "\nStrings are not equal"

exit 0

else

printf $string_2

printf "\nStrings are not equal"

exit 0

fi

Part 2 Answer:

total=0 # variable for total value

average=0 # variable for average value

for (( num=1; num<=5;num++ )); # for loop

do

printf "Enter a number: "

read number

if [ $number == -1 ] # checking the user input

then

printf "Bye !\n"

exit 0

fi

(( total += number )) # calculation the total value

(( average = total/num ))

printf "Total: %d\n" $total

printf "Average: %d\n\n" $average

done

Add a comment
Know the answer?
Add Answer to:
lab software using cygwin part1 part2 1 of 1 1. Write a shell program name it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that uses String method regionMatches to compare two strings input by the user....

    Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...

  • Document2 Tell me Layout References Mailings Review View 1. Write a program named Lab17B that will...

    Document2 Tell me Layout References Mailings Review View 1. Write a program named Lab17B that will read 2 strings and compare them. a. Create a bool function named compareLetters that will accept 2 string variables as parameters and will return true if the strings have the same first letters and the same last letters. It will return a false otherwise. b. Create a bool function named inside that will accept the 2 string variables in the order they were entered)...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • C++ Write A Program: //Please DONT use stdio.h or fancy things like classes Given the following...

    C++ Write A Program: //Please DONT use stdio.h or fancy things like classes Given the following header: vector<string> split(string target, string delimiter); implement the function split so that it returns a vector of the strings in target that are separated by the string delimiter. For example: split("10,20,30", ",") should return a vector with the strings "10", "20", and "30". Similarly, split("do re mi fa so la ti do", " ") should return a vector with the strings "do", "re", "mi",...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Please note that I cannot use the string library function and that it must be coded...

    Please note that I cannot use the string library function and that it must be coded in C89, thank you! Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text in the first problem from “Please enter a string of maximum 30 characters:” to “Enter string: ”. Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade. 2.Comments: Header comments...

  • Overview Writing in the C language, implement a very basic shell, called smash. In this project,...

    Overview Writing in the C language, implement a very basic shell, called smash. In this project, we will work on processing strings and using the appropriate system calls. Build System setup Before we can start writing code we need to get our build system all setup. This will involve writing a very simple makefile. You should leverage your Makefile project for this part of the assignment! Write a Makefile that provides the three targets listed below all - The default...

  • C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings...

    C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings to double values. Calculate the sum,difference,and product of these values and print them. int main(){    // character string value array for user    char stringValue[10];       double sum=0.0;// initialize sum to store the results from 2 double values       double difference=0.0; // initialize difference to store the results from 2 double values       double product = 0.0; // intitialzie product...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT