高分求高手解答! 如果可以 还有追加的分!! 不低 希望高手写清楚点 写简单点 !!!
编写程序,根据输入的学生成绩,给出相应的等级。90分以上的等级为A,60分以下的等级为E,其余每10分为一个等级。注:分别用if-elseif语句和switch语句两种结...
编写程序,根据输入的学生成绩,给出相应的等级。90分以上的等级为A,60分以下的等级为E,其余每10分为一个等级。注:分别用if-else if语句和switch语句两种结构实现。
(2) 求3到100之间的所有的素数。
(3) 编写程序,求e的近似值,直到最后一项的值小于10-4为止。e=1+11! +12! +13! +……+1n!
(4)编写程序,将用户输入的一行字符中的数字字符转换成一个整数输出。例如:若输入 2 A3Bcd 4<CR>或2 3 4<CR> 则输出整数为:234
(5) 编写程序,获得用户输入的一行字符,然后将该字符及其ASCII码值输出。每行输出3对。
(6) 编写函数。输出一下图案,图案的行数由输入的值确定。
A
B B B
C C C C C
D D D D D D D
(7) 编写函数。统计长整数n中指定数字出现的次数。
(8) 编写函数。讲一个大偶数a(a≥6)分解成两个素数之和的形式。例如,若输入数值为10,则输出10=3+7和10=5+5.
(9) 编写函数。用数组元素作为计算器来统计用户输入的一行数字字符中每个数字字符的个数。用下标为0的元素统计字符“0”,下标为1的元素统计字符“1”,……。要求在主函数中输出统计结果,且统计结果倒序输出,即先输出字符“9”的个数,然后输出“8”的个数,……。
(10) 编写函数。对用户输入的一组数字按由大到小进行排序。要求在主函数中输出数组排序前以及排序后的内容。
希望可以标清题号!! 另外 我们用的是C++运行环境, 最好写出的程序能在我们的环境里面运行出来 @!!!!! 展开
(2) 求3到100之间的所有的素数。
(3) 编写程序,求e的近似值,直到最后一项的值小于10-4为止。e=1+11! +12! +13! +……+1n!
(4)编写程序,将用户输入的一行字符中的数字字符转换成一个整数输出。例如:若输入 2 A3Bcd 4<CR>或2 3 4<CR> 则输出整数为:234
(5) 编写程序,获得用户输入的一行字符,然后将该字符及其ASCII码值输出。每行输出3对。
(6) 编写函数。输出一下图案,图案的行数由输入的值确定。
A
B B B
C C C C C
D D D D D D D
(7) 编写函数。统计长整数n中指定数字出现的次数。
(8) 编写函数。讲一个大偶数a(a≥6)分解成两个素数之和的形式。例如,若输入数值为10,则输出10=3+7和10=5+5.
(9) 编写函数。用数组元素作为计算器来统计用户输入的一行数字字符中每个数字字符的个数。用下标为0的元素统计字符“0”,下标为1的元素统计字符“1”,……。要求在主函数中输出统计结果,且统计结果倒序输出,即先输出字符“9”的个数,然后输出“8”的个数,……。
(10) 编写函数。对用户输入的一组数字按由大到小进行排序。要求在主函数中输出数组排序前以及排序后的内容。
希望可以标清题号!! 另外 我们用的是C++运行环境, 最好写出的程序能在我们的环境里面运行出来 @!!!!! 展开
4个回答
展开全部
动脑筋哦!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我这里有原码
#include <stdlib.h>
#include <math.h>
#include <graphics.h>
#include <stdio.h>
#include <process.h>
#define EXCAPE 27
#define ENTER 13
main(){
int press,i,x,y,x1,y1,ch_z=0;
int dian=0;
char ch='0'; /*input + - * / */
char emp[80],sum[80],*e,*s;
double yuan=0.000000000000;
void init(void);
void clear_z(char *u);
double strtoflt(char *p);
int getkey();
int gd=DETECT, gm;
initgraph(&gd, &gm, "");
e=emp;
s=sum;
init();
x = (getmaxx() / 2) - 120;
y = (getmaxy() / 2) - 150;
x1 = (getmaxx() / 2) + 120;
y1 = (getmaxy() / 2) + 150;
while(1){
press = getkey();
switch(press){
case EXCAPE:
exit(0);
case 47:
bar (x + 10, y + 80 + 10, x + 60 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
if (strtoflt(emp)==0.0){
ch='0';
ch_z=0;
dian=0;
emp[0]='\0';
sum[0]='\0';
e=emp;
s=sum;
outtextxy(x+30,y+40,"error!!!!!");
break;
}
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
}
ch='/';
ch_z=0;
emp[0]='\0';
e=emp;
dian=0;
break;
case 42:
bar (x + 60 + 10, y + 80 + 10, x + 60 * 2 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else
outtextxy(x+30,y+40,sum);
}
ch='*';
ch_z=0;
dian=0;
break;
case 45:
bar (x + 60 * 2 + 10, y + 80 + 10, x + 60 * 3 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else
outtextxy(x+30,y+40,sum);
}
ch='-';
ch_z=0;
dian=0;
break;
case 43:
bar (x + 60 * 3 + 10, y + 80 + 10, x + 60 * 4 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else
outtextxy(x+30,y+40,sum);
}
ch='+';
ch_z=0;
dian=0;
break;
case 49:
bar (x + 10, y + 80 + 53 + 10, x + 60 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
for (i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (ch_z==0){
*e='1';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 50:
bar (x + 60 + 10, y + 80 + 53 + 10, x + 60 * 2 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
for (i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (ch_z==0){
*e='2';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 51:
bar (x + 60 * 2 + 10, y + 80 + 53 + 10, x + 60 * 3 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
for (i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (ch_z==0){
*e='3';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case ENTER:
bar (x + 60 * 3 + 10, y + 80 + 53 + 10, x + 60 * 4 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else{
outtextxy(x+30,y+40,sum);
}
}
ch='0';
ch_z=1;
dian=0;
break;
case 52:
bar (x + 10, y + 80 + 53 * 2 + 10, x + 60 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (ch_z==0){
*e='4';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 53:
bar (x + 60 + 10, y + 80 + 53 * 2 + 10, x + 60 * 2 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (ch_z==0){
*e='5';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 54:
bar (x + 60 * 2 +10, y + 80 + 53 * 2 + 10, x + 60 * 3 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (ch_z==0){
*e='6';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 46:
bar (x + 60 * 3 + 10, y + 80 + 53 * 2 + 10, x + 60 * 4 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (dian==0){
if (ch_z==0){
*e='.';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
}
else{
if (ch_z==0)
outtextxy(x+30,y+40,emp);
else
outtextxy(x+30,y+40,sum);
}
dian=1;
break;
case 55:
bar (x + 10, y + 80 + 53 * 3 + 10, x + 60 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='7';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 56:
bar (x + 60 + 10, y + 80 + 53 * 3 + 10, x + 60 * 2 -10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='8';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 57:
bar (x + 60 * 2 + 10, y + 80 + 53 * 3 + 10, x + 60 * 3 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='9';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 48:
bar (x + 60 * 3 + 10, y + 80 + 53 * 3 + 10, x + 60 * 4 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='0';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 32:
emp[0]='\0';
sum[0]='\0';
e=emp;
s=sum;
ch='0';
ch_z=0;
dian=0;
init();
break;
case 8:
delay(8000);
for(i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (i==0)
break;
if (i!=79&&i!=0){
i--;
emp[i]='\0';
e=&emp[i];
}
init();
outtextxy(x+30,y+40,emp);
break;
}
}
}
/*---------------------------------------------------------------------*/
void init(void){
int x, y, x1, y1, i, j;
char emp;
x = (getmaxx() / 2) - 120;
y = (getmaxy() / 2) - 150;
x1 = (getmaxx() / 2) + 120;
y1 = (getmaxy() / 2) + 150;
cleardevice();
setbkcolor(3);
setfillstyle(1, 15);
setcolor(15);
settextstyle(1,0,1);
rectangle (x, y, x1, y1);
rectangle (x - 7, y - 7, x1 + 7, y1 + 7);
rectangle (x + 10, y + 10, x1 - 10, y + 80 - 10);
line (x, y + 80, x1, y + 80);
y = y + 80;
for (j = 1; j <= 4; j++){
x = (getmaxx() / 2) - 120;
for (i = 1; i <= 4; i++){
/* bar (x + 10, y + 10, x + 60 - 10, y + 60 - 10);*/
rectangle(x + 10, y + 10, x + 60 - 10, y + 60 - 10);
if (j == 1){
if (i == 1)
outtextxy(x + 20, y + 20, "/");
if (i == 2)
outtextxy(x + 25, y + 20, "*");
if (i == 3)
outtextxy(x + 27, y + 20, "-");
if (i == 4)
outtextxy(x + 25, y + 20, "+");
}
if (j == 2){
if (i == 1)
outtextxy(x + 25, y + 20, "1");
if (i == 2)
outtextxy(x + 25, y + 20, "2");
if (i == 3)
outtextxy(x + 25, y + 20, "3");
if (i == 4)
outtextxy(x + 25, y + 20, "=");
}
if (j == 3){
if (i == 1)
outtextxy(x + 25, y + 20, "4");
if (i == 2)
outtextxy(x + 25, y + 20, "5");
if (i == 3)
outtextxy(x + 25, y + 20, "6");
if (i == 4)
outtextxy(x + 25, y + 20, ".");
}
if (j == 4){
if (i == 1)
outtextxy(x + 25, y + 20, "7");
if (i == 2)
outtextxy(x + 25, y + 20, "8");
if (i == 3)
outtextxy(x + 25, y + 20, "9");
if (i == 4)
outtextxy(x + 25, y + 20, "0");
}
x = x + 60;
}
y = y + 53;
}
}
/*---------------------------------------------------------------------*/
int getkey(){
char lowbyte;
int press;
while(bioskey(1)==0);
press = bioskey(0);
press = press&0xff? press&0xff: press>>8;
return(press);
}
double strtoflt(char *p)
{
double rtl=0.000000000000;
double pnt=0.000000000000;
double t = 10;
int ispoint = 0;
while (*p!='\0'||*p!='.'){
if(*p<'0'||*p>'9')
break;
rtl*=10;
rtl+=*p-'0';
p++;
}
if (*p=='.'){
ispoint=1;
p++;
}
while(ispoint&&*p!='\0'){
pnt+=(double)(*p-'0')/t;
t*=10;
p++;
}
rtl+=pnt;
return (rtl);
}
/*-----------------------------------------------------------------------*/
void clear_z(char u[]){
int i;
for(i=strlen(u)-1;i>=0;i--){
if (u[i]!='0')
break;
}
if (u[i]=='.'){
u[i]='\0';
}
else{
i++;
u[i]='\0';
}
}.
#include <stdlib.h>
#include <math.h>
#include <graphics.h>
#include <stdio.h>
#include <process.h>
#define EXCAPE 27
#define ENTER 13
main(){
int press,i,x,y,x1,y1,ch_z=0;
int dian=0;
char ch='0'; /*input + - * / */
char emp[80],sum[80],*e,*s;
double yuan=0.000000000000;
void init(void);
void clear_z(char *u);
double strtoflt(char *p);
int getkey();
int gd=DETECT, gm;
initgraph(&gd, &gm, "");
e=emp;
s=sum;
init();
x = (getmaxx() / 2) - 120;
y = (getmaxy() / 2) - 150;
x1 = (getmaxx() / 2) + 120;
y1 = (getmaxy() / 2) + 150;
while(1){
press = getkey();
switch(press){
case EXCAPE:
exit(0);
case 47:
bar (x + 10, y + 80 + 10, x + 60 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
if (strtoflt(emp)==0.0){
ch='0';
ch_z=0;
dian=0;
emp[0]='\0';
sum[0]='\0';
e=emp;
s=sum;
outtextxy(x+30,y+40,"error!!!!!");
break;
}
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
}
ch='/';
ch_z=0;
emp[0]='\0';
e=emp;
dian=0;
break;
case 42:
bar (x + 60 + 10, y + 80 + 10, x + 60 * 2 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else
outtextxy(x+30,y+40,sum);
}
ch='*';
ch_z=0;
dian=0;
break;
case 45:
bar (x + 60 * 2 + 10, y + 80 + 10, x + 60 * 3 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else
outtextxy(x+30,y+40,sum);
}
ch='-';
ch_z=0;
dian=0;
break;
case 43:
bar (x + 60 * 3 + 10, y + 80 + 10, x + 60 * 4 - 10, y + 80 + 60 - 10);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else
outtextxy(x+30,y+40,sum);
}
ch='+';
ch_z=0;
dian=0;
break;
case 49:
bar (x + 10, y + 80 + 53 + 10, x + 60 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
for (i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (ch_z==0){
*e='1';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 50:
bar (x + 60 + 10, y + 80 + 53 + 10, x + 60 * 2 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
for (i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (ch_z==0){
*e='2';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 51:
bar (x + 60 * 2 + 10, y + 80 + 53 + 10, x + 60 * 3 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
for (i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (ch_z==0){
*e='3';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case ENTER:
bar (x + 60 * 3 + 10, y + 80 + 53 + 10, x + 60 * 4 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
init();
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
case '-':
if (strtoflt(sum)>=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
}
else{
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
}
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
e=emp;
break;
}
}
else{
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
e=emp;
}
else{
outtextxy(x+30,y+40,sum);
}
}
ch='0';
ch_z=1;
dian=0;
break;
case 52:
bar (x + 10, y + 80 + 53 * 2 + 10, x + 60 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (ch_z==0){
*e='4';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 53:
bar (x + 60 + 10, y + 80 + 53 * 2 + 10, x + 60 * 2 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (ch_z==0){
*e='5';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 54:
bar (x + 60 * 2 +10, y + 80 + 53 * 2 + 10, x + 60 * 3 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (ch_z==0){
*e='6';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 46:
bar (x + 60 * 3 + 10, y + 80 + 53 * 2 + 10, x + 60 * 4 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
init();
if (dian==0){
if (ch_z==0){
*e='.';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
}
else{
if (ch_z==0)
outtextxy(x+30,y+40,emp);
else
outtextxy(x+30,y+40,sum);
}
dian=1;
break;
case 55:
bar (x + 10, y + 80 + 53 * 3 + 10, x + 60 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='7';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 56:
bar (x + 60 + 10, y + 80 + 53 * 3 + 10, x + 60 * 2 -10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='8';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 57:
bar (x + 60 * 2 + 10, y + 80 + 53 * 3 + 10, x + 60 * 3 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='9';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 48:
bar (x + 60 * 3 + 10, y + 80 + 53 * 3 + 10, x + 60 * 4 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
init();
if (ch_z==0){
*e='0';e++;*e='\0';
outtextxy(x+30,y+40,emp);
}
else{
outtextxy(x+30,y+40,sum);
}
break;
case 32:
emp[0]='\0';
sum[0]='\0';
e=emp;
s=sum;
ch='0';
ch_z=0;
dian=0;
init();
break;
case 8:
delay(8000);
for(i=0;i<=79;i++){
if (emp[i]=='\0')
break;
}
if (i==0)
break;
if (i!=79&&i!=0){
i--;
emp[i]='\0';
e=&emp[i];
}
init();
outtextxy(x+30,y+40,emp);
break;
}
}
}
/*---------------------------------------------------------------------*/
void init(void){
int x, y, x1, y1, i, j;
char emp;
x = (getmaxx() / 2) - 120;
y = (getmaxy() / 2) - 150;
x1 = (getmaxx() / 2) + 120;
y1 = (getmaxy() / 2) + 150;
cleardevice();
setbkcolor(3);
setfillstyle(1, 15);
setcolor(15);
settextstyle(1,0,1);
rectangle (x, y, x1, y1);
rectangle (x - 7, y - 7, x1 + 7, y1 + 7);
rectangle (x + 10, y + 10, x1 - 10, y + 80 - 10);
line (x, y + 80, x1, y + 80);
y = y + 80;
for (j = 1; j <= 4; j++){
x = (getmaxx() / 2) - 120;
for (i = 1; i <= 4; i++){
/* bar (x + 10, y + 10, x + 60 - 10, y + 60 - 10);*/
rectangle(x + 10, y + 10, x + 60 - 10, y + 60 - 10);
if (j == 1){
if (i == 1)
outtextxy(x + 20, y + 20, "/");
if (i == 2)
outtextxy(x + 25, y + 20, "*");
if (i == 3)
outtextxy(x + 27, y + 20, "-");
if (i == 4)
outtextxy(x + 25, y + 20, "+");
}
if (j == 2){
if (i == 1)
outtextxy(x + 25, y + 20, "1");
if (i == 2)
outtextxy(x + 25, y + 20, "2");
if (i == 3)
outtextxy(x + 25, y + 20, "3");
if (i == 4)
outtextxy(x + 25, y + 20, "=");
}
if (j == 3){
if (i == 1)
outtextxy(x + 25, y + 20, "4");
if (i == 2)
outtextxy(x + 25, y + 20, "5");
if (i == 3)
outtextxy(x + 25, y + 20, "6");
if (i == 4)
outtextxy(x + 25, y + 20, ".");
}
if (j == 4){
if (i == 1)
outtextxy(x + 25, y + 20, "7");
if (i == 2)
outtextxy(x + 25, y + 20, "8");
if (i == 3)
outtextxy(x + 25, y + 20, "9");
if (i == 4)
outtextxy(x + 25, y + 20, "0");
}
x = x + 60;
}
y = y + 53;
}
}
/*---------------------------------------------------------------------*/
int getkey(){
char lowbyte;
int press;
while(bioskey(1)==0);
press = bioskey(0);
press = press&0xff? press&0xff: press>>8;
return(press);
}
double strtoflt(char *p)
{
double rtl=0.000000000000;
double pnt=0.000000000000;
double t = 10;
int ispoint = 0;
while (*p!='\0'||*p!='.'){
if(*p<'0'||*p>'9')
break;
rtl*=10;
rtl+=*p-'0';
p++;
}
if (*p=='.'){
ispoint=1;
p++;
}
while(ispoint&&*p!='\0'){
pnt+=(double)(*p-'0')/t;
t*=10;
p++;
}
rtl+=pnt;
return (rtl);
}
/*-----------------------------------------------------------------------*/
void clear_z(char u[]){
int i;
for(i=strlen(u)-1;i>=0;i--){
if (u[i]!='0')
break;
}
if (u[i]=='.'){
u[i]='\0';
}
else{
i++;
u[i]='\0';
}
}.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一题200分总共10题啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询