Ⅰ vb中如何編一個解類似數學題的程序:x=1,y=2 求的題,就是如和讓其代入並計算
建議用VB程序配合VBS腳本
就是VB做好一個程序 點計算按鈕的時候 自動生成一個VBS腳本並運行 就OK了
給你一個具體的例子
'botton1的代碼:
Open "c:\zhen.vbs" For Output As #1
Print #1, "Public Function f(x,y)"
Print #1, " f=" + Text3.Text
Print #1, "End Function"
Print #1, " x=" + Text1.Text
Print #1, " y=" + Text2.Text
Print #1, "Strings=""結果是:"" & f(x,y)
Print #1, " msgbox Strings,,""完成"""
Close #1
Shell "cmd /c c:\zhen.vbs", vbHide
'其中 text1要輸入x的值 text2要輸入Y的值 text3輸入算式 按下botton1後 結果就彈出來了 寫點代碼不容易 追加點分吧!
Ⅱ 用 java 編寫一個應用程序,對數學題目進行評分
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner ipt = null;
System.out.print("輸入題目數:");
ipt = new Scanner(System.in);
int count = ipt.nextInt();
System.out.println("請輸入答案:");
ipt = new Scanner(System.in);
String str = ipt.nextLine();//接受輸入在同一行的所有答案,保存為包括空格在內的字元串
// System.out.println(str);
String[] strs = str.split(" ");//將輸入的字元串以空格為間隔分成一個字元串數組
// System.out.println("長度:"+strs.length);
//將字元串數組轉成int數組,數組zqda就是保存的所有正確答案的數組
int[] zqda = new int[count];
for (int i = 0; i < strs.length; i++) {
zqda[i] = Integer.parseInt(strs[i]);
}
System.out.println("請輸入自己的答案:");
int[] myda = new int[count];
for (int i = 0; i < myda.length; i++) {
System.out.print(i+1+".");//題號
ipt = new Scanner(System.in);
myda[i] = ipt.nextInt();
}
int yes = 0;//用來記錄正確的答案
for (int i = 0; i < myda.length; i++) {
if(zqda[i] == myda[i]) yes++;//如果自己的答案==標准答案,yes+1
}
System.out.println((double)yes/(double)count*100+"%");//百分數輸出貌似應該還有其他簡單的方法,我一時記不起來,就自己拼了一個
}
}
我也正在學習,剛好用你的例子練了一下,相互學習哈!
Ⅲ C++編寫程序實現小學生數學測驗功能
參考實例源碼如下:
//#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int i,j,k,l=0,n;
cout<<"小學數學測試"<<endl;
cout<<"請選擇想測試的題型:1.+ 2.- 3.* 4./:";
cin>>i;
if(i==1)
{
cout<<"請輸入測試題的個數:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100;
int x2=rand()%100;
cout<<x1<<"+"<<x2<<"=:";
cin>>k;
if(k==x1+x2){
cout<<"回答正確!"<<endl;
l++;
}
else
cout<<"回答錯誤!正確答案為:"<<x1+x2<<endl;
}
}
else if(i==2)
{
cout<<"請輸入測試題的個數:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100;
int x2=x1+rand()%50;
cout<<x2<<"-"<<x1<<"=:";
cin>>k;
if(k==x2-x1){
cout<<"回答正確!"<<endl;
l++;
}
else
cout<<"回答錯誤!正確答案為:"<<x2-x1<<endl;
}
}
else if(i==3)
{
cout<<"請輸入測試題的個數:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100;
int x2=rand()%100;
cout<<x1<<"*"<<x2<<"=:";
cin>>k;
if(k==x1*x2){
cout<<"回答正確!"<<endl;
l++;
}
else
cout<<"回答錯誤!正確答案為:"<<x1*x2<<endl;
}
}
else if(i==4)
{
cout<<"請輸入測試題的個數:";
cin>>j;
for(int k1=0;k1<j;k1++)
{
srand((unsigned)time(NULL));
int x1=rand()%100+1;
int x2=x1*(rand()%10);
cout<<x2<<"/"<<x1<<"=:";
cin>>k;
if(k==x2/x1){
cout<<"回答正確!"<<endl;
l++;
}
else
cout<<"回答錯誤!正確答案為:"<<x2/x1<<endl;
}
}
cout<<"這次測試你作對的題目的個數為"<<l<<"個"<<endl;
cout<<"是否繼續測試:0.退出 1.繼續:";
cin>>n;
if(n==1){
return main();}
// system("PAUSE");
return 0;
}
Ⅳ 數學題:編寫一個程序。。。
// 分別計算1到1000之間所有3的倍數之和和所有7的倍數之和
int main()
{
int sumA = 0; //3的倍數的和
int sumB = 0; //7的倍數的和
for(int i = 1; i <= 1000/3; i++) //3的倍數的個數
{
sumA += i*3;
}
for(int i = 1; i <= 1000/7; i++) //7的倍數的個數
{
sumB += i*7;
}
std::cout << "3的倍數的和: " << sumA << std::endl;
std::cout << "7的倍數的和: " << sumB << std::endl;
return 0;
}
如果要求在一個循環內實現,則
for(int i = 1; i <= 1000/3; i++) //3的倍數的個數
{
sumA += i*3;
if( i<=1000/7)
sumB += i*7;
}
Ⅳ C++編程解決數學問題,求大神!
/*
請輸入長方體的長、寬和高(逗號隔開)
:
2,2,2
長方體的體積為:8.000,表面積為:24.000
請輸入變數a,b的值(逗號隔開)
:
3,5
交換前
:
a
=
3.000,b
=
5.000
交換後
:
a
=
5.000,b
=
3.000
請輸入等比數列的公比和項數(逗號隔開)
:
1.5,12
等比數列的前12項的和為
:
257.493
press
any
key
to
continue
*/
#include
<stdio.h>
#include
<math.h>
int
main()
{
double
a,b,c,q,sum;
double
eps
=
1.0e-6;
int
n;
printf("請輸入長方體的長、寬和高(逗號隔開)
:
");
scanf("%lf,%lf,%lf",&a,&b,&c);
printf("長方體的體積為:%.3lf,表面積為:%.3lf\n",a*b*c,2*(a*b
+
b*c
+
c*a));
printf("請輸入變數a,b的值(逗號隔開)
:
");
scanf("%lf,%lf",&a,&b);
printf("交換前
:
a
=
%.3lf,b
=
%.3lf\n",a,b);
c
=
a;
a
=
b;
b
=
c;
printf("交換後
:
a
=
%.3lf,b
=
%.3lf\n",a,b);
printf("請輸入等比數列的公比和項數(逗號隔開)
:
");
scanf("%lf,%d",&q,&n);
if(fabs(q)
-
1.0
>
eps)
sum
=
1.0
*
(1.0
-
pow(q,n))
/
(1.0
-
q);
else
sum
=
1.0
*
n;
printf("等比數列的前%d項的和為
:
%.3lf\n",n,sum);
return
0;
}
Ⅵ 求大神用C語言設計一個程序幫助小學生練習數學。(具體要求見問題補充)
你自己修改修改:
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
#define IDNO_LENGTH 6
#define CALC_KIND 4
#define CALC_NUM 10
bool checkNo(char idNo[]);
char getSignal();
int getResult(int,int,char);
void takeTest();
//main函數
void main()
{
printf("Please input your four digit ID no(begin with two letters):");
char idNo[IDNO_LENGTH];
do
{
scanf("%s",&idNo);
fflush(stdin);
} while(checkNo(idNo)==false);
printf("1.Start a test\t2.Exitb\n");
int choose;
do
{
printf("選擇:");
scanf("%d",&choose);
fflush(stdin);
} while(choose!=1 && choose!=2);
if(choose==1)
takeTest();
else
exit(0);
}
//獲取隨機運算符
char getSignal()
{
char signal[CALC_KIND]={'+','-','*','/'};
srand((unsigned)time(NULL));
return signal[rand()%4];
}
//獲取隨機數
int random(double start, double end)
{
return (int)(start+(end-start)*rand()/(RAND_MAX+ 1.0));
}
//運算
int getResult(int num1,int num2,char signal)
{
int res;
switch(signal)
{
case '+':
res=num1+num2;break;
case '-':
res=num1-num2;break;
case '*':
res=num1*num2;break;
case '/':
res=num1/num2;break;
default:
res=0;
printf("運算符不符合規則\n");
}
return res;
}
//列出10道題
void takeTest()
{
clock_t startTime;
startTime=clock();
int index;
int giveRes;
int num1;
int num2;
char signal;
for(index=0;index<CALC_NUM;index++)
{
srand((unsigned)time(NULL));
signal=getSignal();
num1=random(0,100);
num2=random(1,100);
printf("%d%c%d=",num1,signal,num2);
scanf("%d",&giveRes);
fflush(stdin);
if(getResult(num1,num2,signal)==giveRes)
{
printf("correct\n");
}
else
{
printf("wrong\n");
}
}
printf("解10道題用了%lf秒\n",(double)(clock()- startTime)/CLOCKS_PER_SEC);
}
//檢測idNo是否合規則,合規則返回true
bool checkNo(char idNo[])
{
int index;
bool flag;
flag=true;
for(index=0;index<IDNO_LENGTH;index++)
{
if(index<2)
{
if(!isalpha(idNo[index]))
{
flag=false;
printf("ID no 不符合規則,重新輸入:");
break;
}
}
else
{
if(!isdigit(idNo[index]))
{
flag=false;
printf("ID no 不符合規則,重新輸入:");
break;
}
}
}
return flag;
}
Ⅶ 作一個可供小學生數學運算的程序:10以內的加減乘除,能根據輸入的題數計算機自動出題,並判斷是否正確
Qbasic:
Randomize Timer
INPUT "N="; N
For i = 1 To N
k = Int(Rnd * 4)
Select Case k
Case 0:
a = Int(Rnd * 11)
b = Int(Rnd * 11)
e$ = "+"
c = a + b
Case 1:
c = Int(Rnd * 11)
b = Int(Rnd * 11)
e$ = "-"
a = b + c
Case 2:
a = Int(Rnd * 10)
b = Int(Rnd * 10)
e$ = "*"
c = a * b
Case 3:
c = Int(Rnd * 10)
b = Int(Rnd * 9) + 1
e$ = "/"
a = b * c
End Select
Print a; e$; b; "=";
INPUT d
If c = d Then
Print "right!"
Else
Print "Wrong!"
End If
Next i
Ⅷ 如何編寫一個C語言程序,讓計算機自動出四則運算計算題,要求自動出0-10之間的四則運算題,並批改結果
少年,寫好了,給你參考一下。還可以更復雜。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 10
int Test()
{
int num = 0;
int answer = 0;
int result = 0;
int m = 0;
int n = 0;
char op = 0;
int count = N;
while ( count-- )
{
m = rand() % 10;
n = rand() % 10;
op = rand() % 4;
switch ( op )
{
case 0:
op = '+';
answer = m+n;
break;
case 1:
op = '-';
answer = m-n;
break;
case 2:
op = '*';
answer = m*n;
break;
case 3:
n++;
op = '/';
answer = m/n;
break;
default:
break;
}
printf("\n題目:");
printf("%d%c%d=?\n", m, op, n);
printf("請輸入答案:");
scanf("%d", &result);
if ( answer == result )
num++;
}
return num;
}
int main()
{
srand( time(NULL) );
printf("開始做題:\n");
printf("答題結束,你總共答對%d道題目。\n", Test());
return 0;
}
Ⅸ C語言,設計一個程序幫助小學生練習數學。
1L的哥們竟然沒有分數也沒有讀寫文件記錄,我在他的基礎上加了這個功能,採納誰都可以哦~
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
#define IDNO_LENGTH 6
#define CALC_KIND 4
#define CALC_NUM 10
bool checkNo(char idNo[]);
char getSignal();
int getResult(int,int,char);
void takeTest();
//main函數
void main()
{
printf("Please input your four digit ID no(begin with two letters):");
char idNo[IDNO_LENGTH];
do
{
scanf("%s",&idNo);
fflush(stdin);
} while(checkNo(idNo)==false);
printf("1.Start a test\t2.Check score\t3.Exitb\n");
int choose;
do
{
printf("選擇:");
scanf("%d",&choose);
fflush(stdin);
} while(choose!=1 && choose!=2&& choose!=3);
if(choose==1)
{
takeTest();
}else if(choose==2)
{
FILE *fp;
char ch;
if((fp=fopen("score.txt","rt+"))==NULL)
{
printf("\n你還沒做過題目測試");
getch();
exit(1);
}
ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
}
else
{
exit(0);
}
}
//獲取隨機運算符
char getSignal()
{
char signal[CALC_KIND]={'+','-','*','/'};
srand((unsigned)time(NULL));
return signal[rand()%4];
}
//獲取隨機數
int random(double start, double end)
{
return (int)(start+(end-start)*rand()/(RAND_MAX+ 1.0));
}
//運算
int getResult(int num1,int num2,char signal)
{
int res;
switch(signal)
{
case '+':
res=num1+num2;break;
case '-':
res=num1-num2;break;
case '*':
res=num1*num2;break;
case '/':
res=num1/num2;break;
default:
res=0;
printf("運算符不符合規則\n");
}
return res;
}
//列出10道題
void takeTest()
{
printf("開始答題,每道題10分,總共100分\n");
clock_t startTime;
startTime=clock();
int index;
int giveRes;
int num1;
int num2;
int score=0;
char signal;
for(index=0;index<CALC_NUM;index++)
{
srand((unsigned)time(NULL));
signal=getSignal();
num1=random(0,100);
num2=random(1,100);
printf("%d%c%d=",num1,signal,num2);
scanf("%d",&giveRes);
fflush(stdin);
if(getResult(num1,num2,signal)==giveRes)
{
printf("correct\n");
score+=10;
}
else
{
printf("wrong\n");
}
}
FILE *fp=fopen("score.txt","w");
fprintf(fp,"分數為%d",score);
fclose(fp);
printf("解10道題用了%lf秒\n",(double)(clock()- startTime)/CLOCKS_PER_SEC);
}
//檢測idNo是否合規則,合規則返回true
bool checkNo(char idNo[])
{
int index;
bool flag;
flag=true;
for(index=0;index<IDNO_LENGTH;index++)
{
if(index<2)
{
if(!isalpha(idNo[index]))
{
flag=false;
printf("ID no 不符合規則,重新輸入:");
break;
}
}
else
{
if(!isdigit(idNo[index]))
{
flag=false;
printf("ID no 不符合規則,重新輸入:");
break;
}
}
}
return flag;
}
Ⅹ 一道數學題編寫程序
用JAVA寫的
public static void main(String[] args) {
int x,y,z;
int times = 0;
for(x = 1;x <= 19;x++){
for(y = 1;y<=33;y++){
z = 100-x-y;
if((5*x+3*y+z/3)==100){
times++;
System.out.println("第 "+times+" 組解 :公雞 :"+x+"母雞:"+y+"小雞:"+z);
}
}
}
}
程序運行結果:
第 1 組解 :公雞 :3母雞:20小雞:77
第 2 組解 :公雞 :4母雞:18小雞:78
第 3 組解 :公雞 :7母雞:13小雞:80
第 4 組解 :公雞 :8母雞:11小雞:81
第 5 組解 :公雞 :11母雞:6小雞:83
第 6 組解 :公雞 :12母雞:4小雞:84