cpp: pointer
VS 2022 C++有两种注释方法,一种C++的,还有一种和C#差不多。
读写文件有生成有报错,文件头行加上这行代码
#define _CRT_SECURE_NO_WARNINGS
自定义数据结构数组指针,类对象指针,不熟,瞎摸象,我不知道赋值,调用......
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 | /*****************************************************************/ /** * \file geovindu.h * \brief 业务操作方法 * * \author geovindu,Geovin Du * \date 2023-04-05 ***********************************************************************/ /* * 注释插件 https://www.doxygen.nl/download.html https://computingonplains.wordpress.com/doxygen-and-visual-studio/ https://marketplace.visualstudio.com/items?itemName=sergeb.GhostDoc https://marketplace.visualstudio.com/items?itemName=FinnGegenmantel.doxygenComments https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/comments/ */ #ifndef GEOVINDU_H #define GEOVINDU_H #include <vector> // #include directive #include <string> #include <iostream> #include <string.h> #include <list> #include<iostream> #include<fstream> #include<stdio.h> #include<cstdlib> #include<cstring> #include<iomanip> #include <vector> #include <memory> //#include <sqlite3.h> #include "PigInfo.h" #include "PigNameInfo.h" #include "CinemaScore.h" #include "OpenDoor.h" #include "LeapYear.h" #include "RandomlySampled.h" #include "NumberLottery.h" #include "InputNumberMax.h" #include "DeskKnock.h" #include "NarcissisticNumber.h" #include "NarcissisticInfo.h" #include "NarcissisticList.h" #include "MultiplicationTables.h" #include "CardinalDirection.h" #include "CSVfilemanagement.h" #include "ATMdemo.h" #include "csvstream.h" //#include "csvparser.h" #include "StudentArry.h" #include "student.h" #include "StudentMenu.h" #include "StudentList.h" //#include "GeovinStudent.h" using namespace std; /** * @brief 类库空间名 * geovindu edit * */ namespace geovindu { /** * @brief 简要说明文字 */ enum class colors : short { red, blue, purple, azure }; /** * @brief 简要说明文字 */ struct RGB { short r{ 0 }; // member initialization short g{ 0 }; short b{ 0 }; }; /// <summary> /// 信息 /// </summary> struct GeovinStudent { /// <summary> /// 姓名 /// </summary> std::string studentName; /// <summary> /// 语文 /// </summary> int chineseScore; /// <summary> /// 英语 /// </summary> int englishScore; /// <summary> /// 数学 /// </summary> int mathScore; /// <summary> /// /// </summary> int computerScore; /// <summary> /// 个人总分 /// </summary> int studentTotalScore = chineseScore + englishScore + mathScore + computerScore; //计算 无效 /// <summary> /// 平均 /// </summary> int subjectAverage; /// <summary> /// 名次 /// </summary> int rankingScore; }; /// <summary> /// 语文成绩排序,降 从大到小 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpChineseAsc( const GeovinStudent* a, const GeovinStudent* b) { return a->chineseScore > b->chineseScore; } /// <summary> /// 语文成绩排序,升 从小到大 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpChineseDesc(GeovinStudent* a, GeovinStudent* b) { return a->chineseScore < b->chineseScore; } /// <summary> /// 英语成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpEnglishDesc(GeovinStudent* a, GeovinStudent* b) { return a->englishScore > b->englishScore; } /// <summary> /// 英语成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpEnglishAsc(GeovinStudent* a, GeovinStudent* b) { return a->englishScore < b->englishScore; } /// <summary> /// 数学成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpMathDesc(GeovinStudent* a, GeovinStudent* b) { return a->mathScore > b->mathScore; } /// <summary> /// 数学成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpMathAsc(GeovinStudent* a, GeovinStudent* b) { return a->mathScore < b->mathScore; } /// <summary> /// 计算机成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpComputerDesc(GeovinStudent* a, GeovinStudent* b) { return a->computerScore > b->computerScore; } /// <summary> /// 计算机成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpComputerAsc(GeovinStudent* a, GeovinStudent* b) { return a->computerScore < b->computerScore; } /// <summary> /// 个人总分成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpTotalScoreDesc(GeovinStudent* a, GeovinStudent* b) { return a->studentTotalScore > b->studentTotalScore; } /// <summary> /// 个人总分成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpTotalScoreAsc(GeovinStudent* a, GeovinStudent* b) { return a->studentTotalScore < b->studentTotalScore; } // Function for comparing two students according // to given rules /// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool compareTwoStudentsPoointer( const GeovinStudent* a, const GeovinStudent* b) { // If total marks are not same then // returns true for higher total if (a->studentTotalScore != b->studentTotalScore) return a->studentTotalScore > b->studentTotalScore; // If marks in Maths are same then // returns true for higher marks if (a->chineseScore != b->chineseScore) return a->chineseScore > b->chineseScore; if (a->computerScore != b->computerScore) return a->computerScore > b->computerScore; if (a->englishScore != b->englishScore) return a->englishScore > b->englishScore; return (a->mathScore > b->mathScore); } // Fills total marks and ranks of all Students /// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="n"></param> void computeRanksPoointer(GeovinStudent* a[], int n) { // To calculate total marks for all Students for ( int i = 0; i < n; i++) //a[i]->studentTotalScore = a[i]->chineseScore + a[i]->computerScore + a[i]->englishScore+a[i]->mathScore; // Sort structure array using user defined // function compareTwoStudents() sort(a, a + n, compareTwoStudentsPoointer); //sort(bgein(a), end(a), compareTwoStudents); // Assigning ranks after sorting for ( int i = 0; i < n; i++) { //a[i]->rankingScore = i + 1; } } // Function for comparing two students according // to given rules bool compareTwoStudents(GeovinStudent a, GeovinStudent b) { // If total marks are not same then // returns true for higher total if (a.studentTotalScore != b.studentTotalScore) return a.studentTotalScore > b.studentTotalScore; // If marks in Maths are same then // returns true for higher marks if (a.chineseScore != b.chineseScore) return a.chineseScore > b.chineseScore; if (a.computerScore != b.computerScore) return a.computerScore > b.computerScore; if (a.englishScore != b.englishScore) return a.englishScore > b.englishScore; return (a.mathScore > b.mathScore); } // Fills total marks and ranks of all Students void computeRanks(GeovinStudent a[], int n) { // To calculate total marks for all Students for ( int i = 0; i < n; i++) a[i].studentTotalScore = a[i].chineseScore + a[i].computerScore + a[i].englishScore + a[i].mathScore; // Sort structure array using user defined // function compareTwoStudents() sort(a, a + n, compareTwoStudents); //sort(bgein(a), end(a), compareTwoStudents); // Assigning ranks after sorting for ( int i = 0; i < n; i++) { a[i].rankingScore = i + 1; } } /** *@brief if 比较小猪等作业 实现方法业务 * edit: geovindu */ class Geovin { private : public : /** *@brief *三只小猪重量比较方法(函数) * eidt: geovindu */ void getPig(); /** *@brief *数据类型占内存空间 * edig: geovindu */ void dataTypeSize(); /** *@brief *实体类三只小猪重量比较方法(函数) *edit: geovindu */ void getPigClass(); /** *@brief *画星行列显示 方法(函数) *eidit: geovindu */ void displayFiveStars(); /** *@brief *@param [int] 输入参数名称 行数 *@param [int] 输入参数名称 列数 *运画星行列显示方法(函数) * ediit: geovindu */ void displayFiveStars( int row, int column); /** *@brief *@param [char] 输入参数名称 ASCii字符数组 *ASCii显示方法(函数) * ediit: geovindu */ void displayASCII( char ascii[]); /** *@brief *@param [long] 输入参数名称 运算的第一个数 *@param [long] 输入参数名称 运算的第二个数 *运算符示例 方法(函数) * ediit: geovindu */ void dipslayOperate( long a, long b); /** *@brief *@param [int] 输入参数 第一个整数 *@param [int] 输入参数 第二个整数 *三目运算符示例的显示方法(函数) * ediit: geovindu */ void TrinocularOperator( int a, int b); /** *@brief *@param [long] 输入参数 成绩分数 *判断成绩的及格否(函数) * ediit: geovindu */ void IsPassExamination( long exam); /** * @brief */ void DisplayCinema(); /** * @brief */ void DisplayDoor(); /** * @brief */ void DisplayDays(); /** * @brief */ void DisplayWhile(); /** * @brief */ void DisplayRomd(); /** * @brief */ void DisplayRomd( int number); /** * @brief */ void DisplayRomd( int number, std::list<std::string> choices); /** * @brief. * */ void DisplayNumberLottery(); /** * @brief. * * \param maxnum 【int】输入参数: 整数 */ void DisplayMaxSum( int maxnum); /** * @brief .敲桌子 * * \param maxnum 【int】输入参数: 整数 */ void DisplayDeskKnock( int maxnum); /** * @brief 水仙花数. * 100至1000内的三位数的水仙花数 */ void DisplayNarcissisticNumber(); /** * @brief 水仙花数. * 指定范围内的整数中的水仙花数 * \param min 输入参数 【int】 范围内的最小整数 * \param max 输入参数 【int】 范围内的最大整数 */ void DisplayNarcissisticNumber( int min, int max); /** * @brief 水仙花数. 实体类 * 100至1000内的三位数的水仙花数 */ list<NarcissisticInfo> DisplayNarcissicticInfos(); //NarcissisticInfo getInfo(); /** * @brief . * * \return */ NarcissisticList getInfo(); /** * @brief. * */ void DisplayMultiplicationTables(); /** * @brief 写. * */ void CsvCreate(); /// <summary> /// /// </summary> void DisplayAtemDemo(); /// <summary> /// /// </summary> void Displaycsv(); /** * @brief 显示学生成绩 * * */ void displayScore(); /// <summary> /// /// </summary> void StudentWelcome(); /// <summary> /// /// </summary> void StudentMenuDisplay(); /// <summary> /// /// </summary> void DisplayStudent(); /// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> //bool compareTwoStudents(const GeovinStudent* a,const GeovinStudent* b); /// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="n"></param> //void computeRanks(const GeovinStudent (*a)[], int n); /// <summary> /// /// </summary> void DisplayVectorStudent(); }; /// <summary> /// /// </summary> void Geovin::DisplayVectorStudent() { //GeovinStudent* slist = new GeovinStudent[3]; GeovinStudent slist[3]; //slist ={ //{"geovin",25,45,95,75},{"张三",55,65,45,55},{"涂聚文",25,85,95,75} // };; slist[0] = { "geovin" ,25,45,95,75 }; slist[1] = { "张三" ,55,65,45,55}; slist[2] = { "涂聚文" ,25,85,95,75 }; //GeovinStudent* slistPointer = new GeovinStudent[3]; //GeovinStudent* stuDu = new GeovinStudent; //stuDu->studentName = "geovin"; //stuDu->chineseScore = 25; //stuDu->computerScore = 45; //stuDu->englishScore = 95; //stuDu->mathScore = 75; ////slistPointer= &slist; //stuDu = &slistPointer[0]; GeovinStudent* slistPointer[3]; //slistPointer[0]->studentName = "";// {"geovin", 25, 45, 95, 75 }; //slist = { }; GeovinStudent* student = new GeovinStudent; student->studentName = "geovin" ; student->chineseScore = 25; student->computerScore = 45; student->englishScore = 95; student->mathScore = 75; vector<GeovinStudent *> stu; stu.push_back(student); slistPointer[0]= student; GeovinStudent* student2 = new GeovinStudent; student2->studentName = "张三" ; student2->chineseScore = 55; student2->computerScore = 89; student2->englishScore = 94; student2->mathScore = 62; stu.push_back(student2); slistPointer[1]= student2; GeovinStudent* student3 = new GeovinStudent; student3->studentName = "涂聚文" ; student3->chineseScore = 35; student3->computerScore = 85; student3->englishScore = 45; student3->mathScore = 95; stu.push_back(student3); slistPointer[2]== student3; //GeovinStudent* stu1 = new GeovinStudent; // // sort(begin(stu),end(stu), cmpChineseAsc); //vector<GeovinStudent> slist; //vector<GeovinStudent*> slist; // GeovinStudent student; //student.studentName = "geovin"; //student.chineseScore = 25; //student.computerScore = 45; //student.englishScore = 95; //student.mathScore = 75; //slist.push_back(student); //student.studentName = "张三"; //student.chineseScore = 55; //student.computerScore = 65; //student.englishScore = 45; //student.mathScore = 55; //slist.push_back(student); //student.studentName = "涂聚文"; //student.chineseScore = 25; //student.computerScore = 85; //student.englishScore = 85; //student.mathScore = 75; //slist.push_back(student); //cout << "姓名" << "语文" << "英语" << "数学"<<"总分" << endl; //for (auto du : slist) //{ // cout << du.studentName << du.chineseScore << du.computerScore << du.englishScore << du.mathScore << du.studentTotalScore << endl; //} cout << "姓名\t" << "语文\t" << "计算机\t" << "英语\t" << "数学\t" << "总分\t" << endl; for ( auto du : stu) { du->studentTotalScore = du->chineseScore + du->englishScore + du->mathScore + du->computerScore; cout << du->studentName<< "\t" << du->chineseScore << "\t" << du->computerScore << "\t" << du->englishScore << "\t" << du->mathScore << "\t" << du->studentTotalScore << endl; } sort(begin(stu), end(stu), cmpMathDesc); //数学排序 //sort(slist,slist.size(), cmpMathAsc) //sort(stu, stu.size(), cmpMathAsc) cout << "*********数学排序****************" << endl; for ( auto du : stu) { du->studentTotalScore = du->chineseScore + du->englishScore + du->mathScore + du->computerScore; cout << du->studentName << "\t" << du->chineseScore << "\t" << du->computerScore << "\t" << du->englishScore << "\t" << du->mathScore << "\t" << du->studentTotalScore << endl; } cout << "**********总分排序***************" << endl; computeRanks(slist, 3); for ( auto du : slist) { cout << du.studentName << "\t" << du.chineseScore << "\t" << du.computerScore << "\t" << du.englishScore << "\t" << du.mathScore << "\t" << du.studentTotalScore << endl; } cout << "**********总分排序***************" << endl; computeRanksPoointer(slistPointer, 3); for ( auto du : slistPointer) { cout << du->studentName << "\t" << du->chineseScore << "\t" << du->computerScore << "\t" << du->englishScore << "\t" << du->mathScore << "\t" << du->studentTotalScore << endl; } } |
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 | /*****************************************************************/ /** * \file geovindu.h * \brief 业务操作方法 * * \author geovindu,Geovin Du * \date 2023-04-05 ***********************************************************************/ /* * 注释插件 https://www.doxygen.nl/download.html https://computingonplains.wordpress.com/doxygen-and-visual-studio/ https://marketplace.visualstudio.com/items?itemName=sergeb.GhostDoc https://marketplace.visualstudio.com/items?itemName=FinnGegenmantel.doxygenComments https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/comments/ */ #ifndef GEOVINDU_H #define GEOVINDU_H #include <vector> // #include directive #include <string> #include <iostream> #include <string.h> #include <list> #include<iostream> #include<fstream> #include<stdio.h> #include<cstdlib> #include<cstring> #include<iomanip> #include <vector> #include <memory> //#include <sqlite3.h> #include "PigInfo.h" #include "PigNameInfo.h" #include "CinemaScore.h" #include "OpenDoor.h" #include "LeapYear.h" #include "RandomlySampled.h" #include "NumberLottery.h" #include "InputNumberMax.h" #include "DeskKnock.h" #include "NarcissisticNumber.h" #include "NarcissisticInfo.h" #include "NarcissisticList.h" #include "MultiplicationTables.h" #include "CardinalDirection.h" #include "CSVfilemanagement.h" #include "ATMdemo.h" #include "csvstream.h" //#include "csvparser.h" #include "StudentArry.h" #include "student.h" #include "StudentMenu.h" #include "StudentList.h" //#include "GeovinStudent.h" using namespace std; /** * @brief 类库空间名 * geovindu edit * */ namespace geovindu { /** * @brief 简要说明文字 */ enum class colors : short { red, blue, purple, azure }; /** * @brief 简要说明文字 */ struct RGB { short r{ 0 }; // member initialization short g{ 0 }; short b{ 0 }; }; /// <summary> /// 信息 /// </summary> struct GeovinStudent { /// <summary> /// 姓名 /// </summary> std::string studentName; /// <summary> /// 语文 /// </summary> int chineseScore; /// <summary> /// 英语 /// </summary> int englishScore; /// <summary> /// 数学 /// </summary> int mathScore; /// <summary> /// /// </summary> int computerScore; /// <summary> /// 个人总分 /// </summary> int studentTotalScore = chineseScore + englishScore + mathScore + computerScore; //计算 无效 /// <summary> /// 平均 /// </summary> int subjectAverage; /// <summary> /// 名次 /// </summary> int rankingScore; }; /// <summary> /// 语文成绩排序,降 从大到小 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpChineseAsc( const GeovinStudent* a, const GeovinStudent* b) { return a->chineseScore > b->chineseScore; } /// <summary> /// 语文成绩排序,升 从小到大 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpChineseDesc(GeovinStudent* a, GeovinStudent* b) { return a->chineseScore < b->chineseScore; } /// <summary> /// 英语成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpEnglishDesc(GeovinStudent* a, GeovinStudent* b) { return a->englishScore > b->englishScore; } /// <summary> /// 英语成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpEnglishAsc(GeovinStudent* a, GeovinStudent* b) { return a->englishScore < b->englishScore; } /// <summary> /// 数学成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpMathDesc(GeovinStudent* a, GeovinStudent* b) { return a->mathScore > b->mathScore; } /// <summary> /// 数学成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpMathAsc(GeovinStudent* a, GeovinStudent* b) { return a->mathScore < b->mathScore; } /// <summary> /// 计算机成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpComputerDesc(GeovinStudent* a, GeovinStudent* b) { return a->computerScore > b->computerScore; } /// <summary> /// 计算机成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpComputerAsc(GeovinStudent* a, GeovinStudent* b) { return a->computerScore < b->computerScore; } /// <summary> /// 个人总分成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpTotalScoreDesc(GeovinStudent* a, GeovinStudent* b) { return a->studentTotalScore > b->studentTotalScore; } /// <summary> /// 个人总分成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpTotalScoreAsc(GeovinStudent* a, GeovinStudent* b) { return a->studentTotalScore < b->studentTotalScore; } //// Function for comparing two students according //// to given rules //bool compareTwoStudents(GeovinStudent* a, GeovinStudent* b) //{ // // If total marks are not same then // // returns true for higher total // if (a->studentTotalScore != b->studentTotalScore) // return a->studentTotalScore > b->studentTotalScore; // // If marks in Maths are same then // // returns true for higher marks // if (a->chineseScore != b->chineseScore) // return a->chineseScore > b->chineseScore; // if (a->computerScore != b->computerScore) // return a->computerScore > b->computerScore; // if (a->englishScore != b->englishScore) // return a->englishScore > b->englishScore; // return (a->mathScore > b->mathScore); //} //// Fills total marks and ranks of all Students //void computeRanks(GeovinStudent* a[], int n) //{ // // To calculate total marks for all Students // for (int i = 0; i < n; i++) // a[i]->studentTotalScore = a[i]->chineseScore + a[i]->computerScore + a[i]->englishScore+a[i]->mathScore; // // Sort structure array using user defined // // function compareTwoStudents() // sort(a, a + n, compareTwoStudents); // //sort(bgein(a), end(a), compareTwoStudents); // // Assigning ranks after sorting // for (int i = 0; i < n; i++) // { // a[i]->rankingScore = i + 1; // } //} // Function for comparing two students according // to given rules bool compareTwoStudents(GeovinStudent a, GeovinStudent b) { // If total marks are not same then // returns true for higher total if (a.studentTotalScore != b.studentTotalScore) return a.studentTotalScore > b.studentTotalScore; // If marks in Maths are same then // returns true for higher marks if (a.chineseScore != b.chineseScore) return a.chineseScore > b.chineseScore; if (a.computerScore != b.computerScore) return a.computerScore > b.computerScore; if (a.englishScore != b.englishScore) return a.englishScore > b.englishScore; return (a.mathScore > b.mathScore); } // Fills total marks and ranks of all Students void computeRanks(GeovinStudent a[], int n) { // To calculate total marks for all Students for ( int i = 0; i < n; i++) a[i].studentTotalScore = a[i].chineseScore + a[i].computerScore + a[i].englishScore + a[i].mathScore; // Sort structure array using user defined // function compareTwoStudents() sort(a, a + n, compareTwoStudents); //sort(bgein(a), end(a), compareTwoStudents); // Assigning ranks after sorting for ( int i = 0; i < n; i++) { a[i].rankingScore = i + 1; } } /** *@brief if 比较小猪等作业 实现方法业务 * edit: geovindu */ class Geovin { private : public : /** *@brief *三只小猪重量比较方法(函数) * eidt: geovindu */ void getPig(); /** *@brief *数据类型占内存空间 * edig: geovindu */ void dataTypeSize(); /** *@brief *实体类三只小猪重量比较方法(函数) *edit: geovindu */ void getPigClass(); /** *@brief *画星行列显示 方法(函数) *eidit: geovindu */ void displayFiveStars(); /** *@brief *@param [int] 输入参数名称 行数 *@param [int] 输入参数名称 列数 *运画星行列显示方法(函数) * ediit: geovindu */ void displayFiveStars( int row, int column); /** *@brief *@param [char] 输入参数名称 ASCii字符数组 *ASCii显示方法(函数) * ediit: geovindu */ void displayASCII( char ascii[]); /** *@brief *@param [long] 输入参数名称 运算的第一个数 *@param [long] 输入参数名称 运算的第二个数 *运算符示例 方法(函数) * ediit: geovindu */ void dipslayOperate( long a, long b); /** *@brief *@param [int] 输入参数 第一个整数 *@param [int] 输入参数 第二个整数 *三目运算符示例的显示方法(函数) * ediit: geovindu */ void TrinocularOperator( int a, int b); /** *@brief *@param [long] 输入参数 成绩分数 *判断成绩的及格否(函数) * ediit: geovindu */ void IsPassExamination( long exam); /** * @brief */ void DisplayCinema(); /** * @brief */ void DisplayDoor(); /** * @brief */ void DisplayDays(); /** * @brief */ void DisplayWhile(); /** * @brief */ void DisplayRomd(); /** * @brief */ void DisplayRomd( int number); /** * @brief */ void DisplayRomd( int number, std::list<std::string> choices); /** * @brief. * */ void DisplayNumberLottery(); /** * @brief. * * \param maxnum 【int】输入参数: 整数 */ void DisplayMaxSum( int maxnum); /** * @brief .敲桌子 * * \param maxnum 【int】输入参数: 整数 */ void DisplayDeskKnock( int maxnum); /** * @brief 水仙花数. * 100至1000内的三位数的水仙花数 */ void DisplayNarcissisticNumber(); /** * @brief 水仙花数. * 指定范围内的整数中的水仙花数 * \param min 输入参数 【int】 范围内的最小整数 * \param max 输入参数 【int】 范围内的最大整数 */ void DisplayNarcissisticNumber( int min, int max); /** * @brief 水仙花数. 实体类 * 100至1000内的三位数的水仙花数 */ list<NarcissisticInfo> DisplayNarcissicticInfos(); //NarcissisticInfo getInfo(); /** * @brief . * * \return */ NarcissisticList getInfo(); /** * @brief. * */ void DisplayMultiplicationTables(); /** * @brief 写. * */ void CsvCreate(); /// <summary> /// /// </summary> void DisplayAtemDemo(); /// <summary> /// /// </summary> void Displaycsv(); /** * @brief 显示学生成绩 * * */ void displayScore(); /// <summary> /// /// </summary> void StudentWelcome(); /// <summary> /// /// </summary> void StudentMenuDisplay(); /// <summary> /// /// </summary> void DisplayStudent(); /// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> //bool compareTwoStudents(const GeovinStudent* a,const GeovinStudent* b); /// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="n"></param> //void computeRanks(const GeovinStudent (*a)[], int n); /// <summary> /// /// </summary> void DisplayVectorStudent(); }; /// <summary> /// /// </summary> void Geovin::DisplayVectorStudent() { //GeovinStudent* slist = new GeovinStudent[3]; GeovinStudent slist[3]; //slist ={ //{"geovin",25,45,95,75},{"张三",55,65,45,55},{"涂聚文",25,85,95,75} // };; slist[0] = { "geovin" ,25,45,95,75 }; slist[1] = { "张三" ,55,65,45,55}; slist[2] = { "涂聚文" ,25,85,95,75 }; //slist = { }; GeovinStudent* student = new GeovinStudent; student->studentName = "geovin" ; student->chineseScore = 25; student->computerScore = 45; student->englishScore = 95; student->mathScore = 75; vector<GeovinStudent *> stu; stu.push_back(student); GeovinStudent* student2 = new GeovinStudent; student2->studentName = "张三" ; student2->chineseScore = 55; student2->computerScore = 89; student2->englishScore = 94; student2->mathScore = 62; stu.push_back(student2); GeovinStudent* student3 = new GeovinStudent; student3->studentName = "涂聚文" ; student3->chineseScore = 35; student3->computerScore = 85; student3->englishScore = 45; student3->mathScore = 95; stu.push_back(student3); //GeovinStudent* stu1 = new GeovinStudent; // // sort(begin(stu),end(stu), cmpChineseAsc); //vector<GeovinStudent> slist; //vector<GeovinStudent*> slist; // GeovinStudent student; //student.studentName = "geovin"; //student.chineseScore = 25; //student.computerScore = 45; //student.englishScore = 95; //student.mathScore = 75; //slist.push_back(student); //student.studentName = "张三"; //student.chineseScore = 55; //student.computerScore = 65; //student.englishScore = 45; //student.mathScore = 55; //slist.push_back(student); //student.studentName = "涂聚文"; //student.chineseScore = 25; //student.computerScore = 85; //student.englishScore = 85; //student.mathScore = 75; //slist.push_back(student); //cout << "姓名" << "语文" << "英语" << "数学"<<"总分" << endl; //for (auto du : slist) //{ // cout << du.studentName << du.chineseScore << du.computerScore << du.englishScore << du.mathScore << du.studentTotalScore << endl; //} cout << "姓名\t" << "语文\t" << "计算机\t" << "英语\t" << "数学\t" << "总分\t" << endl; for ( auto du : stu) { du->studentTotalScore = du->chineseScore + du->englishScore + du->mathScore + du->computerScore; cout << du->studentName<< "\t" << du->chineseScore << "\t" << du->computerScore << "\t" << du->englishScore << "\t" << du->mathScore << "\t" << du->studentTotalScore << endl; } sort(begin(stu), end(stu), cmpMathDesc); //数学排序 //sort(slist,slist.size(), cmpMathAsc) //sort(stu, stu.size(), cmpMathAsc) cout << "*********数学排序****************" << endl; for ( auto du : stu) { du->studentTotalScore = du->chineseScore + du->englishScore + du->mathScore + du->computerScore; cout << du->studentName << "\t" << du->chineseScore << "\t" << du->computerScore << "\t" << du->englishScore << "\t" << du->mathScore << "\t" << du->studentTotalScore << endl; } cout << "**********总分排序***************" << endl; computeRanks(slist, 3); for ( auto du : slist) { cout << du.studentName << "\t" << du.chineseScore << "\t" << du.computerScore << "\t" << du.englishScore << "\t" << du.mathScore << "\t" << du.studentTotalScore << endl; } } |
以下这样写的,无法去引用,引用就报错:
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 | // GeovinStudent.h : 此文件包含 "GeovinStudent" 类。学生数组成绩显示方法 C++ 14 // 2023年4月19日 涂聚文 Geovin Du edit. #pragma once #ifndef GEOVINSTUDENT_H #define GEOVINSTUDENT_H #include<iostream> #include<string> #include<string.h> #include<sstream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; /** * */ namespace geovindu { /// <summary> /// 信息 /// </summary> struct GeovinStudent { /// <summary> /// 姓名 /// </summary> std::string studentName; /// <summary> /// 语文 /// </summary> int chineseScore; /// <summary> /// 英语 /// </summary> int englishScore; /// <summary> /// 数学 /// </summary> int mathScore; /// <summary> /// /// </summary> int computerScore; /// <summary> /// 个人总分 /// </summary> int studentTotalScore = chineseScore + englishScore + mathScore + computerScore; //无效 /// <summary> /// 平均 /// </summary> int subjectAverage; /// <summary> /// 名次 /// </summary> int rankingScore; }; /// <summary> /// 语文成绩排序,降 从大到小 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpChineseAsc(GeovinStudent a, GeovinStudent b) { return a.chineseScore > b.chineseScore; } /// <summary> /// 语文成绩排序,升 从小到大 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpChineseDesc(GeovinStudent a, GeovinStudent b) { return a.chineseScore < b.chineseScore; } /// <summary> /// 英语成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpEnglishAsc(GeovinStudent a, GeovinStudent b) { return a.englishScore > b.englishScore; } /// <summary> /// 英语成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpEnglishDesc(GeovinStudent a, GeovinStudent b) { return a.englishScore < b.englishScore; } /// <summary> /// 数学成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpMathAsc(GeovinStudent a, GeovinStudent b) { return a.mathScore > b.mathScore; } /// <summary> /// 数学成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpMathDesc(GeovinStudent a, GeovinStudent b) { return a.mathScore < b.mathScore; } /// <summary> /// 计算机成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpComputerAsc(GeovinStudent a, GeovinStudent b) { return a.computerScore > b.computerScore; } /// <summary> /// 计算机成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpComputerDesc(GeovinStudent a, GeovinStudent b) { return a.computerScore < b.computerScore; } /// <summary> /// 个人总分成绩排序,降 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpTotalScoreAsc(GeovinStudent a, GeovinStudent b) { return a.studentTotalScore > b.studentTotalScore; } /// <summary> /// 个人总分成绩排序,升 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> bool cmpTotalScoreDesc(GeovinStudent a, GeovinStudent b) { return a.studentTotalScore < b.studentTotalScore; } } #endif |
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 | // GeovinStudentSort.cpp : 此文件包含 "GeovinStudentSort" 类。学生数组成绩显示方法 C++ 14 // 2023年4月19日 涂聚文 Geovin Du edit. #include "GeovinStudentSort.h" #include<iostream> #include<fstream> #include<stdio.h> #include<cstdlib> #include<cstring> #include<iomanip> #include <list> #include <vector> #include <memory> #include "GeovinStudent.h" using namespace std; /** * */ namespace geovindu { /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::ChineseAsc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpChineseAsc); list = student; return list; } /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::ChineseDesc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpChineseDesc); list = student; return list; } /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::EnlgishAsc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpEnglishAsc); list = student; return list; } /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::EnlgishDesc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpEnglishDesc); list = student; return list; } /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::MathAsc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpMathAsc); list = student; return list; } /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::MathDesc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpMathDesc); list = student; return list; } /// <summary> /// Computer /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::ComputerAsc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpComputerAsc); list = student; return list; } /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::ComputerDesc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpComputerDesc); list = student; return list; } /// <summary> /// TotalScore /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::TotalScoreAsc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpTotalScoreAsc); list = student; return list; } /// <summary> /// /// </summary> /// <param name="student"></param> /// <returns></returns> vector<GeovinStudent> GeovinStudentSort::TotalScoreDesc(vector<GeovinStudent> student) { vector<GeovinStudent> list; sort(std::begin(student), std::end(student), cmpTotalScoreDesc); list = student; return list; } } |
以上写法不能引用,引用报错,
Automatically Detecting Text Encodings
https://github.com/AutoItConsulting/text-encoding-detect
https://preshing.com/20200727/automatically-detecting-text-encodings-in-cpp/
https://github.com/arc80/plywood
https://learn.microsoft.com/en-us/answers/questions/1058919/automatically-detect-text-file-encoding
https://www.codeproject.com/articles/17201/detect-encoding-for-in-and-outgoing-text
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
Cpp programming
标签:
指针
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!