Midterm Exam (S2023) – Programming Concepts II (PROG1965) – 30marks (25%)
Please read over the entire exam carefully before starting!
Introduction
1. The Midterm Exam is scheduled for 2 hours in class.
a. Late submissions will not be accepted.
b. The exam duration will be extended as appropriate if you have an accommodation on
file and you have requested the right to exercise that accommodation.
c. Bundle and upload your solution to the assignment dropbox in the midterm folder as a
single zip file.
i.
You may submit multiple zip files but…
ii.
Only your latest submission will be looked at and marked.
2. Also, in the Midterm folder you will find a zip file containing a Visual Studio solution that
represents your starting point for the exam.
a. Please start by adding your name and student number to the Text property of the
Form.
3. The exam has 4 questions. Solve ALL questions in the given solution file [You can make space if
you need, but I won’t recommend it] For first 2 questions add a label and answer your question
there. Also note that question #4 is worth considerably more than the other 3 so focus your
efforts accordingly.
4. And finally, a reminder that all solutions will be run through MOSS, the programming language
plagiarism detector, and all academic integrity violations will be dealt with accordingly!
Question 1 (5 marks)
Your junior developer is having a hard time implementing properties in classes. He is not even convinced
that he should use properties. But you stand on your point that properties should be used over getter
and setter methods.
What arguments you might make to him? Discuss three advantages of your suggested arguments.
Question 2 (5 marks)
Add a label, textbox, a button, and another label to the Question 2 groupbox as follows:
Details: When use submits MIME Type button after entering a file name with extension, the label below
textbox will display the related MIME type. (The discussion on MIME Type is given below). As given in
the picture above when user entered “index.html” it displayed “text/html”.
1. Determine MIME type from filename extension:
2. Web browsers and servers exchange streams of bytes, which must be interpreted by the
receiver based on their type. For example, an HTML web page is plain text, while a JPG image is
a binary sequence.
3. The MIME type is made-up of a `type` and a `subtype` separated by a `/` character.
4. Your code must support following MIME types along with *.html → text/html [given above]:
a. *.js –> text/javascript [if user has entered “script.js” text/javascript should be
displayed]
b. * – .jpg, .jpeg –> image/jpeg [if user has entered “car.jpg” image/jpeg should be
displayed]
c. * – .gif –> image/gif [if user has entered “dog.gif” image/gif should be displayed]
d. * – .bmp –> image/bmp [if user has entered “mountain.bmp” image/bmp should be
displayed]
Question 3 (5 marks)
Identify which of the following strings/phrases are a match for the regular expression:
\s\w*z+\w*
“ablaze with fury”
“a dozen eggs”
“blind with ambition”
“inept jazz trio”
“kitchen with refrigeration”
“late-night pizza joint”
“a Regex wiz!”
“training on weather patterns”
“a C# zealot”
To record your answer, enter the matching phrase/strings in the ListBox on the Form in the Question 3
group box when user clicks on Load Matched button. For example, if you thought first, second, and
third will match (this is just a supposition – originally maybe none of them is matching) then your list
box should look like this:
Question 4 (15 marks)
Develop the form further, in the Question 4 group box, to allow users to record patient information. To
do so, the UI needs:
●
●
●
3 input textboxes to enter patient information
A button to record the new patient
A listBox to display all patients name.
To receive full marks for this question you must utilize:
●
●
●
A class to represent patients using overloaded constructors as well as properties to define the
fields.
Exception handling in that class to indicate invalid data
A single array of 10 values to store 10 patients.
This should look as follows:
More specifically, users should be able to:
●
Enter the following data about each patient to be recorded:
○ Patient’s full name:
■ In first and last name format
■ This field is required
○ Age of the patient:
■ This field is also required
■ The age cannot be negative
●
Record the patient by clicking “ADD PATIENT” button. However, the following constraints must
be met:
○ The input fields should be used to instantiate an object of the Patient class you have
defined.
○ The patients recorded should be stored in a single array – For simplicity’s sake, only
define an array of 10 patients.
○ If a patient is recorded successfully, then a message box should inform the user of that
fact.
○ If, on the other hand, there are any validation failures, then the errors, should be shown
in message box.
○ When the patient is successfully added, his/her name should be added to the listbox
collection.
Display the patients:
○ When use clicks on any specific patient’s name in the listbox, that patient’s information
is displayed in the text boxes. The following is an example: Consider three patients are
added here, Alan, Bob, and Christina.
●