add 5-19
This commit is contained in:
parent
bf87703ab3
commit
e45ea8febc
135
Code/GameAcount.c
Normal file
135
Code/GameAcount.c
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
根据战争策略游戏中的游戏号相关属性(账号、密码、金币数、vip等级、材料...)
|
||||||
|
设计结构体的数据类型,实现以下的功能:
|
||||||
|
1)注册账号 2)登录 3)设置账号的相关属性 4)显示
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void Print_Guide()
|
||||||
|
{
|
||||||
|
printf("******************************\n");
|
||||||
|
printf("请输入选项编号:\n");
|
||||||
|
printf("******************************\n");
|
||||||
|
printf(" 1 注册账号\n");
|
||||||
|
printf(" 2 登录\n");
|
||||||
|
printf(" 3 退出\n");
|
||||||
|
printf("******************************\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Print_UserOptions()
|
||||||
|
{
|
||||||
|
printf("******************************\n");
|
||||||
|
printf("请输入选项编号:\n");
|
||||||
|
printf("******************************\n");
|
||||||
|
printf(" 1 设置账号属性\n");
|
||||||
|
printf(" 2 显示用户属性\n");
|
||||||
|
printf(" 3 退出至登录界面\n");
|
||||||
|
printf("******************************\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Acount
|
||||||
|
{
|
||||||
|
char acount_name[20];
|
||||||
|
char password[20];
|
||||||
|
int gold;
|
||||||
|
int vip_level;
|
||||||
|
int material;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int login_option,user_option;
|
||||||
|
char login_name[20];
|
||||||
|
char login_password[20];
|
||||||
|
|
||||||
|
struct Acount acount1;
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
Print_Guide();
|
||||||
|
scanf("%d", &login_option);
|
||||||
|
switch (login_option)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
printf("请输入账号名: ");
|
||||||
|
scanf("%s", acount1.acount_name);
|
||||||
|
printf("请输入密码: ");
|
||||||
|
scanf("%s", acount1.password);
|
||||||
|
printf("账号注册成功!\n");
|
||||||
|
printf("账号名: %s\n", acount1.acount_name);
|
||||||
|
printf("密码: %s\n", acount1.password);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
printf("请输入账号名: ");
|
||||||
|
scanf("%s", login_name);
|
||||||
|
if(strcmp(login_name,acount1.acount_name) != 0)
|
||||||
|
{
|
||||||
|
printf("账号不存在!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("请输入密码: ");
|
||||||
|
scanf("%s", login_password);
|
||||||
|
if (strcmp(login_password, acount1.password) != 0)
|
||||||
|
{
|
||||||
|
printf("密码错误!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("登陆成功!\n");
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
Print_UserOptions();
|
||||||
|
scanf("%d", &user_option);
|
||||||
|
switch (user_option)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
printf("请输入金币数: ");
|
||||||
|
scanf("%d", &acount1.gold);
|
||||||
|
printf("请输入vip等级: ");
|
||||||
|
scanf("%d", &acount1.vip_level);
|
||||||
|
printf("请输入材料数: ");
|
||||||
|
scanf("%d", &acount1.material);
|
||||||
|
printf("账号属性设置成功!\n");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
printf("账号名: %s\n", acount1.acount_name);
|
||||||
|
printf("密码: %s\n", acount1.password);
|
||||||
|
printf("金币数: %d\n", acount1.gold);
|
||||||
|
printf("vip等级: %d\n", acount1.vip_level);
|
||||||
|
printf("材料数: %d\n", acount1.material);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
printf("已退出!\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("无效选项!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(user_option == 3)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
printf("已退出!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(login_option == 3)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
18
Code/digui1.c
Normal file
18
Code/digui1.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int jiecheng(int n)
|
||||||
|
{
|
||||||
|
if(n == 0 )
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return n * jiecheng(n - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
printf("请输入一个数字: ");
|
||||||
|
scanf("%d", &n);
|
||||||
|
printf("%d的阶乘是:%d\n", n, jiecheng(n));
|
||||||
|
return 0;
|
||||||
|
}
|
19
Code/digui2.c
Normal file
19
Code/digui2.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void shizhuanger(int n)
|
||||||
|
{
|
||||||
|
if(n == 0)
|
||||||
|
return;
|
||||||
|
shizhuanger(n / 2);
|
||||||
|
printf("%d",n % 2);
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
printf("请输入一个数字: ");
|
||||||
|
scanf("%d", &n);
|
||||||
|
printf("%d的二进制是:", n);
|
||||||
|
shizhuanger(n);
|
||||||
|
printf("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
19
Code/jiegou1.c
Normal file
19
Code/jiegou1.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
struct Student
|
||||||
|
{
|
||||||
|
|
||||||
|
char name[10];
|
||||||
|
char sex;
|
||||||
|
|
||||||
|
double score;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
struct Student student;
|
||||||
|
|
||||||
|
printf("这个结构体的大小是:%ld个字节\n", sizeof(student));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Code/output/GameAcount
Normal file
BIN
Code/output/GameAcount
Normal file
Binary file not shown.
BIN
Code/output/digui1
Normal file
BIN
Code/output/digui1
Normal file
Binary file not shown.
Binary file not shown.
BIN
Code/output/jiegou1
Normal file
BIN
Code/output/jiegou1
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user