A. 求c语言编程,要求500行,作业……感激不尽
我以前写的,贴给你有600行,学生管理程序
参见hi..com/mark063/blog/item/21ea0cb11e185cacd8335a60.html
#include<stdio.h>
#include <malloc.h>
#include<time.h>
#include<string.h>
typedef struct stu{
char id[20];
char name[14];
int age;
int year,month,day;
char sex[4];
int gpa;
struct stu*next;
}*student;
void out();
void insertStu();
void printStu();
void searchStu();
void dele();
void update();
void open();
void save();
int main()
{
student head=NULL;
int choose,ifopen=0;
printf("\n\t\tWellcome to student manger!\n\n\t\t\t\t\tmade by 马健(09080208)");
printf("\n\n1:insert a student:\n2:show all student\n3:search a student\n4:delete a student\n5:update\n6:open database from disk\n7:save database to disk\n8:exit\n");
printf("\n\nPlease choose:\n");
while(scanf("%d",&choose)!=EOF){
switch(choose){
case 1:insertStu(&head);printf("Press any key..\n");getch();system("cls");break;
case 2:printStu(&head);printf("Press any key..\n");getch();system("cls");break;
case 3:searchStu(&head);printf("Press any key..\n");getch();system("cls");break;
case 4:dele(&head);printf("Press any key..\n");getch();system("cls");break;
case 5:update(&head);printf("Press any key..\n");getch();system("cls");break;
case 6:open(&head,&ifopen);printf("Press any key..\n");getch();system("cls");break;
case 7:save(&head);printf("Press any key..\n");getch();system("cls");break;
case 8:out(&head);return 0;
}
printf("\n\t\tWellcome to student manger!\n\n\t\t\t\t\tmade by 马健(09080208)");
printf("\n\n1:insert a student:\n2:show all student\n3:search a student\n4:delete a student\n5:update\n6:open database from disk\n7:save database to disk\n8:exit\n");
printf("\n\nPlease choose:\n");
}
}
void insertStu(student*head)
{
student last=*head,tmp;
int flag=0;
char id[20];
if(*head==NULL){
*head=(student)malloc(sizeof(struct stu));
printf("Creating new table:\n\n");
printf("Please input id:");
scanf("%s",(*head)->id);
printf("Please intput name:");
scanf("%s",&(*head)->name);
printf("Please input age:");
scanf("%d",&(*head)->age);
printf("Please input year:");
scanf("%d",&(*head)->year);
printf("Please input month:");
scanf("%d",&(*head)->month);
printf("Please input day:");
scanf("%d",&(*head)->day);
printf("Please input sex:");
scanf("%s",&(*head)->sex);
printf("Please input gpa:");
scanf("%d",&(*head)->gpa);
(*head)->next=NULL;
}
else{
printf("Please input id:");
scanf("%s",id);
if(strcmp(id,(*head)->id)<0)flag=1;
while(flag!=1&&last->next!=NULL&&(strcmp(last-> next->id,id)<0)){//为排序做准备,找出应该插入的位置
last=last->next;
}
tmp=(student)malloc(sizeof(struct stu));
strcpy(tmp->id,id);
printf("Please intput name:");
scanf("%s",&tmp->name);
printf("Please input age:");
scanf("%d",&tmp->age);
printf("Please input year:");
scanf("%d",&tmp->year);
printf("Please input month:");
scanf("%d",&tmp->month);
printf("Please input day:");
scanf("%d",&tmp->day);
printf("Please input sex:");
scanf("%s",&tmp->sex);
printf("Please input gpa:");
scanf("%d",&tmp->gpa);
if(flag==1){//插在第一个
tmp->next=(*head);
(*head)=tmp;
}
else if(last->next==NULL){//判断是否该插在最后一个
last->next=tmp;
tmp->next=NULL;
}
else{//该插在中间
tmp->next=last->next;
last->next=tmp;
}
}
}
void printStu(student*head)
{
student last=*head;
float begin=clock(),end;
while(last!=NULL){
printf("id:%s name:%-10sage:%-5dbrithday:%4d-%2d-%2d sex:%-4sgpa:%-d\n"
,last->id,last->name,last->age,last->year,last->month,last->day,last->sex,last->gpa);
last=last->next;
}
end=clock();
printf("you spend:%.2f\n",(end-begin)/1000);
}
void searchStu(student*head)
{
float begin,end;
int flag=0;
student last=*head;
char id[20];
printf("Please input the student id you want to search:\n");
scanf("%s",id);
begin=clock();
while(last->next!=NULL){
if(strcmp(id,last->id)==0){
printf("id:%s name:%-10sage:%-5dbrithday:%4d-%2d-%2d sex:%-4sgpa:%-d\n"
,last->id,last->name,last->age,last->year,last->month,last->day,last->sex,last->gpa);
flag=1;
break;
}
last=last->next;
}
if(flag==0)printf("Not found!\n");
end=clock();
printf("you spend:%.2f\n",(end-begin)/1000);
}
void dele(student*head)
{
student last=(*head)->next,pre=(*head),tmp;//pre来记录last前一个节点
char id[20];
float begin,end;
while(1){
printf("Please input the student id you want to delete:");
scanf("%s",id);
begin=clock();
if(strcmp((*head)->id,id)==0){//检验是否在第一个
tmp=(*head);
(*head)=(*head)->next;
free(tmp);
end=clock();
printf("you spend:%.2f\n",(end-begin)/1000);
return;
}
else{//如果不在第一个
while(1){
if(strcmp(last->id,id)==0){
pre->next=last->next;
free(last);
end=clock();
printf("you spend:%.2f\n",(end-begin)/1000);
return;
}
if(last==NULL)printf("NO id=%.0f student",id);
pre=last;
last=last->next;
}
}
}
}
void update(student*head)
{
char id[20];
float begin=clock(),end;
student last=(*head);
printf("Please input the student id you want to update:");
scanf("%s",id);
while(last!=NULL)
if(strcmp(id,last->id)==0)break;
else last=last->next;
if(last==NULL){
printf("No such student!\n");
return;
}
end=clock();
printf("you spend:%.2f\n",(end-begin)/1000);
printf("\nid:%-13.0s name:%-10sage:%-5dbrithday:%4d-%2d-%2d sex:%-4sgpa:%-d\n"
,last->id,last->name,last->age,last->year,last->month,last->day,last->sex,last->gpa);
printf("\nPlease input the new info:\n");
strcpy(last->id,id);
printf("Please intput name:");
scanf("%s",&last->name);
printf("Please input age:");
scanf("%d",&last->age);
printf("Please input year:");
scanf("%d",&last->year);
printf("Please input month:");
scanf("%d",&last->month);
printf("Please input day:");
scanf("%d",&last->day);
printf("Please input sex:");
scanf("%s",&last->sex);
printf("Please input gpa:");
scanf("%d",&last->gpa);
}
void open(student*head,int*ifopen)
{
FILE*fp;
student tmp,last;
int flag=0;
char id[20];
double begin,end;
if(*ifopen==1){
out(&*head);
}
fp=fopen("database.dat","r");
if(fp==NULL){
printf("No file!\n");
return;
}
(*head)=NULL;
begin=clock();
printf("Loading please wait..\n");
while(fscanf(fp,"%s",&id)&&id[0]!='e'){
if((*head)==NULL){
(*head)=malloc(sizeof(struct stu));
strcpy((*head)->id,id);
fscanf(fp,"%s%d%d%d%d%s%d",(*head)->name,&(*head)->age,&(*head)->year
,&(*head)->month,&(*head)->day,(*head)->sex,&(*head)->gpa);
(*head)->next=NULL;
}
else{
flag=0;
last=(*head);
tmp=malloc(sizeof(struct stu));
if(strcmp(id,(*head)->id)<0)flag=1;//判断是否该插在在第一个
strcpy(tmp->id,id);
last=(*head);
while(flag!=1&&last->next!=NULL&&strcmp(last-> next->id,id)<0){//为排序做准备,找出应该插入的位置
last=last->next;
}
fscanf(fp,"%s%d%d%d%d%s%d",tmp->name,&tmp->age,&tmp->year
,&tmp->month,&tmp->day,tmp->sex,&tmp->gpa);
if(flag==1){//插在第一个
tmp->next=(*head);
(*head)=tmp;
}
else if(last->next==NULL){//判断是否该插在最后一个
last->next=tmp;
tmp->next=NULL;
}
else{//该插在中间
tmp->next=last->next;
last->next=tmp;
}
}
}
end=clock();
printf("you spend:%.2f(s)\n",(end-begin)/1000);
fclose(fp);
*ifopen=1;
}
void save(student*head)
{
FILE*fp;
student last=(*head);
fp=fopen("database.dat","w");
while(last){
fprintf(fp,"%s %s %d %d %d %d %s %d\n",last->id,last->name,last->age,last->year,last->month,last->day,last->sex,last->gpa);
last=last->next;
}
fprintf(fp,"%c\n",'e');
fclose(fp);
}
void out(student*head)
{
student last=*head,tmp;
char sav;
printf("if you want to save?(y/n)\n");
sav=getch();
if(sav=='y'||sav=='Y')save(&*head);
while(last){
tmp=last;
last=last->next;
free(tmp);
}
}
#include<stdio.h>
#include<time.h>
#include<malloc.h>
int main()
{
FILE*fp;
unsigned int id;
int n,k,i,name,age,year,month,day,sex,gpa;
int*out=NULL;
srand(time(NULL));
fp=fopen("database.dat","w");
printf("This is can help lab7 build a database to debug\n");
printf("Please input a number to limit the n:\n");
while(scanf("%d",&n)&&n>32768)printf("intput should less than int,input again:\n");
k=n;
if(fp==NULL)printf("ON FILE");
out=(int*)malloc(n*sizeof(int)+11);
for(i=0;i<n;i++)
out[i]=0;
if(out==NULL)printf("Not enough memoney!\n");
while(n--){
while(1){
id=rand()%k;
if(out[id]==0){
out[id]=1;
break;
}
}
age=rand()%5;
sex=rand()%2+1;
year=rand()%3;
month=rand()%12+1;
day=rand()%30+1;
gpa=rand()%40+61;
fprintf(fp,"%c%.0f ",'0',id+(float)9080201);
for(i=0;i<4;i++){
name=rand()%26;
fprintf(fp,"%c",name+'a');
}
fprintf(fp," %d",(int)16+age);
fprintf(fp," %d %d %d ",year+(int)1989,month,day);
if(sex%2==0)fprintf(fp,"%c",'f');
else fprintf(fp,"%c",'m');
fprintf(fp," %d\n",gpa);
}
fprintf(fp,"%c",'e');
printf("All build ok\n");
fclose(fp);
free(out);
return 0;
}
B. 源代码长度为500行的C语言编程怎么编
源代码500行多用几个函数来回调用就可以了,这样看起来既条理又易懂!
C. 求一个c语言程序设计,大约60行左右就可以
给你一个学生成绩管理的系统,有成绩的录入,分数的排序,删除,修改等功能。
struct__stu{
intstuNum;
charname[20];
intScoreMath;
};
__stustu[50];
intnumberSTU=0;
voidprintinfo(void)
{
printf("1成绩录入 ");
printf("2成绩显示 ");
printf("3成绩修改 ");
printf("4成绩统计 ");
printf("5成绩排序 ");
printf("6显示菜单 ");
printf("7退出 ");
}
voidinputinfo(intn)
{
printf("第%d个学生的学号:",n);
scanf("%d",&stu[n-1].stuNum);
getchar();
printf("第%d个学生的姓名:",n);
gets(stu[n-1].name);
printf("第%d个学生数学成绩:",n);
scanf("%d",&stu[n-1].ScoreMath);
getchar();
}
voiddisplayinfo(intn)
{
inti=0;
printf("学号 姓名 分数 ");
for(i=0;i<n;i++)
{
printf("%d %s %d ",stu[i].stuNum,stu[i].name,stu[i].ScoreMath);
}
}
voidcountNum(intn)
{
inti=0;
inttempNum=0;
for(i=0;i<n;i++)
{
if(stu[i].ScoreMath<60)
{
tempNum++;
}
}
printf("及格的人数为:%d 不及格的人数为:%d ",n-tempNum,tempNum);
}
voidmodify(intstuNumber)
{
inti=0;
for(i=0;i<numberSTU;i++)
{
if(stu[i].stuNum==stuNumber)
{
printf("你想修改的分数为:");
scanf("%d",&stu[i].ScoreMath);
getchar();
printf("修改成功 ");
return;
}
}
printf("学号错误,修改失败 ");
}
voidsoucemath_from_higt_to_low(intn)
{
intindexi;
intindexj;
__stu_temp;
for(indexi=0;indexi<n;indexi++)
{
for(indexj=indexi+1;indexj<n;indexj++)
{
if(stu[indexi].ScoreMath<stu[indexj].ScoreMath)
{
_temp=stu[indexj];
stu[indexj]=stu[indexi];
stu[indexi]=_temp;
}
}
}
printf("数学分数从高到低排列: ");
displayinfo(numberSTU);
}
intmain(intargc,char*argv[])
{
charcasechar=0;
intstudentNUm=1;
printinfo();
while(1)
{
printf("输入指令:");
scanf("%c",&casechar);
getchar();
switch(casechar)
{
case'1':
numberSTU++;
inputinfo(numberSTU);
//printf("输入信息 ");
break;
case'2':
displayinfo(numberSTU);
//printf("显示成绩 ");
break;
case'3':
printf("输入你想修改的学生学号:");
scanf("%d",&studentNUm);
getchar();
modify(studentNUm);
break;
case'4':
countNum(numberSTU);
break;
case'5':
soucemath_from_higt_to_low(numberSTU);
break;
case'6':
printinfo();
break;
case'7':
return0;
}
}
return0;
}
D. C语言 会写 几万行的代码 的人 可以 编程 任何软件了吗!!!!
代码行数 和编写的软件难度没有直接关系.
没有技术含量的累加, 就算是几百万行代码, 也一样是低级的.
另外, C语言是用途很广泛的一门语言,可以完成很多功能.
在驱动上写了几万行代码, 最多可以说在驱动上很熟练了, 改做网络编程一样会一头雾水.
所以 可以编程任何软件,本身就是一个伪概念.
E. C语言课程设计不少于200行代码
#include "stdio.h"
#include"stdlib.h"
#include "conio.h"
#include"string.h"
struct SStudent
{
unsigned number;
char name[10];
char tele[12];
struct SStudent * link;
};
void main()
{
struct SStudent * CreateTable();
void AppendToTable(struct SStudent * stu);
void InsertToTable(struct SStudent * stu);
void QueryTable(struct SStudent * stu, unsigned number);
void SortTable(struct SStudent * stu);
void PrintTable(struct SStudent * stu);
void Save(struct SStudent * stu);
void Load(struct SStudent * stu);
void Help();
void modi(struct SStudent *h);
void search(struct SStudent *h);struct SStudent * student;
unsigned number;
char keyValue;
student = CreateTable();
//clrscr();
system("cls");
Help();
printf("\n= ");
while((keyValue = getche()) != 'q' && keyValue != 'Q' && keyValue != 27)
{
puts("");
switch(keyValue)
{
case 'l': case 'L':
PrintTable(student); break;
case 'd': case 'D':
printf("Please input the number you want delete: ");
scanf("%d", &number);
QueryTable(student, number);
break;
case 'a': case 'A':
AppendToTable(student); break;
case 'i': case 'I':
InsertToTable(student); break;
case 's': case 'S':
SortTable(student);
puts("Sort complished! Please use command L to list.");
break;
case 'f': case 'F':
search(student);
break;
case 'm': case 'M':
modi(student);
break;case 'v': case 'V':
Save(student); break;
case 'o': case 'O':
Load(student); break;
case 'h': case 'H':
Help(); break;
default: puts("Error command!");
}
printf("\n= ");
}
}
struct SStudent * CreateTable()
{
struct SStudent * stu;
stu = (struct SStudent *) malloc(sizeof(struct SStudent));
stu->number = 0;
stu->name[0] = '\0';
stu->tele[0] = '\0';
stu->link = NULL;
return(stu);
}
void AppendToTable(struct SStudent * stu)
{
struct SStudent * next, * last;
int number;
last = stu;
while(last->link) last = last->link;
printf("Please input the number (0 to quit): ");
scanf("%d", &number);
while(number)
{
next = (struct SStudent *) malloc(sizeof(struct SStudent));
next->number = number;
printf("Please input name: ");
scanf("%s", next->name);
printf("Please input tele: ");
scanf("%s", next->tele);
last->link = next;
last = last->link;
printf("\nPlease input the number (0 to quit): ");
scanf("%d", &number);
}
last->link = NULL;
}
void InsertToTable(struct SStudent * stu)
{
struct SStudent * next, * last;
int number;
printf("Please input the number (0 to quit): ");
scanf("%d", &number);
while(number)
{
next = (struct SStudent *) malloc(sizeof(struct SStudent));
next->number = number;
printf("Please input name: ");
scanf("%s", next->name);
printf("Please input tele: ");
scanf("%s", next->tele);
last = stu;
while(last->link)
{
if(last->link->number > next->number)
{
next->link = last->link;
last->link = next;
break;
}
else last = last->link;
}
printf("\nPlease input the number (0 to quit): ");
scanf("%d", &number);
}
}
void QueryTable(struct SStudent * stu, unsigned number)
{
struct SStudent * temp, * next;
next = stu;
while(next->link)
{
if(next->link->number == number)
{
temp = next->link;
next->link = next->link->link;
free(temp);
}
else next = next->link;
}
}
void PrintTable(struct SStudent * stu)
{
stu = stu->link;
if(!stu)
{
puts("The table is EMPTY!");
return;
}
printf("number\tname\ttele\n");
while(stu)
{
printf("%3d\t", stu->number);
printf("%-s\t", stu->name);
printf("%-s\t", stu->tele);
printf("\n");
stu = stu->link;
}
}
void SortTable(struct SStudent * stu)
{
struct SStudent * next, * last, * temp;
int flag;
last = stu;
while(last->link)
{
next = stu; flag = 1;
while(next->link != last->link)
{
if(next->link->number > last->link->number)
{
temp = last->link;
last->link = last->link->link;
temp->link = next->link;
next->link = temp;
flag = 0;
break;
}
else next = next->link;
}
if(flag) last = last->link;
}
}
void Save(struct SStudent * stu)
{
char filename[13];
FILE * fileSave;
printf("Please input the filename you want save in: ");
scanf("%s", filename);
if((fileSave = fopen(filename, "wb")) == 0)
{
printf("Cannot open file %s !\n", filename);
return;
}
puts("Saveing ...");
stu = stu->link;
while(stu)
{
fwrite(stu, sizeof(struct SStudent), 1, fileSave);
stu = stu->link;
}
puts("Saveing is finished!");
}
void Load(struct SStudent * stu)
{char filename[13];<br>FILE * fileLoad;<br>struct SStudent * temp;<br>while(stu->link)<br>{<br>temp = stu->link;<br>stu->link = stu->link->link;<br>free(temp);<br>}
temp = (struct SStudent *) malloc(sizeof(struct SStudent));
printf("Please input the filename you want load from: ");
scanf("%s", filename);
if((fileLoad = fopen(filename, "rb")) == 0)
{
printf("Cannot open file %s !\n", filename);
return;
}
puts("Loading ...");
while(fread(temp, sizeof(struct SStudent), 1, fileLoad))
{stu->link = temp;<br>stu = stu->link;<br>temp = (struct SStudent *) malloc(sizeof(struct SStudent));<br>}
stu->link = NULL;
puts("loading is finished!");
}
void Help()
{ puts(" *********************************************");
puts(" * System Command Help *");
puts(" *********************************************");
puts(" * L = List all records *");
puts(" * D = Delete a record seleced by number *");
puts(" * A = Append records *");
puts(" * I = Insert records *");
puts(" * S = Sort records *");
puts(" * F= Search records *");
puts(" * M= Modi records *");puts(" * H = Show this help message *");
puts(" * V = Save records to a file *");
puts(" * O = Load records from a file *");
puts(" * Q = Quit System *");
puts(" *********************************************");
}
void modi(struct SStudent *h)
{
struct SStudent *p; /* 移动指针*/
unsigned num; /*存放学号的变量*/
// clrscr(); /*清屏幕*/
system("cls");
printf("please enter number for modifi\n");
scanf("%d",&num); /*输入学号*/
p=h; /*将头指针赋给p*/
while( (p->number!=num)&&p!=NULL) /*当记录的姓名不是要找的,且指针不为空时*/
p=p->link; /*移动指针,指向下一结点*/
if(p==NULL) /*如果指针为空*/
printf("\nlist no %d student\n",num); /*显示没有该学生*/
else /*修改找到的记录信息*/
{
printf("Please input new name: ");
scanf("%s", p->name);
printf("Please input new tele: ");
scanf("%s", p->tele);
printf("|number | name | tel | \n");
printf("|----------|---------------|---------------|\n");
printf("|%6d|%-10s|%12s|\n", p->number,p->name,p->tele); }
}
void search(struct SStudent *h)
{
struct SStudent *p; /* 移动指针*/
char s[10]; /*存放姓名的字符数组*/
// clrscr(); /*清屏幕*/
system("cls");
printf("please enter name for search\n");
scanf("%s",s); /*输入姓名*/
p=h; /*将头指针赋给p*/
while(strcmp(p->name,s)&&p!=NULL) /*当记录的姓名不是要找的,且指针不为空时*/
p=p->link; /*移动指针,指向下一结点*/
if(p==NULL) /*如果指针为空*/
printf("\nlist no %s student\n",s); /*显示没有该学生*/
else /*显示找到的记录信息*/
{
printf("\n\n***********************havefound***********************\n");
printf("|number | name | tel | \n");
printf("|----------|---------------|---------------|\n");
printf("|%10d|%-10s|%12s|\n", p->number,p->name,p->tele);
printf("****************************end***************************\n");
}
}
F. c语言编程:打开一文件,输出文件有多少行,每行有多少字符
另一种方法是用fgetc读取字符,每读一个字符,计数器加1,读到ASCII为13时,表示一行结束(或读敬配到文件尾部),计数器输出并清零,继续肆御下一行亮雹指