C++カリキュラムデザイン-じゃんけんゲーム


C++カリキュラムデザイン-じゃんけんゲーム
文書ディレクトリ
  • C++コースデザイン-じゃんけんゲーム
  • 概要
  • コード
  • 概要
    他の人に書く大二自動化「ソフトウェア技術基礎」の授業は、じゃんけんゲームのアカウントの登録、登録とゲーム記録、ランキングを実現することを要求している.今までやったすべての授業の中で最も振り回された1つで、主な面倒はC++の中でioの流れの使用にあり、この点でC++は本当にCより人間的で、ポインタを使わずに一つ一つ突き刺さることができますが、同時に自分にファイルの流れの操作をよく勉強させました.
    コード#コード#
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    void Display();//  display  switch()  
    void Register();//  
    void Enter();//  
    using namespace std;
    int flag;
    int main()
    {
    	Display();//      1  ;2  
    	cin.get();
    	return 0;
    }
    bool cmp(float a,float b){
    	return a>b;
    }
    void Register()//  
    {
    	ofstream outFile("web1.txt");//    ID、code   web1.txt    
    	if(!outFile.is_open())//          
    	{
    		cout<<"   ,       ";
    		cout<<"    ";
    		cin.get();
    		exit(EXIT_FAILURE);
    	}
    	string name;
    	string code;
    	cout<<"Please Enter members name        : ";
    	cin.get();//     
    	getline(cin,name);
    	//  ,               
    
    	outFile<<name<<endl;//        web1.txt   
    
    	cout<<"Please Enter members code     : ";
    	getline(cin,code);
    	//  ,              
    
    	outFile<<code<<endl;//        web1.txt   
    	cout<<"    !";
    	outFile.close();
    	Display();
    }
    void Enter()//  
    {
    	cin.get();
    	ifstream inFile;//  ifstream  
    	inFile.open("web1.txt");//  web1.txt        
    	if(!inFile.is_open())//          
    	{
    		cout<<"   ,       ";
    		exit(EXIT_FAILURE);
    	}
    	string name;
    	string code;
    	string temp;
        string temp0; 
    	cout<<"Please Enter members name        : ";
    	getline(cin,name);
    
    	while(getline(inFile,temp))//     
    	{
    		if(temp==name)//         
    		{
    			cout<<"Please Enter members code     : ";//     
    			getline(cin,code);//code
    			getline(inFile,temp);//  code
    			if(temp==code)//      ,    
    			{
    				
    				cout<<"    ";
    				//  ,            
    				 int cnt=0;
        int total=0;
        char gamer; //     
        int computer; //     
        int result; //     
        //               ,          
        while (1){
        printf("          ,         :
    "
    ); printf("A:
    B:
    C:
    D:
    "
    ); scanf("%c%*c",&gamer); switch (gamer){ case 65 | 97: // A | a gamer=4; break; case 66 | 98: // B | b gamer=7; break; case 67 | 99: // C | c gamer=10; break; case 68 | 100: // D | d exit(0); break; } srand((unsigned)time(NULL)); // computer=rand()%3; // , result=(int)gamer+computer; // gamer char , printf(" "); switch (computer) { case 0:printf("
    "
    );break; //4 1 case 1:printf("
    "
    );break; //7 2 case 2:printf("
    "
    );break; //10 3 } printf(" "); switch (gamer) { case 4:printf("
    "
    );break; case 7:printf("
    "
    );break; case 10:printf("
    "
    );break; } if (result==6||result==7||result==11){ cnt++; total++; printf("
    "
    ); } else if (result==5||result==9||result==10){ cnt--; total++; printf(" !"); } else{ total++; printf(" "); } float pro; pro=float(cnt/total);// ofstream of("rank.txt"); of<<pro<<endl; of.close(); } } } else { cout<<" "; Display();// ! } } } void Display()// { cout<<"1)Register      2)Enter
    3)Exit
    4)
    Choice:"
    ; int choice;// cin>>choice; switch(choice) { case 1:// Register();//call function break; case 2:// Enter();//call function break; case 3:// exit(EXIT_FAILURE); case 4:// float res[10]; memset(res,0,sizeof(res)); ifstream inf("rank.txt"); for(int j=0;j<10;j++){ inf>>res[j]; } sort(res,res+10,cmp); for(int j=0;j<10;j++){ cout<<res[j]<<endl; } } }