//Author: Kevin // Level order prints the cars by price or MPG void specialPrintMenu() { bool isGood = false; while (!isGood) { clearScreen(); cout << "Special print cars with which parameter?" << endl; cout << "1. Print by MPG" << endl; cout << "2. Print by price" << endl; cout << "0. Return to misc" << endl; cout << ": "; int choice = getUserInputAsInt(0, 2); switch (choice) { case 0: isGood = true; break; case 1: mpgBST.levelOrderPrint(); pauseProgram(); break; case 2: priceBST.levelOrderPrint(); pauseProgram(); break; } } }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(11) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main(void) { restartProgram: //宣告與定義(Declaration & Definition) //define input float numf; //--------------------- //call print title function printTitle(); //提示輸入 //版本:1.00(1) printf("請輸入一個實數:"); scanfTriggered = 1; scanf("%f", &numf); //output printf("它的三倍是 %.3f。 ", numf * 3); //pauseProgram if(pauseProgram()) { goto restartProgram; } //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(10) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main() { //宣告與定義(Declaration & Definition) //--------------------- //code from problem char str1[100] = "A funny guy. @@"; /*test01 char str1[100] = "abcdefghi"; *///test01 char str2[100] = "It is 10:15 now."; encrypt(str1); encrypt(str2); printf("Encrypted str1: %s\n", str1); printf("Encrypted str2: %s\n", str2); //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//Author: Kevin // Shows the results of the HashTable efficiency test void testHashEfficiency() { int min = INT_MAX; int max = INT_MIN; int sum = 0; double size = numOfCars; for (int i = 0; i < size; i++) { Car car = carList[i]; int accesses = reviewTable.getNumAccesses(car.getMake(), car.getModel()); if (accesses < min) min = accesses; if (accesses > max) max = accesses; sum = sum + accesses; } clearScreen(); cout << "The load factor is: " << size/reviewTable.getTableSize() << endl; cout << "The minimum amount of accesses before finding a key's value is: " << min << endl; cout << "The maximum amount of accesses before finding a key's value is: " << max << endl; cout << "The average amount of accesses before finding a key's value is: " << sum/size << endl << endl; pauseProgram(); }
//Author: Han // Displays the following statistics: # of reviews/cars, most/least reviewed car, and highest rated car void statsMenu() { clearScreen(); cout << "Total number of reviews in Welp: " << reviewTable.getTotalNumObjects() << endl; cout << "Total number of cars in Welp: " << numOfCars << endl << endl; cout << "Most viewed car: " << viewHeap.getMaxObject() << endl; cout << "Most reviewed car: " << reviewTable.getMax() << endl; cout << "Highest rated car: " << avgRatingBST.maximum().getName() << endl << endl; pauseProgram(); }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(11) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main(void) {restartProgram: //宣告與定義(Declaration & Definition) //--------------------- //print title printTitle(); //第一題 printf("第一題(25分)\n-------------------\n"); q1main(); printf("-------------------\n"); //第二題 printf("第二題(8分)\n-------------------\n"); q2main(); printf("-------------------\n"); //第三題 printf("第三題(12分)\n-------------------\n"); q3main(); printf("-------------------\n"); //第四題 printf("第四題(10分)\n-------------------\n"); q4main(); printf("-------------------\n"); //第五題 printf("第五題\n-------------------\n"); if(q5main() == 0) { printf("\n您的電腦隨機存取記憶體(RAM)可用空間不足,無法演示第五題\n請減少原始碼中PERSONTOTAL常數之大小\n"); printf("\n答案請參閱原始碼\n"); printf("-------------------\n"); } //第六題 printf("第六題(15分)\n-------------------\n"); q6main(); //printf("-------------------\n"); //pauseProgram if(pauseProgram() == 1) { goto restartProgram; } ////pauseProgram //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//main函數架構 //版本:1.00(9) //軟體的運行從main函數開始 int main(void) { //宣告與定義(Declaration & Definition) //--------------------- //printTitle //printTitle(); /*test1 printf("TESTING\ Testing"); */ /*test2 printf("TESTING""TESTING"); */ /*test3 printf("TESTING\n" "TESTING\n" "HILLING "); */ /*test4 printf(""); */ /*test5 char * p; p = "abc"; printf(p); */ /*test 6 "abc"[1] = 'x'; printf("%c", "abc"[1]); */ //test 7 printf("%c", digit_to_hex_char(10)); // //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(10) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main(void) {restartProgram: //宣告與定義(Declaration & Definition) //char. array for saving input string char inputString[13];//four UTF-8 characters MAX., include \0 //--------------------- //prompt //版本:1.00(0) printf("請輸入姓名:"); scanfTriggered = 1; scanf("%s", inputString); { //declare unsigned short int howManyWords; //determine the BIG5 length of the inputString howManyWords = strlen(inputString) / 2; //char array for name and surname char surName[5];//two Big5 char.&& null char. char name[7];//max three Big5 char. //save surname strncpy(surName, inputString, howManyWords == 4/*如果名字有4個字的話就表示有複姓*/ ? 4 : 2); //remember to append a null char.! surName[howManyWords == 4/*如果名字有4個字的話就表示有複姓*/ ? 4 : 2] = '\0'; //save name strncpy(name, inputString + (howManyWords == 4/*如果名字有4個字的話就表示有複姓*/ ? 4 : 2), (howManyWords == 2/*如果名字只有2個字的話就表示單名*/ ? 2 : 4)); //remember to append a null char.! name[howManyWords == 2 ? 2 : 4] = '\0'; //output printf("%s教授%s博士", surName, name); } //pauseProgram if(pauseProgram()) { goto restartProgram; } //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(9) //軟體的運行從main函數開始 //partial code is given by the question int main() { //宣告與定義(Declaration & Definition) //--------------------- //partial code is given by the question printSymbol('$', 13);//print out 13 $'s printSymbol('@', 20);//print out 20 @'s printSymbol('&', 7);//print out 7 &'s //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//mainšçŒÆ¬[ºc //ª©¥»¡G1.00(9) //³nÅ骺¹BŠæ±qmainšçŒÆ¶}©l int main() { //«Å§i»P©wžq(Declaration & Definition) //¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð //printTitle //printTitle(); //code from problem //data given int a[13] = {65, 0, -5, -22, 9, 231, 43, -7, 11, -65, 0, -18, 65}; int b[14] = {65, 0, -5, -22, 9, 231, 43, -7, 11, 65, 0, -18, 65, 88}; int c[14] = {65, 0, 5, 22, 9, 231, 43, 7, 11, 65, 0, 18, 65, 88}; //print the original list in a[]; printf("ì¥ý a[] ¬° {65, 0, -5, -22, 9, 231, 43, -7, 11, -65, 0, -18, 65}\n"); //print the original list in b[]; printf("ì¥ý b[] ¬° {65, 0, -5, -22, 9, 231, 43, -7, 11, 65, 0, -18, 65, 88}\n"); //print the original list in c[]; printf("ì¥ý c[] ¬° {65, 0, 5, 22, 9, 231, 43, 7, 11, 65, 0, 18, 65, 88}\n"); //call func. strangeFunc(a, 13); strangeFunc(b, 14); strangeFunc(c, 14); //print blank line printf("\n"); //print the modified list in a[]; printf("«ášÓ a[] ¬° {%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d}\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12]); //print the modified list in b[]; printf("«ášÓ b[] ¬° {%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d}\n", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13]); //print the modified list in c[]; printf("«ášÓ c[] ¬° {%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d}\n", c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13]); //pause pauseProgram(); //¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð¡Ð //¶ÇŠ^ŒÆŠr¢¯¡]ªíµ{Š¡¹BŠæŠš¥\¡^ //ª©¥»¡G1.00(1) //return«á±€£¥i¥[µùžÑ¡I return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(8) //軟體的運行從main函數開始 int main(void) { //宣告與定義(Declaration & Definition) //define short int myArray[100]; //debug define short int counterDebug; //assign 1 to all array short int counterA; //--------------------- //標題 //版本:1.00(4) printf("程式名稱(Program Name):C Programming Home Practice - Chapter 8-1。\n"); printf("程式敘述(Program Description):\nDefine a 100-element integer array myArray[]. Set the values of all the elements to be 1.。\n"); printf("程式版本(Program Version):1.00(0)\n"); printf("Build by Vdragon@2010\nAll rights RESERVED\n"); printf("---------------------------------\n"); //--------------------- //assign 1 to all array for(counterA = 0 ; counterA < 100 ; counterA++) { //assign myArray[counterA] = 1; } //debug if(debug == 1) { for(counterDebug = 0; counterDebug < 100 ; counterDebug++) { printf("myArray[%hd] = %hd\n", counterDebug, myArray[counterDebug]); } } //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(11) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main(void) {restartProgram: //宣告與定義(Declaration & Definition) //int array for testing int randArray[100]; //--------------------- //random function initialization //版本:1.00(2) srand((unsigned)time(NULL)); //now rand() is usable :D //rand() range: 0 ~ unsigned int MAX. //assign rand number//print value { // unsigned int assranC; // for(assranC = 0; assranC < 100; assranC++) { randArray[assranC] = rand() % 20; //print value printf("%u\t%u\n", assranC, randArray[assranC]); } } ////assign rand number//print value //callfunc indexOfMax(randArray, sizeof(randArray) / sizeof(int)); //pauseProgram if(pauseProgram()) { goto restartProgram; } //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//main函數架構 //版本:1.00(9) //軟體的運行從main函數開始 int main(void) { //宣告與定義(Declaration & Definition) //for loop * 20 short int counterI; //--------------------- //printTitle //printTitle(); //test //for loop * 20 for(counterI = 0; counterI < 20; counterI++) { printf("%d, ", rand10()); } //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(10) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main() { //宣告與定義(Declaration & Definition) char inputString[41];//20 Eng. Name //punc used for strtok //char punc[2] = " "; ////punc used for strtok //--------------------- //prompt name(Type //版本:1.00(0) printf("Input an English name: "); //scanf skips space charactor ...QQ //scanfTriggered = 1; //scanf("%s", inputString); gets(inputString); { //pointer used for get the position in memory of the first char of the firstname //char * ptrFirstName; //char * ptrSecName; //think //token first name printf("%s, ", strtok(inputString, " ")); //print next //ptrSecName = (char * )strtok(NULL, " "); //printf("%c. is a good man!", *ptrSecName); printf("%c. is a good man!", *((char * )(strtok(NULL, " ")))); } //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//main函數架構 //版本:1.00(9) //軟體的運行從main函數開始 int main() { //宣告與定義(Declaration & Definition) //char array char inputChar[15]; //counter for read loop //short int countLoopA; //--------------------- //printTitle //printTitle(); //while loop while(1) { //scanf scanf("%s", inputChar); //if exit break if(inputChar[0] == 'e' && inputChar[1] == 'x' && inputChar[2] == 'i' && inputChar[3] == 't' && inputChar[4] == '\0') { break; } //read /*for(countLoopA = 0; inputChar[countLoopA] == '\n'; countLoopA++) { }*/ //wash array //char inputChar[15] = {0}; } //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(10) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main() { //宣告與定義(Declaration & Definition) //--------------------- restart: //intial player data initialPlayer(&player); ////intial player data //for loop for assign monster data { //declare loop counter unsigned short int assignMonC; //loop for(assignMonC = 0; assignMonC < monsterTotal; assignMonC++) { initialMonster(&monster[assignMonC]); } } ////for loop for assign monster data //for loop for meet batt { unsigned short int meetMonC; for(meetMonC = 0; meetMonC < monsterTotal; meetMonC++) { printPlayerData(player); //while battle while(player.life > 0 && monster[meetMonC].life > 0) { //print line printf("%s碰到一隻半獸人!\n-----------\n", player.name); //into battle battle(&player, &monster[meetMonC]); } ////while battle //break loop if player died if(player.life < 0) { //print result printf("%s死掉了。", player.name); break; } ////break loop if player died } } ////for loop for meet batt //prompt restart //prompt //版本:1.00(0) printf("請問您要讓%s重新開始嗎(N為否、Y為是)?", player.name); if('N' == getche()) { exit(0); } else { //clean screen if(SYSTEM == 0) { system("cls"); } else { system("clear"); } goto restart; } //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//main函數架構 //版本:1.00(9) //軟體的運行從main函數開始 int main(void) { //宣告與定義(Declaration & Definition) //input string char inputUser[13]; char inputPass[13]; //data given const int userTotal = 5; char *ID[userTotal] = { "SHE911", "J90909490", "maydayblog", "jayalfa", "fishleong106" }; char *password[userTotal] = { "iloveyou", "onlyjolin", "mayday", "fantasy", "imfish" }; //counterRead int counterA; //counterWrite int counterB; char ch; //--------------------- //printTitle //printTitle(); while(1) { //prompt printf("請輸入帳號:"); scanfTriggered = 1; scanf("%s", inputUser); //think ID //for loop read for(counterA = 0; counterA < userTotal; counterA++) { //if not same if(strcmp(ID[counterA], inputUser) == 0) { break; } } if(counterA >= userTotal) { printf("帳號錯誤。沒有這個人啦!\n"); continue; } else { //prompt pass printf("請輸入密碼:"); scanfTriggered = 1; //for loop write for(counterB = 0, ch = getch(); ; counterB++, ch = getch()) { //if if(ch == '\r') { inputPass[counterB] = '\0'; break; } //write inputPass[counterB] = ch; //print printf("*"); } //think PASS //if not same if(strcmp(password[counterA], inputPass) != 0) { //wrong printf("\n密碼錯誤。\n"); // continue; } } //break break; } //ok printf("\n密碼正確。登入成功!\n歡迎進入魔法世界! \n"); //pause pauseProgram(); //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }
//--------------主要程式碼(Main Code)-------------- //main函數架構 //版本:1.00(11) //軟體的運行從main函數開始 //void會使debugger無法啟動! int main(void) {restartProgram: //宣告與定義(Declaration & Definition) //char. array for saving input string char inputString[13];//four UTF-8 characters MAX., include \0 //--------------------- //prompt //版本:1.00(0) printf("請輸入姓名:"); scanfTriggered = 1; scanf("%s", inputString); { //declare unsigned short int howManyWords; char * namePosition; //determine the BIG5 length of the inputString howManyWords = strlen(inputString) / 2; //char array for name and surname char surName[5];//two Big5 char.&& null char. //save surname //if 歐陽 is full name if(howManyWords == 2) { //surname should always be one word strncpy(surName, inputString, 2); //end this string with null char. surName[2] = '\0'; //let namePosition be next word namePosition = inputString + 2; } else if(check2surN(inputString)) { //copy to array strncpy(surName, inputString, 4); //end this string with null char. surName[4] = '\0'; //let namePosition be next word namePosition = inputString + 4; } else { //copy surname strncpy(surName, inputString, 2); //end this string with null char. surName[2] = '\0'; //let namePosition be next word namePosition = inputString + 2; } //output printf("%s教授%s博士", surName, namePosition); } //pauseProgram if(pauseProgram()) { goto restartProgram; } //--------------------- //傳回數字0(表程式運行成功) //版本:1.00(1) //return後面不可加註解! return 0; }