课程设计c语言
⑴ c语言课程设计
自己做吧,这样才能学到东西!
⑵ c语言课程设计
刚为别人做了一个,和你这个很像,不过用的是单项链表方式而不是array.
自己修改下满足你的要求吧
#include <stdio.h>
#include <string.h>
#include <stddef.h>
struct StudentCard {
int index; //学生号
char name[80]; //姓名
int age; //年龄
char sex[80]; //性别
int classroom; //班级
char school[80]; //学校
char birthday[80]; //出生年月
struct StudentCard *next; //到下一个学生卡,链表
};
typedef struct StudentCard ELEMENT; //自定义符号
typedef ELEMENT *LINK;
LINK add(LINK head){ //加入一个新的学生信息,该函数将返回一个struct的指针
int index,age,classroom;
char name[80],sex[80],school[80],birthday[80];
printf("Please input index number: ");
scanf("%d",&index);
printf("Please input name: ");
scanf("%s",name);
printf("Please input age: ");
scanf("%d",&age);
printf("Please input sex(nan or nv): ");
scanf("%s",sex);
printf("Please input classroom: ");
scanf("%d",&classroom);
printf("Please input school: ");
scanf("%s",school);
printf("Please input birthday :");
scanf("%s",birthday);
if (!head){ //如果是头链表为空的情况,也就是输入第一个学生卡
head=malloc(sizeof(ELEMENT));
head->index=index;
head->age=age;
head->classroom=classroom;
strcpy(head->name,name);
strcpy(head->sex,sex);
strcpy(head->school,school);
strcpy(head->birthday,birthday);
head->next=NULL; //下一个元素为NULL,空
printf("Successful!\n");
return head; //返回头链
}
else{
LINK tail=head;//用一个哨兵指针指向头元素
while ((tail)&&(tail->index!=index))
//在tail为NULL并且tail的index不与用户输入的index相等之前,tail一直跳到下一个元素
tail=tail->next;
if (tail) //如果存在这个tail
printf("index has already existed! Failed!\n");
else{
tail=head;//再次初始化
while (tail->next) //当哨兵的下一个元素存在时,哨兵跳到哨兵下一个元素
tail=tail->next;
//当上面这个循环结束后,此时tail的下一个元素必定为NULL
tail->next=malloc(sizeof(ELEMENT));//创建新的元素
tail=tail->next; //跳转到下一个新创建的元素
tail->index=index;
tail->age=age;
tail->classroom=classroom;
strcpy(tail->name,name);
strcpy(tail->sex,sex);
strcpy(tail->school,school);
strcpy(tail->birthday,birthday);
tail->next=NULL;
printf("Successful!\n");
return head;
}
}
}
void Print_ALL(LINK head){//该函数输出所有学生信息
LINK tail=head;
if (!head) //如果头元素为NULL,就是链表无一个元素
printf("Empty List!\n");
else{
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
while (tail){//知道哨兵为NULL之前,一直输出哨兵的内容
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
tail=tail->next;
}
}
};
void Print_DEPEND_INDEX(LINK head){ //该函数输出指定的学生号的学生信息
int tem;
LINK tail=head;
printf("Please input the index number of student: ");
scanf("%d",&tem);
if (!head)
printf("Empty List!\n");
else{
while ((tail)&&(tail->index!=tem))
tail=tail->next;
if (!tail)
printf("student not existed!\n");
else{
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
}
}
}
void Print_DEPEND_CLASS(LINK head){ //该函数输出指定的班级的学生信息
int tem;
LINK tail=head;
printf("Please input classroom: ");
scanf("%d",&tem);
if (!head)
printf("Empty List!\n");
else{
while ((tail)&&(tail->classroom!=tem))
tail=tail->next;
if (!tail)
printf("No such classroom!\n");
else{
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
while (tail){
if (tail->classroom==tem){
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
}
tail=tail->next;
}
}
}
}
void Print_DEPEND_SEX(LINK head){ //该函数输出男或女同学信息
char tem[80];
printf("please input sex(nan or nv): ");
scanf("%s",tem);
if (!head)
printf("Empty List!\n");
else{
LINK tail=head;
while ((tail)&&(strcmp(tem,tail->sex)!=0))
//当不相等或者tail有效时,tail跳到下一个元素
tail=tail->next;
if (!tail)
printf("No %s student!\n",tem);
else{
tail=head;
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
while (tail){
if (strcmp(tem,tail->sex)==0){
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
}
tail=tail->next;
}
}
}
}
LINK Edit(LINK head){ //该函数用来修改信息
int tem;
LINK tail=head;
printf("Please input index of student: ");
scanf("%d",&tem);
if (!head){
printf("Empty List!\n");
return NULL;
}
else{
while ((tail)&&(tail->index!=tem))
tail=tail->next;
if (!tail){
printf("No such student!\n");
return head;
}
else{
printf("Please input name: ");
scanf("%s",tail->name);
printf("Please input age: ");
scanf("%d",&tail->age);
printf("Please input sex(nan or nv): ");
scanf("%s",tail->sex);
printf("Please input classroom: ");
scanf("%d",&tail->classroom);
printf("Please input school: ");
scanf("%s",tail->school);
printf("Please input birthday :");
scanf("%s",tail->birthday);
printf("Edit successful!\n");
return head;
}
}
}
LINK DELETE(LINK head){ //该函数用来删除学生信息
int tem;
LINK tail=head;
printf("Please input index of student: ");
scanf("%d",&tem);
if (!head){
printf("Empty List!\n");
return NULL;
}
else if ((head->index==tem)&&(!head->next)){//当头元素满足并且链表只有一个元素
printf("Deleted!\n");
return NULL;
}
else if ((head->index==tem)&&(head->next)){//当头元素满足并且链表有许多元素
printf("Deleted!\n");
return head->next;
}
else{ //当满足条件的元素在链表中间或者结尾
while ((tail)&&(tail->index!=tem))
tail=tail->next;
if (!tail){
printf("No such student!\n");
return head;
}
else{
if (!tail->next){//当满足条件的元素在链表结尾
LINK tail2=head;//新的哨兵
while (tail2->next!=tail)
tail2=tail2->next;
tail2->next=NULL; //直接指向为NULL,表示链表尾,跳过tail
printf("Deleted!\n");
return head;
}
else{ //当满足条件的元素在链表中间
LINK tail2=head;//新的哨兵
while (tail2->next!=tail)
tail2=tail2->next;
tail2->next=tail->next; //跳过tail这个元素
printf("Deleted!\n");
return head;
}
}
}
}
void Display_MENU(){
printf("\t*********studentcard management system*********\n");
printf("\t1.Input student's informations (add a student)\n");
printf("\t2.Print all students' informations\n");
printf("\t3.Input index number,print selected student's information\n");
printf("\t4.Input classroom number,print informations of those students\n");
printf("\t5.Input index number, modify information\n");
printf("\t6.Input index number, remove information\n");
printf("\t7.Print nan or nv informations\n");
printf("\t8.Display Menu\n");
printf("\t9.Exit\n");
printf("\t***********************************************\n");
}
int main(){
LINK head=NULL; //链表头的初始化
int asker;
Display_MENU();
while(1){
printf(">>");
scanf("%d",&asker);
if (asker==1)//加入新学生信息
head=add(head);
else if (asker==2)//输出所有学生信息
Print_ALL(head);
else if (asker==3) //输入学生号,输出学生信息
Print_DEPEND_INDEX(head);
else if (asker==4) //输入班级,输出学生信息
Print_DEPEND_CLASS(head);
else if (asker==5) //输入学生号,修改学生信息
head=Edit(head);
else if (asker==6) //输入学生号,删除学生信息
DELETE(head);
else if (asker==7) //输入男或女,输出学生信息
Print_DEPEND_SEX(head);
else if (asker==8) //显示菜单
Display_MENU();
else if (asker==9) //退出程序,也就是退出while(1)循环
break;
else
printf("please select correct number!\n");
}
printf("system log-out!\n");
return 0;
}
⑶ C语言课程设计
建好结构体,用链表操作然后慢慢调试 还是比较简单的。。
这种基础问题最好还是自己做。。
⑷ C语言程序设计 (学生选修课程设计)
这是我做的,你看是否满意?可能有点大,但也没办法呀,你的题目也比较大,呵呵!所以,如果满意,多给我追加点分!
#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
typedef
struct
course
{
char
number[15],name[25];
int
kind,time,lessontime,practicetime,credit,term;
}type;
FILE
*fp1;
void
overview();
//浏览函数,负责浏览整个课程信息
void
seek();
//查询函数,负责查询课程信息
void
choose_course();//选课函数,负责让用户选课
void
out(type
temp);
void
input();
int
main()
{
int
n,i;
if((fp1=fopen("course_information.txt","wb"))==NULL)
{printf("创建文件失败!\n");exit(0);}
printf("请输入要存储的课程数目:\n");
scanf("%d",&n);
printf("开始创建文件,请输入课程信息:\n\n");
for(i=0;i<n;i++)
{
printf("请输入第%d门课程的信息:\n",i+1);
input();
printf("\n");
}
printf("如想浏览整个课程信息,请输入1;如想查询课程信息,请输入2;
如想进行选课,请输入3;如想结束选修课系统,请输入0!\n");
while((scanf("%d",&n))!=EOF)
{
if(n==1)
overview();
if(n==2)
seek();
if(n==3)
choose_course();
if(n==0)
exit(0);
printf("\n\n如想继续操作,只要按规则输入你要进行的操作即可!\n规则:如想浏览整个课程信息,请输入1;如想查询课程信息,请输入2;如想进行选课,请输入3!\n");
}
printf("欢迎您使用此程序进行选课,谢谢!\n");
fclose(fp1);
return
0;
}
void
input()
{
course
c_a;
printf("请输入课程编码:
");
scanf("%s",c_a.number);
printf("请输入课程名:
");
scanf("%s",c_a.name);
printf("请输入课程性质:限选课,请输入1;选修课,请输入2;必修课,请输入3!
");
scanf("%d",&c_a.name);
printf("请输入课程总学时:
");
scanf("%d",&c_a.time);
printf("请输入课程授课时间:
");
scanf("%d",&c_a.lessontime);
printf("请输入课程实验或实践时间:
");
scanf("%d",&c_a.practicetime);
printf("请输入课程学分:
");
scanf("%d",&c_a.credit);
printf("请输入课程所在的学期,比如第二学期,就输入2即可。");
scanf("%d",&c_a.term);
fwrite(&c_a,sizeof(struct
course),1,fp1);//将一个结构体元素写入文件中
}
void
out(type
temp)
{
printf("课程代码:
%s\n课程名:
%s\n",temp.number,temp.name);
printf("课程名:
%s\n",temp.name);
if(temp.kind==1)
printf("课程性质:
Limited
optional
course\n");
else
if(temp.kind==2)
printf("课程性质:
Optional
course\n");
else
if(temp.kind==3)
printf("课程性质:
Required
Courses\n");
else
printf("该编码系统不认识,即无对应的课程性质存在!\n");
printf("课程总学时:
%d\n课程授课学时:
%d\n实验或上机学时:
%d\n学分:
%d\n课程开课学期:
%d\n\n",temp.time,temp.lessontime,temp.practicetime,temp.credit,temp.term);
}
void
overview()
{
rewind(fp1);
course
temp;
printf("整个课程信息如下:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
out(temp);
}
void
seek()
{
int
judge,credit=0,kind=0;
char
a='N';
course
temp;
printf("如想按学分查询,请输入1;如想按课程性质,请输入2:\n");
scanf("%d",&judge);
rewind(fp1);
//将文件指针位置置为开头
if(judge==1)
{
printf("请输入要查询的学分:\n");
scanf("%d",&credit);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(credit==temp.credit)
out(temp);
}
else
if(judge==2)
{
printf("请输入你要查找课程的性质(限选课,请输入1;选修课,请输入2;必修课,请输入3):");
scanf("%d",&kind);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(temp.kind==kind)
out(temp);
}
else
printf("不好意思,无此类查询!\n");
}
void
choose_course()
{
rewind(fp1);
course
temp;
int
judge=1,n=0,time=0,credit=0;
char
choose[20][20];
r1:
printf("请开始填写课程编号进行选课:\n");
while(judge==1)
{
printf("请输入你所选课程的标号:
");
scanf("%s",choose[n]);
n++;
printf("如想继续选课,请输入1;如想提交,请输入0!\n");
scanf("%d",&judge);
}
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{time=time+temp.time;credit=temp.credit;break;}
}
if(time<270||credit<40)
goto
r1;
printf("你所选的课为:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{out(temp);break;}
}
}
⑸ C语言程序课程设计
我给你发一段编码
然后你粘贴上去,运行看看吧
************************************************
#include <iostream.h>
#include <iomanip.h>
#define SN 10 // 学生人数
#define CN 3 // 课程数目
int course; // 要排序的那门课程
struct student
{ int num;
char name[10];
int score[CN];
};
void bubble(struct student *pstu) //冒泡排序(从大到小)
{ struct student tmp;
for (int i = 0; i < SN; i++) // 要排SN个数,则应排SN遍:
{
for(int j = 0; j < SN - i - 1; j++)
{
if(pstu[j+1].score[course] > pstu[j].score[course]) //比较相邻的两个数:
{ tmp = pstu[j+1];
pstu[j+1]= pstu[j];
pstu[j]= tmp;
} //对调两个数,需要有"第三者"参以
}
}
}
void output(struct student *pstu)
{
cout<<setw(8)<<"学号";
cout<<setw(10)<<"姓名";
cout<<setw(8)<<"语文";
cout<<setw(8)<<"数学";
cout<<setw(8)<<"外语"<<endl;
for(int i=0;i<SN;i++)
{ cout<<setw(8)<<pstu[i].num;
cout<<setw(10)<<pstu[i].name;
for (int j=0;j<CN;j++)
cout<<setw(8)<<pstu[i].score[j];
cout<<endl;}
}
void avgscore(struct student *pstu)
{
int sum[CN],n;
for(n=0; n<CN; n++)
{ sum[n]=0;
for(int j=0; j<SN; j++)
sum[n]+=pstu[j].score[n];
}
cout<<"各科课程的平均成绩:";
for(n=0;n<CN; n++)
cout<<setw(5)<<sum[n]/SN;
cout<<endl;
}
void maxmin(struct student *pstu)
{
int max[CN],min[CN],n;
for(n=0; n<CN; n++)
{ max[n]=0;
min[n]=100;
for(int j=0; j<SN; j++)
{ if (pstu[j].score[n]>max[n])
max[n]=pstu[j].score[n];
if (pstu[j].score[n]<min[n])
min[n]=pstu[j].score[n];
}
}
cout<<"各科课程的最高分: ";
for(n=0;n<CN; n++)
cout<<setw(5)<<max[n];
cout<<endl;
cout<<"各科课程的最低分: ";
for(n=0;n<CN; n++)
cout<<setw(5)<<min[n];
cout<<endl;
}
void main()
{
struct student stu[SN]={
{2004101,"林志颖",89,67,90},
{200,"杨呀呀",65,80,56},
{2004103,"周星驰",76,66,71},
{2004104,"画风",60,76,88},
{2004105,"王小鸭",82,90,78},
{2004106,"陈道明",70,81,93},
{2004107,"刘德华 ",85,60,76},
{2004108,"邹石墙 ",80,76,61},
{2004109,"林大",70,66,98},
{2004110,"张依依",62,60,87},
};
int n;
cout<<setw(30)<<"*** 学生成绩管理 ***"<<endl<<endl;
cout<<"要对第几门课程的成绩排序: ";
cin>>n; //输入要排序的第几门课程
course=n-1;
struct student *pstu=stu;
cout<<endl;
bubble(pstu);
output(pstu);
cout<<endl;
maxmin(pstu);
avgscore(pstu);
}
**************************************************
⑹ C语言课程设计
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <conio.h>
typedef struct linknode
{
long number; /* 编号 */
char name[51]; /* 名称 */
double price; /* 价格 */
long amount; /* 数量 */
double money; /* 总价 */
char procer[21]; /* 生产商 */
struct linknode *next;
} linknode;
linknode *head, *tail;
int NODSIZE;
void error(const char *errmsg);
void init();
void eatenter();
void input(linknode *node);
void insert();
void locate(linknode **pprev, linknode **pnext);
void remove();
void modify();
void output(linknode *node);
void search();
void cleanup();
void display();
void error(const char *errmsg)
{
puts(errmsg);
cleanup();
exit(1);
}
void init()
{
NODSIZE = sizeof(linknode);
head = tail = (linknode *)malloc(NODSIZE);
if (head == NULL)
error("无法分配内存!");
memset(head, 0, sizeof(linknode));
printf("欢迎使用简单货物信息管理系统\n");
}
void eatenter()
{
while (getchar() != '\n');
}
void input(linknode *node)
{
printf("商品名称: ");
scanf("%50[^\n]", node->name);
eatenter();
printf("商品价格: ");
scanf("%lf", &node->price);
eatenter();
printf("商品数量: ");
scanf("%ld", &node->amount);
eatenter();
printf("商品生产商: ");
scanf("%20[^\n]", node->procer);
eatenter();
node->money = node->price * node->amount;
}
/* 添加信息 */
void insert()
{
linknode *node;
long num;
printf("\n请根据提示输入商品信息(编号0结束)\n");
while (1)
{
printf("商品编号: ");
scanf("%ld", &num);
eatenter();
if (num == 0)
break;
node = (linknode *)malloc(NODSIZE);
if (node == NULL)
error("无法分配内存!");
node->number = num;
input(node);
tail->next = node;
tail = node;
tail->next = NULL;
}
}
void locate(linknode **pprev, linknode **pnext)
{
char choice, nm[51];
long num;
int invalid;
printf("请选择查找方式:\n");
printf("1: 名称 2: 编号\n");
do
{
invalid = 0;
choice = getchar();
eatenter();
if (choice != '1' && choice != '2')
{
printf("无效选项!请重新输入。\n");
invalid = 1;
}
}
while (invalid);
if (choice == '1')
{
printf("货物名称: ");
scanf("%50[^\n]", nm);
}
else
{
printf("货物编号: ");
scanf("%ld", &num);
}
eatenter();
printf("\n");
*pprev = head, *pnext = head->next;
invalid = 0;
while (*pnext)
{
if (choice == '1' && !strcmp((*pnext)->name, nm))
{
invalid = 1;
}
else if ((*pnext)->number == num)
{
invalid = 1;
}
if (invalid)
break;
(*pprev) = (*pnext);
(*pnext) = (*pnext)->next;
}
}
/* 删除信息 */
void remove()
{
linknode *prev, *cursor;
locate(&prev, &cursor);
if (cursor)
{
printf("成功删除记录\n");
prev->next = cursor->next;
if (cursor == tail)
tail = prev;
free(cursor);
}
else
{
printf("无法找到记录\n");
}
printf("按任何键返回上层菜单...\n");
getch();
}
/* 修改信息 */
void modify()
{
linknode *prev, *cursor;
locate(&prev, &cursor);
if (cursor)
{
printf("货物编号: ");
scanf("%ld", &cursor->number);
eatenter();
input(cursor);
printf("成功更新记录\n");
}
else
{
printf("无法找到记录\n");
}
printf("按任何键返回上层菜单...\n");
getch();
}
void output(linknode *node)
{
printf("商品编号: %ld\n", node->number);
printf("商品名称: %s\n", node->name);
printf("商品价格: %.2f\n", node->price);
printf("商品数量: %ld\n", node->amount);
printf("商品生产商: %s\n", node->procer);
printf("商品总价: %.2f\n\n", node->money);
}
void search()
{
linknode *prev, *cursor;
locate(&prev, &cursor);
if (cursor)
{
output(cursor);
}
else
{
printf("无法找到记录\n");
}
printf("按任何键返回上层菜单...\n");
getch();
}
void cleanup()
{
linknode *cursor = head;
while (cursor)
{
head = head->next;
free(cursor);
cursor = head;
}
}
void display()
{
linknode *cursor = head->next;
while (cursor)
{
output(cursor);
cursor = cursor->next;
}
printf("按任何键返回上层菜单...\n");
getch();
}
void main()
{
char choice;
printf("欢迎使用简单商品管理系统\n");
init();
while (1)
{
printf("请选择相关操作:\n");
printf("1: 添加记录\t2: 删除记录\t");
printf("3: 查询记录\n4: 修改记录\t");
printf("5: 显示记录\t6: 退出程序\n");
choice = getchar();
eatenter();
switch ( choice )
{
case '1':
insert();
break;
case '2':
remove();
break;
case '3':
search();
break;
case '4':
modify();
break;
case '5':
display();
break;
case '6':
cleanup();
exit(0);
}
system("cls");
}
}
⑺ C语言课程设计
做一个猜数字的游戏,参考代码:
#include "stdio.h"
#include "conio.h"
#include "dos.h"
#include "stdlib.h"
void main()
{
int z,z1,ia,ib,iindex,iindex1,i,ag,i_1,i_2,easy,xianshi;/*定义变量*/
int i1[5],i2[5];
char yesno;
chooes:/*设置GOTO点*/
printf("please chooes :\n 1 for nomal\n 2 for hard\n please input 1 or 2 :");/*选择难度开始*/
scanf("%d",&easy);
if(easy==1)
{
iindex1=20;
}
else
{
if(easy==2)
{
iindex1=10;
}
else
{
if(easy==520)
{
shua();/*调用刷小屏涵数*/
printf("wahahahaaaaa.......\nyou choose -=Crazy=- model!!!\n");
iindex1=5;
getch();
}
else
{
shua();/*调用刷小屏涵数*/
printf("**erroy...\n please input again...\n 1 or 2:");
goto chooes;
}
}
}
for(iindex=0;iindex<10;iindex++)/*为变量赋值*/
{
i1[iindex]=0;
i2[iindex]=0;
}
ia=0,ib=0,z=11;
iindex=0;
do/*随机选取1-9999的数,放弃1-999的数,选择1000-9999的数*/
{
for(iindex=0;iindex {z=random(100)*random(100);}/*随机选数*/
i1[3]=z%10;/*把随即数分成4个*/
i1[2]=z/10%10;
i1[1]=z/100%10;
i1[0]=z/1000%10;
}
while(z<1000||i1[0]==i1[1]||i1[0]==i1[2]||i1[0]==i1[3]||i1[1]==i1[2]||i1[1]==i1[3]||i1
[2]==i1[3]||i1[0]==0);/*判断每一位数是否相同,如果是则重新输出*/
shua();/*调用刷小屏涵数*/
printf("Now!!you have %d lifes!!Game Star!!\n",iindex1);/*游戏开始*/
printf(" please input 4 numbers :\n\n");
for(xianshi=10;iindex1>0;iindex1-=1,xianshi-=1)/*iindex1决定尝试次数*/
{ do
{
printf("*");
scanf("%d",&z1);
i2[3]=z1%10;/*把玩家输入的数分离成4个*/
i2[2]=z1/10%10;
i2[1]=z1/100%10;
i2[0]=z1/1000%10;
if(z1>9999||z1<1000||i2[0]==i2[1]||i2[0]==i2[2]||i2[0]==i2[3]||i2[1]
==i2[2]||i2[1]==i2[3]||i2[2]==i2[3]||i2[0]==0)/*判断玩家输入数字是否每一位不同,是则重新输入
*/
{
shua();/*调用刷小屏涵数*/
printf("\n**erroy...\n please input again :\n\n");
continue;
}
else
{
break;
}
}while(1);/*设置非0,使循环直到break*/
ib=0;/*开始判断:数字正确,位置错误的个数(B)*/
if(i1[0]==i2[1])ib++;
if(i1[0]==i2[2])ib++;
if(i1[0]==i2[3])ib++;
if(i1[1]==i2[0])ib++;
if(i1[1]==i2[2])ib++;
if(i1[1]==i2[3])ib++;
if(i1[2]==i2[0])ib++;
if(i1[2]==i2[1])ib++;
if(i1[2]==i2[3])ib++;
if(i1[3]==i2[0])ib++;
if(i1[3]==i2[1])ib++;
if(i1[3]==i2[2])ib++;
for(ia=0,iindex=0;iindex<4;iindex++)/*开始判断位置正确,数字错误的数(A)*/
{
if(i1[iindex]==i2[iindex])
{
ia++;
}
}
printf("-----\n");
printf("*%dA%dB\n\n",ia,ib);
gotoxy(60,11-xianshi),printf("%2d. %d * %dA%dB",11-xianshi,z1,ia,ib);/*在右边显
示出之前的输入*/
shua();/*调用刷小屏涵数*/
if(z==z1)
{
printf("\n");
break;
}
else
{
printf(" you have last %d life...\n try again :\n\n",iindex1-1);
continue;
}
}
if(iindex1==0)/*判断输赢*/
{
printf("ans is *%d*\n",z);
printf("***sorry you lose...***");
for(i=10;i>0;i--)
{ sound(100*i);
delay(10000000);
nosound();
}
}
else
{ printf("***GREAT!! You WIN!!***");
for(i=1;i<10;i++)
{ sound(100*i);
delay(10000000);
nosound();
}
}
getch();
printf(" \n\nplay again?? y/n : ");/*是否重来*/
scanf("%s",&yesno);
if(strcmp('y',yesno)==0)
{
clrscr();/*清屏*/
goto chooes;
}
else
{
if(strcmp('n',yesno)==0)
{
printf(" 88...\n");
printf(" press any key to quit...");
}
else
{
shua();
printf(" sorry,input again...\n y/n : ");
}
}
getch();
}
shua()/*刷小屏涵数*/
{
int i_1,i_2;
for(i_1=0;i_1<40;i_1++)
{
for(i_2=0;i_2<25;i_2++)
{
gotoxy(i_1,i_2),printf(" ");
}
}
gotoxy(1,1);
}
⑻ c语言课程设计
课程设计是培养学生综合运用所学知识,发现,提出,分析和解决实际问题,锻炼实践能力的重要环节,是对学生实际工作能力的具体训练和考察过程.随着科学技术发展的日新日异,当今计算机应用在是生活中可以说得是无处不在。因此作为二十一世纪的大学来说掌握计算机开发技术十分重要的。
我的题目是文章处理系统的设计,对于我们这些新手来说,这是很大的考验,我一千次一万次的问自己,怎么才能找到课堂所学与实际应用的最佳结合点?怎么才能让自己的程序在篇幅上简单,在使用价值上丰富?怎样让自己的业余更靠近专业?怎样让自己的计划更具有序性,而不会忙无一用?机会是老师,学校,以及无数代教育工作者给的,而能力是自己的,耐性是需要的。经过自己的琢磨,听取了师姐,师兄们的建议,还查阅了很多书籍,才做到了心中有数,才了解了C语言课程设计的真正用意——培养自学能力,养成程序编辑的好习惯。我从来不相信车到山前必有路的说法,认为那只是懒惰者自寻懒惰的借口,我要积极,要把握,要努力。
回顾起此次课程设计,至今我仍感慨颇多,的确,从从拿到题目到完成整个编程,从理论到实践,在整整半个学期的日子里,可以学到很多很多的的东西,同时不仅可以巩固了以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正为社会服务,从而提高自己的实际动手能力和独立思考的能力。在设计的过程中遇到问题,可以说得是困难重重,这毕竟第一次做的,难免会遇到过各种各样的问题,同时在设计的过程中发现了自己的不足之处,对以前所学过的知识理解得不够深刻,掌握得不够牢固,比如说结构体……通过这次课程设计之后,一定把以前所学过的知识重新温故。
这次课程设计终于顺利完成了,在设计中遇到了很多编程问题,最后在郭老师的辛勤指导下,终于游逆而解。同时,在郭老师的身上我学得到很多实用的知识,在次我表示感谢!同时,对给过我帮助的所有同学和各位指导老师再次表示忠心的感谢
在课程设计过程中,我学到了很多人生的哲理,懂得怎么样去制定计划,怎么样去实现这个计划,并掌握了在执行过程中怎么样去克服心理上的不良情绪,黑夜过去了,我们收获的是黎明。在本次实践中,给我印象最为深刻的是在文件删除程序的编译过程中,先有我的各个子程序都已经编辑成功,那么这最后的程序就将是我成功的关键。老天不会让我太过顺利,他在这最后的时刻设置的障碍,是要考验我的能力,他要置我于死地?在这个问题的解决上,我打了退堂鼓,我不能忍受长时间的无功而反,时间正在消磨我的意志。没有了柳暗花明的一天,那么我怎么能说经受住了考验?谢谢老师的那句话,她说:人力有所不能及,然而,人的精神是不会败倒的。我鼓起勇气,到处问,到处查资料,黄天不负有心人,在一篇文章上,终于看到了我所特别要求的函数,我实现了组合是关键的理论。不得不说这是精神的胜利,是永不言败的精神让我的程序重见天日。谢谢给我指点迷津的老师。
6月11日,我们的课程设计结束了,但是它留给我的印象是不可磨灭的。无论我以后会不会涉及到C语言程序编译的研究,我想,我至少掌握了一种系统的研究方法,我们学习的目的就在于运用,我们运用这种研究方法的时候会很多,我最后要感谢课程设计,它的确教会我很多。
另外,虚机团上产品团购,超级便宜
⑼ c语言课程设计!急!!!
#include<stdio.h>
#include<stdlib.h>//应用动态存储分配函数//
#include<time.h>
# define LEN sizeof(struct question)
struct question
{
char ask[200];//选择题题目//
char answer[4][80];//选择题选项,每个答案的长度//
int right;//正确答案//
struct question *next;//next是指针类型的成员,
//它指向struct question类型数据(即next所在的结构体类型)
//使用指针类型成员存放下一个结点的地址
//此步骤实现了问题的连续输入输入
};
int menu(void);//声明菜单选择函数
struct question *seek(struct question *seek,long len,long max);//寻找读取答案的位置
struct question *insert(struct question *fst,const struct question *ad);//插入试题
void getquestion(struct question *s);//获取问题,选项,以及正确答案
void savefile(const struct question *a,FILE *sf);//保存最佳答案在文件中//
struct question *loadfile(struct question *b,FILE *lf);//读取题目,将题目添加到列表中
int getanswer(void);//得到答案
int getyouranswer(void);//得到考生答案
void explainquestion(const struct question *q,int n);//统计答对题目数,显示得分
//选择菜单//
int menu(void)
{
int v;
printf("1—添加选择题\n2—回答选择题\n3—退出\n");
scanf("%d",&v);
return v;
}
//seek函数确定一个读取答案的位置,len代表要读取的答案数,max代表列表的长度//
struct question *seek(struct question *seek,long len,long max)
{
int i;
srand(time(NULL));
while(i=rand()%max+len<max);//随机选取一个读题目的位置//
while(i--)
seek=seek->next;//找到指定的位置//
return seek;
}
//向列表中插入试题//
struct question *insert(struct question *fst,const struct question *ad)
{
struct question *newptr=(struct question *)malloc(LEN);//分配新的内存空间//
if (newptr==NULL)
exit(0);
*newptr=*ad;
newptr->next=fst;
return newptr;
}
//获取问题,选项,以及正确答案//
void getquestion(struct question *s)
{
int i=0;
printf("请输入选择题题目:\n");
scanf("%s",s->ask);//指向结构体中的成员//
while(i<4)
{
printf("请输入选项%c的答案:\n",i+'A');
scanf("%s",s->answer[i++]);
}
s->right=getanswer();
}
//试题保存//
void savefile(const struct question *a,FILE *sf)//使用const说明成员函数//
{
fclose(sf);
if((sf=fopen("kstm.dat","w"))==NULL)//以写的方式重新打开文件//
return;
while(a)
{
fwrite(a,sizeof(struct question),1,sf);
a=a->next;
}
}
//从文件中读取题目,将题目添加到列表中//
struct question *loadfile(struct question *b,FILE *lf)
{
struct question temp;
while (fread(&temp,sizeof(struct question),1,lf))
b=insert(b,&temp);
return b;
}
//统计答对题目数,显示得分//
void explainquestion(const struct question *que,int n)
{
int i=0,t=0;
char result[1001],*p=result;
for(i=0;t<n;que=que->next,t++)
{
printf("%s\nA.%s\nB.%s\nC.%s\nD.%s\n\n",que->ask,que->answer[0],que->answer[1],que->answer[2],que->answer[3]);
if((*p=que->right)==(*(p+1)=getyouranswer()))
++i;
p+=2;
}
*p='\0';
printf("\n%-20s%-20s%s\n","标准答案","你的答案","评价");
for(p=result;*p!='\0';p+=2)
printf("%-20c%-20c%s\n",*p,*(p+1),*p==*(p+1)?"正确":"错误");
printf("\n你回答了%d道题,答对%d道题目,得分:%.2f\n\n",n,i,(float)(i*100.00/n));
}
//得到选择题的答案//
int getanswer(void)
{
static int i=1;
int c=0;//必须进行初始化,避免出现偶然性的错误//
while(c<'A'||c>'D')//确保输入的答案是ABCD中的一个//
{
printf("请输第%d题的正确答案:",i);
scanf("%c",&c);
printf("\n");
if(c>96)
c=c-32;//实现小写向大写的转换//
}i++;
return c;
}
int getyouranswer(void)
{
int c=0;//必须进行初始化,避免出现偶然性的错误//
while(c<'A'||c>'D')//确保输入的答案是ABCD中的一个//
{
printf("请输入你的答案:");
scanf("%c",&c);
if(c>96)
c=c-32;//实现小写向大写的转换//
}
return c;
}
main()
{
struct question *start=NULL,temp;
long int choice,line=0,c;
FILE *fp=fopen("kstm.dat","a+");//用'a+'方式打开文件名为'kstm.dat'文件,可添可读//
start=loadfile(start,fp);
printf(" *****欢迎使用此考试系统,请输入你要执行的步骤的编号*****\n");
while((choice=menu())!=3)//如果考生不选3-退出//
if(choice==1)
{
getquestion(&temp);
start=insert(start,&temp);
++line;//统计列表的长度//
}
else if(choice==2)
{
printf("请输入要回答的问题数量:");
scanf("%d",&c);
start=seek(start,c,line);
explainquestion(start,c);
}
savefile(start,fp);
fclose(fp);
return 0;
}
⑽ c语言课程设计目的
没得题目??那就随便写三。。。比如啥子增加编程技巧,熟练对你那个编程软件的应用,巩固你们教的所学的啥子知识什么的````