<ol id="ebnk9"></ol>
    1. 實訓總結報告

      發布時間:2025-06-26 07:20:20   來源:作文大全    點擊:   
      字號:

      ----《面向對象程序》

        實訓的目的與系統概述

        1、目的:

        (1)掌握面向對象設計開發的基本思想和方法,培養學生在已有的知識基礎上進一步獲取新知識的能力,提高分析問題和解決問題的能力。

        (2)進一步鞏固《面向對象程序設計》課程中所學到的知識,熟練掌握C++語言程序設計,加強對VC++編程環境的使用能力,掌握VC++編程環境中的調試功能,增強實際編程能力。

        (3)培養和提高邏輯思維、抽象思維和統籌規劃能力,培養獨立完成程序設計開發的工作能力。為今后從事專業性軟件開發工作打下基礎。

        2、 功能


        通過將不同類型的人員設計成相應的類,完成的人員的管理。

        3、 系統概述

        學校的人員包括學生、職工;職工又分為教師和行政人員;在職進修教師又具備學生和教師的屬性和行為。

        a) 人員具有姓名、年齡、性別、地址和人員類別等屬性,有顯示屬性的功能和設置屬性的功能。

        b) 學生具有人員的屬性和行為,此外,添加學號、成績屬性。具有的行為有:設置屬性的函數:讓用戶能夠通過鍵盤的輸入設置除了成績之外的基本屬性;錄入成績:輸入學生的各門成績;顯示:顯示基本屬性和他的平均成績。

        c) 職工具有人員的屬性和行為,此外,添加職工號、職稱和工資屬性。

        d) 教師具有職工的屬性和行為,此外,添加教研室、教授的課程屬性。具有的行為有:設置屬性的函數:讓用戶能夠通過鍵盤的輸入設置除了課程信息之外的基本屬性;錄入課程:輸入教師所教的各門成績;顯示:顯示基本屬性。

        e) 行政人員具有職工的屬性和行為,此外,添加辦公室屬性。

        f) 在職進修教師具有教師與學生的屬性和行為,此外,添加進修時間,工作單位屬性。

        通過實現此系統,讓我綜合運用所學知識,掌握面向對象設計開發的基本思想和方法和C++的編程思想來完成簡單的面向對象的程序設計。讓我在已有的知識基礎上進一步獲取新知識的能力,提高分析問題、解決問題和獨立完成程序設計開發的工作能力。為今后從事專業性軟件開發工作打下基礎。


        類的實現

        編程實現上面類的設計。

        主程序中的驗證

        創建對象,檢驗類的功能是否能夠實現。


        

        1、遇到的困難、解決辦法及收獲:

       ?、俑黝悓傩缘膶崿F。

        利用對象數組即方便又能固定調用哪個屬性。在構造函數中定義屬性類型,利用對象數組調用。

       ?、趯ο髷到M中字符串的賦值。

        分配(new實現)一個char型變量長度加一的字符串,再利用拷貝函數拷貝原變量并放在name里,如:

        name=new char;strcpy(name,na);

       ?、垡驗闆]有給原帶參構造函數的形參賦值,主函數中不能聲明類的無參對象。

        在定義一個無參構造函數,如:

        person(){}

       ?、茉谂缮悗嬙旌瘮蹬c基類帶參構造函數所帶參數不同時沒有對基類構造函數的參數初始化。

        構造函數無法被繼承,當派生類帶參構造函數與基類帶參構造函數所帶參數不同時,要在派生類構造函數中對基類構造函數的參數進行初始化,如:

        worker(int num,char *v,int p,char *na,int a,char *s,char *ad,char *l):person(na,a,s,ad,l){}

       ?、萜骄值膶崿F。

        利用對象數組正確調用分數屬性再利用返回值為float的成員函數實現平均分,如:

        float getaverage(student st,int i){

        int a=st.mathscore;

        int b=st.cscore;

        return st.average=(a+b)/2;}

       ?、拚_輸入和調用屬性。

        利用p.屬性名實現屬性的各種行為,如:

        cinp.age;

        cout姓名:p.nameendl;

       ?、遱witch語句總執行完一個case后還繼續執行。

        加入break語句跳出switch語句。

        2、 程序中還需要改進的地方。

        姓名,年齡,地址等屬性限制的實現。


      附件:源程序
      #include iostream.h
      #include string
      using namespace std;
      class person{
      protected:
      char *name;
      int age;
      char *sex;
      char *address;
      char *lb;
      public:
      person(char *na,int a,char *s,char *ad,char *l){//對象數組
      name=new char;
      strcpy(name,na);
      age=a;
      sex=new char;
      strcpy(sex,s);
      address=new char;
      strcpy(address,ad);
      lb=new char;
      strcpy(lb,l);}
      person(){}//無參構造函數,方便聲明無參對象
      virtual void getinf(person p,int n){
      char na1;
      cout姓名:;
      cinna1;
      p.name=new char;//分配na1長度+1的字符串
      strcpy(p.name,na1);//拷貝字符串
      coutendl;
      cout年齡:;
      cinp.age;
      coutendl;
      char s1;
      cout性別:(n:男,w:女);
      cins1;
      p.sex=new char;
      strcpy(p.sex,s1);
      coutendl;
      char ad1;
      cout地址:;
      cinad1;
      p.address=new char;
      strcpy(p.address,ad1);
      coutendl;
      }
      virtual void disp(person p,int n){//有參虛函數,對象數組輸出的事現
      cout姓名:p.nameendl;
      cout年齡:p.ageendl;
      cout性別:p.sexendl;
      cout地址:p.addressendl;}
      };
      class student:public virtual person
      {
      protected:
      int number;
      int mathscore,cscore;
      float average;
      public:
      student(int nu,int ms,int cs,float av,char *na,int a,char *s,char *ad,char *l):person(na,a,s,ad,l){//構造函數無法被繼承,在派生類構造函數帶參數與基類構造函數所帶參數不同時要先對基類構造函數初始化
      number=nu;mathscore=ms;cscore=cs;average=av;}
      student(){}
      virtual void getvalue(student st,int i){
      cout學號:;
      cinst.number;
      coutendl;}
      void getscore(student st,int i){
      cout數學成績:;
      cinst.mathscore;
      coutendl;
      coutC++成績:;
      cinst.cscore;
      coutendl;}
      float getaverage(student st,int i){//平均分的實現
      int a=st.mathscore;
      int b=st.cscore;
      return st.average=(a+b)/2;}
      void show(student st,int i){
      cout學號:st.numberendl;
      }
      virtual void show1(student st,int i){
      st.show(st,i);
      cout數學成績:st.mathscoreendl;
      coutC++成績:st.cscoreendl;
      st.getaverage(st,i);
      cout平均成績:st.averageendl;
      }
      };
      class worker:public virtual person
      {
      protected:
      int number;
      float pay;
      char *value;
      public:
      worker(int num,char *v,int p,char *na,int a,char *s,char *ad,char *l):person(na,a,s,ad,l){
      number=num;
      value=new char;
      strcpy(value,v);
      pay=p;}
      worker(){}
      void getvalue(worker w,int i){
      cout職工號:;
      cinw.number;
      coutendl;
      char v1;
      cout職稱:;
      cinv1;
      w.value=new char;
      strcpy(w.value,v1);
      coutendl;
      cout工資:;
      cinw.pay;
      coutendl;
      }
      void show(worker w,int i){
      cout職工號:w.numberendl;
      cout職稱:w.valueendl;
      cout工資:w.payendl;
      }
      };
      class teacher:public virtual worker,public virtual person{
      protected:
      char *kemu;
      int chengji;
      char *office;
      public:
      teacher(char *of,char *ke,int ch,int num,char *v,int p,char *na,int a,char *s,char *ad,char *l):worker(num,v,p,na,a,s,ad,l),person(na,a,s,ad,l){
      office=new char;
      strcpy(office,of);
      kemu=new char;
      strcpy(kemu,ke);
      chengji=ch;}
      teacher(){}
      void getmessage(teacher t,int i) {
      char of1;
      cout教研室:;
      cinof1;
      t.office=new char;
      strcpy(t.office,of1);
      coutendl;
      char ke1;
      cout科目:;
      cinke1;
      t.kemu=new char;
      strcpy(t.kemu,ke1);
      coutendl;
      cout成績:;
      cint.chengji;
      coutendl;
      }
      void show1(teacher t,int i){
      cout教研室:t.officeendl;
      cout科目:t.kemuendl;
      cout成績:t.chengjiendl;
      }
      };
      class employee:public virtual worker,public virtual person{
      private:
      char *office;
      public:
      employee(char *of,int num,char *v,int p,char *na,int a,char *s,char *ad,char *l):worker(num,v,p,na,a,s,ad,l),person(na,a,s,ad,l){
      office=new char;
      strcpy(office,of);
      }
      employee(){}
      void getmessage(employee e,int i) {
      char of1;
      cout教研室:;
      cinof1;
      e.office=new char;
      strcpy(e.office,of1);
      coutendl;
      }
      void show1(employee e,int i){
      cout教研室:e.officeendl;
      }
      };
      class jingx:public virtual student,public virtual teacher,public virtual worker,public virtual person{
      private:
      int time;
      char *danwei;
      public:
      jingx(int ti,char *da,int nu,int ms,int cs,float av,char *of,char *ke,int ch,int num,char *v,int p,char *na,int a,char *s,char *ad,char *l):student(nu,ms,cs,av,na,a,s,ad,l),teacher(of,ke,ch,num,v,p,na,a,s,ad,l),worker(num,v,p,na,a,s,ad,l),person(na,a,s,ad,l){
      time=ti;
      danwei=new char;
      strcpy(danwei,da);}
      jingx(){}
      void getmessage1(jingx j,int i){
      cout進修時間:;
      cinj.time;
      coutendl;
      char da1;
      cout單位屬性:;
      cinda1;
      j.danwei=new char;
      strcpy(j.danwei,da1);
      coutendl;
      }
      void show2(jingx j,int i) {
      cout進修時間:j.timeendl;
      cout單位屬性:j.danweiendl;
      }
      };
      int i;
      person p; student st; worker wo; teacher te; employee em; jingx jx;
      void main(){
      cout請選擇人員類別:endl;
      cout1、普通人 2、學生 3、學生及成績 4、員工 5、教師 6、行政人員 7、在職進修教師endl;
      cini;
      cout請依次錄入信息endl;
      switch(i){//錄入信息種類選擇的實現
      case 1:{
      p.getinf(p,1);
      cout*************************************endl;
      p.disp(p,1);
      break;}//要有break語句否則將執行case2
      case 2:{
      st.getvalue(st,1);
      p.getinf(p,1);
      cout*************************************endl;
      st.show(st,1);
      p.disp(p,1);
      break;}
      case 3:{
      st.getvalue(st,1);
      p.getinf(p,1);
      st.getscore(st,1);
      cout*************************************endl;
      st.show1(st,1);
      p.disp(p,1);
      break;}
      case 4:{
      wo.getvalue(wo,1);
      p.getinf(p,1);
      cout*************************************endl;
      wo.show(wo,1);
      p.disp(p,1);
      break;}
      case 5:{
      te.getmessage(te,1);
      p.getinf(p,1);
      wo.getvalue(wo,1);
      cout*************************************endl;
      te.show1(te,1);
      p.disp(p,1);
      wo.show(wo,1);
      break;}
      case 6:{
      em.getmessage(em,1);
      p.getinf(p,1);
      wo.getvalue(wo,1);
      cout*************************************endl;
      em.show1(em,1);
      p.disp(p,1);
      wo.show(wo,1);
      break;}
      case 7:{
      jx.getmessage1(jx,1);
      te.getmessage(te,1);
      st.getvalue(st,1);
      wo.getvalue(wo,1);
      p.getinf(p,1);
      st.getscore(st,1);
      cout*************************************endl;
      jx.show2(jx,1);
      p.disp(p,1);
      te.show1(te,1);
      wo.show(wo,1);
      st.show1(st,1);
      break;}
      default :
      cout輸入錯誤!endl;
      }

      }

      国产另类无码专区|日本教师强伦姧在线观|看纯日姘一级毛片|91久久夜色精品国产按摩|337p日本欧洲亚洲大胆精

      <ol id="ebnk9"></ol>