luqingfei@C++
為中華之崛起而崛起!
兼聽則明,偏聽則暗。
類的操作練習題二
接類的操作練習題一
編寫一個函數,比較兩個序列。如果Sequence對象有不同的長度,它們就是不同的,如果Sequence對象有相同的長度,但對應的值不同,它們也是不同的。只有Sequence對象有相同的長度,且對應的值也相同,它們才是相同的。把這個函數編寫為Sequence類的一個成員。
Sequence.h
//
Sequence.h
#ifndef SEQUENCE_H
#define
SEQUENCE_H
//
Class encapsulating a sequence of integers
class
Sequence {
public
:
Sequence();
//
Default constructor
Sequence(
int
start,
int
length
=
2
);
//
Constructor
~
Sequence();
//
Desctructor
void
show();
//
Output a sequence
bool
equals(
const
Sequence
&
seq)
const
;
//
Compare this sequence with another
private
:
int
*
pSequence;
//
Pointer to a sequence
int
length;
//
Sequence length
};
#endif
Sequence.cpp
//
Sequence.cpp
//
Implementation of the Sequence class
//
encapsulating an arbitrary length sequence of integers
#include
"
Sequence.h
"
#include
<
iostream
>
#include
<
iomanip
>
using
std::cout;
using
std::endl;
//
Default constructor
Sequence::Sequence() {
length
=
10
;
pSequence
=
new
int
[length];
for
(
int
i
=
0
; i
<
length; i
++
)
pSequence[i]
=
i;
}
Sequence::Sequence(
int
start,
int
length) {
this
->
length
=
length
<
2
?
2
: length;
pSequence
=
new
int
[length];
for
(
int
i
=
0
; i
<
length; i
++
)
pSequence[i]
=
start
+
i;
}
//
Destructor
Sequence::
~
Sequence() {
cout
<<
"
Destructor called.
"
<<
endl;
delete[] pSequence;
}
//
Output a sequence
void
Sequence::show() {
for
(
int
i
=
0
; i
<
length; i
++
) {
if
(i
%
10
==
0
)
cout
<<
endl;
cout
<<
std::setw(
2
+
(pSequence[
0
]
+
length)
/
10
)
<<
pSequence[i];
}
cout
<<
endl;
}
//
Comparison
bool
Sequence::equals(
const
Sequence
&
seq)
const
{
if
(length
!=
seq.length)
return
false
;
for
(
int
i
=
0
; i
<
length; i
++
)
if
(pSequence[i]
!=
seq.pSequence[i])
return
false
;
return
true
;
}
main.cpp
#include
<
iostream
>
#include
<
cstdlib
>
#include
<
ctime
>
using
std::cout;
using
std::endl;
#include
"
Sequence.h
"
void
main() {
const
int
nSeq
=
5
;
Sequence
**
pSequences
=
new
Sequence
*
[nSeq];
pSequences[
0
]
=
new
Sequence(
5
,
6
);
pSequences[
1
]
=
new
Sequence(
5
,
5
);
pSequences[
2
]
=
new
Sequence(
5
,
6
);
pSequences[
3
]
=
new
Sequence(
5
,
5
);
pSequences[
4
]
=
new
Sequence(
4
,
8
);
for
(
int
i
=
0
; i
<
4
; i
++
)
for
(
int
j
=
i
+
1
; j
<
5
; j
++
)
cout
<<
endl
<<
"
sequences[
"
<<
i
<<
"
]
"
<<
((pSequences[i]
->
equals(
*
pSequences[j]))
?
"
is
"
:
"
is not
"
)
<<
"
equal to
"
<<
"
sequences[
"
<<
j
<<
"
].
"
;
cout
<<
endl;
//
First delete the Sequence objects in the free store
for
(
int
j
=
0
; j
<
nSeq; j
++
)
delete pSequences[j];
delete[] pSequences;
//
Now delete the array holding their addresses
}
posted on 2009-03-18 17:53
luqingfei
閱讀(265)
評論(0)
編輯
收藏
引用
所屬分類:
C++基礎
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
相關文章:
使用lib.exe生成.lib文件
如何區分導入庫和靜態庫
lib文件
[轉]動態鏈接庫、靜態庫、import庫區別
智能指針auto_ptr運用實例:常數型智能指針的特性
智能指針auto_ptr運用實例:移轉擁有權的行為
C++入門經典:(一)基本概念
make工具的用法
什么是Makefile
虛函數、多態性 練習題一
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
導航
C++博客
首頁
新隨筆
聯系
聚合
管理
<
2009年2月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
統計
隨筆 - 105
文章 - 0
評論 - 31
引用 - 0
留言簿
(6)
給我留言
查看公開留言
查看私人留言
隨筆分類
(109)
ACM/ICPC(3)
(rss)
Books(4)
(rss)
C++基礎(31)
(rss)
MFC
(rss)
Win32匯編程語言序設計(21)
(rss)
Windows(6)
(rss)
Windows SDK
(rss)
反匯編(1)
(rss)
匯編語言基礎學習(22)
(rss)
計算機基礎知識(3)
(rss)
開發工具(1)
(rss)
軟件工程(4)
(rss)
生活(1)
(rss)
數據結構與算法(5)
(rss)
團隊(1)
(rss)
文摘(3)
(rss)
游戲開發(3)
(rss)
隨筆檔案
(105)
2013年7月 (4)
2012年5月 (3)
2011年2月 (1)
2011年1月 (2)
2010年11月 (7)
2010年10月 (2)
2010年9月 (10)
2010年8月 (34)
2010年7月 (11)
2010年6月 (3)
2009年4月 (5)
2009年3月 (10)
2009年2月 (13)
Blogers
batch 共享空間
Codes of Sephiroth
doing5552
flyman
itech
jackyxinli
玩音頻播放器的貓咪
kevinlynx
lai3d
luqingfei@.net
megax
mzty
netboy
oxft
匯編高手
SpringSnow
tonykee
tx7do
蓋莫游戲引擎
匯編語言 - IT群技術論壇
孔雀
輪子哥
羅朝輝(飄飄白云)
帥子
我住包子山
小時候可靚了
游戲大觀
站在大世界
Game
17173
游戲開發資源網
Life
劉思妍
青青精品兒童服飾
清泉戶外網
小輝的視頻庫
NodeJs
Node入門
Python
Python
Useful Webs
80x86匯編語言
boost.org
VC 驛站
woaidongmao
山地車
編程愛好者
科學網
農行貸款計算器
思維導圖
大牛
云風的 BLOG
搜索
積分與排名
積分 - 210432
排名 - 124
最新評論
1.?re: 虛函數、多態性 練習題一
評論內容較長,點擊標題查看
--luz
2.?re: Win32匯編--圖形操作--GDI原理
感謝
--11
3.?re: Win32匯編--需要了解的基礎知識
哇,哥,連書里的內容都打上了,這花了不少時間吧
。。。。。。
--solq
4.?re: [轉]各種字符編碼方式詳解及由來(ANSI,GB2312,GBK,UNICODE,UTF-8)
哥們寫得不錯,易懂
--wsh
5.?re: 類繼承練習題一
評論內容較長,點擊標題查看
--scor
6.?re: Win32匯編--圖形操作--GDI原理
好,十分有用
--Jet
7.?re: 數學的魅力:取余運算還可以這樣
我也認為數學真的是很美的
--replica watches
8.?re: 匯編語言--使用BIOS進行鍵盤輸入和磁盤讀寫
評論內容較長,點擊標題查看
--abcgril
9.?re: 10個小故事(轉自羅云彬的編程樂園)
好故事啊,學習啦!
--pa
10.?re: 數學的魅力:取余運算還可以這樣
我也是數學迷..
--designer handbags
11.?re: [轉]Windows下22個實用的代碼編輯器
gVim 挺好用的
--coreBugZJ
12.?re: Win32匯編--使用資源--菜單和加速鍵
初學的匯編(用NASM),仰慕!!
--coreBugZJ
13.?re: 我的天哪!感冒-->鼻炎-->咽喉炎
評論內容較長,點擊標題查看
--可靠上
14.?re: 初識exe程序反匯編小感[轉][未登錄]
好文章,挺詳細的
--KK
15.?re: C++標準程序庫—自修教程與參考手冊
評論內容較長,點擊標題查看
--yh
16.?re: 《C++入門經典》(第3版)
評論內容較長,點擊標題查看
--路青飛
17.?re: [轉]Windows下22個實用的代碼編輯器
評論內容較長,點擊標題查看
--路青飛
18.?re: 我的天哪!感冒-->鼻炎-->咽喉炎
評論內容較長,點擊標題查看
--路青飛
19.?re: 《匯編語言》--讀后感
評論內容較長,點擊標題查看
--路青飛
20.?re: [轉]Windows下22個實用的代碼編輯器
一直用emacs
--Sephiroth Lee
閱讀排行榜
1.?匯編語言--call和ret指令 (24447)
2.?匯編語言--int指令(15499)
3.?Win32匯編--使用MASM(10890)
4.?一個簡單的游戲服務器框架(6174)
5.?初識exe程序反匯編小感[轉](5954)
6.?匯編語言--標志寄存器 (5160)
7.?匯編語言--使用BIOS進行鍵盤輸入和磁盤讀寫(5098)
8.?[轉]Windows下22個實用的代碼編輯器(4756)
9.?Windows環境變量設置(4650)
10.?Win32匯編--使用資源--對話框(一)(4434)
11.?使用lib.exe生成.lib文件(4174)
12.?Win32匯編--圖形操作--GDI原理(4162)
13.?Win32匯編--使用資源--對話框--在對話框中使用子窗口控件(2)(4128)
14.?匯編語言--寄存器(內存訪問)(4007)
15.?Win32匯編--使用資源--菜單和加速鍵(3561)
16.?10個小故事(轉自羅云彬的編程樂園)(3147)
17.?Win32匯編--分析窗口程序(2973)
18.?C++實現插入排序(升序+降序)(2941)
19.?Win32匯編--使用資源--版本信息資源(2846)
20.?匯編中常見的一些錯誤信息(2790)
評論排行榜
1.?匯編語言--端口(4)
2.?《匯編語言》--讀后感(4)
3.?我的天哪!感冒-->鼻炎-->咽喉炎(3)
4.? [轉] 工作到底是為了什么?(2)
5.?虛函數、多態性 練習題一(2)
6.?[轉]Windows下22個實用的代碼編輯器(2)
7.?Win32匯編--圖形操作--GDI原理(2)
8.?數學的魅力:取余運算還可以這樣(2)
9.?C++標準程序庫—自修教程與參考手冊 (1)
10.?Win32匯編--需要了解的基礎知識(1)
11.?[轉]各種字符編碼方式詳解及由來(ANSI,GB2312,GBK,UNICODE,UTF-8)(1)
12.?10個小故事(轉自羅云彬的編程樂園)(1)
13.?類繼承練習題一(1)
14.?《C++入門經典》(第3版)(1)
15.?匯編語言--使用BIOS進行鍵盤輸入和磁盤讀寫(1)
16.?初識exe程序反匯編小感[轉](1)
17.?Win32匯編--使用資源--菜單和加速鍵(1)
18.?Win32匯編--使用資源--圖標和光標(0)
19.?Win32匯編--使用資源--位圖(0)
20.?Win32匯編--使用資源--對話框(一)(0)
Powered by:
C++博客
Copyright © luqingfei
久久久国产精华液
|
99久久无色码中文字幕
|
久久se精品一区二区影院
|
成人免费网站久久久
|
狠狠色婷婷久久一区二区三区
|
综合网日日天干夜夜久久
|
国产69精品久久久久观看软件
|
伊人久久大香线蕉综合网站
|
日韩一区二区三区视频久久
|
精品伊人久久久
|
日韩人妻无码一区二区三区久久
|
亚洲中文字幕久久精品无码APP
|
中文字幕无码免费久久
|
久久精品国产亚洲AV无码偷窥
|
国产精品久久久亚洲
|
国产精品成人精品久久久
|
99999久久久久久亚洲
|
久久久久久夜精品精品免费啦
|
久久99精品国产麻豆宅宅
|
久久av高潮av无码av喷吹
|
国产美女亚洲精品久久久综合
|
久久99精品久久久久久hb无码
|
精品久久久久久久久久久久久久久
|
青青青青久久精品国产h久久精品五福影院1421
|
久久99久国产麻精品66
|
国产精品99久久久久久人
|
久久精品国产精品亚洲人人
|
久久久久99精品成人片直播
|
久久久久久免费一区二区三区
|
久久无码AV中文出轨人妻
|
久久久久成人精品无码中文字幕
|
久久精品无码一区二区三区日韩
|
久久无码中文字幕东京热
|
高清免费久久午夜精品
|
亚洲国产成人精品无码久久久久久综合
|
99久久成人18免费网站
|
亚洲AV无码1区2区久久
|
青青热久久国产久精品
|
久久这里只有精品首页
|
91精品国产综合久久香蕉
|
久久久久久av无码免费看大片
|