




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、本科實驗報告課程名稱:C+面向?qū)ο蟪绦蛟O(shè)計實驗地點:專業(yè)班級: 學(xué)號:學(xué)生姓名: 指導(dǎo)教師:2016 年 5 月 3 日1 / 12實驗名稱實驗三 類與對象實驗?zāi)康暮鸵?. 掌握類的概念2. 理解類與對象的關(guān)系3. 掌握構(gòu)造函數(shù)與析構(gòu)函數(shù)4. 理解類的組合實驗內(nèi)容1. 定義一個復(fù)數(shù)類 Complex,復(fù)數(shù)的實部 Real 與虛步 Image 定義為私有數(shù)據(jù)成員。用復(fù)數(shù)類定 義復(fù)數(shù)對象 c1,c2,c3 ,用構(gòu)造函數(shù)將 c1初始化為 c1=20+40i, 將c2初始化為 c2=0+0i ,用拷 貝構(gòu)造函數(shù)將 c3 初始化為 c3+20+40i ,用公有成員函數(shù) Display ()顯示復(fù)數(shù) c
2、1,c2,c3 的內(nèi) 容。2. 定義一個學(xué)生成績類 Score ,描述學(xué)生成績的私有數(shù)據(jù)數(shù)據(jù)成員為學(xué)號NO,姓名 Name8 ,高等數(shù)學(xué) Math,大學(xué)物理 Phi ,數(shù)據(jù)結(jié)構(gòu) Date,平均得分 ave ,定義能輸入學(xué)生成績的公有 成員函數(shù) Write ,能計算學(xué)生平均分的公有成員函數(shù) Average ,能顯示學(xué)生成績的函數(shù) Display ,在主函數(shù)中用 Score 類定義學(xué)生成績對象數(shù)組 s3 ,用 Write 輸入學(xué)生成績,最 后用 Display 顯示每個學(xué)生的成績。3. 定義一個矩形類 Rectangle ,矩形的左上角與右下角坐標(biāo)定義為保護(hù)數(shù)據(jù)成員。用公有成員 函數(shù)計算出矩形的對
3、角線長度, 公有成員函數(shù) Show顯示矩形的左上角與右上角坐標(biāo)及對角線長度,在主函數(shù)中用 new運算符動態(tài)建立矩形對象 r1 ,然后調(diào)用 Show顯示矩形左上角與右 下角坐標(biāo)及對角線長度,最后用 delete 運算符回收為矩形動態(tài)分配的存儲空間。主要儀器設(shè)備臺式或筆記本電腦實驗記錄(寫出實驗內(nèi)容中 1,2,3的程序代碼和運行結(jié)果 )(可分欄或加頁 )一 . #include stdafx.h #include Complex(Complex &c);Complex() real = 20;image = 40; ;2 / 12 Complex:Complex( int real , int i
4、mage) real = 20;image = 40; Complex:Complex( Complex &c) real = c.real;image = c .image; int main() Complex c1;Complex c2(0, 0);Complex c3(c1); cout c1= ; c1.Display(); cout c2= ;二 #include stdafx.h #include using namespace std; class score int No,Math,Phi,Data,ave; char Name8;public :void Write( sc
5、ore &b) cout 請輸入學(xué)號: b.No;cout 請輸入姓名: b.Name;cout 請輸入數(shù)學(xué)成績: b.Math;cout 請輸入物理成績: b.Phi;cout 請輸入數(shù)據(jù)結(jié)構(gòu)成績: b.Data; int Average( score &a) a.ave=( a.Data+ a.Math+ a.Phi)/3;3 / 12return a.ave; void Display() cout Not Namet Matht Phi t Datat aveendl; ;int main () score s3;int i;for (i=0;i3;i+) si.Write(si);s
6、i.Average(si); cout 學(xué)號t 姓名t 數(shù)學(xué)t 物理t 結(jié)構(gòu)t 平均t endl; for (i=0;i3;i+)si.Display();. #include stdafx.h include iostream using namespace std; class Rectanglepublic :Rectangle( double l , double t, double r, double b) :left( l ), top( t), right( r), bottom( b) 4 / 12double Diagonal();void Show();double Rec
7、tangle :Diagonal() double l, w;l = right - left;w = bottom - top;return (sqrt(l * l + w * w); void Rectangle :Show() cout 矩形左上角坐標(biāo)為: left , top endl; cout 矩形右下角坐標(biāo)為: right , bottom endl; cout 矩形對角線的長為 : Diagonal() Show();delete r1;return 0; 遇到的問題和解決方法心得體會實驗名稱 實驗四 類與對象的其它特征實驗?zāi)康暮鸵?. 了解靜態(tài)對象的定義與使用方法2. 理解
8、靜態(tài)數(shù)據(jù)成員和靜態(tài)成員函數(shù)的定義和使用方法5 / 123. 掌握函數(shù)調(diào)用中參數(shù)的傳遞實驗內(nèi)容1. 設(shè)計一個 Dog類,它用靜態(tài)數(shù)據(jù)成員Dogs 記錄 Dog的個數(shù)2. 編寫一個程序,設(shè)計一個類 Tri ,給定三角形的三條變 X,Y,Z 3. 設(shè)計一個程序,其中 3 個類 CBabk,BBabk, GBabk分別為中國銀行類 主要儀器設(shè)備 臺式或筆記本電腦實驗記錄(寫出實驗內(nèi)容中 1,2,3的程序代碼和運行結(jié)果 )(可分欄或加頁 )一 . class Dog static int Dogs;public :Dog() +Dogs; Dog() -Dogs; static int GetDogs(
9、)return Dogs;int Dog:Dogs = 0;二 . #include stdafx.h #include iostream using namespace std;class Tri private :float x, y, z;public :float Sum();friend float Sum1(float x, float y, float z);void Output();float Sum1(float x, float y, float z) double p = ( x + y + z) / 2;return sqrt(p*(p - x)*(p -y)*(p
10、- z); int main( int argc , _TCHAR* argv ) cout 三角形面積 S為 Sum1(3, 4, 5) endl; return 0; 6 / 12三 . #include stdafx.h #includeiostream #includeString using namespace std; class CBank; class BBank; class GBank;class CBank long int balance;public: CBank() balance=0; CBank(long int b) balance=b; void getba
11、lance()coutbalance;friend void total(CBank,BBank,GBank); ;class BBank long int balance;public: BBank() balance=0; BBank(long int b) balance=b; void getbalance()coutbalance;friend void total(CBank,BBank,GBank); ;class GBank long int balance;public: GBank() balance=0; GBank(long int b)7 / 12balance=b;
12、void getbalance()coutbalance;friend void total(CBank,BBank,GBank); ;void total(CBank A,BBank B,GBank C)cout 總的銀行存款項目: A.balance+B.balance+C.balanceendl; void main() CBank X;BBank Y;GBank Z;X. getbalance();Y.getbalance();Z.getbalance(); total(X,Y,Z);遇到的問題和解決方法心得體會實驗名稱 實驗五 繼承與派生實驗?zāi)康暮鸵?. 理解集成與派生的概念2.
13、掌握派生類定義格式與使用方法實驗內(nèi)容1. 定義描述職工檔案的類 Archives, 私有數(shù)據(jù)成員職工號,姓名性別2. 定義個人信息類 Person,其數(shù)據(jù)成員有姓名,性別,出生年月8 / 12主要儀器設(shè)備臺式或筆記本電腦實驗記錄(寫出實驗內(nèi)容中 1,2 的程序代碼和運行結(jié)果 )(可分欄或加頁 )一 . #include stdafx.h #include iostream using namespace std; class Person char strName10; int nAge;public :Person( char *name, int age) strcpy_s(strName
14、, name);nAge = age;cout constructor of person strName endl;Person() cout deconstrutor of person strName endl; ;class Employee : public Person char strDept20;Person Wang; public :Employee( char *name, int age, char * dept , char *name1, int age1) : Person ( name, age), Wang(name1, age1) strcpy_s(strD
15、ept, dept );cout constructor of Employee endl; Employee() cout deconstrucor of Employee endl; ;int tmain (int argc, TCHA*R argv ), 21);Employee employee1( lixi , 20, student , actorreturn 0;. #include stdafx.h #include iostream9 / 12 using namespace std;class Archives private:int No;char Name8;char
16、Sex;int Age;public:void Show(int No,char Name8,char Sex,int Age)cout 職工號為 Noendl;cout 職工姓名為 Name8endl;cout 職工性別為 Sexendl;cout 職工年齡為 Ageendl;class Laborage:public Archivesprivate:int SSalary;int Security;int Fsalary;public:void Display(int No,char Name8,char Sex,int Age,int SSalary,int Security) cout
17、 職工號為 Noendl;cout 職工姓名為 Nameendl;cout 職工性別為 Sexendl;cout 職工年齡為 Ageendl;cout 職工應(yīng)發(fā)工資為 SSalaryendl;cout 職工的社保金為 Securityendl;void Count(); Fsalary=SSalary-Security;cout 實發(fā)工資為 Fsalaryendl; ;int _tmain(int argc, _TCHAR* argv) Laborage lab; lab.Display(1001,cheng,M,21,2000,100);return 0; 10 / 12. #include
18、 stdafx.h#include iostreamint Birthday;class Student : public Personpublic :int Class;int No;char Professnation50;int English;int Math;void Display( char Name8, char Sex, int Birthday , int Class , int No, char Professnation 50, int English , int Math)cout 學(xué)生姓名為 Name endl;cout 學(xué)生性別為 Sex endl;cout 出生年月 Birthday endl;cout 班級為 Class endl;cout 學(xué)號為 No endl;cout 專業(yè)為 Professnation endl;cout 英語成績 English endl;cout 數(shù)學(xué)成績 Math endl;class Employee : public Person11 / 12 char work8; char task8; int Salary;void Display1( char work8, char
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025園林景觀設(shè)計合同
- 2025年HED-系列厚膜陰極電泳涂料項目建議書
- 2025合同電纜橋架安裝規(guī)范
- 2025安置房的買賣合同
- 2025方案設(shè)計委托合同范本方案設(shè)計委托合同格式
- 2025職場英語口語熟練運用合同條款
- 2025年月桂醇聚醚磷酸鉀項目建議書
- 2025長期重大疾病保險合同示范文本
- 2025合同簽訂要點全面解析
- 2025版本的鐵路交通運輸合同示范文本
- 外包免責(zé)協(xié)議書模板
- 廣東省惠州市惠陽區(qū)知行學(xué)校2024-2025學(xué)年七年級下學(xué)期4月期中數(shù)學(xué)試題(含部分答案)
- 2025年深圳市九年級中考語文二模聯(lián)考試卷附答案解析
- 大部分分校:地域文化形考任務(wù)四-國開(CQ)-國開期末復(fù)習(xí)資料
- 2024年共青團(tuán)入團(tuán)積極分子考試題庫(附答案)
- MOOC 職場英語-西南交通大學(xué) 中國大學(xué)慕課答案
- 2069-3-3101-002WKB產(chǎn)品判定準(zhǔn)則-外發(fā)
- 工廠個人簡歷登記表格
- 用友U8數(shù)據(jù)字典
- 化工概論:典型化工工藝
- 快捷酒店安全現(xiàn)狀評價報告安全現(xiàn)狀評價
評論
0/150
提交評論