Question

In: Computer Science

2. Create two class, a student class, and a course class, take advantage of the codes...

2. Create two class, a student class, and a course class, take advantage of the codes provided in the class slides and sample codes. python

Student

Course

__Username:str

__Courses:list

__courseName:str

__students: list

addCourse():None

dropCourse():None

getCourse():list

addStudent:None

dropStudent:None

getStudents():list

getNumber of students:int

3. Create a student object for every student in the UD.txt (you can use a loop for this)

4. Create 6 course objects:

1. CS131

2. CS132

3. EE210

4. EE310

5. Math320

6. Math220

5. After the student user login to their account as we have done in lab 2. Display the following:

A: Show all courses available

B: Add a course

C: Drop a course

D: Show all my courses

E: Exit

When students choose option A, should display the following, where # is the actual number of students enrolled in the class.

1. CS131                                         students number:#

2. CS132                                         students number:#

3. EE210                                         students number:#

4. EE310                                         students number:#

5. Math 320                                   students number:#

6. Math 220                                   students number:#

Let the students add or drop a classes as they wish. When they choose E, exit the program.

6. For option D, show the courses in the student’s course list.

7. The hard part. Since your program will end when user chose option E. You need to keep track the classes been added and dropped by each students, and who are actually in the classes. Therefore, based on your experiences in lab 3 and 4, create a SI.txt (student info) to store the courses in each student’s course list. Create CI.txt (course info) to store all the students enrolled in each course. This will be executed in the background every time when the user chose option E: Exit. When you run your program, and create your course objects, this information needs to be read into each student and course object. When a student log into his or her account, the student should be able to see what courses is in the course list by chose option D. The number of students in each course also need to be displayed in Option A.

Student info

UD.txt

USERNAME,PASSWORD
sdd233,Pad231
dcf987, BHYW4fw
dgr803,Sb83d2d
mkr212,UNNHS322
lki065,dgw6234
ped332,9891ds
ytr876,dsid21kk
nmh223,3282jd3d2

Solutions

Expert Solution

thanks for the question, here is the fully implemented code in python. All functions are commented so that you can understand what each function does. Let me know in case you have any doubts or questions.

======================================================================================

# student class starts here
class Student():
    def __init__(self,user_name=''):
        self.__username=user_name
        self.__courses=[]
    def addCourse(self,course):
        self.__courses.append(course)
    def dropCourse(self,course_name):
        for course in self.__courses:
            if course.getCourseName()==course_name:
                self.__courses.remove(course)
                print('Course successfully deleted')
                return
    def
getCourse(self):return self.__courses
    def getUserID(self):return self.__username

# Course class starts here
class Course():
    def __init__(self,course_name=''):
        self.__coursename=course_name
        self.__students=[]
    def addStudent(self,student):
        self.__students.append(student)
    def dropStudent(self,id):
        for student in self.__students:
            if student.getUserID()==id:
               self.__students.remove(student)
                print('Student successfully deleted')
                return
    def
getStudents(self):return self.__students
    def getNumberOfStudents(self):return len(self.__students)
    def getCourseName(self):return self.__coursename

# read from the UD.txt file all the ids and password and returns as a dictionary
def readStudentIDPwdFromFile(filename):
    user_id_dict={}
    with open(filename,'r') as infile:
        for line in infile.readlines():
            line = line.strip().split(',')
            user_id_dict[line[0].strip()]=line[1].strip()
    return user_id_dict

# function which ask user to enter id and password and returns True if id password matches
# else it returns false if the id dont exist or the password dont match

def login(student_id_password):
    id=input('Enter user id to login: ')
    password = input('Enter password: ')
    if student_id_password.get(id) is None:return False
    return
student_id_password.get(id)==password
# display menu and ask user to enter a choice adn returns the choice back to main function
def display_menu():
    print('A: Show all courses available')
    print('B: Add a course')
    print('C: Drop a course')
    print('D: Show all my courses')
    print('E: Exit')
    choice=input('Enter choice: ')
    return choice

# displays all the courses the student is enrolled to
def displayAllCourses(courses):
    for i in range(len(courses)):
        print('{0}. {1} students number: {2}'.format(i+1,courses[i].getCourseName(),courses[i].getNumberOfStudents()))

# function to add a course to the student object courses list
def addCourse(student_Id, students, courses):
    course_name= input('Enter course name: ')
    for student in students:
        if student.getUserID()==student_Id:
            for course in courses:
                if course.getCourseName()==course_name:
                    student.addCourse(course)
                    print('Course successfully added')
                    return
           
print('Course not available.')
            return

# function to remove a course from the student courses list
def dropCourse(student_Id, students, courses):
    course_name= input('Enter course name: ')
    for student in students:
        if student.getUserID()==student_Id:
            for course in courses:
                if course.getCourseName()==course_name:
                    student.dropCourse(course_name)
                    return
           
print('Course not available.')
            return

# show all the courses for the students
def showAllCourses(student_Id, students):
    for student in students:
        if student.getUserID()==student_Id:
            courses = student.getCourse()
            for course in courses:
                print('Course Enrolled to: {}'.format(course.getCourseName()))

# driver function
def main():
    # reads the UD.txt file
   
student_id_password=readStudentIDPwdFromFile('D:\\UD.txt')
    # contains all the student objects in a list
   
students=[]
    for student_Id in student_id_password.keys():
        students.append(Student(student_Id))
    # contain all the courses object as a list
   
courses=[]
    courses.append(Course('CS131'))
    courses.append(Course('CS132'))
    courses.append(Course('EE210'))
    courses.append(Course('EE310'))
    courses.append(Course('Math320'))
    courses.append(Course('Math220'))
    if login(student_id_password) is not True:
        print('Invalid login id/password entered. Program will terminate now.')
        return
    while True
:
        choice=display_menu().upper()
        if choice=='A': displayAllCourses(courses)
        elif choice=='B':addCourse(student_Id,students,courses)
        elif choice=='C':dropCourse(student_Id,students,courses)
        elif choice=='D':showAllCourses(student_Id,students)
        elif choice=='E':
            print('Thanks for using the program')
            break



main()


Related Solutions

Language C++ Student-Report Card Generator: create a class called student and class called course. student class...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class this class should contain the following private data types: - name (string) - id number (string) - email (s) - phone number (string) - number of courses (int) - a dynamic array of course objects. the user will specify how many courses are there in the array. the following are public members of the student class: - default constructor (in this constructor, prompt the...
***Given a class called Student and a class called Course that contains an ArrayList of Student....
***Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called dropStudent() as described below. Refer to Student.java below to learn what methods are available.*** Course.java import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{ /** collection of Students */ private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/ public Course(){ roster = new ArrayList<Student>(); } /***************************************************** Remove student with the...
1: Create a class Circle 2: Create two instances of the Circle class 1: Based on...
1: Create a class Circle 2: Create two instances of the Circle class 1: Based on Program 13-1 (see attachment Pr13-1.cpp) in the textbook, create a class name “Circle” with the following declarations (hint: you can use PI=3.14): //Circle class declaration class Circle { private: double radius; public: void setRadius(double); double getRadius() const; double getArea() const; double getPerimeter() const; }; 2: Based on Program 13-2 (see attachment Pr13-2.cpp) in the textbook, create two instances of the Circle class, pizza1 and...
In order to access this course, attend this class as an on-line student, and participate in...
In order to access this course, attend this class as an on-line student, and participate in class discussions, you need to use a specific course management system. Answer the following questions about this system. 1. What is the name of the course management system? 2. Who created this system? 3. Other than your instructor, name three ways to get technical help with this product. 4. Other than class discussions, talk about one function of this product. Define its purpose and...
Create a class called Student which stores • the name of the student • the grade...
Create a class called Student which stores • the name of the student • the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into the grade field. • Calculate the...
In this assignment you are going to create a Student class to demonstrate a Student object....
In this assignment you are going to create a Student class to demonstrate a Student object. Then create a StudentTest class to place the main method in, which demonstrates the Student object. Student class should have the following instance variables: firstName, middleName, lastName (String) id (int) grade (int) Student class should have the following methods: Set and Get methods for each variable Constructor that sets all variables using Set methods that you defined. Design the application in main that you...
Create two child classes, UnderGraduateStudent and GraduateStudent that will extend from the Student class. Override the...
Create two child classes, UnderGraduateStudent and GraduateStudent that will extend from the Student class. Override the char getLetterGrade() method in each of the child classes. Use Student.java class defined below: (complete and compile) class Student {    private int id;    private int midtermExam;    private int finalExam;    public double calcAvg() {       double avg;       avg = (midtermExam + finalExam) / 2.0;       return avg;    }    public char getLetterGrade() {       char letterGrade = ‘ ‘;...
/* The following function receives the class marks for all student in a course and compute...
/* The following function receives the class marks for all student in a course and compute standard deviation. Standard deviation is the average of the sum of square of difference of a mark and the average of the marks. For example for marks={25, 16, 22}, then average=(25+16+22)/3=21. Then standard deviation = ((25-21)^2 + (16-21)^2+(22-21)^2)/3. Implement the function bellow as described above. Then write a test console app to use the function for computing the standard deviation of a list of...
In C++ Create a class that simulates a school calendar for a course and has a...
In C++ Create a class that simulates a school calendar for a course and has a warner that provides the school administration with the option of warning students when the last day is that a student is permitted to drop the course. (Allow administrators to warn or not, as they wish. Do not make this a required function.) You will assume in this calendar that there are 12 months in a year, 4 weeks in a month, and 7 days...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class (CIN int PRIMARY KEY, FirstName varchar(255), LastName varchar(255), Gender varchar(1), EyeColor varchar(50), HairColor varchar(50), HeightInches int,CurrentGrade varchar(1));CREATE TABLE Student (SSN int PRIMARY KEY,FirstName varchar(255),LastName varchar(255), Age int,BirthMonth varchar(255),HeightInches int,Address varchar(255),City varchar(255),PhoneNumber varchar(12),Email varchar(255),FavColor varchar(255),FavNumber int);INSERT INTO Class VALUES(1, "David", "San", "M", "BRN", "BLK", 72, "-");INSERT INTO Class VALUES(2, "Jeff", "Gonzales", "M", "BRN", "BLK", 68, "B");INSERT INTO Class VALUES(3, "Anna", "Grayson", "F", "BRN", "BRN", 62,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT