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课程设计
/******头文件(.h)***********/
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*标准库函数*/
#include "string.h"/*字符串函数*/
#include "ctype.h" /*字符操作函数*/
#define M 50 /*定义常数表示记录数*/
typedef struct /*定义数据结构*/
{
char name[20]; /*姓名*/
char units[30]; /*单位*/
char tele[10]; /*电话*/
}ADDRESS;
/******以下是函数原型*******/
int enter(ADDRESS t[]); /*输入记录*/
void list(ADDRESS t[],int n); /*显示记录*/
void search(ADDRESS t[],int n); /*按姓名查找显示记录*/
int delete(ADDRESS t[],int n); /*删除记录*/
int add(ADDRESS t[],int n); /*插入记录*/
void save(ADDRESS t[],int n); /*记录保存为文件*/
int load(ADDRESS t[]); /*从文件中读记录*/
void display(ADDRESS t[]); /*按序号查找显示记录*/
void sort(ADDRESS t[],int n); /*按姓名排序*/
void qseek(ADDRESS t[],int n); /*快速查找记录*/
void (); /*文件复制*/
void print(ADDRESS temp); /*显示单条记录*/
int find(ADDRESS t[],int n,char *s) ; /*查找函数*/
int menu_select(); /*主菜单函数*/
/******主函数开始*******/
main()
{
int i;
ADDRESS adr[M]; /*定义结构体数组*/
int length; /*保存记录长度*/
clrscr(); /*清屏*/
for(;;)/*无限循环*/
{
switch(menu_select()) /*调用主菜单函数,返回值整数作开关语句的条件*/
{
case 0:length=enter(adr);break;/*输入记录*/
case 1:list(adr,length);break; /*显示全部记录*/
case 2:search(adr,length);break; /*查找记录*/
case 3:length=delete(adr,length);break; /*删除记录*/
case 4:length=add(adr,length); break; /*插入记录*/
case 5:save(adr,length);break; /*保存文件*/
case 6:length=load(adr); break; /*读文件*/
case 7:display(adr);break; /*按序号显示记录*/
case 8:sort(adr,length);break; /*按姓名排序*/
case 9:qseek(adr,length);break; /*快速查找记录*/
case 10:();break; /*复制文件*/
case 11:exit(0); /*如返回值为11则程序结束*/
}
}
}
/*菜单函数,函数返回值为整数,代表所选的菜单项*/
menu_select()
{
char s[80];
int c;
gotoxy(1,25);/*将光标定为在第25行,第1列*/
printf("press any key enter menu......\n");/*提示压任意键继续*/
getch(); /*读入任意字符*/
clrscr(); /*清屏*/
gotoxy(1,1);
printf("********************MENU*********************\n\n");
printf(" 0. Enter record\n");
printf(" 1. List the file\n");
printf(" 2. Search record on name\n");
printf(" 3. Delete a record\n");
printf(" 4. add record \n");
printf(" 5. Save the file\n");
printf(" 6. Load the file\n");
printf(" 7. display record on order\n");
printf(" 8. sort to make new file\n");
printf(" 9. Quick seek record\n");
printf(" 10. the file to new file\n");
printf(" 11. Quit\n");
printf("***********************************************\n");
do{
printf("\n Enter you choice(0~11):"); /*提示输入选项*/
scanf("%s",s); /*输入选择项*/
c=atoi(s); /*将输入的字符串转化为整型数*/
}while(c<0||c>11); /*选择项不在0~11之间重输*/
return c; /*返回选择项,主程序根据该数调用相应的函数*/
}
/***输入记录,形参为结构体数组,函数值返回类型为整型表示记录长度*/
int enter(ADDRESS t[])
{
int i,n;
char *s;
clrscr(); /*清屏*/
printf("\nplease input num \n"); /*提示信息*/
scanf("%d",&n); /*输入记录数*/
printf("please input record \n"); /*提示输入记录*/
printf("name unit telephone\n");
printf("------------------------------------------------\n");
for(i=0;i<n;i++)
{
scanf("%s%s%s",t[i].name,t[i].units,t[i].tele); /*输入记录*/
printf("----------------------------------------------\n");
}
return n; /*返回记录条数*/
}
/*显示记录,参数为记录数组和记录条数*/
void list(ADDRESS t[],int n)
{
int i;
clrscr();
printf("\n\n*******************ADDRESS******************\n");
printf("name unit telephone\n");
printf("------------------------------------------------\n");
for(i=0;i<n;i++)
printf("%-20s%-30s%-10s\n",t[i].name,t[i].units,t[i].tele);
if((i+1)%10==0) /*判断输出是否达到10条记录*/
{
printf("Press any key continue...\n"); /*提示信息*/
getch(); /*压任意键继续*/
}
printf("************************end*******************\n");
}
/*查找记录*/
void search(ADDRESS t[],int n)
{
char s[20]; /*保存待查找姓名字符串*/
int i; /*保存查找到结点的序号*/
clrscr(); /*清屏*/
printf("please search name\n");
scanf("%s",s); /*输入待查找姓名*/
i=find(t,n,s); /*调用find函数,得到一个整数*/
if(i>n-1) /*如果整数i值大于n-1,说明没找到*/
printf("not found\n");
else
print(t[i]); /*找到,调用显示函数显示记录*/
}
/*显示指定的一条记录*/
void print(ADDRESS temp)
{
clrscr();
printf("\n\n********************************************\n");
printf("name unit telephone\n");
printf("------------------------------------------------\n");
printf("%-20s%-30s%-10s\n",temp.name,temp.units,temp.tele);
printf("**********************end***********************\n");
}
/*查找函数,参数为记录数组和记录条数以及姓名s */
int find(ADDRESS t[],int n,char *s)
{
int i;
for(i=0;i<n;i++)/*从第一条记录开始,直到最后一条*/
{
if(strcmp(s,t[i].name)==0) /*记录中的姓名和待比较的姓名是否相等*/
return i; /*相等,则返回该记录的下标号,程序提前结结束*/
}
return i; /*返回i值*/
}
/*删除函数,参数为记录数组和记录条数*/
int delete(ADDRESS t[],int n)
{
char s[20]; /*要删除记录的姓名*/
int ch=0;
int i,j;
printf("please deleted name\n"); /*提示信息*/
scanf("%s",s);/*输入姓名*/
i=find(t,n,s); /*调用find函数*/
if(i>n-1) /*如果i>n-1超过了数组的长度*/
printf("no found not deleted\n"); /*显示没找到要删除的记录*/
else
{
print(t[i]); /*调用输出函数显示该条记录信息*/
printf("Are you sure delete it(1/0)\n"); /*确认是否要删除*/
scanf("%d",&ch); /*输入一个整数0或1*/
if(ch==1) /*如果确认删除整数为1*/
{
for(j=i+1;j<n;j++) /*删除该记录,实际后续记录前移*/
{
strcpy(t[j-1].name,t[j].name); /*将后一条记录的姓名拷贝到前一条*/
strcpy(t[j-1].units,t[j].units); /*将后一条记录的单位拷贝到前一条*/
strcpy(t[j-1].tele,t[j].tele); /*将后一条记录的电话拷贝到前一条*/
}
n--; /*记录数减1*/
}
}
return n; /*返回记录数*/
}
/*插入记录函数,参数为结构体数组和记录数*/
int add(ADDRESS t[],int n)/*插入函数,参数为结构体数组和记录数*/
{
ADDRESS temp; /*新插入记录信息*/
int i,j;
char s[20]; /*确定插入在哪个记录之前*/
printf("please input record\n");
printf("************************************************\n");
printf("name unit telephone\n");
printf("--------------------------------------------------\n");
scanf("%s%s%s",temp.name,temp.units,temp.tele); /*输入插入信息*/
printf("------------------------------------------------\n");
printf("please input locate name \n");
scanf("%s",s); /*输入插入位置的姓名*/
i=find(t,n,s); /*调用find,确定插入位置*/
for(j=n-1;j>=i;j--) /*从最后一个结点开始向后移动一条*/
{
strcpy(t[j+1].name,t[j].name); /*当前记录的姓名拷贝到后一条*/
strcpy(t[j+1].units,t[j].units); /*当前记录的单位拷贝到后一条*/
strcpy(t[j+1].tele,t[j].tele); /*当前记录的电话拷贝到后一条*/
}
strcpy(t[i].name,temp.name); /*将新插入记录的姓名拷贝到第i个位置*/
strcpy(t[i].units,temp.units); /*将新插入记录的单位拷贝到第i个位置*/
strcpy(t[i].tele,temp.tele); /*将新插入记录的电话拷贝到第i个位置*/
n++; /*记录数加1*/
return n; /*返回记录数*/
}
/*保存函数,参数为结构体数组和记录数*/
void save(ADDRESS t[],int n)
{
int i;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","wb"))==NULL) /*打开文件,并判断打开是否正常*/
{
printf("can not open file\n");/*没打开*/
exit(1); /*退出*/
}
printf("\nSaving file\n"); /*输出提示信息*/
fprintf(fp,"%d",n); /*将记录数写入文件*/
fprintf(fp,"\r\n"); /*将换行符号写入文件*/
for(i=0;i<n;i++)
{
fprintf(fp,"%-20s%-30s%-10s",t[i].name,t[i].units,t[i].tele);/*格式写入记录*/
fprintf(fp,"\r\n"); /*将换行符号写入文件*/
}
fclose(fp);/*关闭文件*/
printf("****save success***\n"); /*显示保存成功*/
}
/*读入函数,参数为结构体数组*/
int load(ADDRESS t[])
{
int i,n;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","rb"))==NULL)/*打开文件*/
{
printf("can not open file\n"); /*不能打开*/
exit(1); /*退出*/
}
fscanf(fp,"%d",&n); /*读入记录数*/
for(i=0;i<n;i++)
fscanf(fp,"%20s%30s%10s",t[i].name,t[i].units,t[i].tele); /*按格式读入记录*/
fclose(fp); /*关闭文件*/
printf("You have success read data from file!!!\n"); /*显示保存成功*/
return n; /*返回记录数*/
}
/*按序号显示记录函数*/
void display(ADDRESS t[])
{
int id,n;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","rb"))==NULL) /*打开文件*/
{
printf("can not open file\n"); /*不能打开文件*/
exit(1); /*退出*/
}
printf("Enter order number...\n"); /*显示信息*/
scanf("%d",&id); /*输入序号*/
fscanf(fp,"%d",&n); /*从文件读入记录数*/
if(id>=0&&id<n) /*判断序号是否在记录范围内*/
{
fseek(fp,(id-1)*sizeof(ADDRESS),1); /*移动文件指针到该记录位置*/
print(t[id]); /*调用输出函数显示该记录*/
printf("\r\n");
}
else
printf("no %d number record!!!\n ",id); /*如果序号不合理显示信息*/
fclose(fp); /*关闭文件*/
}
/*排序函数,参数为结构体数组和记录数*/
void sort(ADDRESS t[],int n)
{
int i,j,flag;
ADDRESS temp; /*临时变量做交换数据用*/
for(i=0;i<n;i++)
{
flag=0; /*设标志判断是否发生过交换*/
for(j=0;j<n-1;j++)
if((strcmp(t[j].name,t[j+1].name))>0) /*比较大小*/
{
flag=1;
strcpy(temp.name,t[j].name); /*交换记录*/
strcpy(temp.units,t[j].units);
strcpy(temp.tele,t[j].tele);
strcpy(t[j].name,t[j+1].name);
strcpy(t[j].units,t[j+1].units);
strcpy(t[j].tele,t[j+1].tele);
strcpy(t[j+1].name,temp.name);
strcpy(t[j+1].units,temp.units);
strcpy(t[j+1].tele,temp.tele);
}
if(flag==0)break; /*如果标志为0,说明没有发生过交换循环结束*/
}
printf("sort sucess!!!\n"); /*显示排序成功*/
}
/*快速查找,参数为结构体数组和记录数*/
void qseek(ADDRESS t[],int n)
{
char s[20];
int l,r,m;
printf("\nPlease sort before qseek!\n"); /*提示确认在查找之前,记录是否已排序*/
printf("please enter name for qseek\n"); /*提示输入*/
scanf("%s",s); /*输入待查找的姓名*/
l=0;r=n-1; /*设置左边界与右边界的初值*/
while(l<=r) /*当左边界<=右边界时*/
{
m=(l+r)/2; /*计算中间位置*/
if(strcmp(t[m].name,s)==0) /*与中间结点姓名字段做比较判是否相等*/
{
print(t[m]); /*如果相等,则调用print函数显示记录信息*/
return ; /*返回*/
}
if(strcmp(t[m].name,s)<0) /*如果中间结点小*/
l=m+1; /*修改左边界*/
else
r=m-1; /*否则,中间结点大,修改右边界*/
}
if(l>r) /*如果左边界大于右边界时*/
printf("not found\n"); /*显示没找到*/
}
/*复制文件*/
void ()
{
char outfile[20]; /*目标文件名*/
int i,n;
ADDRESS temp[M]; /*定义临时变量*/
FILE *sfp,*tfp; /*定义指向文件的指针*/
clrscr();/*清屏*/
if((sfp=fopen("record.txt","rb"))==NULL) /*打开记录文件*/
{
printf("can not open file\n"); /*显示不能打开文件信息*/
exit(1); /*退出*/
}
printf("Enter outfile name,for example c:\\f1\\te.txt:\n"); /*提示信息*/
scanf("%s",outfile); /*输入目标文件名*/
if((tfp=fopen(outfile,"wb"))==NULL) /*打开目标文件*/
{
printf("can not open file\n"); /*显示不能打开文件信息*/
exit(1); /*退出*/
}
fscanf(sfp,"%d",&n); /*读出文件记录数*/
fprintf(tfp,"%d",n);/*写入目标文件数*/
fprintf(tfp,"\r\n"); /*写入换行符*/
for(i=0;i<n;i++)
{
fscanf(sfp,"%20s%30s%10s\n",temp[i].name,temp[i].units,
temp[i].tele); /*读入记录*/
fprintf(tfp,"%-20s%-30s%-10s\n",temp[i].name,
temp[i].units,temp[i].tele); /*写入记录*/
fprintf(tfp,"\r\n"); /*写入换行符*/
}
fclose(sfp); /*关闭源文件*/
fclose(tfp); /*关闭目标文件*/
printf("you have success file!!!\n"); /*显示复制成功*/
}
❸ 如何做C语言课程设计
想偷懒的话就写一个控制台程序......
完全不需要图形化的函数什么的.......
工程,文件操作这些都没什么实。
我这边有一套不错的C语言课程设计,如果你喜欢可以拿去直接用,我还没有在网上放过。
❹ C语言课程设计
(C语言)职工信息管理
有任何问题可以到这里留言:
http://moonrosa.googlepages.com/liuyan.htm
【要求】
职工信息包括职工号,姓名,性别,年龄,学历,工资,住址,电话等(职工号不相等)。试设计一职工信息管理系统,使之能够提供下列功能:
(1)系统以菜单方式工作
(2)职工信息录入功能(职工信息用文件保存)
(3)职工信息浏览功能
(4)职工信息查询功能,查询方式:
1)按学历查询
2)按职工号查询
(5)职工信息删除,修改功能(可选项)。
#include<string.h>
void menu()
{
int n,w1;
do
{
printf("\t\t************************************************\n\n");
printf("\t\t************************************************\n\n");
printf("\t\t *** choose function ************\n\n");
printf("\t\t *** 1 Enter new data ************\n\n");
printf("\t\t *** 2 Modify data ************\n\n");
printf("\t\t *** 3 Search by people.xueli and num*****\n\n");
printf("\t\t *** 4 Browse data ************\n\n");
printf("\t\t *** 5 add data ************\n\n");
printf("\t\t *** 6 Exit ************\n\n");
printf("\t\t************************************************\n\n");
printf("\t\t************************************************\n\n");
printf("Choose your number(1-6):[ ]\b\b");
scanf("%d",&n);
if(n<1||n>6)
w1=1;
else w1=0;
}
while(w1==1);
switch(n)
{
case 1:enter();break;
case 2:modify();break;
case 3:search();break;
case 4:browse();break;
case 5:add();break;
case 6:exit(0);
}
}
main()
{
system("cls");
menu();
}
#define N 100
struct people
{
char num[100];
char name[15];
char sex[20];
char age[20];
char xueli[20];
char gong[20];
char address[20];
char telephone[20];
}people[N];
# include <stdio.h>
enter()
{
int i,n;
printf("How many people(0-%d)?:",N-1);
scanf("%d",&n);
printf("\n Enter data now\n\n");
for(i=0;i<n;i++)
{
printf("\n Input %dth people record.\n",i+1);
input(i);
}
if(i!=0)save(n);
printf_back();
}
browse()
{
int i,j,n;
n=load();
printf_face();
for(i=0;i<n;i++)
{
if((i!=0)&&(i%10==0))
{
printf("\n\nPass any key to continue ....");
getch();
puts("\n\n");
}
printf_one(i) ;
}
printf("\tThere are %d record.\n",n);
printf("\nPass any key to back ...");
getch();
menu();
}
add()
{
int i,n,m,k;
FILE*fp;
n=load();
printf("How many people are you want to add(0-%d)?:",N-1-n);
scanf("%d",&m);
k=m+n;
for(i=n;i<k;i++)
{
printf("\nInput %dth people record.\n",i-n+1 );
input(i);
}
if((fp=fopen("Pro.txt","ab"))==NULL)
{
printf("cannot open file\n");
}
for(i=n;i<k;i++)
if(fwrite(&people[i],sizeof(struct people),1,fp)!=1)
printf("file write error\n");
fclose(fp);
printf_back();
}
search()
{
int i,n,k,w1=1,w2,w3,w4,m,a;
struct people p;
n=load();
do
{
printf("\n\nWhich way do you want to choose? \n\t1).By xueli 2).By num [ ]\b\b");
scanf("%d",&m);
switch(m)
{
case 1:
do
{ k=-1;
printf("\n\nEnter xeuli that you want to search! xueli.");
scanf("%s",p.xueli);
printf_face();
for(i=0;i<n;i++)
if(strcmp(p.xueli,people[i].xueli)==0)
{ k=i;
printf_one(k);break;
}
if(k==-1)
{ printf("\n\nNO exist!please");
printf("\n\nAre you again?\n\t1).again 2).NO and back [ ]\b\b");
scanf("%d",&w1);
if(w1==2)
printf_back();
}
}
while(k==-1&&w1==1);break;
case 2:
do
{k=-1;
printf("\n\nEnter num that you want to search! num.");
scanf("%s",p.num);
printf_face();
for(i=0;i<n;i++)
if(strcmp(p.num,people[i].num)==0)
{k=i;
printf_one(k);break;
}
if(k==-1)
{printf("\n\nNO exist!please");
printf("\n\nAre you again?\n\t1).again 2).NO and back [ ]\b\b");
scanf("%d",&w1);
if(w1==2)
printf_back();
}
}
while(k==-1&&w1==1);break;
}
w4=0;w3=0;
if(k!=-1)
{printf("\n\nWhat do you want to do?\n\t 1).Search 2).Modify 3).Delete 4).Back menu [ ]\b\b");
scanf("%d",&w2);
switch(w2)
{case 2:w3=modify_data(k,n);break;
case 3:{printf("\nAre you sure?\n\t 1).Sure 2).No and back [ ]\b\b");
scanf("%d",&w4);
if(w4==1)
for(a=k;a<n;a++)
{strcpy(people[a].num,people[a+1].num);
strcpy(people[a].name,people[a+1].name);
strcpy(people[a].sex,people[a+1].sex);
strcpy(people[a].age,people[a+1].age);
strcpy(people[a].xueli,people[a+1].xueli);
strcpy(people[a].gong,people[a+1].gong);
strcpy(people[a].address,people[a+1].address);
strcpy(people[a].telephone,people[a+1].telephone);
}
break;
}
}
if(w3==1||w4==1)
{save(n);
printf("\n\nSuccessful.^_^.");
printf("\n\nWhant do you want to do? \n\t 1).Search another 2).Back [ ]\b\b" );
scanf("%d",&w2);
}
}
}
while(w2==1);
menu();
}
modify()
{struct people p;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i<n;i++)
{if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.which needed modify.pass any key to contiune ...");
getch();
puts("\n\n");
}
printf_one(i);
}
do
{printf("\n\nEnter NO.that you want to modify! NO.:");
scanf("%s",p.num);
for(i=0;i<n;i++)
if(strcmp(p.num,people[i].num)==0)
{k=i;
p=people[i];
}
if(k==-1)printf("\n\nNO exist!please again");
}while(k==-1);
printf_face();
printf_one(k);
w1=modify_data(k,n);
if(w1==1)
{printf("\nSuccessful ^_^.\n\nAre you modify another ?\n\n\t 1).Yes 2).Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0;
if(w2==1)
people[k]=p;
}
if(w0!=1&&w2==1)
save(n);
}while(w0==1);
menu();
}
save(int n)
{FILE *fp;
int i;
if((fp=fopen("Pro.txt","wb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;i<n;i++)
if(people[i].num!=0)
if(fwrite(&people[i],sizeof(struct people),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
load()
{FILE *fp;
int i;
if((fp=fopen("Pro.txt","rb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;!feof(fp);i++)
fread(&people[i],sizeof(struct people),1,fp);
fclose(fp);
return(i-1);
}
input(int i)
{
no_input(i,i);
printf("num:");
scanf("%s",people[i].num);
printf("name:");
scanf("%s", people[i].name) ;
printf("sex:");
scanf("%s",people[i].sex);
printf("age:");
scanf("%s",people[i].age);
printf("xueli:");
scanf("%s",people[i].xueli);
printf("gong:");
scanf("%s",people[i].gong);
printf("address:");
scanf("%s",people[i].address);
printf("telephone:");
scanf("%s",people[i].telephone);
}
modify_data(int i)
{int c,w1;
do
{puts("\nmodify by=>\n\n 1).num 2).name 3).sex 4).ages 5).xueli 6)gong 7)address 8)telephone ");
printf("Which you needed?:[ ]\b\b");
scanf("%d",&c);
if(c>8||c<1)
{puts("\nChoice error!Please again!");
getchar();
}
}while(c>8||c<1);
do
{switch(c)
{
case 1:printf("num:");scanf("%s",people[i].num);break;
case 2:printf("name:");scanf("%s",people[i].name);break;
case 3:printf("sex:");scanf("%s",people[i].sex);break;
case 4:printf("age:");scanf("%s",people[i].age);break;
case 5:printf("xueli:");scanf("%s",people[i].xueli);break;
case 6:printf("gong:");scanf("%s",people[i].gong);break;
case 7:printf("address:");scanf("%s",people[i].address);break;
case 8:printf("telephone:");scanf("%s",people[i].telephone);break;
}
puts("\nNow:\n");
printf_face();
printf_one(i);
printf("\nAre you sure?\n\n\t 1).Sure 2).No and remodify 3).Back without save in this time [ ]\b\b");
scanf("%d",&w1);
}
while(w1==2);
return(w1);
}
no_input(int i,int n)
{int j,k,w1;
do
{w1=0;
for(j=0;people[i].num[j]!='\0';j++)
if(people[i].num[j]>'9')
{puts("Input error!Only be made up of(0-9).Please reinput!\n");
w1=1;break;
}
if(w1!=1)
for(k=0;k<n;k++)
if(k!=i&&strcmp(people[k].num,people[i].num)==0)
{puts("This record is exist.please reinput!\n");
}
}
while(w1==1);
}
printf_face()
{
printf("\nnum name sex ages xueli gong address telephone \n");
}
printf_one(int i)
{
int j;
printf("%7s%7s%7s%7s%7s%7s%10s%12s\n",people[i].num,people[i].name,people[i].sex,people[i].age,people
[i].xueli,people[i].gong,people[i].address,people[i].telephone);
}
printf_back()
{
int j,w;
printf("\n\n\tSuccessful.^_^\n\n");
printf("What do you want you to do?\n\n\t1).Browse all now\t2).Back: [ ]\b\b");
scanf("%d",&w);
if(w==1)
browse();
else menu();
}
参考资料:http://moonrosa.googlepages.com/cyuyan_zgglxt
❺ c课程设计
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
class controlloer //图书管理员
{
private:
int number;
int age;
char name[20];
public:
controlloer();
controlloer(int c,int a,char b[20] );
int getnumber();
int getage();
char *getname();
void reworkage(int i);
void reworkname(char a[20]);
};
controlloer::controlloer()
{
number=0;
char b[20]="no one";
age=0;
strcpy(name,b);
}
controlloer::controlloer(int c,int a,char b[20])
{
number=c;
age=a;
strcpy(name,b);
}
int controlloer::getage()
{return age;}
char *controlloer::getname()
{return name;}
int controlloer::getnumber()
{return number;}
void controlloer::reworkage(int i)
{age=i;}
void controlloer::reworkname(char a[20])
{strcpy(name,a);}
class reader //读者(学生,老师)
{
private:
int number;
int age;
char name[20];
char ye[20];
char borrowbook[20];
public:
reader();
reader(int c,int a,char b[20],char d[20],char e[20]);
int getnumber();
int getage();
char *getye();
char *getname();
char * getborrowbook();
void reworkborrowbook(char a[20]);
};
reader::reader()
{
char a[20]="没有人";
char b[20]="无职称";
char c[20]="没有借书";
number=0;
age=0;
strcpy(name,a);
strcpy(ye,b);
strcpy(borrowbook,c);
}
reader::reader(int a,int c,char b[20],char d[20],char e[20])
{
number=a;
age=c;
strcpy(name,b);
strcpy(ye,d);
strcpy(borrowbook,e);
}
int reader::getnumber(){return number;}
int reader::getage(){return age;}
char *reader::getye(){return ye;}
char *reader::getname(){return name;}
char * reader::getborrowbook(){return borrowbook;}
void reader::reworkborrowbook(char a[20]){strcpy(borrowbook,a);}
struct book //图书
{
int num;
char name[20];
char people[20];
};
void store() //存入图书信息
{
int i,c,b;
char a[20],d[20];
ifstream file("num.txt");
file>>b;
file.close();
cout<<"现有的图书个数:";
cout<<b<<endl;
cout<<"请输入你要输入的图书信息个数:"<<endl;
cin>>c;
book *shu=new book[c];
cout<<"输入图书信息(编号,名字,作者名:)"<<endl;
for(i=0;i<c;i++)
{
cin>>shu[i].num;
cin>>a>>d;
strcpy(shu[i].name,a);
strcpy(shu[i].people,d);
b++;
}
ofstream outfile("stu.txt",ios_base::app);
for(i=0;i<c;i++)
{
outfile.write((char *)&shu[i],sizeof(shu[i]));
}
outfile.close();
cout<<"存入成功!"<<endl;
ofstream tfile("num.txt");
tfile<<b;
tfile.close();
}
void outbook() //输出图书信息
{
int i,h,j,g,z;
char k ;
ifstream tfile("num.txt");
if(!tfile)
{
cout<<" 文件不存在! ";
tfile.close();
cout<<"你是否想创建(输入Y或N)";
cin>>k;
if(k=='N') exit(0);
else {ofstream tfile("num.txt");g=0;tfile<<g;}
}
else tfile>>g;
cout<<"本图书馆已经有"<<g<<"本图书"<<endl;
if(g==0)
{cout<<"图书馆里没有书!"<<endl;exit(0);}
else
{ book *shu=new book[g];
ifstream is("stu.txt",ios_base::binary);
if(is)
{
for(i=0;i<g;i++)
{
is.read((char *)&shu[i],sizeof(shu[i]));
}
for(i=0;i<g;i++)
{
cout<<"编号 名字 作者名"<<endl;
cout<<shu[i].num<<" "<<shu[i].name<<" "<<shu[i].people<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
ifstream file("readernum.txt");
if(file) { file>>z; file.close();}
else { cout<<"没有文件";}
cout<<"已有的读者个数:";
cout<<z<<endl;
cout<<"输入你的编号:";
cin>>j;
cout<<"你想借哪本书(输入编号):";
cin>>h;
reader *people=new reader[z];
ifstream out("reader.txt",ios_base::binary);
if(out)
{
for(i=0;i<z;i++)
{
out.read((char *)&people[i],sizeof(people[i]));
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
out.close();
people[j-1].reworkborrowbook(shu[h-1].name);
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people[j-1].getnumber()<<" "<<people[j-1].getage()<<" "<<people[j-1].getname()<<" "<<people[j-1].getye()<<" "<<people[j-1].getborrowbook()<<endl;
ofstream outfile("reader.txt",ios_base::binary);
for(i=0;i<z;i++)
{
outfile.write((char *)&people[i],sizeof(people[i]));}
outfile.close();
}
cout<<"借阅成功!";
}
void controller() //图书管理员信息
{
int b,i,d,h=0;
ifstream file("controlloernum.txt");
if(file) { file>>b; file.close();cout<<"图书管理员个数:"<<b<<endl;}
else
{
cout<<"没有图书管信息理员"<<endl;
cout<<"你是否想创建(请输入Y或N):";
cin>>d;
if(d='y') {ofstream infile("controlloernum.txt");infile<<h;exit(0);}
else exit(0);
}
ifstream is("controlloer.txt",ios_base::binary);
if(is)
{
controlloer *bookpeople=new controlloer[b];
for(i=0;i<b;i++)
{
is.read((char *)&bookpeople[i],sizeof(bookpeople[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople[i].getnumber()<<" "<<bookpeople[i].getage()<<" "<<bookpeople[i].getname()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
cout<<"没有这个文件夹"<<endl;
cout<<"你是否想创建(请输入Y或N):";
cin>>d;
if(d='y') {ofstream infile("controlloer.txt");exit(0);}
else exit(0);
}
is.close();
}
void libary() //图书馆的总信息
{
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"学校图书馆由本部图书馆及彭州校区图书馆组成.馆舍面积41048平方米";
cout<<" (其中现有馆舍面积11578 平方米,在建图书馆馆舍面积29470平方米),";
cout<<"各院系资料室面积1120平方米。学校拥有纸质文献198万余册, ";
cout<<"生均81.17册,电子文献161.7万余种。近三年校图书馆每年进书量均超过15万册."<<endl;
}
void storecontroller() //存入新的管理员的信息
{
int i,b,c,h=0;
char a[20],d;
ifstream file("controlloernum.txt");
if(file)
{
file>>b; file.close();cout<<"已有的图书管理员个数:";
cout<<b<<endl;
}
else
{
cout<<"没有图书管信息理员"<<endl;
cout<<"你是否想创建(请输入y或n):";
cin>>d;
if(d=='y')
{ofstream infile("controlloernum.txt");infile<<h;infile.close();b=0;}
else exit(0) ;
}
ofstream outfile("controlloer.txt",ios::app);
cout<<"请输入图书管理员的编号和年龄,名字:";
cin>>c>>i>>a;
controlloer bookpeople(c,i,a);
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople.getnumber()<<" "<<bookpeople.getage()<<" "<<bookpeople.getname()<<endl;
outfile.write((char *)&bookpeople,sizeof(bookpeople));
outfile.close();
b++;
ofstream tfile("controlloernum.txt");
tfile<<b;
tfile.close();
cout<<"保存成功!";
}
void reworkcontrolloer() ///修改图书管理员
{
int i,b,h,j,g;
char d[20];
ifstream file("controlloernum.txt");
if(file) { file>>b; file.close();}
else {cout<<"没有图书管信息理员"; exit(0);}
cout<<"已有的图书管理员个数:";
cout<<b<<endl;
controlloer *bookpeople=new controlloer[b];
ifstream is("controlloer.txt",ios_base::binary);
if(is)
{
for(i=0;i<b;i++)
{
is.read((char *)&bookpeople[i],sizeof(bookpeople[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople[i].getnumber()<<" "<<bookpeople[i].getage()<<" "<<bookpeople[i].getname()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
cout<<"请输入你要修改的管理员编号:";
cin>>h;
cout<<"输入年龄,名字:";
cin>>g>>d;
bookpeople[h-1].reworkage(g);
bookpeople[h-1].reworkname(d);
cout<<"该了后的名字:"<<bookpeople[h-1].getname();
ofstream tfile("controlloer.txt",ios_base::binary);
for(j=0;j<b;j++)
{
tfile.write((char *)&bookpeople[j],sizeof(bookpeople[j]));
}
tfile.close();
}
❻ C语言课程设计 简单的.....
Answer To Question 1 & 2 :
充分利用ISO组织于1999年通过的C语言国际标准中的库函数即可实现第一题。利用简单的双重循环即可解决问题二,用递归算法不是好的选择。
第一题完整源码:
(注意:本源码中,函数GetWeekDay的返回值仅仅表示输入参数是否“正确/有效”(例如前三个参数使用2001,2,29就是无效参数),能否得到预期的星期值;真正的星期值则是通过输出变量返回给主调函数的。)
////////////////////////////////////////////
#include <time.h>
#include <stdio.h>
int GetWeekDay(int nYear,int nMon,int nDay, int *npWeekDay);
int main()
{
int nMyWeekDay;
int nResult;
nResult = GetWeekDay(2007,1,10,&nMyWeekDay);
return 0;
}
//输入日期,返回星期的C语言函数
int GetWeekDay(int nYear,int nMon,int nDay, int *npWeekDay)
{
int nRetVal = 0;
time_t tMyDateTime;
struct tm tmMyDate,*tmpMyDate;
if((nYear<1900||nYear>=3000)
|| (nMon<1 || nMon>12)
|| (nDay<1||nDay>31) )
{
nRetVal = 1;
*npWeekDay = -1;
return nRetVal;
}
//memset(tmMyDate,0,sizeof(struct tm));
tmMyDate.tm_year = nYear-1900;
tmMyDate.tm_mon = nMon-1;
tmMyDate.tm_mday = nDay;
tmMyDate.tm_hour =16;
tmMyDate.tm_min =30;
tmMyDate.tm_sec =30;
tMyDateTime = mktime(&tmMyDate);
if(tMyDateTime<0)
{
nRetVal = 1;
*npWeekDay = -1;
return nRetVal;
}
tmpMyDate = localtime(&tMyDateTime);
*npWeekDay = tmpMyDate->tm_wday;
return nRetVal;
}
//Over
////////////////////////////////////////////////////
第二题:
#include <time.h>
#include <stdio.h>
int Sum(int n, int a);
int main()
{
//出题者可以自己将此处改为要求操作人键入N/A的值
int n=5,a=2,s;
s = Sum(n,a);
return 0;
}
//解决问题的函数
int Sum(int n, int a)
{
int nSum =0;
int nTmp;
int i,j;
for(i=1;i<=n; i++)
{
nTmp =a;
for(j=1;j<=i;j++)
{
nTmp += a*10*(j-1);
}
nSum += nTmp;
}
return nSum;
}
❼ C 课程设计
#include<iostream>
#include<iomanip.h>
#include<math.h>
usingnamespacestd;
intmain()
{
doublesample[6]={6.22,5.46,4.70,3.85,2.48,0.70},ym[6],r[6];
doubleb0,b1,b2,b3;
intflag,i;
b0=sample[0];
for(b2=-10;b2<10;b2+=0.01)
for(b3=-10;b3<10;b3+=0.01)
{
flag=1;
b1=sample[1]-b0-b2-b3;
for(i=2;i<6;i++)
if(fabs(b1-((sample[i]-b0)/i-b2*i-b3*i*i))>0.025)
{flag=0;break;}
if(flag)
{
cout<<"b0=6.22,b1="<<b1<<",b2="<<b2<<",b3="<<b3<<endl;
cout<<"------------------------------ ";
cout<<"xyymr% ";
cout<<"------------------------------ ";
for(i=0;i<6;i++)
{
ym[i]=b0+b1*i+b2*i*i+b3*i*i*i;
r[i]=fabs(ym[i]-sample[i])/sample[i]*100;
cout<<setw(2)<<i<<setw(6)<<sample[i];
cout<<setw(7)<<ym[i]<<setw(7)<<setprecision(2)<<r[i]<<endl;
}
cout<<"------------------------------ ";
return0;
}
}
return0;
}