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
閱讀(268)
評論(0)
編輯
收藏
引用
所屬分類:
C++基礎
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
相關文章:
使用lib.exe生成.lib文件
如何區分導入庫和靜態庫
lib文件
[轉]動態鏈接庫、靜態庫、import庫區別
智能指針auto_ptr運用實例:常數型智能指針的特性
智能指針auto_ptr運用實例:移轉擁有權的行為
C++入門經典:(一)基本概念
make工具的用法
什么是Makefile
虛函數、多態性 練習題一
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
導航
C++博客
首頁
新隨筆
聯系
聚合
管理
<
2010年8月
>
日
一
二
三
四
五
六
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
29
30
31
1
2
3
4
統計
隨筆 - 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
搜索
積分與排名
積分 - 211491
排名 - 122
最新評論
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指令 (24473)
2.?匯編語言--int指令(15521)
3.?Win32匯編--使用MASM(10919)
4.?一個簡單的游戲服務器框架(6181)
5.?初識exe程序反匯編小感[轉](5962)
6.?匯編語言--標志寄存器 (5167)
7.?匯編語言--使用BIOS進行鍵盤輸入和磁盤讀寫(5115)
8.?[轉]Windows下22個實用的代碼編輯器(4765)
9.?Windows環境變量設置(4665)
10.?Win32匯編--使用資源--對話框(一)(4467)
11.?使用lib.exe生成.lib文件(4211)
12.?Win32匯編--圖形操作--GDI原理(4191)
13.?Win32匯編--使用資源--對話框--在對話框中使用子窗口控件(2)(4141)
14.?匯編語言--寄存器(內存訪問)(4014)
15.?Win32匯編--使用資源--菜單和加速鍵(3575)
16.?10個小故事(轉自羅云彬的編程樂園)(3154)
17.?Win32匯編--分析窗口程序(3004)
18.?C++實現插入排序(升序+降序)(2949)
19.?Win32匯編--使用資源--版本信息資源(2865)
20.?匯編中常見的一些錯誤信息(2810)
評論排行榜
1.?匯編語言--端口(4)
2.?《匯編語言》--讀后感(4)
3.?我的天哪!感冒-->鼻炎-->咽喉炎(3)
4.? [轉] 工作到底是為了什么?(2)
5.?[轉]Windows下22個實用的代碼編輯器(2)
6.?虛函數、多態性 練習題一(2)
7.?數學的魅力:取余運算還可以這樣(2)
8.?Win32匯編--圖形操作--GDI原理(2)
9.?類繼承練習題一(1)
10.?[轉]各種字符編碼方式詳解及由來(ANSI,GB2312,GBK,UNICODE,UTF-8)(1)
11.?《C++入門經典》(第3版)(1)
12.?Win32匯編--使用資源--菜單和加速鍵(1)
13.?10個小故事(轉自羅云彬的編程樂園)(1)
14.?C++標準程序庫—自修教程與參考手冊 (1)
15.?初識exe程序反匯編小感[轉](1)
16.?Win32匯編--需要了解的基礎知識(1)
17.?匯編語言--使用BIOS進行鍵盤輸入和磁盤讀寫(1)
18.?匯編語言--直接定址表(0)
19.?《Windows環境下32位匯編語言程序設計》--羅云彬(0)
20.?Win32匯編--準備編程環境(0)
Powered by:
C++博客
Copyright © luqingfei
久久久久se色偷偷亚洲精品av
|
国产色综合久久无码有码
|
亚洲人成网亚洲欧洲无码久久
|
久久久久这里只有精品
|
无码人妻久久一区二区三区蜜桃
|
久久中文精品无码中文字幕
|
久久精品无码一区二区WWW
|
国产精品一区二区久久国产
|
香蕉久久夜色精品国产小说
|
女同久久
|
99国产精品久久
|
久久亚洲天堂
|
精品久久人妻av中文字幕
|
国产精品亚洲综合专区片高清久久久
|
精品国产热久久久福利
|
久久午夜免费视频
|
2021久久精品国产99国产精品
|
久久久久综合国产欧美一区二区
|
欧美777精品久久久久网
|
99久久综合国产精品免费
|
青青青国产成人久久111网站
|
精品久久久久久久国产潘金莲
|
久久久久人妻精品一区二区三区
|
久久国产视屏
|
99久久99久久精品国产片果冻
|
伊人久久大香线蕉亚洲五月天
|
国产精品午夜久久
|
99久久精品免费看国产免费
|
狠狠色丁香婷婷久久综合五月
|
99久久免费只有精品国产
|
国产精品免费福利久久
|
亚洲精品无码久久久久sm
|
久久精品国产亚洲AV不卡
|
色综合色天天久久婷婷基地
|
精品无码久久久久久尤物
|
国产午夜精品久久久久免费视
|
久久一本综合
|
欧美久久一区二区三区
|
亚洲欧美久久久久9999
|
性做久久久久久久久久久
|
久久久久久久综合综合狠狠
|