c 實驗報告

2021-04-20 16:47:25 字數 2228 閱讀 1042

(1) 掌握類的定義和使用;掌握類物件的宣告;練習具有不同訪問屬性的成員的訪問方式;觀察建構函式和析構函式的執行過程;

(2) 學習類組合使用方法;

(3) 使用vc++的debug除錯功能觀察程式流程,跟蹤觀察類的建構函式、析構函式、成員函式的執行順序。

(1) pc+windows 2000+vc 6.0

(1) 第一題:

#include

using namespace std;

int max1(int a,int b);//求兩個整數最大值

int max1(int a,int b,int c); //求三個整數最大值

double max1(double a,double b); //求兩個雙精度數最大值

double max1(double a,double b,double c); //求三個雙精度數最大值

//主函式

int main()

int max1(int a,int b)

int max1(int a,int b,int c)

double max1(double a,double b)

double max1(double a,double b,double c)

(2) 第二題:

#include

using namespace std;

bool swap(int &a,int &b);//交換兩個數值

//主函式

int main()

bool swap(int &a,int &b)

(3) 第三題:

// /cpu.cpp

//類成員函式定義

#include"cpu.h"

int cpu::run()

int cpu::stop()

cpu::cpu(cpu &p)

//cpu.h

//cpu類

#pragma once

#ifndef _cpu_h_

#define _cpu_h_

#include

using namespace std;

enum cpu_rank;

//類定義

class cpu

;#endif

///main.cpp

#include"cpu.h"

//主函式

int main()

(4) 第四題:

computer.cpp

//類成員函式

#include"computer.h"

computer::computer(cpu cpu,ram ram ,cdrom cdrom):cpu(cpu),ram(ram),cdrom(cdrom)

computer::computer(computer &cmp)

computer::~computer()

int computer::run()

int computer::stop()

int computer::print()

///computer.h

//類定義

#pragma once

#ifndef _computer_h_

#define _computer_h_

#include

#include"cpu.h"

using namespace std;

//ram類定義

class ram

//返回成員值

private:

int ram_size;//記憶體大小

};//cdrom類定義

class cdrom

//返回成員值

private:

bool empty;//是否為空標記

};//類定義

class computer

;#endif

///cpu.cpp與cpu.h同第三題

///main.cpp

#include"computer.h"

//主函式

int main()

{ cout<<"1.定義cpu物件:"< cpu cpu;

cout<<"2.定義ram物件:"< ram ram;

cout<<"3.定義cdrom物件:"< cdrom cdrom;

cout<<"4.定義computer物件computer:"<

C實驗報告實驗

高階語言程式設計 實驗報告 班級 學號 姓名 成績 一 實驗目的 1 掌握c語言資料型別,熟悉如何定義整型 字元型和實型變數,以及對其賦值的方法。2 掌握不同型別資料之間賦值的規律 3 學會使用c的有關運算子,以及包含這些運算子的表示式,特別是 和 運算子的使用。4 進一步熟悉c程式的編輯 編譯 連...

c實驗報告

實驗 一 預習報告 上實驗課之前完成 一 實驗目的 1 了解c語言開發環境的組成 2 學習c語言開發環境的使用方法 3 掌握c語言程式從編輯 編譯 連線到執行並得到執行結果的過程。二 實驗內容 1 從鍵盤輸入兩個整數,將其平方和輸出 用函式求平方和 ex701 11.c程式清單 include in...

c 實驗報告

南京資訊工程大學實驗 實習 報告 實驗 實習 名稱資料 指標與字串實驗 實習 日期 5月07日得分指導教師李燕 系計算機專業計科年級 13 班次計科2 姓名塗亮學號20132308063 1.實驗目的 1 學習使用陣列資料物件。2 學習字串資料的組織和處理。3 學習標準c 庫的使用。4 掌握指標的使...