感覺(jué)這里只有題目31 和 題目 34 有用,其他得調(diào)顏色得應(yīng)該絕大部分人用不到(
題目 31題目:請(qǐng)輸入星期幾得第壹個(gè)字母來(lái)判斷一下是星期幾,如果第壹個(gè)字母一樣,則繼續(xù)判斷第二個(gè)字母。
程序分析:用情況語(yǔ)句比較好,如果第壹個(gè)字母一樣,則判斷用情況語(yǔ)句或if語(yǔ)句判斷第二個(gè)字母。
#include<cstdio>int main(){ char c; /gov這里需要一個(gè)一個(gè)輸入單詞才專(zhuān)業(yè)解決問(wèn)題,想想能不能一行解決gov/ while ((c=getchar())!='Y') /gov當(dāng)所按字母為Y時(shí)才結(jié)束gov/ { switch (c) { case 'S': printf("please input second letter\n"); if((c=getchar()) == 'a') printf("Saturday\n"); if ((c=getchar())== 'u') printf("Sunday\n"); break; case 'F':printf("Friday\n");break; case 'M':printf("Monday\n");break; case 'T':printf("please input second letter\n"); if((c=getchar())=='u') printf("Tuesday\n"); else if ((c=getchar())=='h') printf("Thursday\n"); break; case 'W':printf("Wednesday\n");break; default: break; } }}
題目 32
題目:Press any key to change color, do you want to try it. Please hurry up!
#include<conio.h>#include<windows.h>#include<cstdio>// 此部分來(lái)自: https://blog.csdn.net/u012133341/article/details/81487802// 這里本人不太理解。 int textbackground(short iColor){ HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbInfo; GetConsoleScreenBufferInfo(hd, &csbInfo); return SetConsoleTextAttribute(hd, (iColor<<4)|(csbInfo.wAttributes&~0xF0));}int main(){ for(int color = 0;color < 8 ;color++) { textbackground(color); printf("This is color %d\r\n",color); printf("Press any key to continue\n"); getch();//與getchar不同得是,getch專(zhuān)業(yè)看不到字符 }}
題目 33
題目:學(xué)習(xí)gotoxy()與clrscr()函數(shù)
#include<cstdio>#include<conio.h>#include<windows.h>// 此部分來(lái)自: https://blog.csdn.net/u012133341/article/details/81487802// 這里本人不太理解。 int textbackground(short iColor){ HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbInfo; GetConsoleScreenBufferInfo(hd, &csbInfo); return SetConsoleTextAttribute(hd, (iColor<<4)|(csbInfo.wAttributes&~0xF0));}// 建議讀者自行尋求資料。。 這里不打算深究 void gotoxy(int x, int y){ COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);}int main(){ system("cls");//清屏 gotoxy(1,5); textbackground(3); printf("Output at row 5 col 1\n"); gotoxy(20,10); textbackground(2); printf("Output at row 10 col 20\n");}
題目 34
題目:練習(xí)函數(shù)調(diào)用
#include<cstdio>void output_error()// 函數(shù)聲明,void類(lèi)型,最后專(zhuān)業(yè)加return;{ printf("error!"); return;}int main(){ output_error();//知道怎嗎調(diào)用即可。這里不打算介紹參數(shù) }
題目 35
題目:文本顏色設(shè)置
#include<cstdio>#include<windows.h>/gov要深入了解得朋友,建議自行檢索相關(guān)資料gov/void textcolor(int color) { HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOutput, color);}int main(){ for (int color = 1;color < 16;color++) { textcolor(color); printf("This is color %d\r\n", color); } textcolor(128 + 15); printf("This is blinking\r\n");}