Question

Use of search structures! how can i make this program in python? Learning Objectives: You should...

Use of search structures! how can i make this program in python?


Learning Objectives:

You should consider and program an example of using search structures where you will evaluate search trees against hash tables.

Given the three text files under containing the following:
- A list of students (classes Student in the distributed code)
- A list of marks obtained by the students (classes Exam results in the distributed code)
- A list of topics (classes Subject in the distributed code)

There is a program (oving7.py) that has added these files that are specified, except the code that creates data structures to insert and the code that inserts them into this structure. The three classes as representative subjects.py, students.py and exam results.py are also distributed.

This is what i need help to do!:
Your program should be able to do the following: (add and make this to the code that is already made under)
1. List students in alphabetical order by name
2. List data about a student with a given name. The name should be provided by the user of program..
3. Find a topic object based on a topic code. The course code should be given by the user of the program.

student.txt:

1. Nilsen Arne 1997 Data 1

2. Tomassen Birgit 1997 Data 1

3. Andersen Nils 1997 Elektro 1

4. Berg Hanne 1996 Elektro 1

5. Etterstad Tom 1996 Data 2

6. Hansen Brage 1995 Data 2

7. Henriksen Frank 1995 Elektro 2

8. Olsen Hilde 1995 Data 2

9. Berg Erling 1993 Data 3

10. Godalen Arne 1993 Elektro 3

11. Erlingsen Stine 1993 Data 3

12. Salheim Birger 1993 Data 3

examresults.txt:

1. ING100 C

1. MAT100 D

1. FYS100 D

2. ING100 B

3. MAT100 C

4. FYS100 C

5. MAT100 B

6. ING100 A

7. FYS100 B

8. ING100 D

9. MAT100 E

10. FYS100 D

11. ING100 B

12. FYS100 E

13. MAT100 D

14. ING100 B

15. FYS100 E

16. MAT100 D

17. ING100 D

18. FYS100 D

19. MAT100 D

20. ING100 B

21. FYS100 C

22. MAT100 D

23. ING100 A

24. FYS100 C

25. MAT100 C

26. ING100 B

27. FYS100 A

28. MAT100 B

29. ING100 B

30. FYS100 D

31. MAT100 D

32. ING100 B

33. FYS100 C

34. MAT100 D

35. DAT100 C

36. STA100 D

37. DAT100 C

38. ELE100 C

39. DAT100 D

40. DAT100 B

41. STA100 C

42. DAT100 B

43. DAT230 A

44. DAT200 C

45. ELE100 A

46. DAT100 A

47. STA100 C

48. DAT200 B

49. DAT100 D

50. STA100 E

51. DAT230 D

Subjects.txt:

DAT100 Object Oriented Programming V 10

ING100 Engineering Professional Introduction course H 10

MAT100 Mathematics 1 H 10

FYS100 Physics H 10

DAT200 Algorithms and Data Structures H 10

ELE210 Computer Architecture H 10

DAT230 Communication Technology 1 V 10

ELE100 Electrical Engineering 1 V 10

STA100 Statistics 1 V 10

oving7.py:

import student as std
import topic as topic
import exam result as ex
def find _student (student no, student list):
for student in student list:
if student.get_studentnumber () == studentnr:
return student
return None
def find_post (topic code, subject list):
for subject in subject list:
if topic.get_ topic code () == topic code:
return topic
return None
def read_examination results (student list, subject list):
exam list = []
with open ("exam results.txt") as exam_file:
for line in exam_file:
attributes = line.split ("\ t")
student = find_student (int (attributes [0] .strip ()), student list)
topic = find_pub (attributes [1] .strip (), topic list)
new_example result = ex.Example result (student, subject, attributes [2] .strip ())
exam list.append (new_example result)
return exam list
if __name__ == "__main__":
student list = std.les_studentfil ("students.txt")
topic list = topics.les_posts ("Topics.txt")
exam list = lesson_examination results (student list, subject list)

for exam result in exam list:
print (examination result)

Exam Result.py:

class Exam Result:
def __init __ (self, student, subject, character):
self .__ student = student
self .__ topic = topic
self .__ character = character

def get_student (self):
return self .__ student

def get_ topic (self):
return self .__ topic

def get_character (self):
return self .__ character

def __str __ (self):
return f "The student {self .__ student.get_name ()}, {self .__ student.get_firstname ()} has the grade {self .__ character} in the subject {self .__ topic.get_name ()}"

Subject.py:

class Subject:
def __init __ (self, subject code, subject name, semester, credits):
self .__ topic code = topic code
self .__ topic name = topic name
self .__ semester = semester
self .__ credits = credits

def get_emnecode (self):
return self .__ topic code

def get_ topic name (self):
return self .__ topic name

def get_semester (self):
return self .__ semester

def get_studypoints (self):
return yourself .__ credits

def __str __ (self):
return f "Subject {self .__ subject code} - {self .__ subject name}. Semester: {self .__ semester}. Number of credits: {self .__ credits}."


def read_ topics (topic_file):
topics = []
with open (topic_fil) as fila:
for line in file:
attributes = line.split ("\ t")
topics.append (Subject (attributes [0] .strip (), attributes [1] .strip (), attributes [2] .strip (), int (attributes [3] .strip ())))
return topics


if __name__ == "__main__":
topics = les_ topics ("topics.txt")
for topic in topics:
print (topic)

