程序設(shè)計(jì)answer輸出一個(gè)字符串_第1頁(yè)
程序設(shè)計(jì)answer輸出一個(gè)字符串_第2頁(yè)
程序設(shè)計(jì)answer輸出一個(gè)字符串_第3頁(yè)
程序設(shè)計(jì)answer輸出一個(gè)字符串_第4頁(yè)
程序設(shè)計(jì)answer輸出一個(gè)字符串_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Exercise 1.1Output a string輸出一個(gè)字符串Output the string givenhe following.his exercise, you are required to output spel characters,including and .Please add comments in your program輸出下面給出的字符串.這題需要你掌握如何輸出特殊字符,如和.whereappropriate.請(qǐng)?jiān)诔绦蛑羞m當(dāng)?shù)牡胤教砑幼⑨?EXnLE OUTPUT主程序1 #include source 程序文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出Exercise 1

2、.2123456789#include using namespatd;/*This function output the required characters.*/main() cout _$%+*主程序1 #include source 程序文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出Exercise 1.3The meaning of#includehemain program主程序中#include的解釋123456789#include using namespatd;/*This function output the required characters.*/main() cout _

3、$%+*/?);/.;There are two pie which is given, an main program is the each compilation, the source and then incl proprogram is always compil line is replaced by youroreas o the main programa file namedthrough the pre-a在每個(gè)練習(xí)中都有兩個(gè)程序:一個(gè)給定的上被編譯和運(yùn)行的程序。在每次編譯前,過#include source預(yù)處理命令包含入 source行在被件,然后通單地說,主程序總是

4、在它的#includeThere are two types of exercise:am conthe #include source line. the complete programit isplete wiyou needprogram,to provide the exact in order to completemissing par the main protputcorrectly.共有兩類練習(xí)題:在第一類中,主程序只包含一行:能產(chǎn)生正確輸出的整個(gè)程序。在第二類中,主程序中包含程#include source行。這種掉,這部程序中缺少的部分所在位置由#include sou

5、rce行所表示。這種情況下,你要給出分,以使得主程序完整并能正確地輸出。This exercise belongs to the second ty write something to complete theto write an evaluation s anired to ou need這個(gè)練習(xí)題屬于第二類:你需要寫一些東西來(lái)是使主程序完整。具體來(lái)說,你需要寫一個(gè)賦值來(lái)使一個(gè)名為age的整數(shù)變量的值增加10。 EX10EX20LE OUTPUT主程序 1 #include 2 using namespatd; 34main() 6cin age; 78#include source 9

6、10cout age;11 程序文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出Exercise 1.4Define variables定義變量PleaseAn An An Andefine the followingvariables:eger variable, named year. real variable, named seconds.variable, named isMonday. character variable, named code.請(qǐng)定義以下的變量:一個(gè)名為year的整數(shù)變量.一個(gè)名為seconds的實(shí)數(shù)變量.一個(gè)名為isMonday的變量.一個(gè)名為code的字符變量.LE OUT

7、PUTEX48111 age = age + 10;5age;主程序2using namespatd;4main() 6coutsizeof(year) endl;8coutsizeof(isMonday)endl;10程序文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出Exercise 1.5Define and initialize定義并初始化變量variablesPleasedefine and initialize the following variables:An An An Aneger variable, named year, and initialize itto 1990.real va

8、riable, named seconds, and initialize itto 1234.56.variable, named isMonday, and initialize it to true.character variable, named code, and initialize it to C.請(qǐng)定義以下的變量:一個(gè)名為year的整數(shù)變量,并把它初始化為1990。一個(gè)名為seconds的實(shí)數(shù)變量,并把它初始化為1234.56。一個(gè)名為isMonday的變量,并把它初始化為true。1234year; double seconds; bool isMonday; char c

