COMP282 – Advanced Object -Oriented C Languages Coursework 2 – C#
Weighting: 50% Feedback: General feedback will be released shortly after the last possible time you can hand -in (see above). Personal feedback will be released around the same time , depen ding on how close to the last possible time to hand in you did hand in .
Compress your Visual Studio project into a single zip file and submit it via CodeGrade – CodeGrade is only used to make grading easier, but it will be done by hand . In particular, you will not get feedback when su bmitting . Penalties for late work will be applied in accordance with the Code of Practice on Assessment. You can submit multiple times. If you submit more than once, we will only look at and mark the most recent , and late penalties will be based on your f inal submission.
Project Overview: You will create a small Windows GUI application to draw lines and find their intersections . The project consists of several tasks, which you should tackle in order (except for the hard tasks at the end where any subset can be done, and the order is not important). Each non-hard task builds on the previous one. Do as much as you can and then submit your project. Read through this entire document before you start coding, so you are aware of all the tasks and the overall structure of the program. In particular, if you are aiming for all tasks, look especially at the last one, because otherwise you w ill likely need to redo quite a bit . Your solution should demo nstrate your knowledge of C# and GUI development with Visual Studio. Note: Much of the code will be generated for you by Visual Studio. We’ll mark the code you write. User Interface & User Experience Design Your application should look something like the screenshots shown on the next page . It doesn’t have to be identical, but it should have equivalent controls and buttons . The solution is shown working and discussed in the accompanying video. Please watch this to get a good idea of how your application should behave. Runtime errors gives down to -20% If your program makes multiple distinct obvious runtime errors, you lose 20% ( down to at least 40 %) – meaning it keeps crashing even if you do not try t o find errors . If your program makes some subtle runtime errors, you lose 5-10% (again, down to at least 40%) – depending on how subtle .
Solution without the last task Solution with the last task
Part 1 (Worth 15%) Task 1 – Line Class Definition (5%) Create a Line class that stores two points and a line colo ur. Implement a constructor that takes appropriate parameters and stores them in the object. Also , implement the appropriate C# property getters and setters (incl. appropriate access modifiers) . Finally, override the ToString() method for the class so that it outputs information about the two points (we will output the line colo ur in some other way ). 5%: Created Line class Task 2 – Form Layout (1 0%) Use the Visual Studio layout designer to create a form similar to one of the ones shown above . At this stage , the application should be runnable. Also, set up the design so that it is nice to work with, incl. tab order and names of elements. When it’s run, the form window should be displayed without any build errors, although it will not do anything apart from terminate correc tly when the user closes the window. 10%: Made a nice layout Part 2 (Worth 65%) Task 3 – Adding Lines (5%+5 %=10% ) Use a relevant C# container class to store Line objects. Implement the code that runs when the user clicks the Add button. Your code should ret rieve the text entered into the First X, First Y, Second X and Second Y boxes and convert them into a Line object (with so me reasonable de fault colour) . You should also update the GUI so the added lines appear in the large picture box area as well as the list view box (or similar) . Use the format shown above on the previous page (or similar). If something is not entered correctly, make a suit able error message . 5%: Implemented Add button 5%: … with su itable error messages Task 4 – Drawing lines (10%) Every time you click twice in the picture box, a line should be drawn between the two points defined (it is easier and seems more s ensible to do it on MouseUp, but you can also do it on click) . This task is about impleme nting that func tiona lity. You should add the created Line object to the picture box and the list view box (or similar) . 10%: Can draw lines Task 5 – Changing colo ur (5%) You should implement the Color butt on. It should show a ColorDia log and t hen, if the user selects OK, change the default colo ur (i.e. the col our used in future lines ) to the chosen colo ur. It should also set the Fore color of the Color button to be the ch osen colo ur. 5%: Implemented Color button Task 6 – Removing lines (5%+5%=10% ) Your code should find out which item in the list is currently selected (represented by the blue background) and remove it , when the Remove button is clicked . Also, set the selected index in the list to be an adjacent line. Make sure you remove the item from the list as well as the p icture box . Be sure to check the index of the removed item to prevent runtime out -of-bounds errors and display suitable error message s if there are problem s. 5%: Implemented Remove button 5%: … reasonable error messages and the index updates in a sensible manner afterwards Task 7 – Updating Lines (5%+5%=10% ) When the u ser clicks on an item in the visible list (or uses the keyboard to move up and down the list), the text boxes should be updated to reflect the current selection and the Forecolor of the Color button should be set to the colour of the selected line . Implement the code that runs when the user clicks the Update button. Your code should update the current ly selected line with whatever is currently in the text boxes. You should update both the list as well as the picture box. Again, make sure you do not get runti me out -of-bounds errors and make suitable error message s if there are problem s. 5%: Implemented Update button (with error messages) 5%: Chang e fields to be the content of the selected row on click Task 8 – Find intersections (10% +10%=20%) Add the code that runs when the user clicks the Find Inters ections button . You should calculate the intersections between each line and show a circle around every point intersection and a line if the lines overlap in a line , in both cases using the de fault col our. There is a nice a lgorithm by Samo s and Huey for this , running in time O(n log n + k), if there are n lines and k intersections , but you are just expected to use the naïve O(n2) solution where you try all possible pairs of lines (partly because Visual Stu dio 2019 does not have priority que ues – the new version does) . If you can not remember how to find the intersection of two lines, you can look at: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection Note though that it just solves the case where they meet in a point and you will nee d to do something else if you want to find the line overlaps . You get 10% if you get it to wo rk reasonably well (i.e. what you would do if you only looked at that Wikipedia page) with the l ast 10% if you actually get it fully working . 10%: Implemented Find Intersections button with basic behaviour 10%: Find Intersections works fully correctly Part 4 (Worth 10%+10 %=20%) – Make the list a data grid view (or sim ilar) Task 9 – Data grid view Change the list vi ew or similar to be a data grid view. When done correctly, it should let you add /edit lines by simply clicking on them on the list and changing the content (new lines would be added by making a new line at the end) and t herefor e you can remove the corresponding buttons . You should be a ble to change th e colo ur by enterin g/clicking on the Color field of the row (i.e. display the ColorDial og) and it s current color should be displayed as the background col our of that ro w (so you would not change the Fore color of the Color button). To be concrete, the line shou ld be added when all entries of a row are of the right ty pe (and the user has done e diting – i.e. when Ce llEnd Editing is called ) and be updated when all entries are of the right type (and the user has done editing) – if the user does not update a line correctly, use the line before they started these edits. 10%: Used a fair impl ementation of a data g rid view 10%: Did not make any errors How to Submit Locate your Visual Studio project folder and compress it into a single .zip archive. If you use any other format we won’t be able to extract and mark your work. Rename the zip file to be your student id (and then . zip). If you want to draw our attenti on to anything, make a comment in the code itself. We will not read or mark any other documents. Submit your archive via CodeGrade. Marking Descriptors We draw your attention to the standard Department Grade Descriptors, which are listed in the Student Handbook .