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...
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...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
Author code /** * LinkedList class implements a doubly-linked list. */ public class MyLinkedList<AnyType> implements Iterable<AnyType>...
Author code /** * LinkedList class implements a doubly-linked list. */ public class MyLinkedList<AnyType> implements Iterable<AnyType> { /** * Construct an empty LinkedList. */ public MyLinkedList( ) { doClear( ); } private void clear( ) { doClear( ); } /** * Change the size of this collection to zero. */ public void doClear( ) { beginMarker = new Node<>( null, null, null ); endMarker = new Node<>( null, beginMarker, null ); beginMarker.next = endMarker; theSize = 0; modCount++; } /**...
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(); }
Write a code to implement a python queue class using a linked list. use these operations...
Write a code to implement a python queue class using a linked list. use these operations isEmpty • enqueue. • dequeue    • size Time and compare the performances of the operations ( this is optional but I would appreciate it)
#python #code #AP class #Tech write a function code script which will print out number pyramid...
#python #code #AP class #Tech write a function code script which will print out number pyramid in the form of * so the output will be made up of **** resting on top of each other to form a pyramid shape. Bottom layer should be made of 5 multiplication signs like ***** then next 4 multiplication signs and so on. Top part should have only one *
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT