1. Homepage
  2. Programming
  3. ELEC230 Robotic Systems Assignment 1 - Object-Oriented Programming: Classes & Objects in C++

ELEC230 Robotic Systems Assignment 1 - Object-Oriented Programming: Classes & Objects in C++

Engage in a Conversation
LiverpoolELEC230Robotic SystemsObject-Oriented ProgrammingC++

Department of Electrical Engineering and Electronics CourseNana.COM

Assignment Overview CourseNana.COM

Instantiation and manipulation of geometrical objects is significant in robotics. It is also advantageous to be familiar with object-oriented programming features in C++. In this assignment, you will design C++ classes capable of initialising polygons in a particular way, and performing translations and rotations on them. This tests your ability to declare and define classes and instantiate objects, using constructors, inheritance and polymorphism. CourseNana.COM

ProgramA (70%): CourseNana.COM

ELEC 230 C++ & OOP Assignment 1 (2023-2024) CourseNana.COM

1. Write a class called polygon which can initialise regular1 Two-Dimensional (2D) polygons, and translate them in the +/-x and +/-y directions (or both x and y). It should also be able to rotate them by any number of degrees about any point. Come up with your own names for all class members except N and r. The following members must be included in your class, exactly as instructed, and must serve a meaningful purpose in your program: CourseNana.COM

Private members:
o Member of type std::string, to store a ‘user’-defined polygon name (e.g. “t_1”) CourseNana.COM

• Note: the ‘user’-defined polygon name must always take the form l_i where l is a letter, i an integer; this also applies in ProgramB. CourseNana.COM

o Member (r) of type double, to store the radius.
o Member (N) of type integer, to store the number of vertices.
o Member of type std::vector, to store the x-coordinates of the polygon vertices. o Member of type std::vector, to store the y-coordinates of the polygon vertices. CourseNana.COM

o Member function which prints any object’s name, number of vertices and coordinates CourseNana.COM

(as a coordinate pair for each vertex) on screen using the standard output stream. The CourseNana.COM

printed output must take the following exact form (although obviously the ‘user’ CourseNana.COM

defined polygon name, the coordinates and the number of coordinate pairs will vary). CourseNana.COM

All numerical printed output should be rounded to 5 decimal places: CourseNana.COM

              t_1=polygon((1.73205,-1),(0,2),(-1.73205,-1))

Public members:
o Constructor function which, firstly, accepts and stores the name, r and N. Secondly, it CourseNana.COM

then uses this data to initialise and store the coordinates of the polygon vertices. When initialised, each polygon must be centred on the origin (0,0), and its base must be horizontal (parallel with the x axis). o Member function to translate any object, and efficiently print the object name and coordinates before and after translation, and the CourseNana.COM

is anticlockwise.) In the following exact form:
Before rotation: t_1=polygon((1.73205,-1),(0,2),(-1.73205,-1))
After rotation 90 degrees anticlockwise about (1,2): t_1=polygon((4,2.73205),(1,1),(4,-0.73205))
CourseNana.COM

1 ‘Regular’ means that all the polygon’s internal angles are the same, and all edges are of identical length. 3 CourseNana.COM

o The word ‘efficiently’ underlined twice above implies that there are opportunities here to avoid repeating code (DRY). Can you work out how? CourseNana.COM

2. Write a program incorporating the above class in the global scope. In your ‘main’ function, instantiate a triangle, a square and an 𝑛-gon (you choose 𝑛 > 4) using your constructor function created above. For each polygon, following instantiation, call sequentially first the translation, then the rotation function. Rotation must be by 90o about (a,b) and translation by (a,-b), where a and b are the final two non-zero digits in your student ID. For each stage, (instantiation, rotation and translation) copy and paste the relevant terminal output into https://www.desmos.com/calculator to generate an image of a polygon, and include screenshots of both the terminal output and the Desmos polygon in your report, as evidence of your working program (see also Marking Criteria). CourseNana.COM

ProgramB (30%): CourseNana.COM

Write a second program2 by following the steps below: CourseNana.COM

1) Copy and alter your class “polygon” to create a new class3, “polygon3d”, that can initialise, store and print any shape – regular or irregular – in Three-Dimensional (3D) space. Get rid of the member variable for radius, which is no longer meaningful, and alter the constructor function so that it now directly accepts and store the coordinates of the vertices. Delete N too. Don’t make other changes yet. CourseNana.COM

2) Rotation and translation need not be defined in polygon3d. Therefore, turn the functions for translation and rotation into pure virtual members, making polygon3d into an abstract base class. Convert the private members of polygon3d into ‘protected’ members to allow a layer of inheritance. CourseNana.COM

3) Create three new classes publicly inherited from polygon3d, called polygon_xy, polygon_xz and polygon_yz. Each class must only be able to perform rotations and translations in its own active set of planes (defined by xy, xz or yz). You should achieve this by overriding polygon3d’s translation / rotation functions in each inherited class.] CourseNana.COM


Similar rules apply for polygon_xz and polygon_yz in accordance with the planes given in their names. See the ‘Assignment 1 Support’ folder (which will be updated periodically) for help with constructor CourseNana.COM

  • inheritance. CourseNana.COM

    Important: the format of your efficient printed output to terminal should now be changed slightly so that the line containing name and coordinates looks like the following exact form (for example): CourseNana.COM

    t_1=Polygon({(0,0,0),(2,1,3),(1,3,4)}) CourseNana.COM

    In a similar way to ProgramA, create a program, instantiate one object of each class, and apply a translation and a rotation sequentially to each object. This time, choose your own (non-zero) rotation CourseNana.COM

and translation coordinates. Test and produce evidence for your report in https://www.geogebra.org/calculator using the ‘3D Calculator’ option (in a similar way as before with Desmos), and with terminal output screenshots. CourseNana.COM

Now choose either Task 4 or Task 5 (Not both): CourseNana.COM

4) For one of the above inherited classes, add a public member function which overloads the + operator to add one triangle’s coordinates to another’s in a single operation. You should be able to code “object3 = object1 + object2” with the result that the coordinates of object3’s vertices in each dimension become a sum of those of object1 and object2. E.g.: CourseNana.COM

0 CourseNana.COM

o object1 vertex coordinates: (1,2,5), o object2 vertex coordinates: (2,4,6), o object3 vertex coordinates become: (3,6,11), CourseNana.COM

(2,8,5), (3,5,8), (5,13,13), CourseNana.COM

(4,1,5) (2,1,8) (6,2,13) CourseNana.COM

2 Save your original program (ProgramA) as a .cpp file. Then, simply copy the code for class “polygon” into a new .cpp file, rename the class “polygon3d” and modify it according to the instructions. CourseNana.COM

5) Alternatively, in your ‘main’ function, instantiate 3 objects, each of a different inherited class from (3). Then, by using an array of base class pointers, pointing to objects of the derived classes in question (3), write code in your ‘main’ function to batch-translate the objects of the different derived classes, with a single for-loop. Translations should be non-zero in the appropriate plane for each object. (Again, choose your own translation vectors). You will utilise pre-existing functions – so, just as above and in ProgramA, details of the individual operations and starting/finishing object details should be efficiently printed as part of the process. Provide appropriate evidence of the batch translation with screenshots of Desmos or Geogebra and terminal output, as before. CourseNana.COM

Notes for BOTH Parts A and B: CourseNana.COM

  • All objects should be stored in the code (e.g. creating a new object of class polygon should not have to involve deleting a previous object of this class.) CourseNana.COM

  • You should find that the transformations performed by your member functions actually alter the stored object’s attributes. So, for example, if a translation is followed by a rotation on the same object, the coordinates passed into the rotation are the new coordinates following the translation. (This is a requirement of the Assignment.) CourseNana.COM

  • Don’t try to interface with the ‘user’ – there is no need to issue messages to the user inviting them to enter input, etc. When instantiating or manipulating objects, just hardcode these actions into your main function, on behalf of the ‘user’. Similarly, don’t try to create a menu-driven program! CourseNana.COM

    Important Further Hints and Notes: CourseNana.COM

  1. In this particular assignment, it isn’t the destination – it’s the journey. This means that in this assignment, the learning objectives in respect of C++ and OOP are met by following the design instructions closely, paying particular attention to object-oriented-programming and code efficiency where possible/relevant, and not worrying too much about (perceived) usefulness of the resulting programs. Don’t try and shortcut the assignment instructions! CourseNana.COM

  2. Refer to the ‘Assignment 1 Support’ folder – and keep referring back, as it will be periodically updated (it may not contain much when you first look there.) CourseNana.COM

  3. When it comes to writing your report, use the Submission Template which will be added to the above folder in due course. CourseNana.COM

  4. I would like to emphasise something already mentioned: DO NOT try and invite a ‘user’ to instantiate or manipulate objects at runtime – just instantiate/manipulate ‘directly’ (on behalf of the ‘user’, if you will) within the code of your ‘main’ function. So there will not be any call and response at the terminal – when your programs are run, they will simply generate a bunch of output according to what instructions you have given in the main function. CourseNana.COM

  5. To initialise each polygon in Part A, you will need to first set its coordinates using N and r, then rotate it about the origin by some amount so that the base lies ‘horizontal’. CourseNana.COM

  6. Rotational matrix equation for 2D rotation of a single coordinate point, where 𝑥, 𝑦 are the starting coordinates, 𝑥′, 𝑦′ are the coordinates after rotation, and 𝐴 is the angle of rotation about the origin: CourseNana.COM

    6 CourseNana.COM

