Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
COMP2404ABC (Winter 25) -“Introduction to Software Engineering” ,Assignment 1
1 Submission Instructions
2 Learning Outcomes
You will learn the basics of classes, objects, arrays, and using static memory in C++. You will make a few simple classes, populate the members using constructors and write functions to process the data. You will learn how to provide a working Makefile, and implement a small amount of application logic.
You will also be writing a wrapper library for a GUI in the X11 windowing system.
3 Overview
4 Classes Overview
- RGB - The X11 system takes an unsigned long as a colour argument, and reads the first (least significant) 24 bits to get the RGB values (red, green, blue). This class makes defining colours easier.
- Button - a basic, rectangular button with some text written on it.
- Panel - a container for holding GUI elements, so that we can create complex GUI elements that can be reused in different places in our CuWindow. For now, it only holds Buttons.
- CuWindow - the main class. This class must manage GUI elements (for now, it only handles Panels). It also manages creating and destroying an X11 window and graphics context.
- Tester - some functions used to test your code.
- defs.h - this has a preprocessor constant that you may use to initialize your arrays to a consistent size.
All your classes should all be in separate header and source files that are compiled explicitly in your Makefile!!. In addition you should compile and link the Tester class into your executable.
5 Instructions
Download the starting code from Brightspace.
All member variables are private unless otherwise noted. All member functions are public unless otherwise noted. Some return values are not explicitly given. You should use your best judgment (they will often be void, but not always). ALL CLASSES MUST HAVE A PRINT FUNCTION UNLESS OTHERWISE NOTED. This will print to the standard output, not on the window itself. This prints metadata about the class like names or sizes but not data contained in a data structure like an array (unless explicitly specified).
You are allowed to pass string objects by value for this assignment only. Passing by string& does not work with string literals (and we will learn why in the lessons on Encapsulation). You may use string or const string&. For the purposes of this assignment they function the same, but the second version is more efficient, as we will learn.
Your finished code should compile into a single executable called a1 using the command make a1, make, or make all, using a Makefile that you wrote yourself. Your submission should consist of a single zip file with a suitable name (e.g., assignment1.zip) that contains a folder containing all your files. This folder should also contain a README with your name, student number, a list of all files that are included. The main thing it should include is any changes to the specification. I don’t mind when you do things differently - I would encourage it, as long as it is code you write yourself, and not outside libraries - but you must document these changes.
5.1 Notes on Automated Marking
Initially main.cc will not compile because it references classes and functions that do not exist. Feel free to comment out parts that are not working. Or you can write your classes with empty implementations that you complete as you go (which I would recommend, but it is up to you). You may also #include additional header files for classes other than CuWindow. You may make your own file with your own main function and write your own tests, and compile that separately. But the code provided in main.cc using the Tester class is what will be run to determine your application requirements mark.
Likely most of the bugs you experience will be in your own code. However, you might find bugs or inconsistencies in the provided test code as well. Please bring them to my attention.
When there is a conflict between this specification and the test code, the test code takes precedence. I guarantee you there will be discrepancies - most of these can be solved with common sense. A rule of thumb is that running code is far better than exactly following the specification. The specification is just a guide. Your assignment is to produce a running program, whether it follows the specification or not. Make sure it runs correctly, and does the things it is supposed to do!
5.2 The defs.h file
This file defines some handy preprocessor constants so that these values are consistent across our application. In this case it defines MAX COMPONENTS which you should use as the size to initialize your arrays to. It also defines CuColour, which you can use to set the colour when drawing on X11 windows, as well as some predefined colours you may use.
5.3 The RGB Class
The RGB class holds members (ints) for the Red, Green, and Blue values for an X11 colour. Its main purpose is to change this into an appropriate unsigned long to feed to X11 functions, or to change an unsigned long into appropriate r, g, b values. You will need to use bit operations to convert back and forth. Although we are using ints to store the r,g,b values, they each only store 1 byte of information (i.e., we could use unsigned chars instead). And although CuColour is 8 bytes, we are only concerned with the first 3 bytes, where the least significant byte corresponds to the b value, the second-most least significant byte is the g value, and the third-most least significant byte is the r value.
5.4 The Button Class
5.5 The Panel Class
(a) int x, int y: the x and y coordinate of the Panel within its current CuWindow.(b) int width, int height: the width and height of the Panel in pixels.(c) string id: The unique id of the Panel.(d) A statically allocated array of Button objects of size MAX COMPONENTS.(e) An int that keeps track of the current number of Buttons stored (set to 0 initially).
See figure below.
5.6 The CuWindow Class
The CuWindow class handles the X11 logic for making a display, opening a window and getting a graphics context for drawing. It also maintains a statically allocated array of (non-overlapping) Panel objects.
2. In addition, these member variables are necessary to maintain and draw on an X11 window:(a) int width, int height: the current width and height of the window in pixels. Note, for this assignment we will not worry about what happens if a user resizes the window.(b) string name: The name of the window (which should be displayed at the top)(c) A statically allocated array of Panel objects of size MAX COMPONENTS.(d) An int that keeps track of the current number of Panels stored (set to 0 initially).(e) An RGB member for the background colour of the window.
(a) Display* display: Connection to the X server.(b) Window window: To store the XID of the window that we opened.(c) GC gc: A graphics context (so we can draw on the window).
(a) You should make getters and setters as needed.(b) bool addPanel - This function should take a Panel as an argument (passed by reference). If this Panel does not overlap any other Panel in the CuWindow, AND it does not extend outside of the CuWindow boundaries, then add this Panel to the back of the Panel array. Return true if the Panel is added, and false otherwise.(c) bool removePanel (string id) - This function should find the Panel with the given id and remove it from the array. It should ”close the gap” in the array. That is, consider panels p1, p2, p3, and p4 in an array in the following indices: 0:p1, 1:p2, 2:p3, 3:p4. If we remove p2, then the resulting array should look like 0:p1, 1:p3, 2:p4.(d) getPanel(string id): This function should return a pointer to the Panel with the given id, or else nullptr if no such Panel exists.(e) A void draw(); function. You should first fill the window with a rectangle to ”blank” everything out and provide a background colour (using the RGB member variable for the colour). Then you should draw all the Panels and their contents onto the window.NOTE: X11 does not synchronize by default. Thus, if there are changes being made to CuWindow and we attempt to draw, it may not be rendered properly. It is HIGHLY recommended that at the top of this draw function, before doing anything else, you sleep a bit so that any changes to CuWindow can be completed. Run the command usleep(100000) as the very first line of the draw function. You will also need #include <unistd.h> at the top of your file.(f) A print function. This should print (to the console, not to the window) the name of the window and the number of Panels.(g) A printPanels function. This should print out all the Panels.(h) A printPanelButtons function. This should print out all the Buttons from all the Panels.
6 Grading
The marks are divided into three main categories. The first two categories, Requirements and Constraints areworth 34 and 16 marks respectively. The third category, Deductions is where you are penalized marks.
6.1 Specification Requirements
These are marks for having a working application (even when not implemented according to the specification, withinreason). These are the same marks shown in the test suite, repeated here for convenience. Marks are awarded forthe application working as requested.
The test script provides a mark out of 34. If you have implemented everything correctly, this will probably be your mark for these sections. However, you are still responsible for, and may be penalized for, any errors the test suite does not catch, or any drastic departure from the specification (such as using outside libraries). We reserve the right to modify the mark given by the test script in these cases.
General Requirements
- All marking components must be called and execute successfully to earn marks.
- All data handled must be printed to the screen as specified to earn marks.
- 1. [3 marks] Test Buttons
- 2. [3 marks] Test Panels
- 3. [5 marks] Test add, remove, and print Buttons in Panel
- 4. [5 marks] Test add, remove, and print Panels in CuWindow
- 5. [2 marks] Test add, remove, and print Buttons and Panels in CuWindow
- 6. [6 marks, manual inspection] Test render window, see examples below.
- a) [1 mark] Panels are drawn correctly
- b) [2 marks] Buttons are drawn correctly (1 mark each Panel) - ignore the text for this mark, just look at
- the rectangles.
- c) [2 marks] Text is rendered correctly (1 mark each Panel).
- d) [1 marks] Upper Panel is removed correctly, lower Panel still drawn correctly.
- 7. [4 marks, manual inspection] Student tests. You should test different Button colours, different CuWindow colours, and differentplacements of Panels and Buttons, removing Panels, etc. There should be at least 4different configurations of Panels and Buttons in yourtest. Each configuration must have at least 2 Panels and 2 Buttons (if you are testing the remove function, then after removal you may have fewer Panels andButtons). Be sure to output (to cout) what each part is testing for.
Requirements Total: 28 marks
You may earn up to 2 style points as bonus. In the example shown, the buttonsare filled in rectangles, which gets you full marks. However, the lettering is centered in the Button, which would earn you 1 bonus mark.
It is not enough to hard code ”Button 1” in the center of the button. The text must be centered for any sizebutton and any label. The TAs will check you code for this.
You can earn additional bonus for making the buttons appear protruded, or for rounding the corners, or anythingelse that improves the appearance. Each improvement earns 1 mark, and you may earn up to 2 marks total.
Figure 1: Properly rendered window.
Figure 2: Properly rendered window with upper panel removed.
6.2 Constraints
The previous section awards marks if your program works correctly. In this section marks are awarded if your program is written according to the specification and using proper object oriented programming techniques. This includes but is not limited to:
- Proper declaration of member variables (correct type, naming conventions, etc).
- Proper instantiation and initialization of member variables (statically or dynamically).
- Proper instantiation and initialization of objects (statically or dynamically).
- Proper constructor and function signatures.
- Proper constructor and function implementation.
- Proper use of arrays and data structures.
- Passing objects by reference or by pointer. Do not pass by value.
- Note: For this assignment only, strings may be passed by value.
- Proper error checking - check array bounds, data in the correct range, etc.
- Reasonable documentation (remember the best documentation is expressive variable and function names, and clear purposes for each class).
6.2.1 Constraint marks:
- 2 marks: Proper implementation of the RGB class.
- 2 marks: Proper implementation of the Button class.
- 2 marks: Proper implementation of the Panel class.
- 4 marks: Proper implementation of the CuWindow class.
6.3 Deductions
The requirements listed here represent possible deductions from your assignment total. In addition to the constraints listed in the specification, these are global level constraints that you must observe. For example, you may only use approved libraries, and your programming environment must be properly configured to be compatible with the virtual machine. This is not a comprehensive list. Any requirement specified during class but not listed here must also be observed and may be penalized if done incorrectly.
6.3.1 Packaging and file errors:
- 5%: Missing README
- 10%: Missing Makefile (assuming this is a simple fix, otherwise see 4 or 5).
- up to 10%: Failure to use proper file structure (separate header and source files for example), but your program still compiles and runs
- up to 50%: Failure to use proper file structure (such as case-sensitive files and/or Makefile instructions) that results in program not compiling, but is fixable by a TA using reasonable effort.
- up to 100%: Failure to use proper file structure or other problems that severely compromise the ability to compile and run your program.
As an example, submitting Windows C++ code and Makefile that is not compatible with the Linux VM would fall under 4 or 5 depending on whether a reasonable effort could get it running.
- Up to 10%: Substituting C functions where C++ functions exist (e.g. don’t use printf, do use cout).
- Up to 25%: Using smart pointers.
- Up to 25%: Using global functions or global variables other than the main function and those functions and
- Up to 100%: The code must compile and execute in the default course VM provided or Openstack. It must NOT require any additional libraries, packages, or software besides what is available in the standard VM or Openstack.
- Up to 100%: Your program must not use any classes, containers, or algorithms from the standard template library (STL) unless expressly permitted.