Advertisement
Broatlas

ass1

Oct 7th, 2016
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.37 KB | None | 0 0
  1.  
  2. // ass1.cpp
  3.  
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #define _CRTDBG_MAP_ALLOC   // need this to get the line identification
  6. //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF); // in main, after local declarations
  7. //NB must be in debug build
  8. #include <crtdbg.h>
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. #include "Point.h"
  13. #include "Line.h"
  14. #include "GraphicElement.h"
  15. #include "VectorGraphic.h"
  16.  
  17. enum { RUNNING = 1 };
  18. VectorGraphic::VectorGraphic()
  19. {
  20. }
  21.  
  22. void VectorGraphic::AddGraphicElement()
  23. {
  24.     cout << endl << "Adding A Graphic Element " << endl;
  25.  
  26.     //copy old elements over
  27.     if (numGraphicElements > 0)
  28.     {
  29.         GraphicElement* temp = new GraphicElement[numGraphicElements];
  30.         for (int j = 0; j < numGraphicElements; j++)
  31.         {
  32.             strcpy(temp[j].name, pElements[j].name);
  33.             temp[j].numLines = pElements[j].numLines;
  34.             temp[j].pLines = new Line[pElements[j].numLines];
  35.            
  36.             for (int i = 0; i < pElements[j].numLines; i++)
  37.             {
  38.                 temp[j].pLines[i].start.x = pElements[j].pLines[i].start.x;
  39.                 temp[j].pLines[i].start.y = pElements[j].pLines[i].start.y;
  40.                 temp[j].pLines[i].end.x = pElements[j].pLines[i].end.x;
  41.                 temp[j].pLines[i].end.y = pElements[j].pLines[i].end.y;
  42.             }
  43.  
  44.         }
  45.         //adding a new element.
  46.         delete pElements;
  47.  
  48.         numGraphicElements++;
  49.         pElements = new GraphicElement[numGraphicElements];
  50.         for (int j = 0; j < (numGraphicElements-1); j++)
  51.         {  
  52.             strcpy(pElements[j].name, temp[j].name);
  53.             pElements[j].numLines = temp[j].numLines;
  54.             pElements[j].pLines = new Line[temp[j].numLines];
  55.             for (int i = 0; i < temp[j].numLines; i++)
  56.             {
  57.                 pElements[j].pLines[i].start.x = temp[j].pLines[i].start.x;
  58.                 pElements[j].pLines[i].start.y = temp[j].pLines[i].start.y;
  59.                 pElements[j].pLines[i].end.x = temp[j].pLines[i].end.x;
  60.                 pElements[j].pLines[i].end.y = temp[j].pLines[i].end.y;
  61.             }
  62.         }
  63.         delete temp;
  64.     }
  65.     else {
  66.         numGraphicElements++;
  67.         pElements = new GraphicElement[numGraphicElements];
  68.     }
  69.    
  70.             cout << endl << " Please enter the name of the new GraphicElement?(<256 Characters) " << endl;
  71.             cin >> pElements->name;
  72.             cout << endl << "How many lines are there in the new GraphicElement " << endl;
  73.             cin >> pElements->numLines;
  74.             // allocate memory for line
  75.             pElements[(numGraphicElements-1)].pLines = new Line[pElements[(numGraphicElements-1)].numLines];
  76.             for (int i = 0; i < (pElements->numLines); i++)
  77.             {
  78.  
  79.                 cout << "Please enter the x coord of the start point of line index " << i << " : ";
  80.                 cin >> pElements[numGraphicElements - 1].pLines[i].start.x;
  81.                 cout << "Please enter the y coord of the start point of line index " << i << " : ";
  82.                 cin >> pElements[numGraphicElements - 1].pLines[i].start.y;
  83.                 cout << "Please enter the x coord of the end point of line index " << i << " : ";
  84.                 cin >> pElements[numGraphicElements - 1].pLines[i].end.x;
  85.                 cout << "Please enter the y coord of the end point of line index " << i << " : ";
  86.                 cin >> pElements[numGraphicElements - 1].pLines[i].end.y;
  87.             }
  88.  
  89.    
  90.  
  91. }
  92. void VectorGraphic::ReportVectorGraphic()
  93. {
  94.     cout << endl << "Vector Graphic Report" << endl;
  95.     for (int i = 0; i < (numGraphicElements); i++)
  96.     {
  97.         cout << endl << "Reporting Graphic Element " << i << endl;
  98.         cout << endl << "Graphic Element name: " << pElements[i].name;
  99.         for (int j = 0; j < (pElements[i].numLines); j++)
  100.         {
  101.             cout << endl << "Line " << j << " start x: " << pElements[i].pLines[j].start.x;
  102.             cout << endl << "Line " << j << " start y: " << pElements[i].pLines[j].start.y;
  103.             cout << endl << "Line " << j << " end x: " << pElements[i].pLines[j].end.x;
  104.             cout << endl << "Line " << j << " end y: " << pElements[i].pLines[j].end.y;
  105.         }
  106.     }
  107. }
  108. void VectorGraphic::DeleteGraphicElement()
  109. {
  110.  
  111. }
  112.  
  113. int main()
  114. {
  115.     char response;
  116.     _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  117.     VectorGraphic Image;
  118.  
  119.     while (RUNNING)
  120.     {
  121.         cout << endl << "Please select an option:" << endl;
  122.         cout << "1. Add a Graphic Element" << endl;
  123.         cout << "2. Delete a GraphicElement" << endl;
  124.         cout << "3. List the Graphic Elements" << endl;
  125.         cout << "q. Quit" << endl;
  126.         cout << "CHOICE: ";
  127.         cin >> response;
  128.         switch (response)
  129.         {
  130.         case '1':Image.AddGraphicElement(); break;
  131.         case '2':Image.DeleteGraphicElement(); break;
  132.         case '3':Image.ReportVectorGraphic(); break;
  133.         case 'q': return 0;
  134.         default:cout << "Please enter a valid option\n";
  135.         }
  136.         cout << endl;
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement