1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 //**********延时 5 void delay(int n) 6 { 7 int i; 8 n*=50000000; 9 for(i=1;i<=n;i++); 10 } 11 //**********倒计时 12 void countdown(unsigned long s) 13 { 14 int i; 15 unsigned long n; 16 n=s; 17 for(i=0;i<=s;i++) 18 {printf(" %9ld秒!",n); 19 delay(6); 20 if(i<s) 21 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b"); 22 n--; 23 } 24 } 25 //**********小时与分钟化为秒 26 long sum_second(int h,int m,long s) 27 { 28 s=3600*h+60*m+s; 29 return s; 30 } 31 //**********父选择 32 void ch_f(char a[]) 33 { 34 int c; 35 system("cls"); 36 puts(a); 37 printf("1.数秒钟后\n"); 38 printf("2.数分钟后\n"); 39 printf("3.数小时后\n"); 40 } 41 //**********子选择 42 int ch_s(char a[],char b[]) 43 { 44 int t; 45 system("mode con: cols=26 lines=2"); 46 system("color fc"); 47 puts(a); 48 scanf("%d",&t); 49 system("cls"); 50 system("mode con: cols=25 lines=2"); 51 puts(b); 52 return t; 53 } 54 //**********主函数 55 main() 56 { 57 int c,t; 58 char a[20],b[20],d[20]; 59 system("title 关机重启"); 60 system("mode con: cols=25 lines=8"); 61 system("color f9"); 62 printf(" ╪╧╧╧╧╪╧╧╧╧╪\n"); 63 printf("╔═╧╧关机程序╧╧═╗\n"); 64 printf("║※1.倒计时关闭计算机║\n"); 65 printf("║※2.倒计时重启计算机║\n"); 66 printf("║※3.倒计时注销计算机║\n"); 67 printf("║※0.退出系统 ║\n"); 68 printf("╚══════════╝\n"); 69 printf("你的选择是:"); 70 scanf("%d",&c); 71 if(c!=1&&c!=2&&c!=3) 72 c=0; 73 system("cls"); 74 system("mode con: cols=20 lines=5"); 75 system("color f0"); 76 switch(c) 77 { 78 case 1: 79 { 80 strcpy(a,"何时关闭您的计算机?"); 81 strcpy(d,"距关闭还有:"); 82 ch_f(a); 83 scanf("%d",&c); 84 switch(c) 85 { 86 case 1: 87 { 88 strcpy(b,"多少秒钟后关闭您的计算机?"); 89 t=ch_s(b,d); 90 countdown(sum_second(0,0,t)); 91 system("shutdown /s"); 92 if(getch()==27) 93 system("shutdown -a"); 94 else 95 break; 96 } 97 case 2: 98 { 99 strcpy(b,"多少分钟后关闭您的计算机?"); 100 t=ch_s(b,d); 101 countdown(sum_second(0,t,0)); 102 system("shutdown /s"); 103 if(getch()==27) 104 system("shutdown -a"); 105 else 106 break; 107 } 108 case 3: 109 { 110 strcpy(b,"多少小时后关闭您的计算机?"); 111 t=ch_s(b,d); 112 countdown(sum_second(t,0,0)); 113 system("shutdown /s"); 114 if(getch()==27) 115 system("shutdown -a"); 116 else 117 break; 118 } 119 } 120 } 121 case 2: 122 { 123 strcpy(a,"何时重启您的计算机?"); 124 strcpy(d,"距重启还有:"); 125 ch_f(a); 126 scanf("%d",&c); 127 switch(c) 128 { 129 case 1: 130 { 131 strcpy(b,"多少秒钟后重启您的计算机?"); 132 t=ch_s(b,d); 133 countdown(sum_second(0,0,t)); 134 system("shutdown /r"); 135 if(getch()==27) 136 system("shutdown -a"); 137 else 138 break; 139 } 140 case 2: 141 { 142 strcpy(b,"多少分钟后重启您的计算机?"); 143 t=ch_s(b,d); 144 countdown(sum_second(0,t,0)); 145 system("shutdown /r"); 146 if(getch()==27) 147 system("shutdown -a"); 148 else 149 break; 150 } 151 case 3: 152 { 153 strcpy(b,"多少小时后重启您的计算机?"); 154 t=ch_s(b,d); 155 countdown(sum_second(t,0,0)); 156 system("shutdown /r"); 157 if(getch()==27) 158 system("shutdown -a"); 159 else 160 break; 161 } 162 } 163 } 164 case 3: 165 { 166 strcpy(a,"何时注销您的计算机?"); 167 strcpy(d,"距注销还有:"); 168 ch_f(a); 169 scanf("%d",&c); 170 switch(c) 171 { 172 case 1: 173 { 174 strcpy(b,"多少秒钟后注销您的计算机?"); 175 t=ch_s(b,d); 176 countdown(sum_second(0,0,t)); 177 system("shutdown /l"); 178 } 179 case 2: 180 { 181 strcpy(b,"多少分钟后注销您的计算机?"); 182 t=ch_s(b,d); 183 countdown(sum_second(0,t,0)); 184 system("shutdown /l"); 185 } 186 case 3: 187 { 188 strcpy(b,"多少小时后注销您的计算机?"); 189 t=ch_s(b,d); 190 countdown(sum_second(t,0,0)); 191 system("shutdown /l"); 192 } 193 } 194 } 195 case 0: break; 196 } 197 }