C Primer Plus 第七章 编程练习 7-11题

    xiaoxiao2021-03-25  91

    第七题 #include<stdio.h> #define PayHour 40.0 #define PayLevel_1 300.0 #define PayLevel_2 450.0 int main(void) { double WorkTime; printf("Please Input Your Hours:\n"); scanf("%lf",&WorkTime); if(WorkTime > PayHour) WorkTime = (WorkTime-PayHour) * 1.5 + PayHour; double Wages = WorkTime * 10; double Level_1 = PayLevel_1 * (1-0.15); double Level_2 = (PayLevel_2 - PayLevel_1) * (1-0.2); if(Wages < PayLevel_1) Wages = Wages * (1-0.15); else if(Wages >= PayLevel_1 && Wages < PayLevel_2) Wages = Level_1 + (Wages-PayLevel_1) * (1-0.2); else if(Wages >= PayLevel_2) Wages = Level_1 + Level_2 +(Wages-PayLevel_2) * (1-0.25); printf("Your Wages Are %.2lf\n",Wages); return 0; } 第八题 #include<stdio.h> #include<stdbool.h> #include<iso646.h> #define PayHour 40.0 #define PayLevel_1 300.0 #define PayLevel_2 450.0 int main(void) { bool on_off = true; bool Choose = true; int HR; double WageHour; while(on_off) { printf("**********************************************\n"); printf("1)8.75/hr 2)9.33/hr\n"); printf("3)10.00/hr 4)11.20/hr\n"); printf("5)Quit\n"); printf("**********************************************\n"); //Create menu scanf("%d",&HR); switch(HR) { case 1:WageHour = 8.75; break; case 2:WageHour = 9.33; break; case 3:WageHour = 10.00; break; case 4:WageHour = 11.20; break; case 5:on_off = false; printf("Done!"); break; default:printf("There.s A Wrong,Please Try INput Again.\n"); Choose = false; break; } if(Choose == false or on_off == false) //choose 5 or 4 continue; double WorkTime; printf("Please Input Your Hours:\n"); scanf("%lf",&WorkTime); if(WorkTime > PayHour) WorkTime = (WorkTime-PayHour) * 1.5 + PayHour; double Wages = WorkTime * WageHour; double Level_1 = PayLevel_1 * (1-0.15); double Level_2 = (PayLevel_2 - PayLevel_1) * (1-0.2); if(Wages < PayLevel_1) Wages = Wages * (1-0.15); else if(Wages >= PayLevel_1 && Wages < PayLevel_2) Wages = Level_1 + (Wages-PayLevel_1) * (1-0.2); else if(Wages >= PayLevel_2) Wages = Level_1 + Level_2 +(Wages-PayLevel_2) * (1-0.25); printf("Your Wages Are %.2lf\n",Wages); } return 0; } 第九题 #include<stdio.h> const int Floor = 10; int main(void) { int MaxInt; int nu = 0; printf("PLease INput Any Integer:"); scanf("%d",&MaxInt); for(int i = 1 ; i <= MaxInt ; ++i) { int Ti = 0; for(int j = 1 ; j <= i ; ++j) { if(i%j == 0) ++Ti; } if(Ti <= 2) { printf("M ",i); ++nu; if(nu != 0 && nu%Floor == 0) printf("\n"); } } printf("\n"); return 0; } 第十题 #include<stdio.h> #include<stdbool.h> const double Level_1 = 17850; const double Level_2 = 23900; const double Level_3 = 29750; const double Level_4 = 14875; int main(void) { bool on_off = true; while(on_off) { char Ty; double Wages; double TAX; printf("PLease Input Your Wages:"); scanf("%lf",&Wages); getchar(); printf("PLease INput Your Type:\n"); printf("A:Signal B:Master \nC:Married D:Break\nQ:Quit\n"); scanf("%c",&Ty); switch(Ty) { case 'A':if(Wages <= Level_1) TAX = Wages*0.15; else TAX = Level_1 * 0.15 + (Wages - Level_1)*0.28; break; case 'B':if(Wages <= Level_2) TAX = Wages*0.15; else TAX = Level_1 * 0.15 + (Wages - Level_1)*0.28; break; case 'C':if(Wages <= Level_3) TAX = Wages*0.15; else TAX = Level_1 * 0.15 + (Wages - Level_1)*0.28; break; case 'D':if(Wages <= Level_4) TAX = Wages*0.15; else TAX = Level_1 * 0.15 + (Wages - Level_1)*0.28; break; case 'Q':on_off = false; printf("Done!"); break; default:break; } if(on_off == false) continue; else printf("TAX are %.2lf $\n",TAX); } return 0; } 第十一题 #include<stdio.h> #include<stdbool.h> const double Order_K = 1.25; const double Order_S = 0.65; const double Order_C = 0.89; int main(void) { double Weight_K; double Weight_S; double Weight_C; bool on_off = true; while(on_off) { char orders; printf("Please Input Your Order:\n"); printf("A:Korea B:Sweet C:Carrot Q:Quit\n"); scanf("%c",&orders); getchar(); switch(orders) { case 'A':printf("PLease Input Weight(Korea):"); scanf("%lf",&Weight_K); getchar(); break; case 'B':printf("PLease Input Weight(Sweet):"); scanf("%lf",&Weight_S); getchar(); break; case 'C':printf("PLease Input Weight(Carrot):"); scanf("%lf",&Weight_C); getchar(); break; case 'Q':on_off = false; break; defalut:on_off = false; break; } } double Cost_1 = Weight_K * Order_K + Weight_S * Order_S + Weight_C * Order_C; if(Cost_1 > 100) Cost_1 *= 0.95; double Cost_2 = 0; double SumWeight = Weight_K + Weight_S + Weight_C; if(SumWeight <= 5 && SumWeight >0) Cost_2 = 3.5; else if(SumWeight > 5 && SumWeight <= 20) Cost_2 = 10.0; else if(SumWeight > 20) Cost_2 = 8.0 + SumWeight * 0.1; printf("%.2lf Pounds Korea Cost %.2lf\n",Weight_K,Weight_K*Order_K); printf("%.2lf Pounds Sweet Cost %.2lf\n",Weight_S,Weight_K*Order_S); printf("%.2lf Pounds Carrot Cost %.2lf\n",Weight_C,Weight_K*Order_C); printf("Transport Cost %.2lf\n",Cost_2); printf("We All Cost %.2lf\n",Cost_1); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-15184.html

    最新回复(0)