Question

In: Computer Science

Write an AWK program that takes as input salary_file (Imaginary File). The salary_file consists around 150...

Write an AWK program that takes as input salary_file (Imaginary File). The

salary_file consists around 150 records, each record having three fields: name, salary per hour,

and hours worked -- fields 1, 2, and 3, respectively. Save your AWK program in a file. Name the

file according to our standard convention but with .awk extension, hence name it

As5_yourName_p2.awk. Do not forget to have comments inside of your AWK file.

Your AWK program should have all three segments: BEGIN, main (pattern/action), and END

blocks

1. In the BEGIN segment

1. print your name

2. introduce/initiate variables that you are going to use in parts 2. and 3. of this

Problem

2. In the main block/segment, print

1. only names and salaries of employees that earned more than $700.00

2. names of all employees whose names start with capital A, G or W

3. In the END segment, print

1. total number of employees

2. cumulative hours worked by all employees

3. name of the employee that earned the most

4. name of the file that AWK (this program) is processing

Solutions

Expert Solution

Program:

awk 'BEGIN {
FS=",";
print "Name: John\n" "Filename:" ARGV[1];
#initialize Variables
Earnings = 0
EmployeeCount=0; TotalAmountPaid=0; CumulativeHours=0 ;
MostHoursWorked=0; EmployeeMostHoursWorked="";
MostEarned=0; EmployeeMostEarned=""
  
}
{
EmployeeCount++
#get Calculation Earnings = HourlyPay * Hours_woeked
Earnings = 0
Earnings = ($2*$3)
#TotalAmountPaid will be the total Earning of all Employees
TotalAmountPaid+=Earnings
#CumulativeHours will be the total Working Hours of all Employees
CumulativeHours+=$3
  
#Find the MostHoursWorked Employee
if($3 > MostHoursWorked){
MostHoursWorked=$3
EmployeeMostHoursWorked=$1
}
  
#Find the MostEarned Employee
if(Earnings > MostEarned){
MostEarned=Earnings
EmployeeMostEarned=$1
}

#print EmployeeName and Earnings of an Employee when Earnings > 700
if(Earnings > 700 ){  
print $1 " " Earnings
}

#print EmployeeName of an Employee when names start with capital A, D, F, or W and whose names are at least 4 characters long
if(length($1)>=4 && (substr($1,0,1)=="A" || substr($1,0,1)=="D" || substr($1,0,1)=="W" || substr($1,0,1)=="W")){
print $1
}
}
END{
#print Results Calculated
print "Total EmployeeCount =" EmployeeCount
print "TotalAmountPaid =" TotalAmountPaid
print "CumulativeHours =" CumulativeHours
print "EmployeeMostHoursWorked =" EmployeeMostHoursWorked " MostHoursWorked = "MostHoursWorked
print "EmployeeMostEarned =" EmployeeMostEarned " MostEarned = "MostEarned
}
' salary_data_file


-------------------InpputFile(salary_data_file)------------------------
OLIVIA,24,1
RUBY,25,2
EMILY,26,3
GRACE,27,4
JESSICA,28,5
CHLOE,29,6
SOPHIE,30,7
LILY,31,8
AMELIA,32,9
EVIE,33,10
MIA,34,11
ELLA,35,12
CHARLOTTE,36,13
LUCY,37,14
MEGAN,38,15
ELLIE,39,16
ISABELLE,40,17
ISABELLA,41,18
HANNAH,42,19
KATIE,43,20
AVA,44,21
HOLLY,45,22
SUMMER,46,23
MILLIE,47,24
DAISY,48,25
PHOEBE,49,26
FREYA,50,27
ABIGAIL,51,28
POPPY,52,29
ERIN,53,30
EMMA,54,31
MOLLY,55,32
IMOGEN,56,33
AMY,57,34
JASMINE,58,35
ISLA,58,36
SCARLETT,60,37
LEAH,61,38
SOPHIA,62,39
ELIZABETH,63,40
EVA,64,41
BROOKE,65,42
MATILDA,66,43
CAITLIN,67,44
KEIRA,68,45
ALICE,69,46
LOLA,70,47
LILLY,71,48
AMBER,72,49
ISABEL,73,50
LAUREN,74,51
GEORGIA,75,52
GRACIE,76,53
ELEANOR,77,54
BETHANY,78,55
MADISON,79,56
AMELIE,80,57
ISOBEL,81,58
PAIGE,82,58
LACEY,83,60
SIENNA,84,61
LIBBY,85,62
MAISIE,86,63
ANNA,87,64
REBECCA,88,65
ROSIE,89,66
TIA,90,67
LAYLA,73,68
MAYA,74,69
NIAMH,75,70
ZARA,76,71
SARAH,77,72
LEXI,78,73
MADDISON,79,74
ALISHA,80,75
SOFIA,81,76
SKYE,82,77
NICOLE,83,78
LEXIE,84,79
FAITH,85,80
MARTHA,86,81
HARRIET,87,82
ZOE,6,83
EVE,7,84
JULIA,8,85
AIMEE,9,86
HOLLIE,10,87
LYDIA,11,88
EVELYN,12,89
ALEXANDRA,13,90
MARIA,14,91
FRANCESCA,15,92
TILLY,16,93
FLORENCE,17,94
ALICIA,18,95
ABBIE,19,96
EMILIA,20,97
COURTNEY,21,98
MARYAM,22,99
ESME,20,83

--------------------------output----------------------
Name: John
Filename:salary_data_file
AMELIA
LUCY 518
MEGAN 570
ELLIE 624
ISABELLE 680
ISABELLA 738
HANNAH 798
KATIE 860
AVA 924
HOLLY 990
SUMMER 1058
MILLIE 1128
DAISY 1200
DAISY
PHOEBE 1274
FREYA 1350
ABIGAIL 1428
ABIGAIL
POPPY 1508
ERIN 1590
EMMA 1674
MOLLY 1760
IMOGEN 1848
AMY 1938
JASMINE 2030
ISLA 2088
SCARLETT 2220
LEAH 2318
SOPHIA 2418
ELIZABETH 2520
EVA 2624
BROOKE 2730
MATILDA 2838
CAITLIN 2948
KEIRA 3060
ALICE 3174
ALICE
LOLA 3290
LILLY 3408
AMBER 3528
AMBER
ISABEL 3650
LAUREN 3774
GEORGIA 3900
GRACIE 4028
ELEANOR 4158
BETHANY 4290
MADISON 4424
AMELIE 4560
AMELIE
ISOBEL 4698
PAIGE 4756
LACEY 4980
SIENNA 5124
LIBBY 5270
MAISIE 5418
ANNA 5568
ANNA
REBECCA 5720
ROSIE 5874
TIA 6030
LAYLA 4964
MAYA 5106
NIAMH 5250
ZARA 5396
SARAH 5544
LEXI 5694
MADDISON 5846
ALISHA 6000
ALISHA
SOFIA 6156
SKYE 6314
NICOLE 6474
LEXIE 6636
FAITH 6800
MARTHA 6966
HARRIET 7134
EVE 588
JULIA 680
AIMEE 774
AIMEE
HOLLIE 870
LYDIA 968
EVELYN 1068
ALEXANDRA 1170
ALEXANDRA
MARIA 1274
FRANCESCA 1380
TILLY 1488
FLORENCE 1598
ALICIA 1710
ALICIA
ABBIE 1824
ABBIE
EMILIA 1940
COURTNEY 2058
MARYAM 2178
ESME 1660
Total EmployeeCount =101
TotalAmountPaid =268792
CumulativeHours =5032
EmployeeMostHoursWorked =MARYAM MostHoursWorked = 99
EmployeeMostEarned =HARRIET MostEarned = 7134


Related Solutions

[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
Write a program that takes two sets ’A’ and ’B’ as input read from the file...
Write a program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the file...
Write a program that takes its input from a file of number type double and outputs...
Write a program that takes its input from a file of number type double and outputs the average of the numbers in the file to the screen. The file contains nothing but numbers of the type double separated by blanks and/ or line breaks. If this is being done as a class assignment, obtain the file name from your instructor. File name: pr01hw05input.txt 78.0 87.5 98.1 101.0 4.3 17.2 78.0 14.5 29.6 10.2 14.2 60.7 78.3 89.3 29.1 102.3 54.1...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The...
Write a program that takes a date as input and outputs the date's season. The input...
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...
Modify this program so that it takes in input from a TEXT FILE and outputs the...
Modify this program so that it takes in input from a TEXT FILE and outputs the results in a seperate OUTPUT FILE. (C programming)! Program works just need to modify it to take in input from a text file and output the results in an output file. ________________________________________________________________________________________________ #include <stdio.h> #include <string.h> // Maximum string size #define MAX_SIZE 1000 int countOccurrences(char * str, char * toSearch); int main() { char str[MAX_SIZE]; char toSearch[MAX_SIZE]; char ch; int count,len,a[26]={0},p[MAX_SIZE]={0},temp; int i,j; //Take...
Computing A Raise File Salary.java contains most of a program that takes as input an employee’s...
Computing A Raise File Salary.java contains most of a program that takes as input an employee’s salary and a rating of the employee’s performance and computes the raise for the employee. This is similar to question #3 in the pre-lab, except that the performance rating here is being entered as a String—the three possible ratings are “Excellent”, “Good”, and “Poor”. As in the pre-lab, an employee who is rated excellent will receive a 6% raise, one rated good will receive...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT