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...
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(); }
From the MNIST dataset introduced in class, write code in Python that a) Splits the 42000...
From the MNIST dataset introduced in class, write code in Python that a) Splits the 42000 training images into a training set (50% of all the data) and a test set (the rest). The labels should also be split accordingly. (PLEASE ONLY SOLVE 2 & 3) 2) Basically repeat Part 1, but now use 80% of the images for training and the other 20% for testing. Report scores. [10 points] 3) Use the SVM model from part 2 to print...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT