編程實習(xí)報告_第1頁
編程實習(xí)報告_第2頁
編程實習(xí)報告_第3頁
編程實習(xí)報告_第4頁
編程實習(xí)報告_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)專心-專注-專業(yè)精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)編程實習(xí)實習(xí)報告學(xué) 號:_班 級:_學(xué)生姓名:_起始日期:_完成日期:_一、任務(wù)要求用字符串指針實現(xiàn)學(xué)生成績管理系統(tǒng)完成函數(shù) void DeleteStudent(char* students,int* marks); void SortClass(char* students,int* marks); void ShowClass(char* students,int* marks); void EditMarks(char* students,int* marks)

2、;二、詳細設(shè)計void InsertStudent(char* students,int* marks); 插入學(xué)生姓名基本想法:先讀取學(xué)生姓名,判斷指針是否為空,為空則建立內(nèi)存。不為空則再開拓新的內(nèi)存空間,將讀取的學(xué)生與名單進行一一對照。若有相同的,則顯示已存在該學(xué)生,若沒有相同的,則開拓內(nèi)存給新到的學(xué)生,并對名單進行排序,最后釋放內(nèi)存。 開始 讀取插入的學(xué)生姓名判斷指針是否為空 是否 建立初始內(nèi)存 Malloc 擴展新內(nèi)存 realloc判斷學(xué)生是否 在名單內(nèi)顯示該學(xué)生已 在名單內(nèi)開拓成績與姓名的內(nèi)存對所有的學(xué)生進行排序 返回void DeleteStudent(char* student

3、s,int* marks);刪除學(xué)生信息基本想法: 先讀取要刪除的學(xué)生姓名,將讀入的學(xué)生姓名與已存在的學(xué)生進行比較,如相同,記住該學(xué)生所在位置,判斷該學(xué)生下一個是否為空,若為空,就可以直接把該學(xué)生內(nèi)存釋放掉。若不是,則用一個while 將后面的所有學(xué)生向前移一位 直到NULL,再釋放最后的內(nèi)存,最后再釋放學(xué)生姓名的那個內(nèi)存 開始 否 讀取學(xué)生姓名與名單里的學(xué)生作比較是否相同且不為空是該學(xué)生的下一個是否為空 是否將后面的學(xué)生信息向前移一位釋放最后一個的內(nèi)存以及名字的內(nèi)存 返回void SortClass(char* students,int* marks);排序 基本想法: 采用冒泡法來進行排序

4、。N次排序 先進行n-1次比大小,找到最小的,與第一個交換,再進行n-2次。 開始判斷該學(xué)生i是否為空否比大小,名單后最小的學(xué)生將該學(xué)生與學(xué)生i互換 i+ 返回void ShowClass(char* students,int* marks);顯示所有學(xué)生信息基本想法:直接用printf輸出。 開始判斷指針是否為空否 輸出學(xué)生信息 i+ 是判斷該學(xué)生是否為空 結(jié)束void EditMarks(char* students,int* marks); 編輯學(xué)生成績基本想法: 先讀取要編輯的學(xué)生姓名,然后與所有的學(xué)生姓名進行比較,判斷是否在名單內(nèi),若不在,就輸出不在,否則 就再讀取該學(xué)生的5個成績到

5、 marks 開始 讀取編輯學(xué)生的姓名判斷學(xué)生是否在名單內(nèi) 是 否輸入5個成績,并將mark的指針指向這5個成績 顯示該學(xué)生不在名單內(nèi) 返回三、編碼實現(xiàn)void DeleteStudent(char* students,int* marks) int found, i,j; char* students1; int* marks1; students1 = *students; marks1 = *marks; char *name; printf(enter names of students to be deleted separated by commasn); name = ReadL

6、ine(); / 讀姓名 if(students1 =NULL) return ; for(found = i = 0; students1i != NULL; i+)/ 判斷是否已經(jīng)存在該學(xué)生 if (strcmp(students1i,name) = 0) / 判斷函數(shù) 相同為0 found = 1; break; if (!found) /如果不同 printf(student %s not in the Class Listn,name); return; if(students1i+1!= NULL) /判斷下一個學(xué)生是否為空 j=i+1; while(students1j!=NUL

7、L) /不為空時,將學(xué)生信息向前移一位 students1j-1=students1j; marks1j-1= marks1j; j+; students1j-1=NULL; marks1j-1= NULL; free(void*)students1j-1); / 釋放內(nèi)存 free(void*)marks1j-1); else students1i=NULL; marks1i = NULL; free(void*)students1i); free(void*)marks1i); *students = students1; *marks = marks1; free(void*)name)

8、; /釋放姓名內(nèi)存 void ShowClass(char* students,int* marks) int i, j,k; char* students1,*stu1; int* marks1,*mar1; students1 = students; marks1 = marks; for(i = 0; students1i+1 != NULL; i+) / 最小冒泡排序法 k=i; for(j=i+1;students1j !=NULL; j+) if(strcmp(students1j,students1k) 0) k=j; stu1 = students1k; students1k

9、= students1i; students1i = stu1; mar1 = marks1k; marks1k = marks1i; marks1i = mar1; students = students1; marks = marks1; void ShowClass(char* students,int* marks) int i; fflush(stdout); if(students=NULL) /指針為空 則返回 printf(Class is Empty!n); return; printf(Class List:n); printf(students:第一門第二門第三門第四門第

10、五門 總分 n); for(i=0;studentsi!=NULL;i+) if(marksi0=-1&marksi1=-1&marksi2=-1&marksi3 =-1&marksi4=-1) printf(%s: , , , , , n,studentsi); else printf(%s: %d, %d, %d, %d, %d %dn,studentsi,marksi0,marksi1,marksi2,marksi3,marksi4,(marksi0+marksi1+marksi2+marksi3+marksi4); return; void EditMarks(char* studen

11、ts,int* marks) /編輯學(xué)生成績 int found, i,score; char* students1; int* marks1; students1 = students; marks1 = marks; char *name; printf(Enter student name whose marks are to be edited:n); name = ReadLine(); for(found = i = 0; students1i != NULL; i+) if (strcmp(students1i,name) = 0) / 相同為0 found = 1; print

12、f(editing:%sn,name); break; if(!found) printf(student %s not in the Class listn,name); while (found) /讀取輸入的五個成績 printf(to leave the 1st mark unchanged,press n); printf(otherwise type new mark and press n); scanf(%d,&score); while(score=0 & score =100) != 1) printf(incorrect mark entered,re-do:n); sc

13、anf(%d,&score); marksi0=score; printf(to leave the 2nd mark unchanged,press n); printf(otherwise type new mark and press n); scanf(%d,&score); while(score=0 & score =100) !=1) printf(incorrect mark entered,re-do:n); scanf(%d,&score); marksi1=score; printf(to leave the 3rd mark unchanged,press n); pr

14、intf(otherwise type new mark and press n); scanf(%d,&score); while(score=0 & score =100) !=1) printf(incorrect mark entered,re-do:n); scanf(%d,&score); marksi2=score; printf(to leave the 4th mark unchanged,press n); printf(otherwise type new mark and press n); scanf(%d,&score); while(score=0 & score

15、 =100) !=1) printf(incorrect mark entered,re-do:n); scanf(%d,&score); marksi3=score; printf(to leave the 5th mark unchanged,press n); printf(otherwise type new mark and press n); scanf(%d%c,&score); /吃掉回車鍵 while(score=0 & score =100) !=1) printf(incorrect mark entered,re-do:n); scanf(%d%c,&score); m

16、arksi4=score; return; 程序調(diào)試1.在調(diào)試的時候,剛運行的時候在什么都沒有輸入的時候,馬上按2,發(fā)現(xiàn)程序就出現(xiàn)錯誤,我就在delete里面先加入一個判斷 指針是否為空 為空就返回 來避免錯誤 2.在editmarks這個函數(shù)中 我采用scanf這個函數(shù)來讀取成績,在讀取第五個成績的時候發(fā)現(xiàn)讀完后會在函數(shù)主菜單里出現(xiàn)一次的錯誤,詢問同學(xué),發(fā)現(xiàn)應(yīng)該在第五個輸入成績的時候在%s后面再加一個%c 來吃掉一個回車鍵 這樣主菜單就不會出現(xiàn)菜單錯誤的情況 五、總結(jié) 編程實習(xí)中 ,首先要看懂老師所給的部分程序,先了解老師給整個程序的基本方法,比如這個函數(shù)是用多級指針來完成這個程序 ,而不是用結(jié)構(gòu)體來做鏈表來實現(xiàn)的,只有這個先弄懂這些才能做到心中有數(shù)。 在編程的過程中,要有系統(tǒng)的想法,知道整個框架是怎么構(gòu)成的。 另外在編程基本完成后 要進行全面的調(diào)試,針對各個情況都進行嘗試,盡可能避免出現(xiàn)錯誤 本次編程學(xué)習(xí)到了很多知識,特別感受到了鏈表在C語言中比數(shù)組來的更加方便,雖然完成了本次實習(xí)目的,但是設(shè)計出的軟件還有很大缺陷,不是很完善,在幾個地方不是很人性化,有待完善。本次實習(xí)收獲很多,受益匪淺。 思考題 為什么插入一個學(xué)生、刪除一個學(xué)生的函數(shù)(in

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論