Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ass1.cpp
- #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>
- using namespace std;
- #include "Point.h"
- #include "Line.h"
- #include "GraphicElement.h"
- #include "VectorGraphic.h"
- enum { RUNNING = 1 };
- VectorGraphic::VectorGraphic()
- {
- }
- void VectorGraphic::AddGraphicElement()
- {
- cout << endl << "Adding A Graphic Element " << endl;
- //copy old elements over
- if (numGraphicElements > 0)
- {
- GraphicElement* temp = new GraphicElement[numGraphicElements];
- for (int j = 0; j < numGraphicElements; j++)
- {
- strcpy(temp[j].name, pElements[j].name);
- temp[j].numLines = pElements[j].numLines;
- temp[j].pLines = new Line[pElements[j].numLines];
- for (int i = 0; i < pElements[j].numLines; i++)
- {
- temp[j].pLines[i].start.x = pElements[j].pLines[i].start.x;
- temp[j].pLines[i].start.y = pElements[j].pLines[i].start.y;
- temp[j].pLines[i].end.x = pElements[j].pLines[i].end.x;
- temp[j].pLines[i].end.y = pElements[j].pLines[i].end.y;
- }
- }
- //adding a new element.
- delete pElements;
- numGraphicElements++;
- pElements = new GraphicElement[numGraphicElements];
- for (int j = 0; j < (numGraphicElements-1); j++)
- {
- strcpy(pElements[j].name, temp[j].name);
- pElements[j].numLines = temp[j].numLines;
- pElements[j].pLines = new Line[temp[j].numLines];
- for (int i = 0; i < temp[j].numLines; i++)
- {
- pElements[j].pLines[i].start.x = temp[j].pLines[i].start.x;
- pElements[j].pLines[i].start.y = temp[j].pLines[i].start.y;
- pElements[j].pLines[i].end.x = temp[j].pLines[i].end.x;
- pElements[j].pLines[i].end.y = temp[j].pLines[i].end.y;
- }
- }
- delete temp;
- }
- else {
- numGraphicElements++;
- pElements = new GraphicElement[numGraphicElements];
- }
- cout << endl << " Please enter the name of the new GraphicElement?(<256 Characters) " << endl;
- cin >> pElements->name;
- cout << endl << "How many lines are there in the new GraphicElement " << endl;
- cin >> pElements->numLines;
- // allocate memory for line
- pElements[(numGraphicElements-1)].pLines = new Line[pElements[(numGraphicElements-1)].numLines];
- for (int i = 0; i < (pElements->numLines); i++)
- {
- cout << "Please enter the x coord of the start point of line index " << i << " : ";
- cin >> pElements[numGraphicElements - 1].pLines[i].start.x;
- cout << "Please enter the y coord of the start point of line index " << i << " : ";
- cin >> pElements[numGraphicElements - 1].pLines[i].start.y;
- cout << "Please enter the x coord of the end point of line index " << i << " : ";
- cin >> pElements[numGraphicElements - 1].pLines[i].end.x;
- cout << "Please enter the y coord of the end point of line index " << i << " : ";
- cin >> pElements[numGraphicElements - 1].pLines[i].end.y;
- }
- }
- void VectorGraphic::ReportVectorGraphic()
- {
- cout << endl << "Vector Graphic Report" << endl;
- for (int i = 0; i < (numGraphicElements); i++)
- {
- cout << endl << "Reporting Graphic Element " << i << endl;
- cout << endl << "Graphic Element name: " << pElements[i].name;
- for (int j = 0; j < (pElements[i].numLines); j++)
- {
- cout << endl << "Line " << j << " start x: " << pElements[i].pLines[j].start.x;
- cout << endl << "Line " << j << " start y: " << pElements[i].pLines[j].start.y;
- cout << endl << "Line " << j << " end x: " << pElements[i].pLines[j].end.x;
- cout << endl << "Line " << j << " end y: " << pElements[i].pLines[j].end.y;
- }
- }
- }
- void VectorGraphic::DeleteGraphicElement()
- {
- }
- int main()
- {
- char response;
- _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
- VectorGraphic Image;
- while (RUNNING)
- {
- cout << endl << "Please select an option:" << endl;
- cout << "1. Add a Graphic Element" << endl;
- cout << "2. Delete a GraphicElement" << endl;
- cout << "3. List the Graphic Elements" << endl;
- cout << "q. Quit" << endl;
- cout << "CHOICE: ";
- cin >> response;
- switch (response)
- {
- case '1':Image.AddGraphicElement(); break;
- case '2':Image.DeleteGraphicElement(); break;
- case '3':Image.ReportVectorGraphic(); break;
- case 'q': return 0;
- default:cout << "Please enter a valid option\n";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement