# 程式設計實習 ## 0920作業 ### 課後練習 #### 第一題練習題 ###### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230920 #include<iostream> using namespace std; #define US 32.04 //定義聚集常數 美金匯率 #define JP 0.22 //定義聚集常數 日幣匯率 #define CA 23.81 //定義聚集常數 加幣匯率 #define CH 4.39 //定義聚集常數 人民幣匯率 int main(){ double money; cout<<"請輸入要兌換的金額:"; cin>>money; cout<<"可兌換"<<money/US<<"美金\n"; cout<<"或兌換"<<money/JP<<"日幣\n"; cout<<"或兌換"<<money/CA<<"加幣\n"; cout<<"或兌換"<<money/CH<<"人民幣"; } ``` ##### 執行結果 ![](https://hackmd.io/_uploads/Bk3UUMukp.jpg) #### 第二題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230920 #include<iostream> using namespace std; int main (){ int money,ten,five,one; cout<<"請輸入您的換幣金額:"; cin>>money; ten=money/10; //計算十元硬幣兌換個數 five=(money%10)/5; //計算兌換硬幣五元個數 one=(money%10)%5; //計算兌換一元硬幣個數 cout<<money<<"共可以兌換零錢個數"<<"十元"<<ten<<"個"<<"五元"<<five<<"個"<<"一元"<<one<<"個" ; } ``` ##### 執行結果 ![](https://hackmd.io/_uploads/SkpheKO1a.jpg) #### 第三題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230920 #include<iostream> using namespace std; int main(){ float C,F; cout<<"請輸入華氏溫度:"; cin>>F; C=(F-32)*5/9; //溫度轉換公式 cout<<"換算攝氏溫度為"<<C<<"度"; } ``` ##### 執行結果 ![](https://hackmd.io/_uploads/rk347tdJa.jpg) #### 第四題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230920 #include<iostream> using namespace std; int main(){ int money,fifty,ten,five,one; cout<<"請輸入車票價錢:"; cin>>money; fifty=money/50; ten=(money%50)/10; five=((money%50)%10)/5; one=((money%50)%10)%5; cout<<"各硬幣數量最少為:\n"; cout<<"五十元"<<fifty<<"個\n"; cout<<"十元"<<ten<<"個\n"; cout<<"五元"<<five<<"個\n"; cout<<"一元"<<one<<"個"; } ``` ##### 執行結果 ![](https://hackmd.io/_uploads/Bk8y5Yd1p.jpg) #### 心得 今天在做功課時雖然常常會不知道當下在打什麼,但是當打完全部之後回來再看一次就大概能理解,在做最後一個程式時雖然有時還是要參考之前做的但比較能夠自己完成而不是看課本了,希望之後能夠更熟悉c++語言 ## 0927作業 ### 課後練習 #### 第一題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230927 #include<iostream> using namespace std; int main() { float a; cout<<"發生船難,你選擇留下什麼?\n選擇(1)留下老人和孕婦\n選擇(2)留下老人和嬰兒\n選擇(3)留下老人和金銀珠寶\n選擇(4)留下孕婦和嬰兒\n選擇(5)留下孕婦和金銀珠寶\n選擇(6)留下嬰兒和金銀珠寶\n"; cin>> a; if (a==1) cout<<"(1)你的情感很細膩,善於觀察細節。在感情中,相比於戀人的甜言蜜語,你更在乎對方實際的行動。"; else if (a==2) cout<<"(2)在感情中,你不僅洞察力超好,第六感也很強,越是親近的人這種直覺越敏銳,所以另一半對你很難有所隱藏,因為你可以憑借著蛛絲馬跡得到你想要知道的消息。"; else if (a==3) cout<<"(3)你是個典型的顏控,在擇偶時很注重另一半的外表和身高。"; else if (a==4) cout<<"(4)面對感情你很承盾,一方面你很感性,渴望浪漫熱烈的愛情;另一方面你又很理性,明白現實的殘酷和金錢的重要性"; else if (a==5) cout<<"(5)在感情方面你很挑剔,所以很難遇到心動的對象。不過在戀愛時你卻很專一,一旦喜歡上某個人,你就會全心全意的對他好,所以和你談戀愛是一件很幸福的事。"; else if (a==6) cout<<"(6)在感情中你很缺乏安全感,有時候會忍不住通過試探或考驗的方式去確認對方是否愛你。"; else cout<<"亂輸入,活該一輩子舔狗命!!!"; ``` ##### 運行結果 ![](https://hackmd.io/_uploads/ry0AB_Vxp.jpg) #### 第二題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230927 #include<iostream> using namespace std; int main(){ float x; cout<<"請輸入x值"; cin>>x; float y; cout<<"請輸入y值"; cin>>y; if (x>0&&y>0) cout<<"第一象限"; else if (x<0&&y>0) cout<<"第二象限"; else if (x<0&&y<0) cout<<"第三象限"; else if (x>0&&y<0) cout<<"第四象限"; } ``` ##### 運行結果![](https://hackmd.io/_uploads/rkkyp2Ye6.jpg) #### 第三題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230927 #include<iostream> using namespace std; int main(){ cout<<"請輸入層數 : "; int n; cin>>n; for(int i = 1;i<n+1;i++){ for(int j = 1;j<i+1;j++){ cout<<"*"; } cout<<endl; } cout<<endl; for(int i = n;i>0;i--){ for(int j = i+1;j>1;j--){ cout<<"*"; } cout<<endl; } cout<<endl; for(int i = 1;i<n+1;i++){ for(int j = 1;j<n-i+1;j++){ cout<<" "; } for(int j = i+1;j>1;j--){ cout<<"*"; } cout<<endl; } cout<<endl; for(int i = 1;i<n+1;i++){ for(int j = i;j>1;j--){ cout<<" "; } for(int j = 0;j<n-i+1;j++){ cout<<"*"; } cout<<endl; } cout<<endl; } ``` ##### ![](https://hackmd.io/_uploads/ByRP80M-T.jpg) #### 第四題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230927 #include<iostream> using namespace std; int main(){ int a,b; cout<<"請輸入民國出生年:"; cin>>a; b=(a%12); if (b==0) cout<<"豬"; else if (b==1) cout<<"鼠"; else if (b==2) cout<<"牛"; else if (b==3) cout<<"虎"; else if (b==4) cout<<"兔"; else if (b==5) cout<<"龍"; else if (b==6) cout<<"蛇"; else if (b==7) cout<<"馬"; else if (b==8) cout<<"羊"; else if (b==9) cout<<"猴"; else if (b==10) cout<<"雞"; else if (b==11) cout<<"狗"; } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/Skz7ZTKx6.jpg) #### 第五題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20230927 #include<iostream> using namespace std; int main(){ int a,b; cout<<"請輸入西元年"; cin>>a; if (a%4==0&&a%100!=0) cout<<"閏年"; else cout<<"非閏年"; } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/BkD97Ttga.jpg) #### 心得 在這禮拜的程式設計實習的上課內容及練習作業中我學到了運用if和else以及else if來去運算一些生活上的應用內容,雖然一開始覺得有點難,但後來就慢慢上手了,希望下一次可以更加熟練地掌握寫程式的方法,但是迴圈好難,腦子不夠用 ## 1004作業 ### 課後練習 #### 第一題練習題 ##### 程式碼(未完成) ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int mian(){ int a; float money; cout<<"夏季電費,請輸入用電量:"; cin>>a; if(a<=120){ money+=a*1.63; } else if(a>120&&a<=330){ money+=120*1.63+(a-120)*2.38; } else if(a>330&&a<=500){ money+=120*1.63+(330-120)*2.38+(a-330)*3.52; } else if(a>500&&a<=700){ money+=120*1.63+(330-120)*2.38+(500-330)*3.52+(a-500)*4.80; } else if(a>700&&a<=1000){ money+=120*1.63+(330-120)*2.38+(500-330)*3.52+(700-500)*4.80+(a-700)*5.83; } else{ money+=120*1.63+(330-120)*2.38+(500-330)*3.52+(700-500)*4.80+(1000-700)*5.83+(a-1000)*7.69; } cout<<"電費:"<<money<<"元"<<endl; } ``` ##### 運行結果 #### 第二題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int main(){ cout<<"請輸入成績多個成績 "<<endl; int a,count = 0; do{ cin>>a; count+=a; } while(a != -1); count+=1; cout<<"總分是"<<count<<endl; } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/B1DPwbQ-a.jpg) #### 第三題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int main(){ int a; cout<<"請輸入數值:"; cin>>a; if(a%2 == 1){ cout<<"你輸入的是奇數"<<endl; } else{ cout<<"你輸入的是偶數"<<endl; } } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/SkkWdZmZa.jpg) #### 第四題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int main(){ int x; x = 1; while(x == 1){ cout<<"請輸入一個整數"<<endl; int a,b = 3,count = 0; cin>>a; x = 0; b = 0; while(b<=a){ count+=b; b+=3; } cout<<count<<endl; cout<<"是否再算一次"<<endl; cin>>x; } } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/rkbQFbXZ6.jpg) #### 第五題練習題 ##### ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int main(){ cout<<"購買商品定價為"<<endl; int a,b,c; cin>>a; cout<<"是會員打1,不是會員打2"<<endl; cin>>b; if(b == 1){ cout<<"是鑽石會員打1,是白金會員打2,是普通會員打3"<<endl; cin>>c; if(c == 1){ cout<<"購買商品金錢為"<<a*0.7<<endl; } else if(c == 2){ cout<<"購買商品金錢為"<<a*0.8<<endl; } else{ cout<<"購買商品金錢為"<<a*0.9<<endl; } } else{ cout<<"購買商品金錢為"<<a<<endl; } } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/BkpptWmZp.jpg) #### 第六題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int main(){ cout<<"請同學輸入全班人數:"; int a,count = 0,pass = 0,fail = 0; cin>>a; cout<<"再輸入每位同學成績"<<endl; for(int i = 0;i<a;i++){ int b; cin>>b; count+=b; if(b>=60){ pass+=1; } else{ fail+=1; } } count/=a; cout<<"全班成績平均"<<count<<endl; cout<<"及格人數"<<pass<<endl; cout<<"不及格人數"<<fail<<endl; } ``` ##### ![](https://hackmd.io/_uploads/HJBFq-m-6.jpg) #### 第七題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int main(){ cout<<"請輸入一整數:" ; int a; cin>>a; int b = -a; cout<<a<<" 的絕對值是 "<<b<<endl; } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/rJ1Qo-m-T.jpg) #### 第八題練習題 ##### 程式碼 ``` //1206123資訊一甲23陳麒文 //20231004 #include<iostream> using namespace std; int main(){ int a,b; cout<<"有幾隻動物"; cin>>a; cout<<"有幾隻腳"; cin>>b; int c = b-2*a; int d = c/2; int e = a-d; cout<<"兔: "<<d<<"雞: "<<e<<endl; } ``` ##### 運行結果 ![](https://hackmd.io/_uploads/S1-FjZXZ6.jpg)