Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

作業 1 資料型態宣告、基本運算子及基礎類別

繳交期限: 10/12 晚上 10:00 前, 上傳到 e-learning。


上傳時,將所有程式碼整合成一個檔案上傳。檔名:U1133000_H1.cpps
demo 期限: 10/19!
demo 請在夜間輔導時間,到電腦教室找助教 demo,沒有 demo 沒有分數。
未能在期限前 demo 完畢,遲一週,分數乘上 0.9 , 依週累乘,直到期末考前
二週。

1. 撰寫下列程式,請寫出輸出內容,合理嗎?請解釋。
bool b;

b = 0; cout << b << endl;


b = b-1; cout << b << endl;
b = b-1; cout << b << endl;
b = b +1; cout << b << endl;
b = b +1; cout << b << endl;

2. 撰寫下列程式,請寫出輸出內容,合理嗎?請解釋。
char b;
b = '5'; cout << b << endl;
b = b-1; cout << b << endl;
b = b-2; cout << b << endl;
b = b+4; cout << b << endl;

b = 'C'; cout << b << endl;


b = b-1; cout << b << endl;
b = b-200; cout << b << endl;
b = b+400; cout << b << endl;

3. 撰寫下列程式,請寫出輸出內容,合理嗎?請解釋。
short b;
b = '5'; cout << b << endl;
b = b-1; cout << b << endl;
b = b-2; cout << b << endl;
b = b+4; cout << b << endl;
b = 'C'; cout << b << endl;
b = b-1; cout << b << endl;
b = b-200; cout << b << endl;
b = b+400; cout << b << endl;

4. 撰寫程式,輸入一個 4 位數的整數,( int x; cin >> x; ) 請使用 div, 及 mod 運


算得到四個位數分別的數值。請輸出這四個數值以及這四個數值相加總合。

5. 撰寫程式,輸入二個小於 10 的有小數點的數值,將比較小的乘上 10 之後除


以比較大的,列印出結果。

6. 請設計一個類別 Card,資料成員有 suit 以及 number ,型別分別為 string 及


int 。設計一個建構子 可以給 suit 及 number。設計 suit 及 number 的 set 及 get
成員函式。成員函式 setNumber 必須要檢查是否 number 介於 1 ~ 13 之間,若
不是則不進行設定。設計一個 display 函式,可以列印出 suit 及 number。撰
寫主程式,進行宣告,set, get 以及 display。
( suit 表示花色, 使用的字串為 spade, heart, diamond 以及 club )
( number 表示點數,使用的整數為 1, 2, 3, …, 13)

You might also like