我是靠谱客的博主 沉静灯泡,这篇文章主要介绍c++ easyx简单矢量管理系统大一下课程设计一级标题c++ easyx简单矢量管理系统大一下课程设计,现在分享给大家,希望可以做个参考。

一级标题c++ easyx简单矢量管理系统大一下课程设计

课程设计要求,附加部分未实现
可以画点,线,圆,椭圆,矩形,多边形,折线。
画出图形的数据可保存在同文件夹下的txt文档中
在这里插入图片描述
填充功能要在同文件夹下放入名为image名称的jpg图片即可完成填充功能
在这里插入图片描述
代码如下
我是把设计的图形分为不同的类,用分文件编写 你也可放在同一个文件中。
在这里插入图片描述
图形类 (虚基类)无cpp部分
shape.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once #include<iostream> #include<iomanip> using namespace std; class shape { public: int m_Id; int Id; //图形种类 int x, y; //点的参数 int m_x1, m_x2;//线的参数 int m_y1, m_y2; int m_x, m_y; //圆的参数 int radius; int left; //椭圆的参数 int top; int right; int bottom; int left1;//矩形的参数 int top1; int right1; int bottom1; int color1, color2; //边框色,和填充色 int line_shape; //线性 int line_width; //线宽 int num; //多边形的顶点也是边数的个数 和折线的点数 int m_point[100] = {}; virtual void showInfo() = 0; };

圆类Circle.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//圆的实现 #include<iostream> using namespace std; #include"shape.h" class circle1 :public shape { public: /*int m_x,m_y; int radius;*/ circle1(int m_id, int id, int x, int y, int radius,int color3,int color4, int lineshape, int linewidth); void showInfo(); };

圆类Circle.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include"Circle.h" circle1::circle1(int m_id, int id, int x, int y, int radius1, int color3, int color4, int lineshape, int linewidth) { m_Id = m_id; Id = id; m_x = x; m_y = y; radius = radius1; color1 = color3; color2 = color4; line_shape = lineshape; line_width = linewidth; } void circle1::showInfo() { cout << "编号:" << m_Id << " "; cout << "图形种类: " << "3.圆" << "t圆心点坐标:" << "t(" <<m_x << "," << m_y << ")" << "t半径为:" << radius << "t边框颜色:" <<color1 << "t填充颜色:" << color2 << " 线类型:" << line_shape << " 线宽:" << line_width; cout << endl; }

点类point.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once #include<iostream> using namespace std; #include"shape.h" class point1 :public shape { public: point1(int m_id, int id, int x1, int y1, int color3); void showInfo(); };

点类point.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include"point.h" point1::point1(int m_id, int id, int x1, int y1, int color3) { m_Id = m_id; Id = id; x = x1; y = y1; color1 = color3; } void point1::showInfo() { cout << "编号:" << m_Id << " "; cout << "图形种类: " << "1.点" << "t点坐标:" << "t(" << x << "," << y << ")" << "t 点颜色:" << color1 ; cout << endl; }

直线Line.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once #include<iostream> using namespace std; #include"shape.h" class Line1 :public shape { public: /*int m_x1,m_x2; int m_y1,m_y2;*/ Line1(int m_id, int id, int x1, int y1, int x2, int y2, int color3, int lineshape, int linewidth); void showInfo(); };

直线Line.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include"Line.h" Line1::Line1(int m_id, int id, int x1, int y1, int x2, int y2, int color3, int lineshape, int linewidth) { m_Id = m_id; Id = id; m_x1 = x1; m_x2 = x2; m_y1 = y1; m_y2 = y2; color1 = color3; line_shape = lineshape; line_width = linewidth; } void Line1::showInfo() { cout << "编号:" << m_Id << " "; cout << "图形种类: " << "2.直线 "; cout<< "t直线两点坐标:" << "t(" << m_x1 << "," << m_y1 << ")" << " " << "(" << m_x2 << "," << m_y2 << ")" << "t线颜色:" <<color1 << " 线类型:" << line_shape << " 线宽:" << line_width; cout << endl; }

椭圆类ellipse.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#pragma once #include<iostream> using namespace std; #include"shape.h" class ellipse1 :public shape { public: /*int left; int top; int right; int bottom;*/ ellipse1(int m_id, int id, int left1, int top1, int right1, int bottom1, int color3, int color4, int lineshape, int linewidth); void showInfo(); };

椭圆类ellipse.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include"ellipse.h" ellipse1::ellipse1(int m_id, int id, int left1, int top1, int right1, int bottom1, int color3, int color4, int lineshape, int linewidth) { m_Id = m_id; Id = id; left = left1; top = top1; right = right1; bottom = bottom1; color1 = color3; color2 = color4; line_shape = lineshape; line_width = linewidth; } void ellipse1::showInfo() { cout << "编号:" << m_Id << " "; cout << "图形种类: " << "4.椭圆" << "t椭圆位置坐标:" << "t(" << left << "," << top << ")" << " " << "(" << right << "," << bottom << ")" << "t边框颜色:" <<color1 << "t填充颜色:" <<color2 << " 线类型:" <<line_shape << " 线宽:" <<line_width; cout << endl; }

多边形solidpolygon1.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once #include<iostream> using namespace std; #include"shape.h" class solidpolygon11:public shape { public: solidpolygon11(int m_id,int id, int num1,int m_point1[], int color3, int color4, int lineshape, int linewidth); void showInfo(); };

多边形solidpolygon1.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include"solidpolygon1.h" solidpolygon11::solidpolygon11(int m_id, int id, int num1 , int m_point1[], int color3, int color4, int lineshape, int linewidth) { m_Id = m_id; Id = id; num = num1; for (int i = 0; i < 2*num; i++) { m_point[i] = m_point1[i]; } color1 = color3; color2 = color4; line_shape = lineshape; line_width = linewidth; } void solidpolygon11::showInfo() { cout << "编号:" << m_Id << " "; cout << "图形种类: " << "6.多边形: " << "边数:" << num << " "; cout << "t多边形坐标:"; for (int i = 0; i < 2*num; i += 2) { cout << "(" << m_point[i] << "," << m_point[i+ 1] << ")"; }; cout<< "t线颜色:" << color1 << "t填充颜色:" << color2 << " 线类型:" << line_shape << " 线宽:" << line_width; cout << endl; }

折线polyline1.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once #include"shape.h" using namespace std; class polyline1 :public shape { public: polyline1(int m_id, int id, int num1, int m_point1[], int color3,int lineshape, int linewidth); void showInfo(); };

折线polyline1.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include"polyline1.h" polyline1::polyline1(int m_id, int id, int num1,int m_point1[], int color3,int lineshape, int linewidth) { m_Id = m_id; Id = id; num = num1; for (int i = 0; i < 2 * num; i++) { m_point[i] = m_point1[i]; } color1 = color3; line_shape = lineshape; line_width = linewidth; } void polyline1::showInfo() { cout << "编号:" << m_Id << " "; cout << "图形种类: " << "7.折线: " << "点数:" << num << " "; cout << "t点坐标:"; for (int i = 0; i < 2*num; i+=2) { cout << "(" << m_point[i] << "," << m_point[i + 1] << ")"; }; cout << "t线颜色:" << color1 << " 线类型:" << line_shape << "线宽:" << line_width; cout << endl; }

矩形rectangle.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#pragma once #include<iostream> using namespace std; #include"shape.h" class rectangle1 :public shape { public: /*int left; int top; int right; int bottom;*/ rectangle1(int m_id, int id, int left1, int top1, int right1, int bottom1, int color3, int color4, int lineshape, int linewidth); void showInfo(); };

矩形rectangle.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include"rectangle.h" rectangle1::rectangle1(int m_id, int id, int left2, int top2, int right2, int bottom2, int color3, int color4,int lineshape, int linewidth) { m_Id = m_id; Id = id; left1 = left2; top1 = top2; right1 = right2; bottom1 = bottom2; color1 = color3; color2 = color4; line_shape = lineshape; line_width = linewidth; } void rectangle1::showInfo() { cout << "编号:" << m_Id << " "; cout << "图形种类: " << "5.矩形" << "t矩形位置坐标:" << "t(" << left1 << "," << top1 << ")" << " " << "(" << right1 << "," << bottom1 << ")" << "t边框颜色:" << color1 << "t填充颜色:" << color2 << " 线类型:" << line_shape << " 线宽:" << line_width; cout << endl; }

图形类graph.h完成功能的部分

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once #include<iostream> using namespace std; #include <graphics.h> // 引用图形库头文件 #include <conio.h> #include"shape.h" #include"Circle.h" #include"ellipse.h" #include"Line.h" #include"rectangle.h" #include"point.h" #include"solidpolygon1.h" #include"polyline1.h" #include<fstream> #define FILENAME "empFile.txt" class Graph { public: Graph();//构造函数 static int count; int m_graphNum;//记录图形个数 bool m_FileIsEmpty;//判断文件是否为空 int get_graphNum();//记录文件图形数量 void init_graph();//初始化图形 将文件中的图形保存在程序中 void show_menu();//菜单展示 void show_graph();//显示图形信息 //void sort_graph();//按照编号排序 int isExist(int id);//判断图形是否存在 void Find_graph();//查找图形 void Mod_graph();//修改图形信息 void del_graph();//删除图形 void draw_graph();//画出图形 void drawline(int x, int y, int n);//画点 void Setlinestyle(int linestyle1, int linewidth1);//画线的样式 void Setlinecolor(int n);//边和 void Setfillcolor(int n);//填充色 void exitsystem();//退出 void save(); //保存文件 shape** m_graphArray; //图形数组指针 void add_graph();//添加图形 void showcolor();//选择图形的边颜色和填充颜色 void lineshapewidth();//选择图形边的形状和宽度 //清空文件 void clear_File(); ~Graph(); };

图形类graph.cpp完成功能的部分
函数体实现部分

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
#include "graph.h" int Graph::count = 1; //构造函数实现 Graph::Graph() { //文件不存在 ifstream ifs; ifs.open(FILENAME, ios::in); if (!ifs.is_open()) { cout << "文件不存在!" << endl; m_graphNum = 0;//图形个数为零 m_FileIsEmpty = true;//初始化文件为空 m_graphArray = NULL; ifs.close(); return; } //文件存在 数据为空 char ch; ifs >> ch; if (ifs.eof()) { cout << "您的图形系统为空!添加请按1!" << endl; m_graphNum = 0; m_graphArray = NULL; m_FileIsEmpty = true; ifs.close(); return; } //文件存在,并且记录数据 int num = get_graphNum(); m_graphNum = num; m_graphArray = new shape * [m_graphNum];//开辟空间 init_graph();//将文件中的数据保存在数组中 count = m_graphArray[m_graphNum - 1]->m_Id+1; //show_graph(); } //菜单展示实现 void Graph::show_menu() { cout << "********************************" << endl; cout << "****欢迎使用矢量图处理系统******" << endl; cout << "********0.退出管理系统**********" << endl; cout << "********1.添加矢量图形**********" << endl; cout << "********2.显示图形信息**********" << endl; cout << "********3.画出矢量图形**********" << endl; cout << "********4.按照编号查找图形******" << endl; cout << "********5.修改图形信息**********" << endl; cout << "********6.按编号删除图形********" << endl; cout << "********7.清空图形文件**********" << endl; cout << "********************************" << endl; cout << endl; } //添加图形数量 void Graph::add_graph() { cout << "请输入添加图形的数量" << endl; int addnum = 0;//保存用户输入的数量 cin >> addnum; if (addnum > 0) { //添加代码 //计算添加新的空间大小 int newsize = m_graphNum + addnum; //开辟新空间 shape** newspace = new shape * [newsize]; //将原来空间下的数据拷贝在新空间下 if (m_graphArray != NULL) { for (int i = 0; i < m_graphNum; i++) { newspace[i] = m_graphArray[i]; } } //批量添加新数据 for (int i = 0; i < addnum; i++) { cout << "请输入添加的第" << i + 1 << "个图形" << endl; cout << "1.点" << endl; cout << "2.直线" << endl; cout << "3.圆" << endl; cout << "4.椭圆" << endl; cout << "5.矩形" << endl; cout << "6.多边形" << endl; cout << "7.折线" << endl; int id;//图形的种类 cin >> id; shape* w = NULL; if (id == 1) { int m_id; m_id = count; int x1, y1; int color1, color2; cout << "请输入点参数" << endl; cout << "第一个点 "; cin >> x1 >> y1; showcolor(); cin >> color1; w = new point1(m_id,id, x1, y1,color1); count++; } if (id == 2) { int m_id; m_id = count; int x1, x2; int y1, y2; int color1, color2; int lineshape, linewidth; cout << "请输入直线的两个点参数" << endl; cout << "第一个点 "; cin >> x1 >> y1; cout << "第二个点 "; cin >> x2 >> y2; showcolor(); cin >> color1; lineshapewidth(); cin >> lineshape >> linewidth; w = new Line1(m_id,id, x1, y1, x2, y2,color1,lineshape, linewidth); count++; } if (id == 3) { int m_id; m_id = count; int x, y; int radius; int color1, color2; int lineshape, linewidth; cout << "请输入圆的圆心 " << endl; cin >> x >> y; cout << "半径 "; cin >> radius; showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new circle1(m_id,id, x, y, radius, color1, color2, lineshape, linewidth); count++; } if (id == 4) { int m_id; m_id = count; int x1, x2; int y1, y2; int color1, color2; int lineshape, linewidth; cout << "请输入椭圆的两个点参数" << endl; cout << "第一个点 "; cin >> x1 >> y1; cout << "第二个点 "; cin >> x2 >> y2; showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new ellipse1(m_id,id, x1, y1, x2, y2, color1, color2, lineshape, linewidth); count++; } if (id == 5) { int m_id; m_id = count; int left, top, right, bottom; int color1, color2; int lineshape, linewidth; cout << "请输入矩形的两点参数" << endl; cout << "请输入第一个点 "; cin >> left >> top; cout << "第二个点 "; cin >> right >> bottom; showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new rectangle1(m_id,id, left, top, right, bottom, color1, color2, lineshape, linewidth); count++; } if (id == 6) { int m_id; m_id = count; int num1; int m_point1[50]= { 0 }; int color1, color2; int lineshape, linewidth; cout << "请输入多边形的边数:" << endl; cin >> num1; int index1 = 1; for (int j = 0; j < 2 * num1; j += 2) { cout << "第"<<index1<< "个点的x坐标: "; cin >> m_point1[j]; cout << "第" <<index1<< "个点的y坐标: "; cin >> m_point1[j+1]; index1++; } showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new solidpolygon11(m_id,id,num1,m_point1,color1,color2,lineshape,linewidth); count++; } if (id == 7) { int m_id; m_id = count; int num1; int m_point1[100] = { 0 }; int color1; int lineshape, linewidth; cout << "请输入折线的点数:" << endl; cin >> num1; int index1 = 1; for (int j = 0; j < 2 * num1; j += 2) { cout << "第" << index1 << "个点的x坐标: "; cin >> m_point1[j]; cout << "第" << index1 << "个点的y坐标: "; cin >> m_point1[j + 1]; index1++; } showcolor(); cin >> color1; lineshapewidth(); cin >> lineshape >> linewidth; w = new polyline1(m_id,id, num1, m_point1, color1, lineshape, linewidth); count++; } //将创建的图形保存在数组中 newspace[m_graphNum + i] = w; } //释放原有的空间 delete[]m_graphArray; //更改新空间的指向 m_graphArray = newspace; //更新图形的数量 m_graphNum = newsize; //更新职工不为空的标志 m_FileIsEmpty = false; //提示添加成功 cout << "成功添加" << addnum << "个图形" << endl; //成功添加后,保存在文件中 save(); } else { cout << "输入有误!" << endl; } //按任意键后 清屏回到上极目录 system("pause"); system("cls"); } //将数据保存在文件中 void Graph::save() { ofstream ofs; ofs.open(FILENAME, ios::out);//用输出的方式打开文件--写文件 for (int i = 0; i < m_graphNum; i++) { if (m_graphArray[i]->Id == 1) { ofs << m_graphArray[i]->Id << " " << m_graphArray[i]->x << " " << m_graphArray[i]->y <<" " <<m_graphArray[i]->color1<<" " << m_graphArray[i]->m_Id << " " << endl; } if (m_graphArray[i]->Id == 2) { ofs << m_graphArray[i]->Id << " "; ofs << m_graphArray[i]->m_x1 << " "; ofs << m_graphArray[i]->m_y1 << " "; ofs << m_graphArray[i]->m_x2 << " "; ofs << m_graphArray[i]->m_y2 << " "; ofs << m_graphArray[i]->color1 << " "; ofs << m_graphArray[i]->line_shape << " "; ofs << m_graphArray[i]->line_width << " "; ofs << m_graphArray[i]->m_Id << " "; ofs << endl; } if (m_graphArray[i]->Id == 3) { ofs << m_graphArray[i]->Id << " " << m_graphArray[i]->m_x << " " << m_graphArray[i]->m_y << " " << m_graphArray[i]->radius << " " << m_graphArray[i]->color1 << " " << m_graphArray[i]->color2 << " " << m_graphArray[i]->line_shape << " " << m_graphArray[i]->line_width << " " << m_graphArray[i]->m_Id << " " << endl; } if (m_graphArray[i]->Id == 4) { ofs << m_graphArray[i]->Id << " " << m_graphArray[i]->left << " " << m_graphArray[i]->top << " " << m_graphArray[i]->right << " " << m_graphArray[i]->bottom << " " << m_graphArray[i]->color1 << " " << m_graphArray[i]->color2<<" " << m_graphArray[i]->line_shape << " " << m_graphArray[i]->line_width << " " << m_graphArray[i]->m_Id << " " <<endl; } if (m_graphArray[i]->Id == 5) { ofs << m_graphArray[i]->Id << " " << m_graphArray[i]->left1 << " " << m_graphArray[i]->top1 << " " << m_graphArray[i]->right1 << " " << m_graphArray[i]->bottom1 << " " << m_graphArray[i]->color1 << " " << m_graphArray[i]->color2 << " " << m_graphArray[i]->line_shape << " " << m_graphArray[i]->line_width << " " << m_graphArray[i]->m_Id << " " << endl; } if (m_graphArray[i]->Id == 6) { ofs << m_graphArray[i]->Id << " "; ofs << m_graphArray[i]->num << " "; for (int j = 0; j < 2 * m_graphArray[i]->num; j += 2) { ofs << m_graphArray[i]->m_point[j] << " " << m_graphArray[i]->m_point[j + 1] << " "; }; ofs<< m_graphArray[i]->color1 << " " << m_graphArray[i]->color2 << " " << m_graphArray[i]->line_shape << " " << m_graphArray[i]->line_width << " " << m_graphArray[i]->m_Id << " " << endl; } if (m_graphArray[i]->Id ==7) { ofs << m_graphArray[i]->Id << " "; ofs << m_graphArray[i]->num << " "; for (int j = 0; j < 2 * m_graphArray[i]->num; j += 2) { ofs << m_graphArray[i]->m_point[j] << " " << m_graphArray[i]->m_point[j + 1] << " "; }; ofs << m_graphArray[i]->color1 << " " << m_graphArray[i]->line_shape << " " << m_graphArray[i]->line_width << " " << m_graphArray[i]->m_Id << " " << endl; } } //关闭文件 ofs.close(); } //按照编号排序 //void Graph::sort_graph() //{ // if (m_FileIsEmpty) // { // cout << "文件不存在或为空!" << endl; // system("pause"); // system("cls"); // } // else // { // for (int i = 0; i < m_graphNum; i++) // { // int max = i; // for (int j = i + 1; j < m_graphNum; j++) // { // if (m_graphArray[max]->m_Id> m_graphArray[j]->m_Id) // { // max = j; // } // } // if (i != max) // { // shape* temp = m_graphArray[i]; // m_graphArray[i] = m_graphArray[max]; // m_graphArray[max] = temp; // } // } // } // cout << "排序成功!排序后的结果为: " << endl; // save(); //排序后结果保存在文件中 // // show_graph();//展示所有的图形 //} //判断图形是否存在 int Graph::isExist(int id) { int index = -1; for (int i = 0; i < m_graphNum; i++) { if (m_graphArray[i]->m_Id == id) { index = i; break; } } return index; } //查找图形 void Graph::Find_graph() { if (m_FileIsEmpty) { cout << "文件不存在或者为空!" << endl; } else { int Fid; cout << "请输入要查找图形的编号!" << endl; cin >> Fid; int ret = isExist(Fid); if (ret != -1) { cout << "查找成功!该图形的信息如下: " << endl; m_graphArray[ret]->showInfo(); } else { cout << "查找失败!没有此图!" << endl; } } //按任意键清屏 system("pause"); system("cls"); } //修改图形信息 void Graph::Mod_graph() { if (m_FileIsEmpty) { cout << "文件不存在或者为空!" << endl; } else { show_graph(); cout << " 1.修改颜色线性和线宽信息 2.修改这个图形的全部信息n"; //查到编号的图形 int select = 0;//保存修改的种类 1.修改颜色线性和线宽信息 2.修改这个图形的全部信息 cin >> select; cout << "请输入修改图形的编号!" << endl; int Mid; cin >> Mid; int ret = isExist(Mid); //找到修改图形 if (ret != -1)//修改信息 { // 1.修改颜色线性和线宽信息 if (select == 1) { if (m_graphArray[ret]->Id == 1) { cout << "你要修改的是点,请输入要修改点的颜色:" << endl; int color; showcolor(); cin >> color; m_graphArray[ret]->color1 = color; } if (m_graphArray[ret]->Id == 2) { cout << "你要修改的是线,请输入要修改点的属性:" << endl; int n=1; cout << "要修改线的颜色请输入0" << endl; cin >> n; if (n == 0) { showcolor(); int change_color = 0; m_graphArray[ret]->color1 == change_color; n = 1; } cout << "要更改线的类型请输入0n"; cin >> n; if (n == 0) { lineshapewidth(); int change_shape = 0; cin >> change_shape; m_graphArray[ret]->line_shape = change_shape; n = 1; } cout << "要更改线的宽度请输入0n"; cin >> n; if (n == 0) { cout << "请输入线的宽度:" << endl; int change_width = 0; cin >> change_width; m_graphArray[ret]->line_width = change_width; n = 1; } } if (m_graphArray[ret]->Id == 3) { cout << "你要修改的是圆,请输入要修改点的属性:" << endl; int n = 1; cout << "要修改圆线的颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_color = 0; m_graphArray[ret]->color1 == change_color; n = 1; } cout << "要修改圆的填充颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_fillcolor = 0; m_graphArray[ret]->color2 == change_fillcolor; n = 1; } cout << "要更改圆边的类型请输入0n"; cin >> n; if (n == 0) { lineshapewidth(); int change_shape = 0; cin >> change_shape; m_graphArray[ret]->line_shape = change_shape; n = 1; } cout << "要更改圆边线的宽度请输入0n"; cin >> n; if (n == 0) { cout << "请输入圆边线的宽度:" << endl; int change_width = 0; cin >> change_width; m_graphArray[ret]->line_width = change_width; n = 1; } } if (m_graphArray[ret]->Id == 4) { cout << "你要修改的是椭圆,请输入要修改点的属性:" << endl; int n = 1; cout << "要修改椭圆线的颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_color = 0; m_graphArray[ret]->color1 == change_color; n = 1; } cout << "要修改椭圆的填充颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_fillcolor = 0; m_graphArray[ret]->color2 == change_fillcolor; n = 1; } cout << "要更改椭圆边的类型请输入0n"; cin >> n; if (n == 0) { lineshapewidth(); int change_shape = 0; cin >> change_shape; m_graphArray[ret]->line_shape = change_shape; n = 1; } cout << "要更改椭圆边线的宽度请输入0n"; cin >> n; if (n == 0) { cout << "请输入椭圆边线的宽度:" << endl; int change_width = 0; cin >> change_width; m_graphArray[ret]->line_width = change_width; n = 1; } } if (m_graphArray[ret]->Id == 5) { cout << "你要修改的是矩形,请输入要修改点的属性:" << endl; int n = 1; cout << "要修改矩形线的颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_color = 0; m_graphArray[ret]->color1 == change_color; n = 1; } cout << "要修改矩形的填充颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_fillcolor = 0; m_graphArray[ret]->color2 == change_fillcolor; n = 1; } cout << "要更改矩形边的类型请输入0n"; cin >> n; if (n == 0) { lineshapewidth(); int change_shape = 0; cin >> change_shape; m_graphArray[ret]->line_shape = change_shape; n = 1; } cout << "要更改矩形边线的宽度请输入0n"; cin >> n; if (n == 0) { cout << "请输入矩形线的宽度:" << endl; int change_width = 0; cin >> change_width; m_graphArray[ret]->line_width = change_width; n = 1; } } if (m_graphArray[ret]->Id == 6) { cout << "你要修改的是多边形,请输入要修改点的属性:" << endl; int n = 1; cout << "要修改多边形线的颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_color = 0; m_graphArray[ret]->color1 == change_color; n = 1; } cout << "要修改多边形的填充颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_fillcolor = 0; m_graphArray[ret]->color2 == change_fillcolor; n = 1; } cout << "要更改多边形边的类型请输入0n"; cin >> n; if (n == 0) { lineshapewidth(); int change_shape = 0; cin >> change_shape; m_graphArray[ret]->line_shape = change_shape; n = 1; } cout << "要更改多边形边线的宽度请输入0n"; cin >> n; if (n == 0) { cout << "请输入多边形线的宽度:" << endl; int change_width = 0; cin >> change_width; m_graphArray[ret]->line_width = change_width; n = 1; } } if (m_graphArray[ret]->Id == 7) { cout << "你要修改的是折线,请输入要修改折线的属性:" << endl; int n = 1; cout << "要修改折线的颜色请输入0n" << endl; cin >> n; if (n == 0) { showcolor(); int change_color = 0; m_graphArray[ret]->color1 == change_color; n = 1; } cout << "要更改折线的类型请输入0n"; cin >> n; if (n == 0) { lineshapewidth(); int change_shape = 0; cin >> change_shape; m_graphArray[ret]->line_shape = change_shape; n = 1; } cout << "要更改多边形折线的宽度请输入0n"; cin >> n; if (n == 0) { cout << "请输入折线的宽度:" << endl; int change_width = 0; cin >> change_width; m_graphArray[ret]->line_width = change_width; n = 1; } } } // 2.修改这个图形的全部信息 else { delete m_graphArray[ret]; cout << "请输入修改后的图形种类" << endl; cout << "1.点" << endl; cout << "2.直线" << endl; cout << "3.圆" << endl; cout << "4.椭圆" << endl; cout << "5.矩形" << endl; cout << "6.多边形" << endl; cout << "7.折线" << endl; int id;//图形的种类 cin >> id; shape* w = NULL; if (id == 1) { int x1, y1; int color1, color2; cout << "请输入点参数" << endl; cout << "第一个点 "; cin >> x1 >> y1; showcolor(); cin >> color1; w = new point1(Mid, id, x1, y1, color1); } if (id == 2) { int x1, x2; int y1, y2; int color1, color2; int lineshape, linewidth; cout << "请输入直线的两个点参数" << endl; cout << "第一个点 "; cin >> x1 >> y1; cout << "第二个点 "; cin >> x2 >> y2; showcolor(); cin >> color1; lineshapewidth(); cin >> lineshape >> linewidth; w = new Line1(Mid, id, x1, x2, y1, y2, color1, lineshape, linewidth); } if (id == 3) { int x, y; int radius; int color1, color2; int lineshape, linewidth; cout << "请输入圆的圆心 " << endl; cin >> x >> y; cout << "半径 "; cin >> radius; showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new circle1(Mid, id, x, y, radius, color1, color2, lineshape, linewidth); } if (id == 4) { int x1, x2; int y1, y2; int color1, color2; int lineshape, linewidth; cout << "请输入椭圆的两个点参数" << endl; cout << "第一个点 "; cin >> x1 >> y1; cout << "第二个点 "; cin >> x2 >> y2; showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new ellipse1(Mid, id, x1, y1, x2, y2, color1, color2, lineshape, linewidth); } if (id == 5) { int left, top, right, bottom; int color1, color2; int lineshape, linewidth; cout << "请输入矩形的两点参数" << endl; cout << "请输入第一个点 "; cin >> left >> top; cout << "第二个点 "; cin >> right >> bottom; showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new rectangle1(Mid, id, left, top, right, bottom, color1, color2, lineshape, linewidth); } if (id == 6) { int num1; int m_point1[50] = { 0 }; int color1, color2; int lineshape, linewidth; cout << "请输入多边形的边数:" << endl; cin >> num1; int index1 = 1; for (int j = 0; j < 2 * num1; j += 2) { cout << "第" << index1 << "个点的x坐标: "; cin >> m_point1[j]; cout << "第" << index1 << "个点的y坐标: "; cin >> m_point1[j + 1]; index1++; } showcolor(); cin >> color1 >> color2; lineshapewidth(); cin >> lineshape >> linewidth; w = new solidpolygon11(Mid, id, num1, m_point1, color1, color2, lineshape, linewidth); } if (id == 7) { int num1; int m_point1[100] = { 0 }; int color1; int lineshape, linewidth; cout << "请输入折线的点数:" << endl; cin >> num1; int index1 = 1; for (int j = 0; j < 2 * num1; j += 2) { cout << "第" << index1 << "个点的x坐标: "; cin >> m_point1[j]; cout << "第" << index1 << "个点的y坐标: "; cin >> m_point1[j + 1]; index1++; } showcolor(); cin >> color1; lineshapewidth(); cin >> lineshape >> linewidth; w = new polyline1(Mid, id, num1, m_point1, color1, lineshape, linewidth); } m_graphArray[ret] = w; cout << "修改成功!" << endl; } //保存在文件中 save(); } else { cout << " 修改失败,查无此人!" << endl; } } //按任意键清屏 system("pause"); system("cls"); } //删除图形 void Graph::del_graph() { if (m_FileIsEmpty) { cout << "文件不存在或记录为空" << endl; } else { cout << "请输入想要删除的图形编号" << endl; cout << "你共有以下图形!" << endl; show_graph(); int id = 0; cin >> id; int index = isExist(id); if (index != -1)//说明图形存在并且要删除index位置上的图形 { for (int i = index; i < m_graphNum; i++) { m_graphArray[i] = m_graphArray[i + 1]; } m_graphNum--;//更新数组中记录图形的个数 save();//数据同步到文件中 cout << "删除成功" << endl; } else { cout << "删除失败,未找到该职工!" << endl; } } //按任意键清屏 system("pause"); system("cls"); } //初始化图形 将文件中的图形保存在程序中 void Graph::init_graph() { ifstream ifs; ifs.open(FILENAME, ios::in); int m_id; int id ; int x = 0, y = 0; int m_x1 = 0, m_x2 = 0;//线的参数 int m_y1 = 0, m_y2 = 0; int m_x = 0, m_y = 0; //圆的参数 int radius = 0; int left = 0; //椭圆的参数 int top = 0; int right = 0; int bottom = 0; int left1 = 0;//矩形的参数 int top1 = 0; int right1 = 0; int bottom1 = 0; int color1=0, color2=0; int lineshape = 0, linewidth = 0; int num1 = 0; int m_point1[100] = { 0 }; int index = 0; while (ifs >> id) { shape* w= NULL; if (id == 1) //点 { ifs >> x; ifs >> y; ifs >> color1; ifs >> m_id; w = new point1(m_id,id, x, y,color1); } if (id == 2) //直线 { ifs >> m_x1;ifs >> m_y1; ifs >> m_x2; ifs >> m_y2; ifs >> color1; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; w = new Line1(m_id,id, m_x1, m_y1, m_x2, m_y2, color1, lineshape, linewidth); } if (id == 3) { ifs >> m_x; ifs >> m_y; //圆的参数 ifs >> radius; ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; w = new circle1(m_id,id, m_x, m_y,radius, color1, color2, lineshape, linewidth); } if (id == 4) { ifs >> left; //椭圆的参数 ifs >> top; ifs >> right; ifs >> bottom; ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; w = new ellipse1(m_id,id, left, top, right, bottom, color1, color2, lineshape, linewidth); } if (id == 5) { ifs >> left1; //矩形的参数 ifs >> top1; ifs >> right1; ifs >> bottom1; ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; w = new rectangle1(m_id,id, left1, top1, right1, bottom1,color1, color2, lineshape, linewidth); } if (id == 6) { ifs >> num1; //多边形的参数 for (int i = 0; i < 2 * num1; i += 2) { ifs >> m_point1[i]; ifs >> m_point1[i + 1]; } ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; w = new solidpolygon11(m_id,id, num1, m_point1,color1, color2, lineshape, linewidth); } if (id == 7) { ifs >> num1; //连续线段的参数 for (int i = 0; i < 2 * num1; i += 2) { ifs >> m_point1[i]; ifs >> m_point1[i + 1]; } ifs >> color1; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; w = new polyline1(m_id,id, num1, m_point1, color1, lineshape, linewidth); } m_graphArray[index] = w; index++; } //关闭文件 ifs.close(); } //统计文件图形数量 int Graph::get_graphNum() { ifstream ifs; ifs.open(FILENAME, ios::in);//打开文件,读文件 int m_id; int Id = 0; int x = 0, y = 0; int m_x1 = 0, m_x2 = 0;//线的参数 int m_y1 = 0, m_y2 = 0; int m_x = 0, m_y = 0; //圆的参数 int radius = 0; int left = 0; //椭圆的参数 int top = 0; int right = 0; int bottom = 0; int left1 = 0;//矩形的参数 int top1 = 0; int right1 = 0; int bottom1 = 0; int color1=0, color2=0; int lineshape = 0, linewidth = 0; int num1 = 0; int m_point1[50] = { 0 }; int num = 0;// while (ifs >> Id) { if (Id == 1) { ifs >> x; ifs >> y; ifs >> color1; ifs >> m_id; num++; } if (Id == 2) { ifs >> m_x1; ifs >> m_y1; ifs >> m_x2; ifs >> m_y2; ifs >> color1; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; num++; } if (Id == 3) { ifs >> m_x; ifs >> m_y; //圆的参数 ifs >> radius; ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; num++; } if (Id == 4) { ifs >> left; //椭圆的参数 ifs >> top; ifs >> right; ifs >> bottom; ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; num++; } if (Id == 5) { ifs >> left1; //矩形的参数 ifs >> top1; ifs >> right1; ifs >> bottom1; ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; num++; } if (Id == 6) { ifs >> num1; //多边形的参数 for (int i = 0; i < 2 * num1; i += 2) { ifs >> m_point1[i]; ifs >> m_point1[i + 1]; } ifs >> color1; ifs >> color2; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; num++; } if (Id == 7) { ifs >> num1; //折线的点数 for (int i = 0; i < 2 * num1; i += 2) { ifs >> m_point1[i]; ifs >> m_point1[i + 1]; } ifs >> color1; ifs >> lineshape; ifs >> linewidth; ifs >> m_id; num++; } } return num; } //显示图形信息 void Graph::show_graph() { //判断文件是否为空 if (m_FileIsEmpty) { cout << "文件存在或记录为空!" << endl; } else { //文件存在,并且记录数据 int num = get_graphNum(); m_graphNum = num; cout << "文件中的图形的数量为:" << num << endl; m_graphArray = new shape * [m_graphNum];//开辟空间 init_graph();//将文件中的数据保存在数组中 for (int i = 0; i < m_graphNum; i++) { m_graphArray[i]->showInfo(); } } } //画出图形 void Graph::draw_graph() { //判断文件是否为空 if (m_FileIsEmpty) { cout << "文件存在或记录为空!" << endl; } else { //文件存在,并且记录数据 int num = get_graphNum(); m_graphNum = num; cout << "文件中的图形的数量为:" << num << endl; m_graphArray = new shape * [m_graphNum];//开辟空间 init_graph();//将文件中的数据保存在数组中 cout << "选择是否填充" << endl; cout << "1.不填充" << endl; cout << "2.填充" << endl; int select = 0; cin >> select; initgraph(1200, 600);//初始化绘图窗口 setbkcolor(WHITE);//设置背景色为白色 cleardevice(); //调用清屏 if(select==1) { for (int i = 0; i < m_graphNum; i++) { if (m_graphArray[i]->Id == 1) { drawline(m_graphArray[i]->m_x, m_graphArray[i]->m_y, m_graphArray[i]->color1); } if (m_graphArray[i]->Id == 2) { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setlinecolor(m_graphArray[i]->color1); line(m_graphArray[i]->m_x1, m_graphArray[i]->m_y1, m_graphArray[i]->m_x2, m_graphArray[i]->m_y2); } if (m_graphArray[i]->Id == 3) { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setfillcolor(m_graphArray[i]->color2); Setlinecolor(m_graphArray[i]->color1); fillcircle(m_graphArray[i]->m_x, m_graphArray[i]->m_y, m_graphArray[i]->radius); } if (m_graphArray[i]->Id == 4) { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setfillcolor(m_graphArray[i]->color2); Setlinecolor(m_graphArray[i]->color1); fillellipse(m_graphArray[i]->left, m_graphArray[i]->top, m_graphArray[i]->right, m_graphArray[i]->bottom); } if (m_graphArray[i]->Id == 5) { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setfillcolor(m_graphArray[i]->color2); Setlinecolor(m_graphArray[i]->color1); fillrectangle(m_graphArray[i]->left1, m_graphArray[i]->top1, m_graphArray[i]->right1, m_graphArray[i]->bottom1); } if (m_graphArray[i]->Id == 6) { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setfillcolor(m_graphArray[i]->color2); Setlinecolor(m_graphArray[i]->color1); fillpolygon((POINT*)(m_graphArray[i]->m_point), m_graphArray[i]->num); } if (m_graphArray[i]->Id == 7) { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setlinecolor(m_graphArray[i]->color1); polyline((POINT*)(m_graphArray[i]->m_point),m_graphArray[i]->num); } } } else { for (int i = 0; i < m_graphNum; i++) { if (m_graphArray[i]->Id == 1) //点 { drawline(m_graphArray[i]->m_x, m_graphArray[i]->m_y, m_graphArray[i]->color1); } if (m_graphArray[i]->Id == 2) //线 { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setlinecolor(m_graphArray[i]->color1); line(m_graphArray[i]->m_x1, m_graphArray[i]->m_y1, m_graphArray[i]->m_x2, m_graphArray[i]->m_y2); } if (m_graphArray[i]->Id == 3) //圆 { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setlinecolor(m_graphArray[i]->color1); IMAGE image; loadimage(&image, _T(".\image.jpg")); setfillstyle(BS_DIBPATTERN, NULL, &image); fillcircle(m_graphArray[i]->m_x, m_graphArray[i]->m_y, m_graphArray[i]->radius); } if (m_graphArray[i]->Id == 4) //椭圆 { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setlinecolor(m_graphArray[i]->color1); IMAGE image; loadimage(&image, _T(".\image.jpg")); setfillstyle(BS_DIBPATTERN, NULL, &image); fillellipse(m_graphArray[i]->left, m_graphArray[i]->top, m_graphArray[i]->right, m_graphArray[i]->bottom); } if (m_graphArray[i]->Id == 5) //矩形 { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setlinecolor(m_graphArray[i]->color1); IMAGE image; loadimage(&image, _T(".\image.jpg")); setfillstyle(BS_DIBPATTERN, NULL, &image); fillrectangle(m_graphArray[i]->left1, m_graphArray[i]->top1, m_graphArray[i]->right1,m_graphArray[i]->right1); } if (m_graphArray[i]->Id == 6) //多边形 { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setfillcolor(m_graphArray[i]->color2); Setlinecolor(m_graphArray[i]->color1); IMAGE image; loadimage(&image, _T(".\image.jpg")); fillpolygon((POINT*)(m_graphArray[i]->m_point), m_graphArray[i]->num); } if (m_graphArray[i]->Id == 7) //折线 { Setlinestyle(m_graphArray[i]->line_shape, m_graphArray[i]->line_width); Setlinecolor(m_graphArray[i]->color1); polyline((POINT*)(m_graphArray[i]->m_point), m_graphArray[i]->num); } } } _getch(); } } //退出系统 void Graph::exitsystem() { cout << "欢迎下次使用!" << endl; system("pause"); exit(0);//退出程序 } //选择图形的边颜色和填充颜色 void Graph::showcolor() { cout << "请选择边框颜色和填充颜色,不封闭图形仅输入线条颜色n"; cout << setw(15) << "黑色" << setw(10) << "0n" << setw(15) << "蓝色" << setw(10) << "1n" << setw(15) << "绿色" << setw(10) << "2n" << setw(15) << "蓝绿色" << setw(10) << "3n" << setw(15) << "红色" << setw(10) << "4n" << setw(15) << "洋红" << setw(10) << "5n" << setw(15) << "棕色" << setw(10) << "6n" << setw(15) << "浅灰色" << setw(10) << "7n" << setw(15) << "深灰" << setw(10) << "8n" << setw(15) << "浅蓝" << setw(10) << "9n" << setw(15) << "浅绿" << setw(10) << "10n" << setw(15) << "浅青" << setw(10) << "11n" << setw(15) << "浅红" << setw(10) << "12n" << setw(15) << "浅品红色" << setw(10) << "13n" << setw(15) << "黄" << setw(10) << "14n" << setw(15) << "白" << setw(10) << "15n"; } //选择图形边的形状和宽度 void Graph::lineshapewidth() { cout << "请选择线型和输入线宽n"; cout << setw(15) << "实线" << setw(10) << "0n" << setw(15) << "--------" << setw(10) << "1n" << setw(15) << "…………" << setw(10) << "2n" << setw(15) << "_._._." << setw(10) << "3n" << setw(15) << "_.._.._.." << setw(10) << "4n" << setw(15) << "线线不可见" << setw(10) << "5n"; } //边色 void Graph::Setlinecolor(int n) //边色 { switch (n) { case 0:setlinecolor(BLACK); break; case 1:setlinecolor(BLUE); break; case 2:setlinecolor(GREEN); break; case 3:setlinecolor(CYAN); break; case 4:setlinecolor(RED); break; case 5:setlinecolor(MAGENTA); break; case 6:setlinecolor(BROWN); break; case 7:setlinecolor(LIGHTGRAY); break; case 8:setlinecolor(DARKGRAY); break; case 9:setlinecolor(LIGHTBLUE); break; case 10:setlinecolor(LIGHTGREEN); break; case 11:setlinecolor(LIGHTCYAN); break; case 12:setlinecolor(LIGHTRED); break; case 13:setlinecolor(LIGHTMAGENTA); case 14:setlinecolor(YELLOW); case 15:setlinecolor(WHITE); default:cout << "error"; break; } } //填充的颜色 void Graph::Setfillcolor(int n) { switch (n) { case 0:setfillcolor(BLACK); break; case 1:setfillcolor(BLUE); break; case 2:setfillcolor(GREEN); break; case 3:setfillcolor(CYAN); break; case 4:setfillcolor(RED); break; case 5:setfillcolor(MAGENTA); break; case 6:setfillcolor(BROWN); break; case 7:setfillcolor(LIGHTGRAY); break; case 8:setfillcolor(DARKGRAY); break; case 9:setfillcolor(LIGHTBLUE); break; case 10:setfillcolor(LIGHTGREEN); break; case 11:setfillcolor(LIGHTCYAN); break; case 12:setfillcolor(LIGHTRED); break; case 13:setfillcolor(LIGHTMAGENTA); case 14:setfillcolor(YELLOW); case 15:setfillcolor(WHITE); default:cout << "error"; break; } } //画线的样式 void Graph::Setlinestyle(int linestyle1, int linewidth1) { switch (linestyle1) { case 0:setlinestyle(PS_SOLID,linewidth1); break; case 1:setlinestyle(PS_DASH,linewidth1); break; case 2:setlinestyle(PS_DOT,linewidth1); break; case 3:setlinestyle(PS_DASHDOT,linewidth1); break; case 4:setlinestyle(PS_DASHDOTDOT,linewidth1); break; case 5:setlinestyle(PS_NULL,linewidth1); break; default:cout << "error"; break; } } 画点 void Graph::drawline(int x,int y,int n) { switch (n) { case 0:putpixel(x,y,BLACK); break; case 1:putpixel(x, y, BLUE); break; case 2:putpixel(x, y, GREEN); break; case 3:putpixel(x, y, CYAN); break; case 4:putpixel(x, y, RED); break; case 5:putpixel(x, y, MAGENTA); break; case 6:putpixel(x, y, BROWN); break; case 7:putpixel(x, y, LIGHTGRAY); break; case 8:putpixel(x, y, DARKGRAY); break; case 9:putpixel(x, y, LIGHTBLUE); break; case 10:putpixel(x, y, LIGHTGREEN); break; case 11:putpixel(x, y, LIGHTCYAN); break; case 12:putpixel(x, y, LIGHTRED); break; case 13:putpixel(x, y, LIGHTMAGENTA); case 14:putpixel(x, y, YELLOW); case 15:putpixel(x, y, WHITE); default:cout << "error"; break; } } //清空文件 void Graph::clear_File() { cout << "确定清空吗?" << endl; cout << "1、确定" << endl; cout << "2、返回" << endl; int select = 0; cin >> select; if (select == 1) { //清空文件 ofstream ofs(FILENAME, ios::trunc);//删除文件后重新创建 ofs.close(); if (m_graphArray!= NULL) { //删除堆区的每个职工对象 for (int i = 0; i < m_graphNum; i++) { delete m_graphArray[i]; m_graphArray[i] = NULL; } // 删除堆区数组的指针 delete m_graphArray; m_graphArray = NULL; m_graphNum = 0; m_FileIsEmpty = true; } cout << "清空成功!" << endl; } system("pause"); system("cls"); } //析构函数 Graph::~Graph()//析构函数 { if (m_graphArray != NULL) { for (int i = 0; i < m_graphNum; i++) { if (m_graphArray[i]!= NULL) { delete m_graphArray[i]; } } delete[]m_graphArray; m_graphArray = NULL; } }

矢量管理系统.cpp
用户输入选择部分

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream> using namespace std; #include <graphics.h> // 引用图形库头文件 #include <conio.h> #include"graph.h" #include"Line.h" #include"shape.h" #include"Circle.h" #include"ellipse.h" #include"rectangle.h" #include"solidpolygon1.h" #include"polyline1.h" int main() { /* point* w = new line(1, 2, 3, 4); //测试代码 w->showinfo(); delete w; */ Graph wm; int choice = 0; //存储选择 while (true) { wm.show_menu(); cout << "请输入您的选择" << endl; cin >> choice; switch (choice) { case 0: //退出系统 wm.exitsystem(); break; case 1: //增加图形 wm.add_graph(); break; case 2: // 显示图形信息 wm.show_graph(); break; case 3: //画出文件中的图形 wm.draw_graph(); break; //case 4: //按照图形编号把图形排序 // wm.sort_graph(); break; case 4: //查找图形 wm.Find_graph(); break; case 5: //修改图形信息 wm.Mod_graph(); break; case 6: //按照编号删除图形 wm.del_graph(); break; case 7: //清空文件 wm.clear_File(); break; default: system("cls"); break; } } return 0; }

这是我存在系统中的图形数据,按2可以显示

可选择是否填充
不填充
填充
这个矢量管理系统的填充功能需要在同文件夹下放一个图片 名字需要是image.jpg
jpg类型的图片
在这里插入图片描述

我的文件中是这个图片
在这里插入图片描述

大一以来写代码最长的一次,将近两千行。

有很多缺点就是,画图形只能先输入图形数据,然后再画出图形,画图界面与输入数据界面不能同时存在。

其中如果输入错误数据也可能使程序崩掉,也有许多的错误。

慢慢完善!

最后

以上就是沉静灯泡最近收集整理的关于c++ easyx简单矢量管理系统大一下课程设计一级标题c++ easyx简单矢量管理系统大一下课程设计的全部内容,更多相关c++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部