Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

AWK Programming - Please show new working code with screenshot please. Save the

ID: 3604754 • Letter: A

Question

AWK Programming - Please show new working code with screenshot please.

Save the following data in a file named teamlist.txt:

Name,Team,First Test, Second Test, Third Test Tom,Red,5,17,22
Joe,Green,3,14,22
Maria,Blue,6,18,21

Fred,Blue,2,15,23 Carlos,Red,-1,15,24 Phuong,Green,7,19,21 Enrique,Green,3,16,20 Nancy,Red,9,12,24

Write an AWK script that will compute the average score for every person in the list, the average score for each test, and the average score for each team. If a score is negative, that means the person missed the test, and the score must not become part of the average.

Print the output to look like the following. In the list by name, the names must be left justified in a field of size 10 (hint: %-10s in printf), and the averages must be seven characters wide with two digits to the right of the decimal point (%7.2f).

Name
--------
Tom
Joe
Maria
Fred
Carlos
Phuong 15.67
Enrique 13.00
Nancy 15.00 --------------------------------- Average for Test 1: 5
Average for Test 2: 15.75 Average for Test 3: 22.125 --------------------------------- Average for Red Team: 16 Average for Green Team: 13.8889 Average for Blue Team: 14.1667

Average ------- 14.67 13.00 15.00 13.33 19.50

1

AWK Programming

The Pseudocode

Below is a pseudo-code to help you write the program.

BEGIN{

set FS to a comma

print the header

}

{
if (NR > 1) # this test skips the first line of the file {

Set individualTotal and individualCount to zero

for (field=3; field <=5; field++) {

if ($field >= 0) {

add contents of $field to individualTotal add one to individualCount

# Now update the testTotal and testCount arrays
# subtract 2 from the field number so that our arrays begin at 1 add contents of $field to testTotal indexed by (field-2)
add 1 to testCount array indexed by (field-2)

# Use contents field 2 as the index for the team array

add contents of $field to teamTotal array indexed by $2

add 1 to teamCount array indexed by $2

} }

print the person's name and his individual average

} }

END {
print "------------------" for (n=1; n<=3; n++) {

print average for test n using testTotal and testCount arrays }

print "------------------"

print average for "Red" team
print average for "Green" team
print average for "Blue" team
(these all use the teamTotal and teamCount arrays)

}

Explanation / Answer

Ans:

BEGIN{

set FS to a comma

print the header

}

{
if (NR > 1) {

int individualTotal=0;int individualCount =0;

for (field=3; field <=5; field++) {

if ($field >= 0) {

$field=Name;

individualTotal =$field;

individualCount=1;

Array testTotal=new Array[7];

Arraylist testCount=new Arraylist[7];

Array team=new Array[3]{blue,green,red};

for (field=1;field<testTotal.count-2;field++){

testTotal[field]=$field;

team[field]=testTotal[field];

}

testCount++;

} }

Array Names={Tom,Joe,Maria,Fred,Carlos,Phuong ,Enrique ,Nancy}

printf("%-10s","Names:"+Names);

} }

END {
print "------------------" for (n=1; n<=3; n++) {

print (testTotal,testCount.list;

print "------------------"

printf("%7.2f","Average for Red Team: 16");
printf("%7.2f","Average for Green Team: 13.8889");
print("%7.2f","Average for Blue Team: 14.1667");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote