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

Hello im learning lua and i got this problem where i have to read this file 4a.

ID: 3590703 • Letter: H

Question

Hello im learning lua and i got this problem where i have to read this file

4a. Reading in the file

Read the file into an array of tables, then sort the table by Area of Research

Sort the table alphabetically by the area of research the award was given for. Print the results in some neat form.

The output should look something like this, for example:

4b. Sort the table by Institution of Winner,

Sort the table alphabetically by the institution of the winner. Print the results in some neat form.

The output should look something like this:

The file looks like this.

1966 Alan Perlis Yale University Compilers 1967 Maurice Wilkes University of Cambridge Hardware 1968 Richard Hamming Bell Telephone Laboratories Coding Systems 1969 Marvin Minsky MIT AI 1970 James Wilkinson National Physical Laboratory Numerical Analysis 1971 John McCarthy MIT AI 1972 Edsger Dijkstra Eindhoven University of Technology Programming Languages 1973 Charles Bachman General Electric Databases 1974 Donald Knuth Stanford University Algorithms 1975 Allen Newell Carnegie-Mellon University AI 1975 Herbert Simon Carnegie-Mellon University AI 1976 Michael Rabin Hebrew University Automata Theory 1976 Dana Scott University of Oxford Automata Theory 1977 John Backus IBM Programming Languages 1978 Robert Floyd Stanford University Programming Languages 1979 Kenneth Iverson IBM Programming Languages 1980 Charles Hoare University of Oxford Programming Languages 1981 Edgar Codd IBM Databases 1982 Stephen Cook University of Toronto Algorithms

Explanation / Answer

Suppose our file is a text file.

data = {}

local file1 = io.open("InputFile.txt", "r")
for line in file1 :lines() do
   data [#data + 1]= line:match("^(%d+)+(%a+)%s+(%a+)%s+(%a+)%s$")
end

-- you can use table.insert also for inserting data into a table then sort. Below is the example here only 2 columns are shown

-- for sorting on subject

-- for sorting on institution

-- This part is for just printing the output data
for i = 1, #data do
year = data [i][1] -- Get year from array for checking further
name = data [i][2] -- Get Name from array for checking further
print(data [i][1].." ".. data[i][2].." ".. data[i][3] .." ".. data[i][4]);
end

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