CourseNana.COM

x' = x * cos(θ) - y * sin(θ) y' = x * sin(θ) + y * cos(θ) CourseNana.COM

  1. For the rotation function, you may find that you want to create a copy of your object. Note, firstly, that the ‘=’ operator will automatically invoke the default copy constructor (Without you needing to write a copy constructor). But what to make it equal to? That’s where the ‘this’ keyword could come in handy. ‘this’ is a keyword which refers to the current object. Since ‘this’ is actually a pointer, dereference it (*this) and make your dummy/copy object equal to it. CourseNana.COM

  2. If in doubt, assume within reason that the same rules about functionality and output apply for ProgramB as ProgramA unless instructed differently. If still unsure, ask! CourseNana.COM

  3. Read the Marking Criteria on Page 2 of this Assignment brief and take a look at the Assignment 1 Discussion Board on Canvas – even if you don’t have any questions, the answers to questions there might reveal misconceptions you didn’t know you had. CourseNana.COM

Note: In the Robot Operating System (ROS), 3D rotations are achieved with quaternions. Although this Assignment does not ask you to perform full 3D rotations or use quaternions, you can read more about them here. CourseNana.COM

What to submit
1. Commented standalone code for each program, should be formatted and added to the report. CourseNana.COM

2. A Report as a pdf: CourseNana.COM

Your Report should strictly follow the template provided sticking to page and word limits. o Screenshots for each task, showing (a) the program output at the terminal and (b) the corresponding polygons generated in Desmos or GeoGebra. (These should, of course, be presented as figures with figure numbers and captions and annotation if required. Feel CourseNana.COM

free to combine the polygons on 1 graph)
o A discussion of each program’s design and results, showing your understanding of your CourseNana.COM

own code and of C++ features used. You can enhance this with snapshots or snippets of your code, CourseNana.COM

Your Report should also an Appendix with full-screen screenshots as instructed in the Marking Criteria, p.2, in the same order of appearance as in the main body of the report. CourseNana.COM

Follow also all the other instructions in the Marking Criteria, p.2. CourseNana.COM

Warning CourseNana.COM

When marking your reports, we will be looking very closely for any signs of collusion, as this is unacceptable. We want to assess your own ability, not that of your friend or colleague. If we find any evidence of collusion or copying then the formal University rules will be followed which may result in your suspension. Similarly, your code, comments and discussion must be your own and not taken from any other source (e.g. online.) If we find evidence that part(s) of your work is/are copied or closely paraphrased from any source then the formal University rules will be followed on plagiarism and collusion, which may result in your suspension or termination of studies. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Liverpool代写,ELEC230代写,Robotic Systems代写,Object-Oriented Programming代写,C++代写,Liverpool代编,ELEC230代编,Robotic Systems代编,Object-Oriented Programming代编,C++代编,Liverpool代考,ELEC230代考,Robotic Systems代考,Object-Oriented Programming代考,C++代考,Liverpoolhelp,ELEC230help,Robotic Systemshelp,Object-Oriented Programminghelp,C++help,Liverpool作业代写,ELEC230作业代写,Robotic Systems作业代写,Object-Oriented Programming作业代写,C++作业代写,Liverpool编程代写,ELEC230编程代写,Robotic Systems编程代写,Object-Oriented Programming编程代写,C++编程代写,Liverpoolprogramming help,ELEC230programming help,Robotic Systemsprogramming help,Object-Oriented Programmingprogramming help,C++programming help,Liverpoolassignment help,ELEC230assignment help,Robotic Systemsassignment help,Object-Oriented Programmingassignment help,C++assignment help,Liverpoolsolution,ELEC230solution,Robotic Systemssolution,Object-Oriented Programmingsolution,C++solution,