面向對象程序設計 試卷A 2023_第1頁
面向對象程序設計 試卷A 2023_第2頁
面向對象程序設計 試卷A 2023_第3頁
面向對象程序設計 試卷A 2023_第4頁
面向對象程序設計 試卷A 2023_第5頁
全文預覽已結束

下載本文檔

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

文檔簡介

面向對象程序設計試卷第1頁(共5頁)PAGE6試題編號:重慶郵電大學2022-2023學年第二學期(試卷)面向對象程序設計(期末)(A卷)(開卷)一、讀程題(本大題共5小題,每小題10分,共50分)程序1:#define_CRT_SECURE_NO_DEPRECATE#include<iostream>usingnamespacestd;classPerson{public: Person(constcharnameV[],boolsexV,intageV){ cout<<"構造:我知道怎么設置人的屬性,我已完成!"<<endl; strncpy(name,nameV,sizeof(name));//姓名 sex=sexV;//性別 age=ageV;//年齡 } ~Person(){ cout<<"析構:"<<name<<endl; } voidprint(){ cout<<"我是一個人,我的屬性值為:"<<name<<"," <<sex<<"," <<age<<"," <<endl; }public: charname[20];//姓名 boolsex; //性別 intage; //年齡};Personp1("張三",0,18);//張三intmain(){ p1.print(); cout<<endl; Personp2("李四",1,16);//李四 p2.print();}1、依據(jù)程序1畫出Person類圖;2、依據(jù)程序1畫出p1對象圖;3、根據(jù)該程序描述畫出程序運行的時序圖;程序2://Sport.hclassSport{public: Sport(); Sport(constchar*pName); voidprint(); ~Sport();private: charname[20];};//Sport.cpp#define_CRT_SECURE_NO_DEPRECATE#include<iostream>#include<string.h>#include"Sport.h"usingnamespacestd;Sport::Sport(){}Sport::Sport(constchar*pName){ strncpy(name,pName,sizeof(name)); name[sizeof(name)-1]='\0';}voidSport::print(){ cout<<name<<endl;}Sport::~Sport(){}//Person.h#include"Sport.h"classPerson{public: Person(); Person(constchar*pName); ~Person(); voidlike(Sport*likeSport); Sport*likedSport(); voidprint();private: charname[20]; Sport*sport;};//Person.cpp#define_CRT_SECURE_NO_DEPRECATE#include<iostream>#include<string.h>#include"Person.h"usingnamespacestd;Person::Person(){}Person::Person(constchar*pName){ strncpy(name,pName,sizeof(name)); name[sizeof(name)-1]='\0';}Person::~Person(){}voidPerson::like(Sport*likeSport){ sport=likeSport;}Sport*Person::likedSport(){ returnsport;}voidPerson::print(){ cout<<name;}//app.cpp#include<iostream>#include"Person.h"usingnamespacestd;intmain(){ Sports1("足球"); Sports2("籃球"); Sports3("乒乓球"); Personp1("張三"); p1.like(&s1); p1.print(); cout<<"最喜歡"; p1.likedSport()->print(); Personp2("李四"); p2.like(&s2); p2.print(); cout<<"最喜歡"; p2.likedSport()->print(); Personp3("王五"); p3.like(&s2); p3.print(); cout<<"最喜歡"; p3.likedSport()->print();}4、使用計算順序圖描述程序中表達式p1.likedSport()->print()的計算順序,并標注出主要步驟的計算結果;5、使用對象圖描述程序中創(chuàng)建的對象及其連接。二、編程題(本大題共3小題,每小題10分,共30分)根據(jù)下面的類圖:1、請依據(jù)給出的類圖,編寫Student類的聲明代碼;2、給Student類重載一個新的構造函數(shù)Student(constchar*pName,constTdate&tBirthday,boolbSex),編寫其實現(xiàn)代碼;3、給GraduateStudent類重載一個新的構造函數(shù)GraduateStudent(constchar*pName,constTdate&tBirthday,boolbSex,floatfCredit,Teacher*t),編寫其實現(xiàn)代碼。三、開發(fā)步驟及任務(本大題共2小題,每小題10分,共20分

溫馨提示

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

評論

0/150

提交評論