In: Computer Science
Code in python:
FIle: main.py
class student(object): # creating class
def __init__ (self,name,netid,gpa): # creating constructor
self.name=name
self.netid=netid
self.gpa=gpa
def display_data (self): # display method
print("name: "+self.name)
print("netid: "+self.netid)
print("gpa: "+self.gpa)
def search_student(nid,arr): # method to search
students
for i in arr:
if (i.netid==nid):
i.display_data()
flag=1 # setting flag to 1
break
else :
flag=0
if flag==0:
print("information not found") # printing error
message
arr=[]
nstd=int(input("Enter the number of student: ")) # accept input
using for loop
for i in range (nstd):
name=input("Enter the name: ")
nid=input("Please enter the id: ")
gpa=input("Please enter the gpa: ")
arr.append(student(name,nid,gpa))
fid=input("Enter netid of student to search: ")
search_student(fid,arr) # calling method to search
Screen: