精華區beta NTUCH-HW 關於我們 聯絡資訊
功能 計點 用到的觀念 用visual C++ 編譯 class CODE /*PROGRAMMER :楊翔斌*/ /*DATE :2009-12-24*/ /*FILENAME :HW06A002.cpp*/ /*DESCRIPTION:divide the card and calculate the number of big cards*/ #include "stdafx.h" #include"iostream" #include"iomanip" #include "consola.h"//can color and move the place #include "shuffle.h"//a class that can shuffle the card using namespace std; #include "compare.h"//compare the number #include "ctime" using std::time; int _tmain(int argc, _TCHAR* argv[]) { shuffle call;//declare the variable as shuffle compare Max1;//declare the variable as compare srand(time(0));//give random number char sign;////declare the variable as char int a[52],i,sumw=0,sume=0,sumn=0,sums=0,max1,max2,max3,b[52];//declare the variable and store the sum for(i=0;i<52;i++)//run the loop { a[i]=i+1;//give initial value } call.shuffle1(a);//give a to the class "shuffle" for(i=0;i<52;i++)//run the loop to divide the card { if(i==0)//divide the card to east { cout<<"east: "<<endl; } if(i>=0&&i<=12)////divide the card to east { sign=a[i]%4+3;//write the sign of the card gotoxy(1,i+2);//move the place cout<<sign;//show the sign gotoxy(2,i+2);//move the place if((a[i]%13+1)!=1&&(a[i]%13+1)!=11&&(a[i]%13+1)!=12&&(a[i]%13+1)!=13)//if it's not AJQK, show the number { cout<<a[i]%13+1;//show the number } else//if it's 13, show k. if it's 12, show Q. if it's 1, show J. if it's 1, show A. { if((a[i]%13+1)==1) cout<<"A"; else if((a[i]%13+1)==11) cout<<"J"; else if((a[i]%13+1)==12) cout<<"Q"; else if((a[i]%13+1)==13) cout<<"K"; if((a[i]%13+1)==13)//the following calculate the sum of big number of the cards { sume+=3; } else if((a[i]%13+1)==12) { sume+=2; } else if((a[i]%13+1)==11) { sume+=1; } else if((a[i]%13+1)==1) { sume+=4; } } } else if(i==13)//as above { gotoxy(8,1); cout<<"west: "; } if(i>=13&&i<=25) { sign=a[i]%4+3; gotoxy(8,i-11); cout<<sign; gotoxy(9,i-11); if((a[i]%13+1)!=1&&(a[i]%13+1)!=11&&(a[i]%13+1)!=12&&(a[i]%13+1)!=13) { cout<<a[i]%13+1; } else { if((a[i]%13+1)==1) cout<<"A"; else if((a[i]%13+1)==11) cout<<"J"; else if((a[i]%13+1)==12) cout<<"Q"; else if((a[i]%13+1)==13) cout<<"K"; if((a[i]%13+1)==13) { sumw+=3; } else if((a[i]%13+1)==12) { sumw+=2; } else if((a[i]%13+1)==11) { sumw+=1; } else if((a[i]%13+1)==1) { sumw+=4; } } } if(i==26) { gotoxy(14,1); cout<<"south: "; } if(i>=26&&i<=38) { sign=a[i]%4+3; gotoxy(14,i-24); cout<<sign; gotoxy(15,i-24); if((a[i]%13+1)!=1&&(a[i]%13+1)!=11&&(a[i]%13+1)!=12&&(a[i]%13+1)!=13) { cout<<a[i]%13+1; } else { if((a[i]%13+1)==1) cout<<"A"; else if((a[i]%13+1)==11) cout<<"J"; else if((a[i]%13+1)==12) cout<<"Q"; else if((a[i]%13+1)==13) cout<<"K"; if((a[i]%13+1)==13) { sums+=3; } else if((a[i]%13+1)==12) { sums+=2; } else if((a[i]%13+1)==11) { sums+=1; } else if((a[i]%13+1)==1) { sums+=4; } } } if(i==39) { gotoxy(21,1); cout<<"north: "; } if(i>=39&&i<=51) { sign=a[i]%4+3; gotoxy(21,i-37); cout<<sign; gotoxy(22,i-37); if((a[i]%13+1)!=1&&(a[i]%13+1)!=11&&(a[i]%13+1)!=12&&(a[i]%13+1)!=13) { cout<<a[i]%13+1; } else { if((a[i]%13+1)==1) cout<<"A"; else if((a[i]%13+1)==11) cout<<"J"; else if((a[i]%13+1)==12) cout<<"Q"; else if((a[i]%13+1)==13) cout<<"K"; if((a[i]%13+1)==13) { sumn+=3; } else if((a[i]%13+1)==12) { sumn+=2; } else if((a[i]%13+1)==11) { sumn+=1; } else if((a[i]%13+1)==1) { sumn+=4; } } } } gotoxy(1,16);//move the place cout<<"the number of big card"<<endl;//show the instruction cout<<"east:"<<sume<<setw(10)<<"west:"<<sumw<<setw(10)<<"south:"<<sums<<setw(10)<<"north:"<<sumn<<setw(10)<<endl;//show the big number gotoxy(20,20);//move the place textcolor(LIGHTMAGENTA);//color it Max1.findmax(sumn,sums,sume,sumw);//call the function to find the max system("pause");//stop return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.7.59