跳至主要內容

article management system

AI悦创原创大约 12 分钟...约 3709 字

Introduction

Hi, we need to implement an article management system in Python. The system should be able to store articles submitted by students, assist the teacher in grading the articles, and manage the grades.
Fortunately, you don't need to design it from scratch. The TA has provided the framework for this system, and you can implement some functions based on this framework to complete the system.

You can also modify the code we have provided or design it from scratch.

Features

Log In

10 marks

Firstly, this system requires user login. The system will verify if the user has entered the correct password. If the password is correct, the user can proceed with subsequent operations; if the password is incorrect, the system will exit immediately. The default username is "admin", and its password is "ZDHH". The system also allows adding users, enabling users with different names to log in during subsequent logins.

After logging in, users can select the desired service by entering a number as choice. If the choice is invalid, the system ask the user to try again.

Example:

D:\OneDrive - The Hong Kong Polytechnic University\COMP1012_materials\2023_project_solution>python main.py
Enter your user id: admin
Enter your password: ZDHH
Login successful

Welcome to the article management system! Type in the number of the action you want to perform:
1. Help
2. Add user
3. Exit
4. Add a submission from student
5. Grade a student's submission
6. List all submissions
7. List all submissions have not been graded
8. Display the average score
9. Display the student who has the highest score
10. Display the students whose score is less than a threshold
11. Send emails to students notifying them of their grades (Optional)
12. Store the grade to a json file
13. Load the grade from a json file
14. Delete a submission and its grade

Enter your choice: 

Guidance for users

10 marks

If the user inputs 1, the system will display the following guidance for users.

Example:

Enter your choice: 1
Type in the number of the action you want to perform:
1. Help
2. Add user
3. Exit
4. Add a submission from student
5. Grade a student's submission
6. List all submissions
7. List all submissions have not been graded
8. Display the average score
9. Display the student who has the highest score
10. Display the students whose score is less than a threshold
11. Send emails to students notifying them of their grades (Optional)
12. Store the grade to a json file
13. Load the grade from a json file
14. Delete a submission and its grade

Enter your choice: 

Add a user

10 marks

If the user inputs 2, the user can add a new user by specifying a new username and setting the corresponding password. Then the user can log in the system by the new name.

Hint: You can store the username and password in a file so that even after exiting the system, the username and password will be preserved. Upon the next login, the system can read this file and determine whether the user is allowed to log in.

Example:

Add a new user and then log out.

Enter your choice: 2
Enter the new user id: Samy
Enter the new password: YXN
Enter your choice: 3

Log in by the new name

D:\OneDrive - The Hong Kong Polytechnic University\COMP1012_materials\2023_project_solution>python main.py
Enter your user id: Samy
Enter your password: YXN
Login successful

Welcome to the article management system! Type in the number of the action you want to perform:
1. Help
2. Add user
3. Exit
4. Add a submission from student
5. Grade a student's submission
6. List all submissions
7. List all submissions have not been graded
8. Display the average score
9. Display the student who has the highest score
10. Display the students whose score is less than a threshold
11. Send emails to students notifying them of their grades (Optional)
12. Store the grade to a json file
13. Load the grade from a json file
14. Delete a submission and its grade

Enter your choice: 

Exit

If the user inputs 3, the user can exit the system. We have implemented this feature, and you can learn how to call functions defined in another file by exploring the implementation of this feature.

You can also modify our implementation to support the other features.

# In main.py
import util  # We import the file whose name is util.py
'''
    ....
    ....
    ....
'''
        elif user_choice == "3":
            util.exit()  # We call the function `exit` defined in the util.py.

Add submission

10 marks

If the user inputs 4, the user can store a file submitted from the student. Specifically, the user input three attributes, including student id, assignment id, and the submission file path.

Then, the system copy the submission file to the folder './data', and rename the file as '{student id}_{assignment id}.txt'. For example, if the student id is '10000000d', assignment id is 'Quiz1', the new file's name is 10000000d_Quiz1.txt and it can be found at './data/10000000d_Quiz1.txt'. If the specified submission file path does not exist, the system should prompt the user and let the user type in the choice again. We assume that there are no underscores (_) in either the student ID or the assignment ID.

Example:

Add six files

Enter your choice: 4
Enter the student id: 0001
Enter the assignment id: A1
Enter the submission path: ../submission_samples/file1.txt
Enter your choice: 4
Enter the student id: 0001
Enter the assignment id: A2
Enter the submission path: ../submission_samples/file2.txt
Enter your choice: 4
Enter the student id: 0002
Enter the assignment id: A2
Enter the submission path: ../submission_samples/file3.txt
Enter your choice: 4
Enter the student id: 0003
Enter the assignment id: A1
Enter the submission path: ../submission_samples/file4.txt
Enter your choice: 4
Enter the student id: 0003
Enter the assignment id: A2
Enter the submission path: ../submission_samples/file5.txt
Enter your choice: 4
Enter the student id: 0004
Enter the assignment id: A1
Enter the submission path: ../submission_samples/file6.txt
Enter your choice:

Six files are copied and renamed

# file1.txt
The content in File1.txt

# file2.txt
The content in File2.txt

# file3.txt
The content in File3.txt

# file4.txt
The content in File4.txt

# file5.txt
The content in File5.txt

# file6.txt
The content in File6.txt

# 0001_A1.txt
The content in file1.txt

# 0001_A2.txt
The content in file2.txt

# 0002_A2.txt
The content in file3.txt

# 0003_A1.txt
The content in file4.txt

# 0003_A2.txt
The content in file5.txt

# 0004_A1.txt
The content in file6.txt

When specify a non existing file

Enter your choice: 4
Enter the student id: 123
Enter the assignment id: A1
Enter the submission path: ./some/not/exist/file
The submission does not exist
Enter your choice: 

Grade a submission

10 marks

If the user inputs 5, the user can grade a submission. Specifically, the user input two attributes, including student id and assignment id. The system will print the content of a file at path './data/{student id}_{assignment id}.txt' and receives a score from the user. The system should store the grade for following process. If the specified submission does not exist, the system should prompt the user and let the user type in the choice again. We assume the grade is always an integer.

Example:

Grade existing submissions

Enter your choice: 5
Enter the student id: 0001
Enter the assignment id: A1
The content of the submission is:
The content in file1.txt
Enter the score: 90
Enter your choice: 0001
Invalid choice; Exiting...
Enter your choice: 5
Enter the student id: 0001
Enter the assignment id: A2
The content of the submission is:
The content in file2.txt
Enter the score: 80
Enter your choice: 5
Enter the student id: 0002
Enter the assignment id: A2
The content of the submission is:
The content in file3.txt
Enter the score: 10
Enter your choice: 5
Enter the student id: 0003
Enter the assignment id: A1
The content of the submission is:
The content in file4.txt
Enter the score: 25
Enter your choice: 5
Enter the student id: 0003
Enter the assignment id: A2
The content of the submission is:
The content in file5.txt
Enter the score: 50
Enter your choice: 5
Enter the student id: 0004
Enter the assignment id: A1
The content of the submission is:
The content in file6.txt
Enter the score: 70

The input specifies a non existing submission.

Enter your choice: 5
Enter the student id: odednd
Enter the assignment id: cdsc
The submission does not exist
Enter your choice: 

List all submissions

10 marks

If the user inputs 6, the system will show all the submissions. Each submission is described in a line, which includes the student ID, assignment ID, and the grade. If the submission has not been graded, the grade is represented as '/'.

Example:

All submissions are not graded

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: /
Assignment ID: A1, Student ID: 0003, Score: /
Assignment ID: A1, Student ID: 0004, Score: /
Assignment ID: A2, Student ID: 0001, Score: /
Assignment ID: A2, Student ID: 0002, Score: /
Assignment ID: A2, Student ID: 0003, Score: /

All submissions are graded

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50

List all submissions have not been graded

If the user inputs 7, the system will show all the submissions which have not been graded. Each submission is described in a line, which includes the student ID, assignment ID. Furthermore, submissions for the same assignment should be displayed consecutively.

Display the average score

10 marks
If the user inputs 8, the system will calculate and display the average score of graded submissions. The system determines which submissions' average score to calculate based on the user's input. If the user inputs 'ALL', the system calculate the average score of all submissions. Otherwise, If the user inputs the id of an submission, the system will calculate the average score of submissions for the assignment. If there is no graded submissions, the average score is 0. If the input is not a valid assignment id or ALL (e.g., for an assignment id, if all submission files in ./data do not have the corresponding assignment id, we treat the assignment id as an invalid assignment id), the system should exit. We assume the assignment id will not be ALL.

Example:

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Enter your choice: 8
Enter the assignment id: ALL
The average score is: 54.166666666666664
Enter your choice: 8
Enter the assignment id: A1
The average score is: 61.666666666666664
Enter your choice: 8
Enter the assignment id: uyy
Invalid assignment id

Display the student who has the highest score

10 marks

If the user inputs 9, the system needs to output the ID of student who achieved the highest score in each assignment. If all the submissions for a assignment are not graded, the corresponding student ID is '/'.

Example:

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Enter your choice: 9
Assignment ID: A1, Student ID: 0001
Assignment ID: A2, Student ID: 0001

Another example

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Assignment ID: A3, Student ID: 0005, Score: /
Enter your choice: 9
Assignment ID: A1, Student ID: 0001
Assignment ID: A2, Student ID: 0001
Assignment ID: A3, Student ID: /

Display the student whose score is less than a threshold

10 marks
If the user inputs 10, the system should output the IDs of students whose scores are below a specified threshold. Users are required to input two attributes: the assignment ID and the score threshold. Subsequently, the system will print the IDs and grades of students whose scores for the specified assignment fall below the given threshold. Submissions that have not been graded will not be considered, and their grades will not be treated as falling below the threshold. If the assignment id is invalid, the system will prompt the user and let the user type in the choice again.

Example:

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Assignment ID: A3, Student ID: 0005, Score: /
Enter your choice: 10
Enter the assignment id: A1
Enter the threshold: 50
Assignment ID: A1, Student ID: 0003, Score: 25
Enter your choice: 10
Enter the assignment id: A2
Enter the threshold: 50
Assignment ID: A2, Student ID: 0002, Score: 10
Enter your choice: A3
Invalid choice; Try again...
Enter your choice: 10
Enter the assignment id: A4
Enter the threshold: 10
Invalid assignment id
Enter your choice: 

Send emails to students notifying them of their grades (Optional)

If the user inputs 11, the system can send an email to each student to notify them of their grades. You can attempt to implement this interesting feature as it can be beneficial. However, it is a bit challenging and will require you to search the web for guidance on how to implement it. This feature is optional, and we will not assess its implementation.

Store the grade to a JSON file

10 marks
If the user inputs 12, the system can store the grade to a JSON file. The system requires the user to input the path of the JSON file which storing the grade data. You can use the function save_json in the util.py to implemented this function. Furthermore, you can also make the system automatically save grades every time it exits. This is a practical feature in real-world systems. However, we will not deduct marks if you do not implement the "automatically save grades on exit" feature.

Example:

The system has stored the following data and then store them to a JSON file.

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Enter your choice: 12
Enter the json path: grade.json

The content of the JSON file

// filename:grade.json
{
  "A1": {
    "0001": 90,
    "0003": 25,
    "0004": 70
  },
  "A2": {
    "0001": 80,
    "0002": 10,
    "0003": 50
  }
}

Retrieve grade from a JSON file

10 marks

If the user inputs 13, the system can retrieve grades from a JSON file. The user needs to provide the path to the JSON file that stores the grade data. The system will then extract the grades from the specified JSON file and incorporate them into the system. You can use the read_json function in the util.py file to implement this functionality.

Example:

Given a JSON file with content

// filename:grade.json
{
  "A1": {
    "0001": 90,
    "0003": 25,
    "0004": 70
  },
  "A2": {
    "0001": 80,
    "0002": 10,
    "0003": 50
  }
}

and then retrieve data from it.

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: /
Assignment ID: A1, Student ID: 0003, Score: /
Assignment ID: A1, Student ID: 0004, Score: /
Assignment ID: A2, Student ID: 0001, Score: /
Assignment ID: A2, Student ID: 0002, Score: /
Assignment ID: A2, Student ID: 0003, Score: /
Enter your choice: 13
Enter the json path: grade.json
Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50

Delete a submission and its grade

10 marks

If the user enter 14, the system will delete a specified submission. Specifically, the user input two attributes, including student id, assignment id. Then, the system will delete the file '{student id}_{assignment id}.txt' under the folder './data' and delete the corresponding grade.

Example:

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Assignment ID: A3, Student ID: 0005, Score: /
Enter your choice: 14
Enter the student id: 0005
Enter the assignment id: A3
The submission has been deleted
Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50

Another example

Enter your choice: 6
Assignment ID: A1, Student ID: 0001, Score: 90
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Enter your choice: 14
Enter the student id: 0001
Enter the assignment id: A1
The submission has been deleted
Enter your choice: 6
Assignment ID: A1, Student ID: 0003, Score: 25
Assignment ID: A1, Student ID: 0004, Score: 70
Assignment ID: A2, Student ID: 0001, Score: 80
Assignment ID: A2, Student ID: 0002, Score: 10
Assignment ID: A2, Student ID: 0003, Score: 50
Enter your choice: 9
Assignment ID: A1, Student ID: 0004
Assignment ID: A2, Student ID: 0001
Enter your choice: 

Tips

  1. You can use third-party libraries to meet your requirements. For example, you can use the Path(p).exists() function from the pathlib library to check if the path p exists.

  2. You can also use third-party libraries to get the file names under a specific folder.

  3. We assume that only this system has access to the data folder, and the files within the data folder will only be modified by this system and cannot be altered by users in any other way.

  4. We assume that there are no underscores (_) in either the student ID or the assignment ID.

  5. We assume the assignment id will not be ALL.

[10 marks] Please name the operators in the following expressions. If the expression is valid, please provide the value (include decimal point where necessary) and if the expression is invalid, please explain why.

ExpressionOperator NamesValue or Validity
5 * 2 + 1 / 2.0
(int) 2.3 + 6.7
2.6 % 1.5
(char) (66 - (-1))
(int) Math.E + 1.14
  1. [6 marks] Write as Java expressions:
    a) x+y3+7z\frac{x+y}{3} + 7z

b) xy+42(xy)\frac{\frac{x}{y} + 4}{2(x - y)}

c) 43πr3\frac{4}{3} \pi r^3

  1. [10 marks] Use the symbols +, -, *, /, %, (, and ) as often as you wish, together with the numerals 2, 1, 7, and 4, each used once, in the given order, to create Java expressions whose values are 0, 1, ..., 10.

As an example, to obtain the value zero, we could write:
-2 - 1 + 7 - 4 -> -3 + 3 -> 0

ValueEquivalent Expression
1
2
3
4
5
6
7
8
9
10
  1. [4 marks] Evaluate:
ExpressionValue / Range of Values
((3*Math.random()) + 4)
Math.ceil(Math.cos(0.1))
Math.round(3.14/0.1)*0.1
Math.abs(-Math.min(-3, 10))
  1. [8 marks] Suppose the following declarations/initializations have occurred:

int i = 3, k = 5, n = 2;

Using the values above, write the value of each variable after the following statements have been executed (assume each question exists in isolation).

a. i = ++k + n++;
i = ___, k = ____, n =____

b. i = (int) 'k'- n--;
i = ___, k = ___, n = ___

c. k = --i * k % ++n + '4';
i = ____, k = ____, n = ______

d. i += n = (k++ + 4) % ++k;
i = ____, k = ____, n = ______

e. n += i = k = ++i + 5 + n++;
i = ____, k = ____, n = ______
  1. [4 marks] To switch the values contained in the variables x and y (already declared/initialized), a programmer wrote the following segment:
x = y;
y = x;

a) If, before execution of the segment, x contained the value 6 and y contained the value 10, what value would each have after the segment was performed?
b) Rewrite the segment so that it performs the intended task correctly.

  1. [7 marks] For each valid fragment, state what it does. If a fragment contains an error, explain the nature of the error and rewrite the fragment with the error corrected.

a)

char a = 'F';
a = a - 5;

b)

int g = 'f';
++g;
g -= 'k';

c)

char e = 's' + 5;
e++;
int ee = e;

d)

int e = 's' + 5;
e++;
char ee = e;

e)

char d = 'R';
--d;
char dd = d-- - 'M';
上次编辑于:
贡献者: AndersonHJB
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度