帮忙做个C语言程序,谢谢!再麻烦写完整点,我是个菜鸟!!!谢谢谢谢!!!

2024年11月30日 15:28
有1个网友回答
网友(1):

//VC++6。0下调试通过
//这是用C++写的一个简单的抽获程序。你自己试试吧。
/*抽奖程序
预先将参加抽奖者的资料输入存储起来,主要用结构体数组实现,用结构体表示每项记录,
包括身份证号码、姓名、电话、住址等信息。
开始抽奖时,屏幕上快速闪动参与者的身份证号码,按任意键停止闪动,
把中奖人的信息用显示在屏幕上。可反复抽出一、二、三等奖若干名。
设计实现以下功能:
(1)录入:完成抽奖者信息的输入;
(2)删除:完成抽奖者信息的删除;
(3)修改:允许对已经录入的数据重新进行编辑、修改;
(4)显示:显示所有中奖者的信息;
(5)抽奖:*/
//Cpp43.cpp
#include
#include
#include
#include
using namespace std;

struct Player
{
char id[20];
char name[20];
char telnum[15];
char addr[50];
};

static Player arr[100]={
{"612123123456789012","Sha Zhi Kuayi","12345678900","xi'an china"},
{"512123123456789013","Zhi Jing Xuantie","12345678999","xi'an china"},
{"412123123456789014","Ni Ming","12345678988","anywhere"},
{"312123123456789015","Jack Tie","12345678977","WOW"},
{"212123123456789016","Mack Kua","12345678966","HK"}
};
static signed short len=5;

void printMenu()
{
cout<<"----------------------------------------"< cout<<"Press 1 -->Add a new player information. "< cout<<"Press 2 -->Delete a player Info. by ID."< cout<<"Press 3 -->Update a player Info. by ID."< cout<<"Press 4 -->Display players."< cout<<"press 5 -->Game Start!"< cout<<"press 0 exit system"< cout<<"----------------------------------------"< cout<<">>";
}

bool addInfo(Player player)
{
if (100==len)
return false;
arr[len++]=player;
return true;
}

int deleteInfo(char* id)
{
if (!id)
return -2;
for (int i=0; i {
if (!strcmp(arr[i].id,id))
break;
}
if (i==len)
return -1;
Player player;
for (; i {
player=arr[i+1];
arr[i]=player;
}
return --len;
}

int findInfo(char* id)
{
if (!id)
return -2;
for (int i=0; i {
if (!strcmp(arr[i].id,id))
return i;
}
return -1;
}

void updateInfo(int index, Player player)
{
arr[index]=player;
}

int displayInfo()
{
cout<<"-------身份证-------";
cout<<"-------姓名-------";
cout<<"----电话----";
cout<<"---------地址---------"< for (int i=0; i {
cout.width(20);
cout< cout.width(18);
cout< cout.width(12);
cout< cout.width(20);
cout< }
return len;
}

int runGame(int delay=100)
{
fflush(stdin);
for (int i=0; !kbhit(); i=(i++%(len-1)))
{
Sleep(delay);
cout< }
cout< return i;
}

void main()
{
printMenu();
char menu;
while (cin>>menu)
{
fflush(stdin);
switch (menu)
{
case '1':
while (1)
{
Player player;
memset(&player,0,sizeof(Player));
cout<<"please input player's ID(0 will break): ";
cin.getline(player.id,20);
if (!strcmp(player.id,"0"))
break;
cout<<"please input player's name: ";
cin.getline(player.name,20);
cout<<"please input player's telephone number: ";
cin.getline(player.telnum,15);
cout<<"please input player's address: ";
cin.getline(player.addr, 50);
if (addInfo(player))
cout<<"Succeed!"< else cout<<"Failing!"< }
printMenu();
break;
case '2':
while (1)
{
char id[20];
cout<<"please input player's ID(0 will break): ";
cin.getline(id,20);
if (!strcmp(id,"0"))
break;
int r=deleteInfo(id);
switch (r)
{
case -1:
cout<<"Sorry, can't find player Info by this ID."< break;
case -2:
cout<<"Sorry, any records are use for delete."< break;
default:
cout<<"Succeed! player amount: "< }
}
printMenu();
break;
case '3':
while (1)
{
char id[20];
cout<<"please input player's ID(0 will break): ";
cin.getline(id,20);
if (!strcmp(id,"0"))
break;
int index=findInfo(id);
switch (index)
{
case -1:
cout<<"Sorry, can't find player Info by this ID."< break;
case -2:
cout<<"Sorry, any records are use for update."< break;
default:
Player player;
cout<<"ID:"<> ";
cin.getline(player.id,20);
cout<<"Name:"<> ";
cin.getline(player.name,20);
cout<<"Telephone Number:"<> ";
cin.getline(player.telnum,15);
cout<<"Address:"<> ";
cin.getline(player.addr,50);
updateInfo(index, player);
cout<<"Succeed!"< }
}
printMenu();
break;
case '4':
displayInfo();
printMenu();
break;
case '5':
int winner;
int i;
for (i=0; i<3; i++)
{
cout<<"No."< getch();
winner=runGame();
cout<<"No."< cout<<"Name:"< cout< cout< }
break;
case '0':
cout<<"Thanks! Bye!"< return;
default:
printMenu();
}
fflush(stdin);
}
cout<<"Thanks! Bye!"<}