Question

In: Computer Science

Create a program that creates a sorted list from a data file. The program will prompt...

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:

  • > < == compare the group to another group, using Last name, First name, then age, and return a bool

Your program should do the following:

  • Prompt the user for the name of the file
  • Open the file
  • Read the data into the array of group objects (maximum size 20)
  • Close the file
  • Sort the array
  • Display the array

==============

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

Solutions

Expert Solution

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()


Related Solutions

c++ Create a program that creates a sorted list from a data file. The program will...
c++ 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...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user for five numbers, and write them, one at a time, on both the screen and into the file. Close the file, then open it again for reading only, and display the contents on the screen. Handle error conditions that may occur. Please Need this to be done in PERL. Thanks
In this assignment you will write a PHP program that reads from a data file, creates...
In this assignment you will write a PHP program that reads from a data file, creates an associative array, sorts the data by key and displays the information in an HTML table. Create a PHP file called hw4.php that will do the following: - Display your name. - Read text data from a file. The data file is hw3.txt. The file hw3.txt will hold the following text: PQRParrot, Quagga, Raccoon DEFDo statements, Else statements, For statements GHIGeese, Hippos, If statements...
Write a program that creates a concordance. There will be two ways to create a concordance. The first requires a document to be read from an input file, and the concordance data is written to an output file.
Concepts tested by this program            Hash Table,            Link List,hash code, buckets/chaining,exception handling, read/write files (FileChooser)A concordance lists every word that occurs in a document in alphabetical order, and for each word it gives the line number of every line in the document where the word occurs.Write a program that creates a concordance. There will be two ways to create a concordance. The first requires a document to be read from an input file, and the concordance data is written to...
Create a program that will loop and prompt to enter the highlighted data items in the...
Create a program that will loop and prompt to enter the highlighted data items in the structure below. This is every item except customerNumber , isDeleted and newLine; const int NAME_SIZE = 20; const int STREET_SIZE = 30; const int CITY_SIZE = 20; const int STATE_CODE_SIZE = 3; struct Customers { long customerNumber; char name[NAME_SIZE]; char streetAddress_1[STREET_SIZE]; char streetAddress_2[STREET_SIZE]; char city[CITY_SIZE]; char state[STATE_CODE_SIZE]; int zipCode;     char isDeleted;     char newLine; }; Always set the item isDeleted to 'N' and...
Create an ADT class that creates a friend contact list. The program should be able to...
Create an ADT class that creates a friend contact list. The program should be able to add, remove and view the contacts. In C++
Project 6-1: Email Creator C++ code Create a program that reads a file and creates a...
Project 6-1: Email Creator C++ code Create a program that reads a file and creates a series of emails. Console Email Creator ================================================================ To:      [email protected] From:    [email protected] Subject: Deals! Hi James, We've got some great deals for you. Check our website! ================================================================ To:      [email protected] From:    [email protected] Subject: Deals! Hi Josephine, We've got some great deals for you. Check our website! ================================================================ To:      [email protected] From:    [email protected] Subject: Deals! Hi Art, We've got some great deals for you. Check our website! Specifications...
(JAVA) Create a program that takes in 15 numbers in sorted order from the console and...
(JAVA) Create a program that takes in 15 numbers in sorted order from the console and stores them in a 1D array of size 15. Next, prompt the user for a number to search for in the array (target). Then, print the array. Next, search the array using a linear search – printing out each of the indices (or “indexes”) that are being examined until the algorithm either finds the target or doesn’t. Then, do the same thing for a...
(previous program) Prompt the user for the filename. Create a new file object sensehat_data_file which opens...
(previous program) Prompt the user for the filename. Create a new file object sensehat_data_file which opens the file in write mode. Write a loop which will read in 20 values for temperature and humidity from the SenseHat. Sleep 0.5 seconds between each reading taken from the SenseHat Write out the temperature and humidity to the file sensehat_data_file, separated by a comma. Close the file.) ONLY ANWSER problem below Then Open the file in read only mode. Use a loop to...
Write a Java program to read in words from the given file “word.txt”. a. Prompt the...
Write a Java program to read in words from the given file “word.txt”. a. Prompt the user for two words b. Print out how many words in the file fall between those words c. If one of the two words is not contained in the file, print out which word is not found in the file d. If both words are not found in the file, print out a message e. Sample output: Please type in two words: hello computer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT