c++課程設(shè)計(jì)——職工工資管理系統(tǒng)_第1頁(yè)
c++課程設(shè)計(jì)——職工工資管理系統(tǒng)_第2頁(yè)
c++課程設(shè)計(jì)——職工工資管理系統(tǒng)_第3頁(yè)
c++課程設(shè)計(jì)——職工工資管理系統(tǒng)_第4頁(yè)
c++課程設(shè)計(jì)——職工工資管理系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、題 目 c+面向?qū)ο蟪绦蛟O(shè)計(jì)課程設(shè)計(jì) 清單:5小題+職工工資管理系統(tǒng)(類、鏈表實(shí)現(xiàn)) 姓 名: 學(xué) 號(hào): 專 業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 學(xué) 院: 指導(dǎo)教師: 2018年6月17日Part 1: 小程序練習(xí)1 類的繼承定義一個(gè)point類,包含私有數(shù)據(jù)成員x,y,成員函數(shù)包括無參構(gòu)造函數(shù),帶參構(gòu)造函數(shù),set和get屬性函數(shù)。定義circle類,從point類公有派生,增加數(shù)據(jù)成員半徑r,成員函數(shù)包括無參構(gòu)造函數(shù),帶參構(gòu)造函數(shù),計(jì)算面積函數(shù)getarea。在main函數(shù)中定義一個(gè)circle的對(duì)象,并計(jì)算其面積。/*1定義Point類,設(shè)置其成員函數(shù)(構(gòu)造函數(shù),拷貝構(gòu)造函數(shù)和析構(gòu)函數(shù))以及setx

2、() sety() getx() gety() 四個(gè)屬性函數(shù)。2定義circle類,設(shè)置其成員函數(shù)(構(gòu)造函數(shù),拷貝構(gòu)造函數(shù)和析構(gòu)函數(shù))以及獲取半徑r的函數(shù)get_r() 計(jì)算面積并獲取面積的函數(shù)getarea()。3在主函數(shù)中定義類的對(duì)象c1并初始化r=2。再調(diào)用getarea()函數(shù)輸出面積*/#include using namespace std;class point/定義point類public:point() point(int x, int y)void set_x(int x)this-x = x;int get_x() return x;void set_y(int y)th

3、is-y = y;int get_y()return y;private:/私有對(duì)象x yint x;int y;class circle :public point/circle類公有派生pointpublic:circle() circle(double r,int x,int y):point(x,y)this-r = r;double get_r() return r;double getarea() return(3.14*r*r);private:int r;/circle私有對(duì)象r;int main()circle c1(2,3,6);coutr=c1.get_r()endl;c

4、out 該圓面積=c1.getarea() ,功能。在main函數(shù)里測(cè)試該類。/*1.定義counter類,私有成員數(shù)據(jù)weight,設(shè)置其成員函數(shù)(構(gòu)造函數(shù)和析構(gòu)函數(shù))2.重載自加自減運(yùn)算符和運(yùn)算符。3.在主函數(shù)中實(shí)現(xiàn)運(yùn)算符重載。4.友元函數(shù)需要聲明。*/#include#includeusing namespace std;class counter;istream& operator(istream& is,counter& a);ostream& operator(istream& is,counter& a); /聲明友元,重載輸入運(yùn)算符friend ostream& operato

5、r(istream& in,counter& a) /運(yùn)算符重載實(shí)現(xiàn)ina.P;if(!in)cerr輸入錯(cuò)誤!endl;return in;ostream& operator(ostream& out,counter& a) /運(yùn)算符重載實(shí)現(xiàn)outa.P;return out;int main()counter c1(236),c2(632); coutc1=c1endlc2=c2endl;cout+c1=+c1endl; /測(cè)試coutc1+=c1+endl;coutc2-=c2-endl;cout-c2=-c2endl;system(pause);return 0;運(yùn)行結(jié)果分析:定義c1

6、的值為236,c2的值為632;此時(shí)+c1的數(shù)值為237;c1+輸出時(shí)為237,輸出后為238;此時(shí)c2-輸出時(shí)為632;-c2輸出時(shí)為630,輸出后為630;3 虛函數(shù)和抽象類定義一個(gè)抽象類shape,包括公有的計(jì)算面積area函數(shù),計(jì)算體積volume函數(shù),輸出基本信息函數(shù)printinfo(三個(gè)函數(shù)均為純虛函數(shù))。從shape公有派生point類,增加私有數(shù)據(jù)成員x,y坐標(biāo),以及構(gòu)造函數(shù),析構(gòu)函數(shù)。從point公有派生circle類,增加私有數(shù)據(jù)成員半徑r,以及構(gòu)造函數(shù),析構(gòu)函數(shù)。從circle公有派生cylinder類,增加私有數(shù)據(jù)成員高度h,以及構(gòu)造函數(shù),析構(gòu)函數(shù)。(在定義三個(gè)派生類

7、的過程中,自己考慮需要重定義哪個(gè)虛函數(shù))。在main函數(shù)中,定義shape類的指針,指向派生類的對(duì)象,輸出三類對(duì)象的基本信息,面積,體積;(將shape指針改為引用再嘗試)。/*1先定義基類shape。設(shè)置三個(gè)純虛函數(shù)并且聲明:聲明計(jì)算面積純虛函數(shù)area();聲明計(jì)算體積純虛函數(shù)volume();聲明輸出基本信息純虛函數(shù)printinfo();2定義類point共有繼承自類shape。并且在該類中實(shí)現(xiàn)三個(gè)純虛函數(shù)。3定義類circle共有繼承自類point。并且在該類中實(shí)現(xiàn)三個(gè)純虛函數(shù)。4定義類cylinder共有繼承自類circle。并且在該類中實(shí)現(xiàn)三個(gè)純虛函數(shù)。5在主函數(shù)中分別創(chuàng)建類po

8、int的對(duì)象a,circle的對(duì)象b,cylinder的對(duì)象c,并初始化;6在主函數(shù)中分別定義shape類的指針和引用,調(diào)用printinfo()函數(shù)。*/#include #include #define Pi 3.using namespace std;class shapepublic:virtual double area() = 0;/三個(gè)純虛函數(shù):面積,體積,基本輸出virtual double volume() = 0;virtual void printinfo () = 0;class point :public shape/shape派生的point類;點(diǎn)并沒有體積面積,所

9、以只寫printinfo函數(shù)public:point() point(double x, double y)this-x = x;this-y = y;void printinfo()cout x= x ,y= y r = r;double area()return Pi*r*r;void printinfo()point:printinfo();cout 半徑為 r endl;cout 圓的面積是 area() h = h;/*double area()return 2*Pi*this-r+circle:area();/未實(shí)現(xiàn)計(jì)算圓柱表面積*/double volume()return h*

10、circle:area();void printinfo()circle:printinfo();cout 高為 h endl;cout 圓柱的體積是 volume() endl;cylinder() private:double h;int main()cylinder temp(6, 2, 3, 3);shape *s;/實(shí)例化一個(gè)圓柱對(duì)象s = &temp;(*s).printinfo();printf(n);cout temp中數(shù)據(jù)構(gòu)成的圓面積為 area() endl;cout 體積為 (*s).volume() endl;system(pause);return 0;運(yùn)行結(jié)果:4

11、模板編寫一個(gè)使用類模板對(duì)數(shù)組進(jìn)行查找、求元素和、重載下標(biāo)運(yùn)算符,以及輸出的程序。1)設(shè)計(jì)一個(gè)類模板:形式1為templateclass Array;形似2為templateclass Array;用于對(duì)T類型的數(shù)組進(jìn)行構(gòu)造和輸出;2)產(chǎn)生模板類Array和Array進(jìn)行測(cè)試;3)產(chǎn)生模板類Array和Array進(jìn)行測(cè)試。/先實(shí)現(xiàn)第(2)小題#include #include using namespace std;template class Arrayprivate: T* list; int size; public: Array(int size = 10); /構(gòu)造函數(shù) Array()

12、; /析構(gòu)函數(shù) T & operator (int i); /重載” const T & operator (int i) const;T sum(int n); int search(T e,int n); int getSize() const; void resize(int sz); ;template Array:Array(int sz) /構(gòu)造函數(shù) assert(sz = 0); size = sz; list = new T size; template Array:Array() /析構(gòu)函數(shù) delete list;/重載下標(biāo)運(yùn)算符template T &Array:oper

13、ator (int n) assert(n = 0 & n size); return listn; template const T &Array:operator (int n) const assert(n = 0 & n size); return listn; /取當(dāng)前數(shù)組的大小template int Array:getSize() const return size;/ 將數(shù)組大小修改為sztemplate void Array:resize(int sz) assert(sz = 0); if (sz = size) return; T* newList = new T sz;

14、 int n = (sz size) ? sz : size; for (int i = 0; i n; i+) newListi = listi; delete list; /刪除原數(shù)組 list = newList; / 使list指向新數(shù)組 size = sz; /更新sizetemplateT Array:sum(int n) T sum = list0; for(int i = 1; i n; i+) sum += listi;return sum;/查找templateint Array:search(T e, int n) for(int i = 0; i n; i+) if(l

15、isti = e) return i;return -1;int main() Array a(5); int i,n,m, count = 0; cout n; for (i = 1; i m;if (count = a.getSize() a.resize(count * 2);acount+ = m; for ( i = 0; i count; i+) cout ai; cout endl;cout數(shù)組和為:a.sum(n)endl; cout數(shù)字4在數(shù)組中的位置是:a.search(4,n)endl;/* Array進(jìn)行測(cè)試Array a(5); int i,n,m, count =

16、0; cout n; for (i = 1; i m;if (count = a.getSize() a.resize(count * 2);acount+ = m; for ( i = 0; i count; i+) cout setw(8) ai; cout endl;cout數(shù)組和為:a.sum(n)endl; cout數(shù)字4在數(shù)組中的位置是:a.search(4,n)endl;*/ return 0;/然后實(shí)現(xiàn)第(3)小題#include #include using namespace std;template class Arrayprivate: T *list ; public

17、: Array(); /構(gòu)造函數(shù) Array(); /析構(gòu)函數(shù) T & operator (int i); /重載” const T & operator (int i) const;T sum(); int search(T e); ;template Array:Array() /構(gòu)造函數(shù) list=new Tn; template Array:Array() /析構(gòu)函數(shù) delete list;/重載下標(biāo)運(yùn)算符template T &Array:operator (int i) return listi; templateT Array:sum() T sum = list0; for(

18、int i = 1; i n; i+) sum += listi;return sum;/查找templateint Array:search(T e) for(int i = 0; i n; i+) if(listi = e) return i;return -1;int main() Array a; int i,n,m, count = 0; cout n; for (i = 1; i m;acount+ = m; for ( i = 0; i count; i+) cout ai; cout endl;cout數(shù)組和為:a.sum()endl; cout數(shù)字4在數(shù)組中的位置是:a.se

19、arch(4)endl;/* Array進(jìn)行測(cè)試Array a; int i,n,m, count = 0; cout n; for (i = 1; i m;if (count = a.getSize() a.resize(count * 2);acount+ = m; for ( i = 0; i count; i+) cout setw(8) ai; cout endl;cout數(shù)組和為:a.sum(n)endl; cout數(shù)字4在數(shù)組中的位置是:a.search(4,n)endl;*/ return 0;運(yùn)行結(jié)果:5 文件讀寫定義學(xué)生類數(shù)組,有N個(gè)人(N=5),包括姓名和語數(shù)外三名課的成

20、績(jī),通過重載運(yùn)算符實(shí)現(xiàn)學(xué)生數(shù)組的文件讀寫。/*1.定義student類,私有數(shù)據(jù)成員字符數(shù)組name20;2.定義運(yùn)算符重載;3.在住函數(shù)中定義student 類數(shù)組sN;并以輸出和二進(jìn)制的方式打開文件*/#include #include #include #define N 5using namespace std;class student;ostream& operator (istream & is, student &s);class student/student類:姓名 + 4門成績(jī)public:student() student(string name, int chines

21、e_socre, int maths_score, int english_score)this-name = name;this-chinese_score= chinese_score;this-maths_score = maths_score;this-english_score = english_score;friend ostream& operator(ostream & os, student s)/聲明友元,重寫os s.chinese_score s.maths_score s.english_score (istream & is, student &s)

22、is s.chinese_score s.maths_score s.english_score;return is;private:string name;int chinese_score;int maths_score;int english_score;int main()int i;student sN;for( i=0;isi;ofstream ofs(c:testtest.txt, ios_base:out); if(!ofs)cerrfile open failedendl;exit(1);for( i=0;iN;i+)/這個(gè)我也不太明白-ofs.write(re

23、interpret_cast(& si),sizeof(student);ifstream ifs(c:testtest.txt, ios_base:out);if(!ifs)cerrfile open failedendl;exit(1);for( i=0;iN;i+)ifs.read(reinterpret_cast(& si),sizeof(student);for(i=0;iN;i+)coutNext用來接收調(diào)用瀏覽函數(shù)時(shí)所傳遞過來的實(shí)參,用設(shè)置好的輸出格式(print()、Display()以及while循環(huán),不為空則開始打印信息。4、查詢信息 1)按工號(hào)查詢聲明鏈表指針ptr指向N

24、ext ,cout、cin提示輸入工號(hào)并賦值給code,匹配ptr中的m_code,顯示匹配結(jié)果即可;2)按科室查詢聲明鏈表指針ptr指向Next ,cout、cin提示輸入科室并賦值給post,匹配ptr中的m_post,顯示匹配結(jié)果即可;3)雙匹配查詢聲明鏈表指針ptr指向Next ,cout、cin提示輸入工號(hào)、科室并賦值給code、post,匹配ptr中的m_code、m_post,顯示匹配結(jié)果5、修改信息 通過職工的工號(hào)修改職工信息。聲明鏈表指針ptr,調(diào)用查找函數(shù)Search_Unique_Front()找到需修改的職工信息,再次賦值即可。需要用 cout提示要輸入的內(nèi)容,接著用

25、cin輸入相應(yīng)的內(nèi)容。6、刪除信息 鍵盤輸入的職工號(hào),通過職工的工號(hào)code刪除職工信息。鏈表指針匹配m_code并刪除Head-Next7、計(jì)算科室平均工資 在按科室查找SearchPost函數(shù)中定義一個(gè)int類型 n(為科室人數(shù)),初始化為 0;每添加一人,則 sum+=ptr-m_Wage。用總的工資除以總?cè)藬?shù),算出平均工資。六、源代碼#include #include #include #include #include #include #include #include using namespace std; int n=0;class employee public:strin

26、g m_Code; /職工工號(hào)string m_Name; string m_phone; string m_Sex; string m_Post;/所在科室unsigned int m_Average;unsigned int m_Cash;unsigned int m_Wage; /鏈表節(jié)點(diǎn)的指針域- employee* Next; public:void Print();employee* Create(employee* Head);/創(chuàng)建一個(gè)鏈表 void Rel(employee* Head); employee* Add(employee* Head); bool Search(

27、employee* Head); int SearchPost(employee* Head,string post);employee* Search_Unique_Front(employee* Head); void Display_List(employee* Head); void Display_Node(employee* pNode); employee* Modify(employee* Head); employee* Del(employee* Head); void Save_ByFile(employee* Head,fstream& ofile); employee

28、* Sort(employee* Head); ;employee* employee:Create(employee* Head) /創(chuàng)建一個(gè)帶頭節(jié)點(diǎn)的空鏈表。 Head=new employee; if(!Head) cout分配內(nèi)存失?。_Code=; Head-m_Name=; Head-m_phone=; Head-m_Sex=; Head-m_Post=; Head-m_Wage=0; Head-Next=NULL;Head-m_Average=0;Head-m_Cash=0;return Head; void employee:Rel(employee* Head) /釋放鏈表

29、。 employee* ptr;/聲明一個(gè)操作用的指針。 while(Head!=NULL) ptr=Head; Head=Head-Next; delete ptr;/釋放節(jié)點(diǎn)資源。 employee* employee:Add(employee* Head) /輸入職工信息/前插法添加數(shù)據(jù)。 employee* pNew;/ 聲明一個(gè)新節(jié)點(diǎn)。 char again; string code,name,sex,post,phone; unsigned int wage; do pNew=new employee; /數(shù)據(jù)域。 coutcode; coutendlname; coutendlp

30、hone; coutendlsex; coutendlpost; coutendlwage; while(cin.fail() cout請(qǐng)輸入正確的工資數(shù)據(jù)。wage; coutm_Code=code; pNew-m_Name=name; pNew-m_phone=phone; pNew-m_Sex=sex; pNew-m_Post=post; pNew-m_Wage=wage; /指針域。 pNew-Next=Head-Next; Head-Next=pNew; cout數(shù)據(jù)添加成功!是否繼續(xù)添加?(Y/N)again; while(again=Y|again=y); return Head

31、; bool employee:Search(employee* Head) /查詢同時(shí)滿足“姓名”和“科室”的職工信息。 employee* ptr; string name,post; ptr=Head-Next; coutpost; coutendlname; coutendltt-查詢結(jié)果-m_Name=name)&(ptr-m_Post=post) Display_Node(ptr);/打印滿足條件的節(jié)點(diǎn)。 return true; ptr=ptr-Next;/查詢下一節(jié)點(diǎn)。 coutn無此職工的信息。Next;coutcode;coutendltt-查詢結(jié)果-m_Code=code)Display_Node(ptr);return ptr;ptr=ptr-Next;coutn無此職工的信息。Next;while(ptr)if(ptr-m_Post=post)sum+=ptr-m_Wage;n+;ptr=ptr-Next;cout科室post里的平均工資為:sum/n endl;return 0;void employee:Print()coutsetw(10)left工號(hào); coutsetw(10)left姓名; coutsetw(18)left電話; coutsetw(10)left性別;coutsetw(10)left科室; cou

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論