student.py:

class Student:
def __init __ (self, student number, last name, first name, year of birth, field of study, year course):
self .__ student number = student number
self .__ last name = last name
self .__ first name = first name
self .__ year of birth = year of birth
self .__ field of study = field of study
self .__ year rate = year rate

def get_studentnumber (self):
return self .__ student number

def get_ last name (self):
return self .__ last name

def get_ first name (self):
return self .__ first name

def get_ year of birth (self):
return self .__ food feeder

def get_study direction (self):
return self .__ field of study

def get_year rate (self):
return self .__ year rate

def __str __ (self):
return f "Student {self .__ student number}: {self .__ last name}, {self .__ first name}, attends {self .__ year course}. year {self .__ field of study}"


def read_student file (file_med_students):
with open (fil_med_studenter) as file:
student list = []
for line in file:
attributes = line.split ("\ t")
studentlist.append (Student (int (attributes [0] .strip ()), attributes [1], attributes [2], int (attributes [3] .strip ()),
attributes [4], int (attributes [5] .strip ())))
return student list


if __name__ == "__main__":
student list = read_student file ("students.txt")
for student in student list:
print (student)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

def sortAlphabeticalOrder(studentlist):
   return studentlist.sort(key=get_first_name) #sort has key parameter where we can pass a function which applies on the calling objcet itself according to which we can sort

2.

def findStudentByName(studentList):          #passing studentList as parameter inputing the name and searching through entire list.
   studentName = input("Enter name of the student you want to search for: ")
   for student in studentList:
       if(student.get_first_name()+" "+student.get_last_name()==studentName):
           print(student)
           return
   print("Couldn't find any student with the provided name!.")

3.

def topicObject(topicList):                   #passing topicList and inputing courseid with we we search through entire list.
   topicCode = input("Enter course Code you wanted to search for: ")
   for topic in topicList:
       if topic.__topic_code == topicCode:
           print(subject)
           return
   print("Couldn't find any topic with the course code provided!.")

#in some function name of yours there are spaces which is not acceptable. I have use _ instead of spaces here.

#Please leaving your rating. It makes me motivated. Also don't hesitate to ask any doubts in the comments section below.

Add a comment
Know the answer?
Add Answer to:
Use of search structures! how can i make this program in python? Learning Objectives: You should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How do I make my code print out the text in the ServiceNotifier class? Python Code:...

    How do I make my code print out the text in the ServiceNotifier class? Python Code: class ServiceNotifier: #Subject responsible for notifying registered observer objects    Observer = [Email, SMS, Phone]       def attach(self):    #add new observer        Observer.append(insertnewobserverhere)    def dettach(self):    #remove an observer        Observer.pop(insertnewobserverhere)    def servicenotifier(self):        for observers in Observer:            print("Due to the forecast for tomorrow, all university and campus operations will be closed.")       ...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

  • Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Ini...

    Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Initialize the object properties def __init__(self, id, name, mark): # TODO # Print the object as an string def __str__(self): return ' - {}, {}, {}'.format(self.id, self.name, self.mark) # Check if the mark of the input student is greater than the student object # The output is either True or False def is_greater_than(self, another_student): # TODO # Sort the student_list # The output is the sorted...

  • I am currently facing a problem with my python program which i have pasted below where...

    I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks! class Animal: def __init__(self, name, types, species, mass): self.name=name self.type=types...

  • I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i...

    I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks! class Animal: def __init__(self, name, types, species, mass): self.name=name self.type=types...

  • Score Analysis creating a class named "Student" in python and use matplotlib package

    class students:       count=0       def __init__(self, name):           self.name = name           self.scores = []           students.count = students.count + 1       def enterScore(self):                     for i in range(4):                 m = int(input("Enter the marks of %s in %d subject: "%(self.name, i+1)))                self.scores.append(m)             def average(self):                 avg=sum(self.scores)/len(self.scores)                           return avg               def highestScore(self):                           return max(self.scores)         def display(self):                          print (self.name, "got ", self.scores)                      print("Average score is ",average(self))                          print("Highest Score among these courses is",higestScore(self))          name = input("Enter the name of Student:")  s = students(name)  s.enterScore()  s.average()  s.highestScore()  s.display()So I need to print two things, first one is to compute the average score of these courses and second one is to print out the course name with the highest score among these courses. Moreover I need to import matplotlib.pyplot as plt to show the score figure. I barely could pull the code this...

  • In Python !!! In this exercise you will continue to work with Classes and will build...

    In Python !!! In this exercise you will continue to work with Classes and will build on the Book class in Lab 13.10; you should copy the code you created there as you will need to extend it in this exercise. You will extend the Book class to accommodate the case where there may be multiple authors for a book. The attribute author should become a list. The constructor will still take a parameter that is a string for author,...

  • PYTHON QUESTION... Building a Binary Tree with extended Binary Search Tree and AVL tree. Create a...

    PYTHON QUESTION... Building a Binary Tree with extended Binary Search Tree and AVL tree. Create a class called MyTree with the methods __init__(x), getLeft(), getRight(), getData(), insert(x) and getHeight(). Each child should itself be a MyTree object. The height of a leaf node should be zero. The insert(x) method should return the node that occupies the original node's position in the tree. Create a class called MyBST that extends MyTree. Override the method insert(x) to meet the definitions of a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT