0% found this document useful (0 votes)
5 views

Assignment 4

The assignment requires students to develop a GUI-based application in Visual Basic to manage staff records, including functionalities for adding, displaying, modifying, and saving records. Students must implement error handling for various scenarios, such as invalid input and file operations. The project must be submitted as a zipped file by the deadline, with specific guidelines for file naming and submission procedures.

Uploaded by

tsefukho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Assignment 4

The assignment requires students to develop a GUI-based application in Visual Basic to manage staff records, including functionalities for adding, displaying, modifying, and saving records. Students must implement error handling for various scenarios, such as invalid input and file operations. The project must be submitted as a zipped file by the deadline, with specific guidelines for file naming and submission procedures.

Uploaded by

tsefukho
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CSCI1580 Visual Programming

Assignment 4
Deadline: 4-Dec-2022 (Sun) 23:59

Objectives
This assignment allows you to practice using classes, objects, lists, strings, and file I/O.

Task
In this assignment, your task is to use Visual Basic to develop a GUI-based application to maintain some
staff records. Each staff record consists of the following elements:

(1) ID: a unique non-empty string with no commas


(2) Staff name: a non-empty string with no commas
(3) Position: a non-empty string with no commas
(4) Salary: a positive integer

After creating a Windows Form Application in Visual Studio, it initially contains a file named Form1.vb,
please rename it to be StaffRecordSystem.vb. After that, please create a new class file named
StaffRecord.vb, which contains the definition of the StaffRecord class as follows:

' Each object created from this class represents a staff record
Public Class StaffRecord
' four private instance variables
Private id_ As String
Private name_ As String
Private position_ As String
Private salary_ As Integer

' TODO: four read-only properties: ID, Name, Position, Salary


' TODO: one constructor with four parameters to set all the instance variables
' TODO: one instance method: IncreaseSalary
End Class

After that, in StaffRecordSystem.vb, you can use the StaffRecord class to create StaffRecord objects,
where each object represents a staff record. In addition, you are required to use a List to store all the
StaffRecord objects. In the beginning of the program, there is no staff record in the system.

1
Your program has to provide the following features:

1. Add a staff record by specifying the ID, the name, the position, and the salary.
 After the record is added, display a successful message.
 But for the following cases, display an appropriate error message and no record will be
added:
i. The ID, the name, or the position is an empty string.
ii. The ID, the name, or the position contains commas.
iii. The salary cannot be converted to an integer.
iv. The salary is a non-positive number.
v. A staff record with the same ID already exists.

2. Display all staff records.


 If there is no staff record, display an appropriate error message.

3. Display a staff record with a specific ID.


 If the specified staff record cannot be found, display an appropriate error message.

4. Display all staff records with a specific position.


 It is possible to display more than one record.
 If the specified staff record(s) cannot be found, display an appropriate error message.

5. Remove a staff record with a specific ID.


 After the staff record is found and removed, display a successful message.
 But if the staff record cannot be found, display an appropriate error message.

6. Clear all staff records.


 Display a successful message afterwards.

7. Increase the salary of a staff by specifying the ID and the increase rate (in %), which is a number
with or without decimal places. The new salary will be rounded the nearest integer (rounding up
or to the nearest even). For example, if the original salary is $25,580 and the increase rate is 3.1%,
the new salary will be $26,373.
 After the salary in the record is updated, display a successful message with the new salary.
 But for the following cases, display an appropriate error message and the record will not
be updated:
i. The staff record cannot be found.
ii. The increase rate cannot be converted to a Decimal (e.g., contains characters).
iii. The increase rate is not a positive number.

2
8. Compute the total sum of the salaries of all the staff records in the system.
 If there is no staff record, the result will be $0.

9. Save all records to a specified file.


 In the output file, each line stores a staff record. The fields in the record are separated
by commas, where the four fields are: ID, name, position, and salary. An example is
shown as follows:

M001,Alice Ho,Manager,35000
S102,Bob Chan,Sales,18500
S250,Chloe Chu,Sales,21000

 If the file can be saved successfully, display a message to indicate the number of records
saved.
 If the file cannot be saved, display an appropriate error message.
 Your program should not crash when there is any IO exception.

10. Load all records from a specific file.


 The format of the input file is the same as that of the output file.
 For simplicity, you can assume that the format and the contents of the file must be
complete and valid.
o E.g., no missing fields, no empty strings, no commas in ID/name/position, no
duplicate ID, no non-positive numbers for salary, etc.
 If the file exists, all the records in the system will be cleared first before loading records
from the file. After that, display a message to indicate the number of staff records loaded.
 If the file cannot be found or cannot be opened, display an appropriate error message.
The existing records in the system will not be modified in this case.
 Your program should not crash when there is any IO exception.

Note that in StaffRecordSystem.vb, if you want to define a constructor (this is optional, depending on the
class design), you will need to call InitializeComponent() as follows:

' The constructor for StaffRecordSystem


Public Sub New()
' This call is required by the form designer.
InitializeComponent()

' You can put other code here ...

End Sub

3
Saving the Project Files
Please use “Save All” to save all the project files in one location but avoid using “Save <file_name>.vb As”
to save some of the files in other locations. Otherwise, we may not be able to open your submission
successfully.

Assessment Scheme
 Correctness 80%
 Class Design 10%
 Readability (E.g., comments (required), meaningful identifiers, clear user interface) 10%

Testing Platform
Microsoft Visual Studio Community 2022, Windows 10

Declaration
As required by the University, please place the following declaration as the comment in the beginning of
your VB source code.

' CSCI1580 Visual Programming


'
' Assignment <assignment_number>
'
' I declare that the assignment here submitted is original except for source
' material explicitly acknowledged. I also acknowledge that I am aware of
' University policy and regulations on honesty in academic work, and of the
' disciplinary guidelines and procedures applicable to breaches of such policy
' and regulations, as contained in the following University website:
' http://www.cuhk.edu.hk/policy/academichonesty/.
'
' Student Name: <your_name>
' Student ID: <your_student_ID>
' Date: <date>

Submission
Please follow the following steps to submit your work.

Step 1: Zip your Visual Basic project folder into a zip file Assg4_<your_student_id>.zip, where
<your_student_id> should be replaced by your student ID (e.g. Assg4_1234567890.zip).

You can find your project folder at

C:\Users\<user_name>\source\repos

Step 2: Go to BlackBoard and login your account by using your CWEM password.

Step 3: Go to the page for CSCI1580, choose Assignments => Assignment 4

4
Step 4: Upload your zip file prepared in Step 1.

Resubmissions are allowed. But only the latest one will be counted. 10% of your marks will be deducted
for late submission each day after the deadline. Late submissions more than three days will not be graded.

You might also like