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時,表示一行結束(或讀敬配到文件尾部),計數器輸出並清零,繼續肆御下一行亮雹指