[Solved] CST 8219 Assignment #2

$25

File Name: CST_8219__Assignment_#2.zip
File Size: 216.66 KB

SKU: [Solved] CST 8219 – Assignment #2 Category: Tag:
5/5 - (1 vote)

Vector Graphic with Overloaded Operators

Purpose: This assignment is a direct continuation of assignment 1 that uses overloaded operators. In anticipation of polymorphism in ass3 it now stores Graphic Elements as a dynamic array. Also the Stash is replaced by a better container: the vector template class.

Part of the code is shown on the next page; it is also on the Web Site in text files that you can copy and paste from so you dont make any mistakes. You must use this code without modification or additions because I will use it to mark your assignment. Your task is to implement the member functions that are declared in the Point.h, Line.h, GraphicElement.h and VectorGraphic.h header files and not add any new ones your code is in the files Point.cpp, Line.cpp, GraphicElement.cpp and VectorGraphic.cpp.

In this assignment, when the application is running the user can

  • Add a new Graphic Element (together with its lines) to the Vector Graphic
  • Delete a Graphic Element
  • Report a Graphic Element
  • Print all the details of the Graphic Elements in the Vector Graphic
  • Edit a Graphic Element

An example of the output of the running application is given at the end. Yours must work identically and produce identical output.

Note the following:

  • The files you submit must be named Point.cpp, Line.cpp, GraphicElement.cpp and VectorGraphic.cpp.
  • you must use C++ syntax including new and delete and cin and cout
  • You can only use functions like strlen() and strcpy() or similar etc. from the standard C library to handle strings (this assignment does not use the C++ string class).
  • When the application terminates it releases all dynamically allocated memory so it does not have a resource leak (or you lose 30%).

See the Marking Sheet for how you can lose marks, but you will lose at least 60% if: you change or add to the supplied code, it fails to build in Visual Studio 2013, it crashes in normal operation (such as printing from an empty list etc.), it doesnt produce the example output.

Part of the code is shown on the next page. You MUST use this code without modification. Your task is to add the implementation of the functions that are declared using the style of the posted Submission Standard. All your code is in the files Point.cpp, Line.cpp, GraphicElement.cpp and VectorGraphic.cpp.

What to Submit : Use Blackboard to submit this assignment as a zip file (not RAR) containing only the source code files (Point.cpp, Line.cpp, GraphicElement.cpp and VectorGraphic.cpp). The name of the zipped folder must contain your name as a prefix so that I can identify it, for example using my name the file would be tyleraAss2CST8219.zip. It is also vital that you include the Cover Information (as specified in the Submission Standard) as a file header in your source file so the file can be identified as yours. Use comment lines in the file to include the header.

Before you submit the code,

  • check that it builds and executes in Visual Studio 2013 as you expect if it doesnt build for me, for whatever reason, you get a deduction of at least 60%.
  • make sure you have submitted the correct file if I cannot build it because the file is wrong or missing from the zip, even if its an honest mistake, you get 0.
  • theres a late penalty of 25% per day. Dont send me file(s) as an email attachment it will get 0.

Example code I will use it to mark your assignment. Dont change or add to it.

// Point.h#ifndef POINT#define POINT class Point{int x, y; public:Point() :x(0), y(0){}Point(int x, int y) :x(x), y(y){}friend ostream& operator<<(ostream&,Point&);}; #endif // Line.h#ifndef LINE#define LINE class Line{Point start; Point end; public:Line() :start(), end(){}Line(Point start, Point end) :start(start), end(end){}friend ostream& operator<<(ostream&, Line&);}; #endif

// GraphicElement.h {public: GraphicElement&);}; #endif #ifndef GRAPHICELEMENT #define GRAPHICELEMENTclass GraphicElementchar* name; vector<Line> Lines; // a vectorof LinesGraphicElement():name(nullptr){};GraphicElement(char*);GraphicElement(vector<Line>, char*);GraphicElement(GraphicElement&);~GraphicElement(){if (name) delete []name;}GraphicElement& operator=(GraphicElement&); friend ostream& operator<<(ostream&, // VectorGraphic.hclass VectorGraphic{ public: }; #endif #ifndef VECTORGRAPHIC#define VECTORGRAPHIC GraphicElement** Elements; // elements on the heap unsigned int numElements; // how manyVectorGraphic():numElements(0),Elements(nullptr){}~VectorGraphic(){for (int i = 0; i < numElements; i++)delete Elements[i]; delete[] Elements;}void AddGraphicElement(); void DeleteGraphicElement(); void ReportVectorGraphic(); void EditGraphicElement(); GraphicElement& operator[](int); friend ostream& operator<<(ostream&, VectorGraphic&);
// ass2 W17 #define _CRT_SECURE_NO_WARNINGS#define _CRTDBG_MAP_ALLOC // need this to get the line identification//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF); // in main, after local declarations//NB must be in debug build#include <crtdbg.h> #include <iostream> #include <vector> using namespace std; #include Point.h#include Line.h#include GraphicElement.h #include VectorGraphic.h enum{ RUNNING = 1 }; VectorGraphic Image; int main(){char response;_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); while (RUNNING){cout<<endl<<Please select an option:
<<endl; cout<<1. Add a Graphic Element
; cout<<2. Delete a Graphic Element
; cout<<3. Report a Graphic Element
; cout<<4. List the Graphic Elements
;cout<<5. Edit a Graphic Elements
; cout<<q. Quit
; cout<<CHOICE: ;cin>>response; switch (response){case 1:Image.AddGraphicElement(); break;case 2:Image.DeleteGraphicElement(); break; case 3:
int index;cout << Please enter the index of the Graphic Element: ; cin >> index; cout << Image[index];break;case 4:Image.ReportVectorGraphic(); break; case 5:Image.EditGraphicElement(); break; case q:return 0; default:cout<<Please enter a valid option
;} cout<<endl;
} } return 0;

Example Output:

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 1

Please enter the name of the new GraphicElement(<256 characters): big mouth

How many lines are there in the new GraphicElement? 4

Please enter the x coord of the start point of line index 0 1 Please enter the y coord of the start point of line index 0 2

Please enter the x coord of the end point of line index 0 3

Please enter the y coord of the end point of line index 0 4

Please enter the x coord of the start point of line index 1 5

Please enter the y coord of the start point of line index 1 6

Please enter the x coord of the end point of line index 1 7

Please enter the y coord of the end point of line index 1 8

Please enter the x coord of the start point of line index 2 9

Please enter the y coord of the start point of line index 2 0

Please enter the x coord of the end point of line index 2 1

Please enter the y coord of the end point of line index 2 2

Please enter the x coord of the start point of line index 3 3

Please enter the y coord of the start point of line index 3 4

Please enter the x coord of the end point of line index 3 5

Please enter the y coord of the end point of line index 3 6

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 1

Please enter the name of the new GraphicElement(<256 characters): left eye

How many lines are there in the new GraphicElement? 3

Please enter the x coord of the start point of line index 0 1

Please enter the y coord of the start point of line index 0 2

Please enter the x coord of the end point of line index 0 3

Please enter the y coord of the end point of line index 0 4

Please enter the x coord of the start point of line index 1 5

Please enter the y coord of the start point of line index 1 6

Please enter the x coord of the end point of line index 1 7

Please enter the y coord of the end point of line index 1 8

Please enter the x coord of the start point of line index 2 9

Please enter the y coord of the start point of line index 2 0

Please enter the x coord of the end point of line index 2 1

Please enter the y coord of the end point of line index 2 2

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 4

VectorGraphic Report

Reporting Graphic Element #0 name = big mouth

Line #0: start is x = 1, y = 2. end is x = 3, y = 4

Line #1: start is x = 5, y = 6. end is x = 7, y = 8

Line #2: start is x = 9, y = 0. end is x = 1, y = 2

Line #3: start is x = 3, y = 4. end is x = 5, y = 6

Reporting Graphic Element #1 name = left eye

Line #0: start is x = 1, y = 2. end is x = 3, y = 4

Line #1: start is x = 5, y = 6. end is x = 7, y = 8

Line #2: start is x = 9, y = 0. end is x = 1, y = 2

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 3

Please enter the index of the Graphic Element: 1 name = left eye

Line #0: start is x = 1, y = 2. end is x = 3, y = 4

Line #1: start is x = 5, y = 6. end is x = 7, y = 8

Line #2: start is x = 9, y = 0. end is x = 1, y = 2

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 2

Please enter the index for the element to delete, between 0 and 1 0

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 4

VectorGraphic Report

Reporting Graphic Element #0 name = left eye

Line #0: start is x = 1, y = 2. end is x = 3, y = 4

Line #1: start is x = 5, y = 6. end is x = 7, y = 8

Line #2: start is x = 9, y = 0. end is x = 1, y = 2

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 5

EDIT A GRAPHIC ELEMENT

Please enter the index for the element to edit, between 0 and 0 0

Please enter the new name of the GraphicElement(<256 characters): right eye

How many lines are there in the GraphicElement? 1

Please enter the x coord of the start point of line index 0 1

Please enter the y coord of the start point of line index 0 2

Please enter the x coord of the end point of line index 0 3 Please enter the y coord of the end point of line index 0 4

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit

CHOICE: 4

VectorGraphic Report

Reporting Graphic Element #0 name = right eye

Line #0: start is x = 1, y = 2. end is x = 3, y = 4

Please select an option:

  1. Add a Graphic Element
  2. Delete a Graphic Element
  3. Report a Graphic Element
  4. List the Graphic Elements 5. Edit a Graphic Elements
  5. Quit CHOICE:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CST 8219 Assignment #2
$25