9、ode;9cout sizeof(code) endl;7cout sizeof(seconds) endl;5#include source31 #include 一個(gè)名為code的字符變量,并把它初始化為C。LE OUTPUTEX19901234.561C主程序2using namespatd;4main() 6coutyear endl;8coutisMondayendl;10程序文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出Exercise 1.6ition個(gè)實(shí)數(shù)ofareal numberInput a real number andthe output itsegart and fraction

10、 partwo lines, respectively.輸入一個(gè)實(shí)數(shù)并把它的整數(shù)部分和小數(shù)部分分別在兩行輸出.1234year = 1990;double seconds = 1234.56; bool isMonday = true; char code = C;9cout code endl;7cout seconds endl;5#include source31 #include EXLE INPUT12.34EXLE OUTPUT120.34主程序1 #include source 程序文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出123456789101112131415161718#inclu

11、de using namespatd;/*This function input a real numberand outputs itsegart and fraction part, respectively.*/main() / read a real number double number;cin number;/ obtain itsegart by/ converting to anger eger = number;/ obtain its fraction part by/ reducing itsegartnumber -=eger; 21/ output the two

12、partscout eger endl;cout number endl; 25 Exercise 1.7Last two binary digits最后兩個(gè)2進(jìn)制位Input an second lastif aneger number and then output its last binary digit and eger digit, separated by a single empty space. eger is divided by 2, its second last binary digititses it last binary digit.輸入一個(gè)整數(shù)并輸出它的最后一

13、位2進(jìn)制位和倒數(shù)第二位2進(jìn)制位,中間用一個(gè)空格隔開。提示:當(dāng)一個(gè)整數(shù)被除2,它的倒數(shù)第二位2進(jìn)制位將變成它的最后一位2進(jìn)制位。EX2LE INPUTEXLE OUTPUT0 1主程序1 #include source 程序文本框測(cè)試數(shù)據(jù)12345678910111213141516171819202122#include using namespatd;/*This function inputs aneger and output its last binary digit and its second last binary digit.*/main() / input the numbe

14、r number;cin number;/ output its last binary digit and an empty space cout number % 2 ;/ make the second last binary digit the last binary digit number /= 2;/ output the new last (theinal second last) binary digit cout number % 2;保存和測(cè)試測(cè)試輸出Exercise 1.8Test equality測(cè)試相等Input two otherwise.egers.Output

15、 theeger if they are equal, output 0H: if bool equals = (number1 = number2),then we can obtain a 0 the two numbers are notby converting quals to aneger value whenequal, and obtain a 1 otherwise.輸出兩個(gè)整數(shù)。如果它們相同則輸出整數(shù)的值,否則輸出0。提示:如果bool equals = (number1 = number2),在兩個(gè)數(shù)不相同的時(shí)候獲得一個(gè)0,其它時(shí)候獲得一個(gè)1??梢园裶uals轉(zhuǎn)換為一個(gè)整

16、數(shù)而EXLE INPUT 110 10EX10LE OUTPUT 1EX10 20LE INPUT 2EXLE OUTPUT 20主程序1 #include source 程序12345#include using namespatd;/*This function inputs twoeger variables,文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出Exercise 1.9Consecutive characters連續(xù)的字符Input an English letter character characters.輸出一個(gè)英文字符并打印出它后面的3個(gè)字符and prout its followi

17、ng threeEXCLE INPUTEXDEFLE OUTPUT6and then outputs one of them if the twoegers are equal. It outputs 0 otherwise.*/main() 789/ input twoeger variablesnumber1;number2;cin number1 number2; 14/ test equalitybool equals = (number1 = number2); 17/ obtain aneger 1 if equals, 0 otherwisetimes = equals; 20/ output 0 if not equalcout (number1 * times); 23 主程序1 #include source 程序文本框測(cè)試數(shù)據(jù)保存和測(cè)試測(cè)試輸出保存于 16:26.42導(dǎo)出123456789101112#include using namespatd;/*This function inputs an English letter character a

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論