Question

In: Computer Science

This is Python programming Focus 1. Classes and Objects 2. Creating objects 3. Manipulating objects This...

This is Python programming

Focus
1. Classes and Objects

2. Creating objects

3. Manipulating objects

This lab maps to learning the following objectives: Write a working program that creates a Class, Instances of Objects from that Class, and Functions that use Objects as parameters.

For this portion of the lab, you will create a new program for your Professor. Create a class named Student that holds the following data about a student:

1. Name

2. Student ID number

3. GPA

4. Expected grade in this course

5. Full time or part time

Create five student objects from this class and pass data to fill in the class data above. Besides creating the objects, you will write a menu-driven program that performs the following tasks:
1. Look up and print the student GPA

2. Add a new student to the class

3. Change the GPA of a student

4. Change the expected grade of a student

5. Print the data of all the students in a tabular format

6. Quit the program Save all the files that you create in this program with appropriate file names.

Solutions

Expert Solution

Solution:

This problem is solved using two python files

student.py:

class Student: #student class definition
name=''
studentID=0 #variables declaration
GPA=0
expected_grade=''
type_fp=''
def __init__(self,name,studentID,GPA,expected_grade,type_fp): #constructor of class
self.name=name #set all the class variables
self.studentID=studentID
self.GPA=GPA
self.expected_grade=expected_grade
self.type_fp=type_fp

def setGPA(self,GPA): #method to set gpa
self.GPA=GPA

def set_expected_grade(self,grade): #method to set grade
self.expected_grade=expected_grade

s1=Student("name1",1,8.5,'A',"full time") #create sample student class objects
s2=Student("name2",2,7.0,'B',"part time")
s3=Student("name3",3,8.9,'A',"part time")
s4=Student("name4",4,8.5,'A',"full time")
s5=Student("name5",5,6.0,'C',"full time")

student_objects=[s1,s2,s3,s4,s5] #Use list that stores all the student objects

menu.py:

from student import * #import student module
while(1):
print("1. Lookup and print student GPA") #print menu options
print("2. Add a new student to the class")
print("3. Change the GPA of a student")
print("4. Change the expected grade of a student")
print("5. Print the data of all the students in a tabular format.")
print("6.Quit")
ch=int(input("Enter choice")) #read choice
if ch==1:
sname=input("Enter name") #If ch is 1,read name
for i in student_objects:
if i.name==sname: #check names of students
print("The GPA is "+str(i.GPA)) #print GPA if name matches
break
elif ch==2: #IF ch is 2
name=input("Enter name") #read details of student
studentID=int(input("Enter ID"))
GPA=float(input("Enter GPA"))
expected_grade=input("Enter expected grade")
type_fp=input("Enter full time or part time")
student_objects.append(Student(name,studentID,GPA,expected_grade,type_fp))#add student object to list
print("Student added to the class")
elif ch==3:#If ch is 3
n=int(input("Enter student ID")) #Get student id
for i in student_objects:
if i.studentID==n: #If student id is found, update the gpa
gpa=int(input("Enter gpa")) #read gpa
i.setGPA(gpa)
elif ch==4:
n=int(input("Enter student ID")) #if ch is 4,read is from user
for i in student_objects:
if i.studentID==n:
grade=int(input("Enter grade")) #If id is found read grade
i.set_expected_grade(grade) #update the grade

elif ch==5:
for i in student_objects: #If ch is 5,print data
print("%5s \t %d \t %1.1f \t %s \t %s"%(i.name,i.studentID,i.GPA,i.expected_grade,i.type_fp))

elif ch==6: #If ch is 6,break loop
break

Screenshots:

The Screenshots are attached below for reference.

Please follow them for proper indentation.

Please create two python files with names that i mentioned above.

Make sure that the both files are present in same folder.


Related Solutions

Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects •...
Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects • Methods • Arrays of Primitive Values • Arrays of Objects • Recursion • for and if Statements • Insertion Sort 2. Use the following Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for...
This task is about classes and objects, and is solved in Python 3. We will look...
This task is about classes and objects, and is solved in Python 3. We will look at two different ways to represent a succession of monarchs, e.g. the series of Norwegian kings from Haakon VII to Harald V, and print it out like this: King Haakon VII of Norway, accession: 1905 King Olav V of Norway, accession: 1957 King Harald V of Norway, accession: 1991 >>> Make a class Monarch with three attributes: the name of the monarch, the nation...
Use JAVA BASICS  classes, aggregation and manipulating arrays of objects. I DO NOT WANT THE SAME SOLUTION...
Use JAVA BASICS  classes, aggregation and manipulating arrays of objects. I DO NOT WANT THE SAME SOLUTION WHICH ALREADY EXISTS ON CHEG. DO NO USE ARRAY LIST Scenario: A dog shelter would like a simple system to keep track of all the dogs that pass through the facility. The system must record for each dog: dogId (int) - must be unique name (string) age (double) - cannot be less than 0 or more than 25 breed (string) sex (char) – m...
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play....
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play. This will include, at least, the game board, the two types of pieces and the two sides. You will need to determine the best way to represent the relationship between them. 2) Set up one side of the board. Print the status of the board.
Explain what classes and objects are in object - oriented programming. Give an example of each...
Explain what classes and objects are in object - oriented programming. Give an example of each and explain how they work together in a computer program.
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until...
Objectives: use Scite 1. Use recursion to solve a problem 2. Create classes to model objects...
Objectives: use Scite 1. Use recursion to solve a problem 2. Create classes to model objects Problem 1: Compute greatest common divisor using recursion (filename: TestRecusiveGCD.java) The gcd(m, n) can be defined recursively as follows: If m % n is 0, gcd (m, n) is n. Otherwise, gcd(m, n) is gcd(n, m % n). Write a recursive method to find the GCD of two given integers. Write a test program that prompts the user to enter two integers, calls the...
Programming Assignment 1: Representing, Managing and Manipulating Travel Options You may NOT do any of the...
Programming Assignment 1: Representing, Managing and Manipulating Travel Options You may NOT do any of the following: change any of the function names or signatures (parameter lists and types and return type) introduce any global or static variables use any arrays or vectors inside the TravelOptions class! Not for this assignment!! (You may use them as you see fit in any driver/tester programs you write) You MAY do any of the following as you see fit: Introduce helper functions. But...
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience...
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience on the use of: 1. integers (int) 2. floats (float) 3. conditionals(if statements) 4. iteration(loops) The goal of this project is to make a fictitious comparison of the federal income. You will ask the user to input their taxable income. Use the income brackets given below to calculate the new and old income tax. For the sake of simplicity of the project we will...
Creating a Dictionary (python 3) Description Larry is an immigrant in the USA and has a...
Creating a Dictionary (python 3) Description Larry is an immigrant in the USA and has a hard time understanding English there. So he decides to make a software that will tell him the synonyms of the word that he types. He has asked you for help. Remember, you will first need to choose a data structure that you will use to store the information about the words. You can use lists or dict or tuple or anything else for this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT