《數(shù)據(jù)結(jié)構(gòu)c++描述》教材習題解答.rar
《數(shù)據(jù)結(jié)構(gòu)c++描述》教材習題解答,共包括以下7個章節(jié)內(nèi)容:第1章 緒論第2章 數(shù)組第3章 鏈表第4章 棧與隊列第5章 遞歸與廣義表第6章 樹與森林第7章 集合與搜索 部分內(nèi)容節(jié)選:1-4.什么是抽象數(shù)據(jù)類型?試用c++的類聲明定義“復數(shù)”的抽象數(shù)據(jù)類型。要求(1) 在復數(shù)內(nèi)部用浮點數(shù)定義它的實部和虛部。(2) 實現(xiàn)3個...
該文檔為壓縮文件,包含的文件列表如下:


內(nèi)容介紹
原文檔由會員 王蕓 發(fā)布
《數(shù)據(jù)結(jié)構(gòu)c++描述》教材習題解答
共包括以下7個章節(jié)內(nèi)容:
第1章 緒論
第2章 數(shù)組
第3章 鏈表
第4章 棧與隊列
第5章 遞歸與廣義表
第6章 樹與森林
第7章 集合與搜索
部分內(nèi)容節(jié)選:
1-4.什么是抽象數(shù)據(jù)類型?試用C++的類聲明定義“復數(shù)”的抽象數(shù)據(jù)類型。要求
(1) 在復數(shù)內(nèi)部用浮點數(shù)定義它的實部和虛部。
(2) 實現(xiàn)3個構(gòu)造函數(shù):缺省的構(gòu)造函數(shù)沒有參數(shù);第二個構(gòu)造函數(shù)將雙精度浮點數(shù)賦給復數(shù)的實部,虛部置為0;第三個構(gòu)造函數(shù)將兩個雙精度浮點數(shù)分別賦給復數(shù)的實部和虛部。
(3) 定義獲取和修改復數(shù)的實部和虛部,以及+、-、*、/等運算的成員函數(shù)。
(4) 定義重載的流函數(shù)來輸出一個復數(shù)。
【解答】
抽象數(shù)據(jù)類型通常是指由用戶定義,用以表示應用問題的數(shù)據(jù)模型。抽象數(shù)據(jù)類型由基本的數(shù)據(jù)類型構(gòu)成,并包括一組相關(guān)的服務(wù)。
//在頭文件complex.h中定義的復數(shù)類
#ifndef _complex_h_
#define _complex_h_
#include
class comlex {
public:
complex ( ){ Re = Im = 0; } //不帶參數(shù)的構(gòu)造函數(shù)
complex ( double r ) { Re = r; Im = 0; } //只置實部的構(gòu)造函數(shù)
complex ( double r, double i ) { Re = r; Im = i; } //分別置實部、虛部的構(gòu)造函數(shù)
double getReal ( ) { return Re; } //取復數(shù)實部
double getImag ( ) { return Im; } //取復數(shù)虛部
void setReal ( double r ) { Re = r; } //修改復數(shù)實部
void setImag ( double i ) { Im = i; } //修改復數(shù)虛部
complex& operator = ( complex& ob) { Re = ob.Re; Im = ob.Im; } //復數(shù)賦值
complex& operator + ( complex& ob ); //重載函數(shù):復數(shù)四則運算
complex& operator – ( complex& ob );
complex& operator * ( complex& ob );
complex& operator / ( complex& ob );
......
共包括以下7個章節(jié)內(nèi)容:
第1章 緒論
第2章 數(shù)組
第3章 鏈表
第4章 棧與隊列
第5章 遞歸與廣義表
第6章 樹與森林
第7章 集合與搜索
部分內(nèi)容節(jié)選:
1-4.什么是抽象數(shù)據(jù)類型?試用C++的類聲明定義“復數(shù)”的抽象數(shù)據(jù)類型。要求
(1) 在復數(shù)內(nèi)部用浮點數(shù)定義它的實部和虛部。
(2) 實現(xiàn)3個構(gòu)造函數(shù):缺省的構(gòu)造函數(shù)沒有參數(shù);第二個構(gòu)造函數(shù)將雙精度浮點數(shù)賦給復數(shù)的實部,虛部置為0;第三個構(gòu)造函數(shù)將兩個雙精度浮點數(shù)分別賦給復數(shù)的實部和虛部。
(3) 定義獲取和修改復數(shù)的實部和虛部,以及+、-、*、/等運算的成員函數(shù)。
(4) 定義重載的流函數(shù)來輸出一個復數(shù)。
【解答】
抽象數(shù)據(jù)類型通常是指由用戶定義,用以表示應用問題的數(shù)據(jù)模型。抽象數(shù)據(jù)類型由基本的數(shù)據(jù)類型構(gòu)成,并包括一組相關(guān)的服務(wù)。
//在頭文件complex.h中定義的復數(shù)類
#ifndef _complex_h_
#define _complex_h_
#include
class comlex {
public:
complex ( ){ Re = Im = 0; } //不帶參數(shù)的構(gòu)造函數(shù)
complex ( double r ) { Re = r; Im = 0; } //只置實部的構(gòu)造函數(shù)
complex ( double r, double i ) { Re = r; Im = i; } //分別置實部、虛部的構(gòu)造函數(shù)
double getReal ( ) { return Re; } //取復數(shù)實部
double getImag ( ) { return Im; } //取復數(shù)虛部
void setReal ( double r ) { Re = r; } //修改復數(shù)實部
void setImag ( double i ) { Im = i; } //修改復數(shù)虛部
complex& operator = ( complex& ob) { Re = ob.Re; Im = ob.Im; } //復數(shù)賦值
complex& operator + ( complex& ob ); //重載函數(shù):復數(shù)四則運算
complex& operator – ( complex& ob );
complex& operator * ( complex& ob );
complex& operator / ( complex& ob );
......