In: Computer Science
Create a program that creates a sorted list from a data file. The program will prompt the user for the name of the data file.
Create a class object called group that contains a First Name, Last Name, and Age. Your main() function should declare an array of up to 20 group objects, and load each line from the input file into an object in the array.
The group class should have the following private data elements:
first name ,last name age
The group class should have the following functions:
Constructor(s)
Destructor - optional
Get - read first name, last name, and age from an input stream
Put - write last name, first name, and age to an output stream
The group class should have the following operators:
Your program should do the following:
==============
text file
Ann ember 70
jacob Mark 68
David smith 45
Frank lee 37
John doe 30
Kathleen honor 34
bob ember 42
bob ember 13
Richard start 47
Susan hox 36
Hi as there is no specific progamming language mentioned I am writing it with python.
class ReadFile:
def __init__(self):
self.path = input("Enter file name:
")
self.group = []
def readData(self):
with open(self.path, 'r') as
f:
for line in
f:
user = line.split(" ")
userObj = {
"firstName": user[0],
"lastName": user[1],
"age": user[2].replace('\n',
'')
}
# print(user)
self.group.append(userObj)
def sortData(self):
self.sortedGroup =
sorted(self.group, key=lambda k: (k['lastName'], k['lastName'],
k['age']))
def printGroup(self):
for group in
self.sortedGroup:
print(group["firstName"] + " " + group["lastName"] + " " +
group["age"])
if __name__ == "__main__":
reader = ReadFile()
reader.readData()
reader.sortData()
reader.printGroup()