Question

In: Computer Science

Code in python: Write a class that implements a struct. In your struct store Student information...

Code in python:

  1. Write a class that implements a struct. In your struct store Student information such as name, netid, and gpa. Write a function that can access a student in a list of 5 structs by netid and print their name and gpa. Show that your function works by calling it.

Solutions

Expert Solution

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:


Related Solutions

a) Write C code using a struct to hold student information: integer id integer number of...
a) Write C code using a struct to hold student information: integer id integer number of hours taken integer number of hours passed double gpa b) create a variable of the type in #25 and initialize it with some data.
Please do this code with python. Thank you! struct Node {     int data;     struct...
Please do this code with python. Thank you! struct Node {     int data;     struct Node* left;     struct Node* right; }; // Node creation struct Node* newNode(int data) {     struct Node* nn         = new Node;     nn->data = data;     nn->left = NULL;     nn->right = NULL;     return nn; } // Function to insert data in BST struct Node* insert(struct Node* root, int data) {   if (root == NULL)         return newNode(data);     else {...
Write a java code for LinkedStack implementation and the code is: public final class LinkedStack<T> implements...
Write a java code for LinkedStack implementation and the code is: public final class LinkedStack<T> implements StackInterface<T> {    private Node topNode; // References the first node in the chain       public LinkedStack()    {        topNode = null;    } // end default constructor       public void push(T newEntry)    { topNode = new Node(newEntry, topNode); //       Node newNode = new Node(newEntry, topNode); //       topNode = newNode;    } // end push    public...
Please write a python code which implements the counting sort algorithm by creating a CountingSort function...
Please write a python code which implements the counting sort algorithm by creating a CountingSort function with an array input in the form of a list. Then write code to sort 3 randomly generated arrays and the data array listed below, print the output clearly for all four test arrays, develop and comment on the growth function of your code. Comment on the Big O notation of the code. ( Please do not forget to comment on your code to...
CODE must using C++ language. Write the definition of the class dayTye that implements the day...
CODE must using C++ language. Write the definition of the class dayTye that implements the day of the week in a program. The class dayType should store the day of the week as integer. The program should perform the following operations on an object of type dayType 1. set the day 2. display the day as a string - Sunday, ... Saturday 3. return the day as an integer 4. return the next as an integer 5. return the previous...
Write a Python program that creates a class which represents a Student Grade. The class includes...
Write a Python program that creates a class which represents a Student Grade. The class includes a function that reads a text file called Course_Score.txt. A sample of the file is provided below. Each row in the file corresponds to the Last Name, First Name, ClassWork score (100), Mid-Term score (100), and Final-Exam score (100). Also include the the following functions to process the content read from the file. a. getData(): This method reads the data from a file and...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Write a python source code for a Unit class corresponding to the UML model of a...
Write a python source code for a Unit class corresponding to the UML model of a Unit shown. The description method should return a string value corresponding to the attributes of a Movie. Unit -code: String -name: String -credit points: int + __init__ (self, code, name, credit_points) + description (): String
How do you write the constructor for the three private fields? public class Student implements Named...
How do you write the constructor for the three private fields? public class Student implements Named { private Person asPerson; private String major; private String universityName; @Override public String name() { return asPerson.name(); }
Create a class that will store all the information needed for a song. Your class will...
Create a class that will store all the information needed for a song. Your class will store the following data: A string for the song title. A string for the Artist/Band title A string for the Album/Compilation Name A string for the Genre A boolean called liked that represents whether you like the song The class will have the following methods: A constructor that will make a Song object from a song title, artist and album name A constructor that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT