『壹』 求大富翁源代碼
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#define _GOLD 2 //標志有金子的格子
#define _TRAP 3 //標志有陷阱的格子
#define _OBSTACLE 4 //標志有障礙物的格子
class simgame
{
public:
simgame(char *nm,int);
void terminate(){delete []name;};
void init(int data[],int n);
void run();
void display();
private:
char *name;
int way[50]; //標志環道格子種類的數組
int location;
int life;
int money;
int isdead; //判斷是否死亡
int isforward; //判斷是順行還是逆行
};
simgame::simgame(char *nm,int isfd=1)
{
strcpy(name,nm);
isforward=isfd;
location=0;
life=money=100;
isdead=0;
}
void simgame::init(int data[],int n)
{
int nn=0; //用於循環data數組以保證把way數組完整賦值
int i;
way[0]=0;
if(isforward)
{
for(int i=1;i<50;i++)
{
if(nn=n)nn=0; //如果data數組到達末尾,從頭開始
way[i]=data[nn];
nn++;
}
}
else
{
nn=n-1;
for(i=1;i<50;i++)
{
if(nn<0)nn=n-1;
way[i]=data[nn];
nn--;
}
}
}
void simgame::display()
{
cout<<"老鼠"<<name<<":";
if(life>0)
{
cout<<"位置="<<setw(5)<<location;
cout<<"生命="<<setw(5)<<life;
cout<<"金錢="<<setw(5)<<money;
}
else
cout<<"Dead!";
}
void simgame::run()
{
int i;
int isstop=0;
if(isdead)return;
if(isforward) //正常行走的過程
{
for(i=1;i<5;i++)
{
if(location+i==50)
location-=50; //如果到達末尾則從頭開始走,並把位置變數重新賦值
if(way[location+i]==_OBSTACLE) //如果途中有障礙物,則停止
{
location+=i;
isstop=1; //標志,表示是否停留
break;
}
}
if(!isstop)
location+=4;
switch(way[location])
{
case _GOLD:money+=50;break;
case _TRAP:life-=80;break;
default:break;
}
if(life<=0)isdead=1;
}
else //逆行的過程
{
for(i=1;i<4;i++)
{
if(location+i==50)
location-=50;
if(way[location+i]==_OBSTACLE)
{
location+=i;
isstop=1;
break;
}
}
if(!isstop)
location+=3;
switch(way[location])
{
case _GOLD:money+=50;break;
case _TRAP:life-=80;break;
default:break;
}
if(life<=0)isdead=1;
}
}
void main()
{
simgame mice1("A");
simgame mice2("B",0);
int data[20]={1,2,2,2,3,2,3,4,1,2,3,4,1,2,3,4,3,2,2,1};
mice1.init(data,20);
mice2.init(data,20);
for(int i=0;i<5;i++)
{
mice1.run();
mice2.run();
cout<<"輪次:"<<i+1<<endl;
mice1.display();
mice2.display();
}
mice1.terminate();
mice2.terminate();
}
可以編譯,但不可以運行,求大蝦給診斷一哈,謝謝謝謝
問題補充:題目:一條由50個格子組成的環形跑道,其中一個格子是起點,兩只鼠都從起點按相反方向出發,一隻鼠按正方向前進且每次前進4格,另一隻鼠按反方向出發,且每次前進3個格子,每隻鼠出發時都有100點生命值和100個金子;跑道由普通格子,帶金幣的格子,帶陷阱的格子,帶障礙的格子等四種組成!
規則:a,起點是普通格子,任何普通格子鼠可以順利通過.
b.鼠每路過或停在一個帶金幣的格子上就增加50個金幣
c.鼠停留在陷阱的格子上,損失生命80點.
d.鼠路過帶障礙的格子時,本輪停止前進.
1.並實現相關的類,同時模擬此游戲
輸入:已在main()中提供一個大小為20的一維整型數組data,數值可為1,2,3,4,分別表示四種類型的格子,其中data(0)表示起點.
輸出:10輪次內,每輪走完後兩只老鼠的各自位置,生命,和擁有的金幣數.
要main()函數應為如下格式
void main()
{
int data[20]={1,2,2,2,3,2,3,4,1,2,3,4,1,2,3,4,3,2,2,1};
simgame game;
game.init(data,20);
game.run(5)
game.terminate();
}
輸出:
輪次1:
老鼠A:位置=##生命=##金錢=##
老鼠B:位置=##生命=##金錢=##
輪次2:
.......
宏:
#define _GOLD 2 //金子
#define _TRAP 3 //陷阱
#define _OBSTACLE 4 //障礙物
『貳』 求C語言編譯器代碼
c語言編譯器源代碼
運行環境:9x/Me/NT/2000/XP/
源碼語言:簡體中文
源碼類型:編程源碼 - VC++源碼
下載地址:http://down2.newasp.net/code/vc/cvery_4136142.rar
或:http://www.newasp.net/code/vc/2445.html
visual c++ 功能強大,不過需要的容量也很大 ,
TC2.0也不錯 很適合初學者 不過不是很標准 下面有它們的下載網站 你自己根據自己的情況,自己選擇吧,我的建議是VC6.0
TC2.0的:
http://218.64.170.103/dload1.html?cid=
http://218.64.170.103/dload1.html?cid=
VC6.0 的:
http://218.64.170.103/dload1.html?cid=
http://218.64.170.103/dload1.html?cid=
-----------------------------------
TC 比較基礎,運行也比較快,但是是DOS界面
win-tc 是tc的windows版本,圖形化界面,很好使用。
VC 適合windows平台。集成開發環境。調試方便。
[
在http://msdn.microsoft.com/visualc/vctoolkit2003/
網站點擊( Download the Visual C++ Toolkit 2003 )
]
GCC 用於Linex,但是也有windows版本。移植性比較好
另外還有c-free,div c等,也可以在windows下使用
『叄』 在線等待 關於績點計算器的TC源代碼
你的代碼錯誤很多,由於不知道你要實現的功能,只能暫時改掉錯誤,編譯運行通過了,但是不保證實現你要求的功能。你參考一下吧
#include<stdio.h>
struct data
{
int score;
int credit;
};
void enter(struct data a[],int n);
float point(struct data a[],int n);
float totalpoint(struct data point[],int n);
void main()
{
int n;
struct data data1[30];
float b;
printf("Plese input the sum of the subjects(n<=30):");
scanf("%d",&n);
enter(data1,n);
point(data1,n);
b=totalpoint(data1,n);
printf("Your totalpoint is:%f",b);
}
void enter(struct data a[],int n)
{
int i;
printf("Please input the data(score,credit):");
for(i=0;i<n;i++)
{ printf("Please input %d data:",i+1);
scanf("%d %d",&a[i].score,&a[i].credit);
}
}
float point(struct data a[],int n)
{
int i;
for(i=0;i<n;i++)
{
if(a[i].score>=90)return 4;
else if(a[i].score>=85)return 3.7;
else if(a[i].score>=82)return 3.3;
else if(a[i].score>=78)return 3.0;
else if(a[i].score>=75)return 2.7;
else if(a[i].score>=72)return 2.3;
else if(a[i].score>=68)return 2.0;
else if(a[i].score>=66)return 1.7;
else if(a[i].score>=64)return 1.5;
else if(a[i].score>=60)return 1.0;
else return 0;
}
}
float totalpoint(struct data point[],int n)
{
int i;
float a,c,b;
for(i=0;i<n;i++)
{
a=point[i].score;
a=a+a;
c=point[i].credit;
c=c+c;
}
b=a/c;
return b;
}
『肆』 誰有TC源代碼
這東西應該沒有的吧,人家還要靠他賺錢呢,不可能開放源代碼給你的
------淡淡仙戀------
『伍』 求解TC小型計算器C語言源代碼
#include<stdio.h>
main()
{
int a,b;
char ch;
printf("請輸入表達式如:1+2 \n");
scanf("%d%c%d",&a,&ch,&b);
if(ch=='/' && b==0)
printf("被除數為0請檢查表達式是否出錯?");
else
{ switch(ch)
{
case '+': printf("%d+%d=%d\n",a,b,a+b);break;
case '-': printf("%d-%d=%d\n",a,b,a-b);break;
case '*': printf("%d*%d=%d\n",a,b,a*b);break;
case '/': printf("%d/%d=%d\n",a,b,a/b);break;
}
}
}
『陸』 誰有TC寫的計算器程序源代碼
#include<iostream.h> #include<malloc.h> #include<string.h> typedef struct{ int item; long num; char p; }S1; typedef struct{ int lv; char p; }S2; S1 *S=(S1*)malloc(sizeof(S1)); S2 *P=(S2*)malloc(sizeof(S2)); long l1=0,l2=0; void S1I(void){ if(!l1)S=(S1*)realloc(S,sizeof(S1)); else S=(S1*)realloc(S,sizeof(S1)*l1); }void S2I(void){ if(!l2)P=(S2*)realloc(P,sizeof(S2)); else P=(S2*)realloc(P,sizeof(S2)*l2); }int L(char n){ switch(n){ case '+':case '-':return(1); case '*':case '/':return(2); case '(':return(3); case ')':return(4); default:return(5); } }void O(char n[]){ int i,s=strlen(n),k; for(i=0;i<s;i++){ k=L(n[i]); if(k==5){ l1++; S1I(); S[l1-1].item=0; S[l1-1].num=0; for(;i<s;i++){ if(n[i]<'0'||n[i]>'9'){i--;break;} S[l1-1].num*=10; S[l1-1].num+=(n[i]-'0'); }continue; }if(l2==0||k==3){ l2++; S2I(); P[l2-1].lv=k; P[l2-1].p=n[i]; continue; }if(k!=4){ for(;l2>0;){ if(P[l2-1].lv<k||P[l2-1].lv==3)break; l1++; S1I(); S[l1-1].item=1; S[l1-1].p=P[l2-1].p; l2--; S2I(); }l2++; S2I(); P[l2-1].lv=k; P[l2-1].p=n[i]; continue; }for(;l2>1;){ if(P[l2-1].lv==3)break; l1++; S1I(); S[l1-1].item=1; S[l1-1].p=P[l2-1].p; l2--; S2I(); }l2--; S2I(); }for(;l2>0;){ l1++; S1I(); S[l1-1].item=1; S[l1-1].p=P[l2-1].p; l2--; S2I(); }l2=l1; }long sum(int a,int b,char p){ switch(p){ case '+':return(a+b); case '-':return(a-b); case '*':return(a*b); default:return(a/b); } }long sum(int s){ long sk; if(!S[s-2].item){ if(!S[s-3].item){ l2=s-3; sk=sum(S[s-3].num,S[s-2].num,S[s-1].p); return(sk); }else{ sk=sum(sum(s-2),S[s-2].num,S[s-1].p); return(sk); } }else{ sk=sum(s-1); if(!S[l2-1].item){ sk=sum(S[l2-1].num,sk,S[s-1].p); return(sk); }else{ sk=sum(sum(l2),sk,S[s-1].p); return(sk); } } }void main(){ char n[100]; cin>>n; O(n); cout<<sum(l1)<<endl; } 不知道TC支不支持,VC下測試通過.暫時只支持所有計算後結果小於1e7,且沒有錯誤,只使用+-*/的計算
『柒』 求~~!在TC下的程序源代碼!~《學生成績查詢系統》
#include "stdio.h" /*I/O函數*/
#include "stdlib.h" /*其它說明*/
#include "string.h" /*字元串函數*/
#include "conio.h" /*屏幕操作函數*/
#include "mem.h" /*內存操作函數*/
#include "ctype.h" /*字元操作函數*/
#include "alloc.h" /*動態地址分配函數*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j<i;j++,k++)
{
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移動游標*/
textcolor(YELLOW); /*設置文本顯示顏色為黃色*/
textbackground(BLUE); /*設置背景顏色為藍色*/
window(1,1,99,99); /* 製作顯示菜單的窗口,大小根據菜單條數設計*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}
}
你自己修改,在WIN-TC下通過了編譯