A. c語言課程設計
main()
{
int i,j;
scanf("%d",&i);
j=i/10
switch(i)
{
case 10:
case 9: printf("優秀"); break;
case 8: printf("良好"); break;
case 7: printf("中等"); break;
case 6: printf("及格"); break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: printf("不及格"); break;
default : printf("輸入有誤");
}
}
B. c語言課程設計:圖書管理系統設計的基本思路是什麼
圖書管理系統主要要求可以錄入書籍,添加書目,查找書本信息,刪除或修改信息,有的還要求顯示是否被借閱等。
一般採用結構體數組,鏈表,文件操作和自定義函數。主要是需要對基礎知識掌握牢固。
先定義結構體,然後對結構體的成員進行定義,選擇數組存儲書本各種信息。錄入信息可以用for和do while循環等來做。
存放信息需要文件操作函數,比如fopen,fwrite等。
刪除和添加可以刪除節點或者增加節點。
查找之類的可以用字元串操作的各種函數實現。
附上參考源代碼
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#definebooks"f:\books.txt"
#definebooksbak"f:\booksbak.txt"
structbookinfo
{
charisbn[20];
chartitle[30];
charauthor[20];
intcount;
};
structbook
{
structbookinfoonebook;
structbook*next;
};
structbook*searchBook(structbook*listptr,charisbn[])
{
while(listptr!=(structbook*)0)
if(strcmp(listptr->onebook.isbn,isbn)==0)
returnlistptr;
else
listptr=listptr->next;
return(structbook*)0;
}
voidMainSearchbook(structbook*firstptr)
{
structbook*ptr;
charisbnno[20];
printf("請輸入ISBN:");
scanf("%s",&isbnno);
ptr=searchBook(firstptr,isbnno);
if(ptr!=(structbook*)0)
{
printf("找到了!!! ");
printf("ISBN:%s ",ptr->onebook.isbn);
printf("Title:%s ",ptr->onebook.title);
printf("Author:%s ",ptr->onebook.author);
}
else
printf("sorry,notfound!!! ");
}intaddBook(structbook*listptr,structbookinfonote)
{
while(listptr->next!=0)
listptr=listptr->next;
listptr->next=(structbook*)malloc(sizeof(structbook));
listptr->next->onebook=note;
listptr->next->next=0;
return0;
}
voidMainAdd(structbook*listptr,FILE*fp)
{
intok;
structbookinfonote;
printf("請輸入ISBN:");
scanf("%s",¬e.isbn);
printf("請輸入Title:");
scanf("%s",¬e.title);
printf("請輸入Author:");
scanf("%s",¬e.author);
ok=addBook(listptr,note);
if(ok==0)
{
//將加入的圖書寫到文件中保存
fprintf(fp," %s%s%s%d",note.isbn,note.title,note.author,0);
printf("添加圖書成功!!! ");
}
else
printf("添加圖書失敗!!! ");
}
intremoveBook(structbook*listptr,charisbn[])
{
while(listptr->next!=(structbook*)0)
{
if(strcmp(listptr->next->onebook.isbn,isbn)==0)
{
listptr->next=listptr->next->next;
return0;
}
else
listptr=listptr->next;
}
return-1;
}
voidMainRemove(structbook*listptr,FILE*fp)
/************************************************************************/
/*刪除書籍函數,通過ISBN刪除鏈表節點,同時刪除文件中對應信息*/
/*刪除文件中一行,用的是笨方法,把需要的信息寫到新文件,刪除舊文件,重命名..*/
/************************************************************************/
{
charisbnno[20];
intok;
structbookinfoonebook;
printf("請輸入ISBN:");
scanf("%s",&isbnno);
ok=removeBook(listptr,isbnno);
if(!ok)
{
FILE*fpbak;
if((fpbak=fopen(booksbak,"a+"))==NULL)
printf("文件打開失敗!!! ");
fseek(fp,0,SEEK_SET);//移到文件開始
while((fscanf(fp,"%s%s%s%d ",&onebook.isbn,&onebook.title,&onebook.author,&onebook.count))!=EOF)
{
if(strcmp(onebook.isbn,isbnno)!=0)
{
fprintf(fpbak,"%s%s%s%d ",onebook.isbn,onebook.title,onebook.author,onebook.count);
}
}
fclose(fp);
fclose(fpbak);
if(remove(books))//刪除失敗返回非0
{
printf("刪除文件失敗!!! ");
return;
}
else
if(rename(booksbak,books))//重命名失敗返回非0值
{
printf("重命名失敗!!! ");
return;
}
printf("刪除成功!!! ");
}
else
printf("查無此書!!!");
}
intchoice(void)
{
intc;
printf("1.查看圖書 ");
printf("2.添加圖書 ");
printf("3.刪除圖書 ");
printf("4.退出程序 ");
printf("請選擇序號:");
returnc=getchar();
//returnc=getche();
printf(" ");
}
intaddEntry(FILE*fp,structbook*firstptr)
/************************************************************************/
/*主要用來載入文件中存放的圖書信息*/
/************************************************************************/
{
structbookinfoonebook;
while((fscanf(fp,"%s%s%s%d ",&onebook.isbn,&onebook.title,&onebook.author,&onebook.count))!=EOF)
{
while(firstptr->next!=0)
firstptr=firstptr->next;
firstptr->next=(structbook*)malloc(sizeof(structbook));
firstptr->next->onebook=onebook;
firstptr->next->next=0;
}
return0;
}
intmain(intargc,char*argv[])
{
intch;
structbookfirst;
strcpy(first.onebook.isbn,"123456");
strcpy(first.onebook.title,"ProgrammingC");
strcpy(first.onebook.author,"yhb");
first.next=0;
structbook*firstptr=&first;//鏈表頭指針
FILE*fp;
if((fp=fopen(books,"a+"))==NULL)
printf("文件打開失敗!!!");
addEntry(fp,firstptr);
while(1)
{
system("CLS");//清屏
/************************************************************************/
/*想想這里為什麼要清空緩沖區?*/
/*由於上一次(choice函數)的getchar(),還有一個' '留在緩沖區....*/
/*可以把這句話注釋掉看看,沒有這句話會遇到麻煩*/
/*如果不用fflush,可以將上面的getchar()換成getche()*/
/*比較getchar(),getch(),getche()......*/
/************************************************************************/
fflush(stdin);
ch=choice()-48;
switch(ch)
{
case1:
MainSearchbook(firstptr);
break;
case2:
MainAdd(firstptr,fp);
break;
case3:
MainRemove(firstptr,fp);
break;
case4:
printf("謝謝使用... ");
exit(0);
default:
printf("請輸入正確序號!");
}
system("PAUSE");
}
return0;
}
C. 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;
}
D. 想了半天,實在是沒有思路,誰能給我點提示啊!不勝感激c語言課程設計
提示一句:一個數的層數為,它所有因數中層數最大的那個因數的下一層。
然後就有了以下構造過程:
voidinitList(){
inti;
structMyNode*tail=&head;
for(i=1;i<=N;i++){
structMyNode*p=(structMyNode*)malloc(sizeof(structMyNode));
p->num=i;
intmaxLay=0;
structMyNode*q;
for(q=head.pNext;q;q=q->pNext){
if(p->num>q->num&&p->num%q->num==0){
if(q->lay+1>maxLay){
maxLay=q->lay+1;
}
}
}
p->lay=maxLay;
tail->pNext=p;
p->pNext=NULL;
tail=p;
}
}
然後簡單的排序和輸出就行了
E. c語言課程設計報告
#include<stdio.h>
#include<conio.h>
int
CF(int
i)/*求10的i次方的函數*/
{
int
j,m=1;
for(j=0;j<i;j++)
m=10*m;
return
m;
}
void
sort(int
fun[],int
n)/*對分離後的六個數進行從小到大排序*/
{
int
i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(fun[i]>fun[j])
{
temp=fun[i];
fun[i]=fun[j];
fun[j]=temp;
}
}
}
}
int
pick(int
a,int
s)/*挑選這個數乘以s後滿足的數a*/
{
int
i;
int
fun1[6],fun2[6],b;
b=a*s;
for(i=0;i<6;i++)
{
fun1[i]=a%CF(i+1)/CF(i);/*求這個六位數每位上的數字*/
fun2[i]=b%CF(i+1)/CF(i);
}
sort(fun1,6);/*對數字進行排序*/
sort(fun2,6);
for(i=0;i<6;i++)
{
if(fun1[i]!=fun2[i])
break;/*依次進行比較,如果均相同即滿足,返回1*/
}
if(i==6)
return
1;
else
return
0;
}
int
search(int
a[],int
s)/*搜索到滿足題意的結果保存在數組a[]中*/
{
int
i,n=0;
for(i=100000;i<166668;i++)
{
if(pick(i,s))
{
a[n]=i;
n++;
}
else
continue;
}
return
n;
}
void
print(int
a[],int
n)/*在屏幕上列印結果*/
{
int
i;
for(i=0;i<n;i++)
{
printf("%d
",a[i]);
}
printf("\n\n");
}
void
main()
{
int
a[100],m,s[5]={2,3,4,5,6},i;
for(i=0;i<5;i++)
{
printf("這個數乘以%d後滿足條件的結果\n",s[i]);
m=search(a,*(s+i));
print(a,m);
}
getch();
}
這個程序是求出一個六位數乘以2,3,4,5,6後得到的六位數仍由原書的數字組成,並分別輸出結果。
F. c語言課程設計目的
沒得題目??那就隨便寫三。。。比如啥子增加編程技巧,熟練對你那個編程軟體的應用,鞏固你們教的所學的啥子知識什麼的````
G. C語言課程設計求解釋。。。
#include <stdio.h>
struct student //定義一個結構體
{
char no[20];
char name[20];
float math,english,computer;
double total;
double avr;
};
struct student stu[50]; //定義stu結構體數組
//以下四個是函數聲明語句
struct student input(); //學生數據輸入函數,返回值是結構體
void display(struct student stu[],int count); //顯示函數
void sort(struct student stu[],int count); //排序函數
void stat(struct student stu[],int count); //成績分析函數
void main()
{
int count;
char ch;
ch='y';
printf("請按以下格式輸入學生信息(可用Tab鍵對齊):");
printf("\n");
count=0;
while ((ch=='y') || (ch=='Y'))
{
stu[count]=input(); //調用input函數輸入一個學生的信息給stu數組
count++; //這個循環是當ch為y時添加學生成績信息
printf("\n是否繼續?(按Y繼續,其它結束)");
scanf(" %c",&ch);
}
printf("\n學生信息如下:");
sort(stu,count); //調用排序函數進行排序
display(stu,count); //顯示排序後的結構
stat(stu,count); //調用分析函數顯示分析結果
system("PAUSE"); //我這里加了一個暫停語句,可以把結果停留在輸出窗口觀看
}
struct student input()
{ int i;
struct student studn;
while(1) //這個循環是當有學號重復時讓用戶重復輸入
{printf("\n學號\t\t姓名\t數學\t英語\t計算機\n");
while(1)
{scanf("%s %s %f %f %f",&studn.no,studn.name,&studn.math,&studn.english,&studn.computer);
if((studn.math>0)&&(studn.math<=100)&&(studn.english>0)&&(studn.english<=100)&&(studn.computer>0)&&(studn.computer<=100))break;
printf("輸入的成績不符合要求,請重新輸入\n");
fflush(stdin);}
for(i=0;i<50;i++) //這個循環是查找stu數組中有沒有和輸入的學號有重復的信息,
if(strcmp(stu[i].no,studn.no)==0)break; //如果有就用break跳出for循環
if(i==50)break; //如果for循環後i值等於50,表示該學號沒有重復,用break跳出while循環
printf("輸入的學號已存在,請重新輸入\n");
}
studn.total=studn.math+studn.english+studn.computer; //計算該學生的總分
studn.avr=studn.total/3.0; //計算該學生的平均分
return studn;
}
void display(struct student stu[],int count)
{ //這個函數很簡單,用循環把stu數組的內容輸出來
int i;
printf("\n排名\t學號\t\t姓名\t數學\t英語\t計算機\t總分\t平均分");
printf("\n");
for(i=0;i<count;i++)
{
printf("%d",i+1);
printf("\t%s",stu[i].no);
printf("\t%s",stu[i].name);
printf("\t%.1f",stu[i].math);
printf("\t%.1f",stu[i].english);
printf("\t%.1f",stu[i].computer);
printf("\t%.2f",stu[i].total);
printf("\t%.2f",stu[i].avr);
printf("\n");
}
}
void sort(struct student stu[],int count)
{ //這個函數是把stu數組進行排序
int i,j;
struct student t;
for(i=0;i<count;i++) //排序方法是冒泡排序
for(j=0;j<count-i-1;j++)
{
if(stu[j].avr<stu[j+1].avr) //按每個學生的3科平均分大小有高到低排序
{
t=stu[j];
stu[j]=stu[j+1];
stu[j+1]=t;
}
}
}
void stat(struct student stu[],int count)
{ //這個是分數段處理函數
int i;
double avr=0;
for(i=0;i<count;i++) //這個循環是統計全班3科成績平均分的班的總平均分
avr += stu[i].avr;
avr /= count;
printf("全班平均分為%.2f,\n在平均分以上的同學有:\n",avr);
for(i=0;i<count;i++) //這個循環的功能上面printf語句說得很清楚了
if(stu[i].avr>=avr)
{
printf("%s\t",stu[i].name);
}
printf("\n");
}
H. 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;
}