# 程式設計實習_30 鄭宇琋 ## 20230913 課堂作業 ### 第一道練習題 ``` #include<iostream> using namespace std; int main(){ int a = 10; float b = 101.7; char c = 'c'; } ``` ![](https://hackmd.io/_uploads/rJ2tQzOkT.png) ### 第二道練習題 ``` #include<iostream> using namespace std; int main(){ cout<<"Please enter capital letters:";//請輸入英文字母大寫 char a ; cin>>a; cout<<a<<"The lower case is "<<char(a+32)<<endl;//變數a的小寫是 } ``` ![](https://hackmd.io/_uploads/rkKRmfdkp.png) ### 第三道練習題 ``` #include<iostream> using namespace std; int main(){ int numA = 60; int numB = 80; int temp = 0; temp = numA; numA = numB; numB = temp; cout<<numA<<" "<<numB<<endl; } ``` ![](https://hackmd.io/_uploads/Bk2W4fdka.png) ### 第四道練習題 ``` #include<iostream> #include<math.h> using namespace std; int main(){ const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679; int r; double area; cout<<"請輸入半徑(公分)"; cin>>r; area = pow(r,2)*pi; cout<<"半徑"<<r<<"公分的圓面積 = "<<area<<"平方公分"<<endl; } ``` ![](https://hackmd.io/_uploads/SkeNNfdyT.png) ### 心得 ``` 今天上課學習到了很多東西, 包括變數的各種型態, ex: int,float,char,double, 而且也學習了單引號和雙引號的差別, 單引號是字元, 雙引號是字串, 也學習了變數交換的程式, 今天學習兩個變數的交換, 但是以此類推, 三個,四個,多個變數我都會了, 也學習const的真正含義和用法, 讓我有更大想要繼續寫程式的動力 ``` ## 20230920 課堂作業 ### 第一道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; #define usa 0.032 #define jpa 4.78 int main() { int a; cout<<"請輸入要兌換的金額"; cin>>a; double b = usa*a; double c = jpa*a; cout<<"可兌換"<<b<<"美金"<<endl; cout<<"可兌換"<<c<<"日幣"<<endl; } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/r18r3DEH6.png) #### 執行結果 ![](https://hackmd.io/_uploads/BJjFQXukp.png) ### 第二道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"請輸入你的換幣金額"; int a ; cin>>a; int b = a/10; int c = (a-b*10)/5; int d = (a-b*10-c*5); cout<<a<<"元共可兌換零錢 : 十元"<<b<<"個 "<<"五元"<<c<<"個 " <<"一元"<<d<<"個 "<<endl; } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/BJLI2PNrp.png) #### 執行結果 ![](https://hackmd.io/_uploads/B1N1EXu1a.png) ### 第三道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"請輸入華氏的溫度:" ; float a ; cin>>a; float b = (a-32)*5/9; cout<<a<<"換算成攝氏溫度為"<<b<<"度"<<endl; } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/S1VP3PNBa.png) #### 執行結果 ![Uploading file..._38euhzztu]() ### 第四道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"請輸入車票票價 = "; int a ; cin>>a; int b = a/50; int c = (a-b*50)/10; int d = (a-b*50-c*10)/5; int e = (a-b*50-c*10-d*5); cout<<a<<"元,各種幣值的最少數量為 : "<<endl; cout<<" 五十元"<<b<<"個 "<<endl; cout<<"十元"<<c<<"個 " <<endl; cout<<"五元"<<d<<"個 "<<endl; cout<<"一元"<<e<<"個 "<<endl; } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/BJBuhPVrT.png) #### 執行結果 ![](https://hackmd.io/_uploads/rkX17QOJa.png) ### 心得 ``` 今天我學習了很多東西, 學習了什麼是唯獨變數, 還有巨集常數, 最重要的是學習了運算子和運算式, 包括算術運算子.關係運算子.邏輯運算子和指定運算子. ``` ## 20230927 課堂作業 ### 第一道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"發生船難,你選擇留下什麼?"<<endl; cout<<"選擇(1)留下老人和孕婦"<<endl; cout<<"選擇(2)留下老人和嬰兒"<<endl; cout<<"選擇(3)留下老人和金銀珠寶"<<endl; cout<<"選擇(4)留下孕婦和嬰兒"<<endl; cout<<"選擇(5)留下孕婦和金銀珠寶"<<endl; cout<<"選擇(6)留下嬰兒和金銀珠寶"<<endl; int a; cin>>a; if(a == 1){ cout<<"(1)你的情感很細膩,善於觀察細節。在感情中,相比於戀人的甜言蜜語,你更在乎對方實際的行動。"<<endl; } else if(a == 2){ cout<<"(2)在感情中,你不僅洞察力超好,第六感也很強,越是親近的人這種直覺越敏銳,所以另一半對你很難有所隱藏,因為你可以憑借著蛛絲馬跡得到你想要知道的消息。"<<endl; } else if(a == 3){ cout<<"(3)你是個典型的顏控,在擇偶時很注重另一半的外表和身高。"<<endl; } else if(a == 4){ cout<<"(4)面對感情你很承盾,一方面你很感性,渴望浪漫熱烈的愛情;另一方面你又很理性,明白現實的殘酷和金錢的重要性"<<endl; } else if(a == 5){ cout<<"(5)在感情方面你很挑剔,所以很難遇到心動的對象。不過在戀愛時你卻很專一,一旦喜歡上某個人,你就會全心全意的對他好,所以和你談戀愛是一件很幸福的事。"<<endl; } else if(a == 6){ cout<<"(6)在感情中你很缺乏安全感,有時候會忍不住通過試探或考驗的方式去確認對方是否愛你。"<<endl; } else{ cout<<"亂輸入,活該一輩子舔狗命!!!"<<endl; } } ``` #### 程式碼 ![](https://hackmd.io/_uploads/ByipLMbgT.png) #### 執行結果 ![](https://hackmd.io/_uploads/ByGxwGZg6.png) ### 第二道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ int a,b; cout<<"請輸入X值(不可輸入零) : "; cin>>a; cout<<"請輸入Y值(不可輸入零) : "; cin>>b; if(a>0){ if(b>0){ cout<<"( "<<a<<", "<<b<<")"<<"在第一象限"<<endl; } else{ cout<<"( "<<a<<", "<<b<<")"<<"在第二象限"<<endl; } } else{ if(b>0){ cout<<"( "<<a<<", "<<b<<")"<<"在第三象限"<<endl; } else{ cout<<"( "<<a<<", "<<b<<")"<<"在第四象限"<<endl; } } } ``` #### 程式碼 ![](https://hackmd.io/_uploads/BysNKfZgp.png) #### 執行結果 ![](https://hackmd.io/_uploads/SkeVtMWxp.png) ### 第三道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #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/rkiZ0Mbxa.png) #### 執行結果 ![](https://hackmd.io/_uploads/r1gI0Gbxp.png) ### 第四道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"請輸入民國(年) : "; int a; cin>>a; if(a%12 == 0){ cout<<"豬"<<endl; } else if(a%12 == 1){ cout<<"鼠"<<endl; } else if(a%12 == 2){ cout<<"牛"<<endl; } else if(a%12 == 3){ cout<<"虎"<<endl; } else if(a%12 == 4){ cout<<"兔"<<endl; } else if(a%12 == 5){ cout<<"龍"<<endl; } else if(a%12 == 6){ cout<<"蛇"<<endl; } else if(a%12 == 7){ cout<<"馬"<<endl; } else if(a%12 == 8){ cout<<"羊"<<endl; } else if(a%12 == 9){ cout<<"猴"<<endl; } else if(a%12 == 10){ cout<<"雞"<<endl; } else if(a%12 == 11){ cout<<"狗"<<endl; } } ``` #### 程式碼 ![](https://hackmd.io/_uploads/By03kXWea.png) #### 執行結果 ![](https://hackmd.io/_uploads/rJVhk7-lT.png) ### 第五道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"請輸入一個西元年 : "; int a; cin>>a; if(a%400 == 0||(a%100!=0&&a%4 == 0)){ cout<<a<<"年是閏年" <<endl; } else{ cout<<a<<"年非閏年" <<endl; } } ``` #### 程式碼 ![](https://hackmd.io/_uploads/rJH4G7-lp.png) #### 執行結果 ![](https://hackmd.io/_uploads/HyZzGXZgT.png) ![](https://hackmd.io/_uploads/B1nezQWxp.png) ### 心得 ``` 今天學習了流程控制, 流程控制分成條件判斷控制和迴圈控制, 條件判斷有IF ELSE和SWITCH CASE, 我個人比較習慣用IF ELSE, 因為我一開始學程式沒有學SWITCH CASE, 但是我現在也覺得SWITCH CASE也很好用, ``` ## 20231004 課堂作業 ### 第一道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"夏季電費,請輸入用電度數:"; int a; float money; 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+210*2.38+(a-330)*3.52; } else if(a>=500&&a<700){ money+=120*1.63+210*2.38+170*3.52+(a-500)*4.80; } else if(a>=700&&a<1000){ money+=120*1.63+210*2.38+170*3.52+200*4.80+(a-700)*5.83; } else { money+=120*1.63+210*2.38+170*3.52+200*4.80+300*5.83+(a-1000)*7.69; } cout<<"本月電費為:"<<money<<"元"<<endl; } ``` #### 程式碼 ![](https://hackmd.io/_uploads/BkQNTFqeT.png) #### 執行結果 ![](https://hackmd.io/_uploads/Syympt9lp.png) ### 第二道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #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/SyVfYd9la.png) #### 執行結果 ![](https://hackmd.io/_uploads/r1NVKuqla.png) ### 第三道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ int a; cin>>a; if(a%2 == 1){ cout<<"你輸入的是奇數"<<endl; } else{ cout<<"你輸入的是偶數"<<endl; } } ``` #### 程式碼 ![](https://hackmd.io/_uploads/BycpFucea.png) #### 執行結果 ![](https://hackmd.io/_uploads/r1F3tOcxT.png) ### 第四道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #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/SkX2QYceT.png) #### 執行結果 ![](https://hackmd.io/_uploads/HkJs7F5lT.png) ### 第五道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #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/H1CVRu9gT.png) #### 執行結果 ![](https://hackmd.io/_uploads/HkXN0_5g6.png) ### 第六道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #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/SknLhu5x6.png) #### 執行結果 ![](https://hackmd.io/_uploads/rk6Bh_ce6.png) ### 第七道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ cout<<"請輸入一整數:" ; int a; cin>>a; int b = -a; cout<<a<<" 的絕對值是 "<<b<<endl; } ``` #### 程式碼 ![](https://hackmd.io/_uploads/Sy_tqOqla.png) #### 執行結果 ![](https://hackmd.io/_uploads/ByP_5Ocl6.png) ### 第八道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #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/SJi-Ltclp.png) #### 執行結果 ![](https://hackmd.io/_uploads/S1Gg8K9gT.png) ## 20231101 課堂作業 ### 第一道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int m(int a){ if(a == 196){ cout<<"語音費率每秒:0.0869元"<<endl; } else if(a == 396){ cout<<"語音費率每秒:0.0782元"<<endl; } else{ cout<<"語音費率每秒:0.0696元"<<endl; } } int main(){ cout<<"請輸入要查詢的月租費方案(196、396、796):"; int a; cin>>a; m(a); } ``` #### 程式碼 ![image.png](https://hackmd.io/_uploads/BknnkKJ7p.png) #### 執行結果 ![image.png](https://hackmd.io/_uploads/HkTJgYyQp.png) ### 第二道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> #include<stdlib.h> #include<time.h> using namespace std; int x(int a,int n){ if(a == n){ cout<<"猜對了!YA!"<<endl; } else if(a<n){ cout<<"猜錯了,再大一點"<<endl; } else{ cout<<"猜錯了,再小一點"<<endl; } } int main(){ srand(time(0)); int n = (rand()%10)+1; cout<<"猜猜看數字是多少?(1~10) : "; int a; do{ cin>>a; x(a,n); }while(a!=n); } ``` #### 程式碼 ![image.png](https://hackmd.io/_uploads/rJE3PDOXp.png) #### 執行結果 ![image.png](https://hackmd.io/_uploads/Hykq4D1XT.png) ### 第三道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int x(int a,int b,int c){ if(a+b<=c){ cout<<a<<"."<<b<<"."<<c<<"不可組成三角形"<<endl; } else if(c+a<=b){ cout<<a<<"."<<b<<"."<<c<<"不可組成三角形"<<endl; } else if(c+b<=a){ cout<<a<<"."<<b<<"."<<c<<"不可組成三角形"<<endl; } else{ cout<<a<<"."<<b<<"."<<c<<"可組成三角形"<<endl; } } int main(){ cout<<"請輸入三角形的三個邊長:"; int a,b,c; cin>>a>>b>>c; x(a,b,c); } ``` #### 程式碼 ![image.png](https://hackmd.io/_uploads/r1K6PvOX6.png) #### 執行結果 ![image.png](https://hackmd.io/_uploads/ry2NDDyX6.png) ### 第四道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int x(int a){ if(a == 1){ return 1; } return a*x(a-1); } int main(){ cout<<"請輸入一個整數n(n>0): "; int aa; cin>>aa; cout<<"階層"<<aa<<"!="<<x(aa)<<endl; } ``` #### 程式碼 ![image.png](https://hackmd.io/_uploads/Skj3Fw1Qp.png) #### 執行結果 ![image.png](https://hackmd.io/_uploads/SJj9Fv1ma.png) ### 第五道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include <stdio.h> #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int x(int a){ if(a == 1){ return 1; } return a*x(a-1); } void y(int a,int b,int c){ if(a+b<=c){ cout<<a<<"."<<b<<"."<<c<<"不可組成三角形"<<endl; } else if(c+a<=b){ cout<<a<<"."<<b<<"."<<c<<"不可組成三角形"<<endl; }ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss else if(c+b<=a){ cout<<a<<"."<<b<<"."<<c<<"不可組成三角形"<<endl; } else{ cout<<a<<"."<<b<<"."<<c<<"可組成三角形"<<endl; } } void z(int a,int n){ if(a == n){ cout<<"猜對了!YA!"<<endl; } else if(a<n){ cout<<"猜錯了,再大一點"<<endl; } else{ cout<<"猜錯了,再小一點"<<endl; } } void p01(){ cout<<"請輸入要查詢的月租費方案(196、396、796):"; int a; cin>>a; if(a == 196){ cout<<"語音費率每秒:0.0869元"<<endl; } else if(a == 396){ cout<<"語音費率每秒:0.0782元"<<endl; } else{ cout<<"語音費率每秒:0.0696元"<<endl; } } void p02(){ srand(time(0)); int n = (rand()%10)+1; cout<<"猜猜看數字是多少?(1~10) : "; int a; do{ cin>>a; z(a,n); }while(a!=n); } void p03(){ cout<<"請輸入三角形的三個邊長:"; int a,b,c; cin>>a>>b>>c; y(a,b,c); } void p04(){ cout<<"請輸入一個整數n(n>0): "; int aa; cin>>aa; cout<<"階層"<<aa<<"!="<<x(aa)<<endl; } int main() { string menuItem[]= { "[1]查詢語音費率函式", "[2]猜數字遊戲", "[3]組成三角形", "[4]遞迴", "[0]離開" }; int i,num; int selMenu=99; while(selMenu!=0) { system("chcp 950"); //編碼 system("cls"); //清除畫面 cout<<"程式設計實習 資訊一甲 30 鄭宇琋 \n"; cout<<"-----------------------------"<<endl; int arrLength=sizeof(menuItem)/sizeof(menuItem[0]); for(i=0; i<arrLength; i++) { cout<<menuItem[i]<<endl; } cout<<"請輸入選項:"; cin>>selMenu; switch(selMenu) { case 1: p01(); break; case 2: p02(); break; case 3: p03(); break; case 4: p04(); break; } system("PAUSE"); cout<<"\n"; } } ``` ## 20231115 課堂作業 ### 第一道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> #include<time.h> #include<stdlib.h> #include<algorithm> using namespace std; int a[5]; void x(){ for(int i = 0;i<5;i++){ a[i] = (rand()%39)+1; } } int main(){ int count = 0; srand(time(0)); cout<<"本期樂透號碼開出順序:"<<endl; cout<<"開出順序: "; x(); for(int i = 0;i<5;i++){ cout<<a[i]<<" "; } cout<<endl; cout<<"號碼順序: "; sort(a,a+5); for(int i = 0;i<5;i++){ cout<<a[i]<<" "; } cout<<endl; for(int i = 1;i<6;i++){ cout<<"請輸入號碼"<<i<<":"; int num; cin>>num; if(num == a[i-1]){ count++; } } if(count == 5){ cout<<"頭獎"<<endl; } else if(count == 4){ cout<<"二獎"<<endl; } else if(count == 3){ cout<<"三獎"<<endl; } else if(count == 2){ cout<<"四獎"<<endl; } else{ cout<<"沒中獎"<<endl; } } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/rkfUovVr6.png) #### 執行結果 ![image](https://hackmd.io/_uploads/H170O1GV6.png) ### 第二道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> #include<time.h> #include<stdlib.h> #include<algorithm> using namespace std; int main(){ int b[10]; for(int i = 0;i<10;i++){ cout<<"請輸入A["<<i<<"]的字元:"; char a; cin>>a; b[i] = a; } sort(b,b+10); cout<<"陣列內容由小排列至大"<<endl; for(int i = 0;i<10;i++){ cout<<char(b[i]); } } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/BJFwiv4H6.png) #### 執行結果 ![image](https://hackmd.io/_uploads/B18MoJGEa.png) ### 第三道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> #include<time.h> #include<stdlib.h> #include<algorithm> using namespace std; int a[10]; void x(){ for(int i = 0;i<10;i++){ a[i] = (rand()%10)+1; } } int main(){ int even = 0; int odd = 0; srand(time(0)); cout<<"The numbers:"; x(); for(int i = 0;i<10;i++){ cout<<a[i]<<","; if(a[i]%2 == 0){ even+=a[i]; } else{ odd+= a[i]; } } cout<<endl; cout<<"The sum of even numbers:"<<even<<endl; cout<<"The sum of odd numbers:"<<odd<<endl; } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/r1dFiD4ST.png) #### 執行結果 ![image](https://hackmd.io/_uploads/B1LRgezNT.png) ### 第四道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> #include<time.h> #include<stdlib.h> #include<algorithm> using namespace std; int main(){ cout<<"輸入幾位學生"; int n; cin>>n; int a[n][5]; cout<<"輸入每位學生的成績(依序為國、英、數、基電、物理,以空格區隔)"<<endl; for(int i = 0;i<n;i++){ int num; cout<<i+1<<" 號學生:"; for(int j = 0;j<5;j++){ cin>>a[i][j]; } } cout<<"班級成績單"<<endl; cout<<"座號 國文 英文 數學 基電、物理 總分"<<endl; cout<<"=============================="<<endl; for(int i = 0;i<n;i++){ int score = 0; cout<<i+1; for(int j = 0;j<5;j++){ cout<<" "<<a[i][j]; score+=a[i][j]; } cout<<" "<<score; cout<<endl; } } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/rJHoivNr6.png) #### 執行結果 ![image](https://hackmd.io/_uploads/BJtEExMNp.png) ## 20231129 課堂作業 ### 第一道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ int a,b; cin>>a>>b; int x[a][b]; for(int i = 0;i<a;i++){ for(int j = 0;j<b;j++){ cin>>x[i][j]; } } for(int i = 0;i<a;i++){ for(int j = 0;j<b;j++){ cout<<"iArray["<<i<<"]["<<j<<"] = "<<x[i][j]<<endl; } } } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/Hkeh9vEr6.png) #### 執行結果 ![image](https://hackmd.io/_uploads/r1xsN2HVSa.png) ### 第二道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> using namespace std; int main(){ int score = 0; int a[5]; for(int i = 0;i<5;i++){ cin>>a[i]; score+=a[i]; } cout<<score<<endl; } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/H1Gc9PNHT.png) #### 執行結果 ![image](https://hackmd.io/_uploads/HyTD6SEHa.png) ### 第三道練習題 ``` //程式設計實習 資訊一甲 30號 鄭宇琋 #include<iostream> #include<algorithm> using namespace std; int main(){ int *p = new int[5]; for(int i = 0;i<5;i++){ cin>>p[i]; } cout<<"指標變數p所指向的記憶體起點:"<<p<<endl; sort(p,p+5); cout<<"最大值為"<<p[4]<<endl;; int *a = new int(p[4]); cout<<"最大值的記憶體位址:"<<a<<endl; delete[] p; } ``` #### 程式碼 ![image](https://hackmd.io/_uploads/S1YucPVB6.png) #### 執行結果 ![image](https://hackmd.io/_uploads/ryV-NLVBa.png) ## 20231206 課堂作業 ### 第一道練習題 ``` a004. 文文的求婚 #include<iostream> using namespace std; int main(){ int n; while(cin>>n){ if(n%400==0||n%4==0&&n%100!=0){ cout<<"閏年"<<endl; } else{ cout<<"平年"<<endl; } } } ``` #### (1)解題思路 閏年要如何判斷 #### (2)判斷流程圖 ![image](https://hackmd.io/_uploads/rktGVTII6.png) #### (3)選擇此題之原因,我學會了甚麼? 我一直想知道閏年怎麼辨別,我業照常學會 IF ELSE 的用法 ### 第二道練習題 ``` a005. Eva 的回家作業 #include<iostream> using namespace std; int main(){ int n; cin>>n; for(int i = 0;i<n;i++){ int a,b,c,d; cin>>a>>b>>c>>d; if(b-a==c-b&&c-b==d-c){ cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<d+(d-c)<<endl; } else if(b/a==c/b&&c/b==d/c){ cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<d*(d/c)<<endl; } } } ``` #### (1)解題思路 用等比和等差數列的原理 #### (2)判斷流程圖 ![image](https://hackmd.io/_uploads/SJ35_6ILa.png) #### (3)選擇此題之原因,我學會了甚麼? 可以順便複習等差數列和等比數列 ### 第三道練習題 ``` a006. 一元二次方程式 #include<iostream> #include<math.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; if((b*b)-(4*a*c)>0){ cout<<"Two different roots x1="<<(-b+sqrt((b*b)-(4*a*c)))/(2*a)<<" , x2="<<(-b-(sqrt((b*b)-(4*a*c))))/(2*a)<<endl; } else if((b*b)-(4*a*c) == 0){ cout<<"Two same roots x="<<(-b+sqrt((b*b)-(4*a*c)))/(2*a)<<endl; } else{ cout<<"No real root"<<endl; } } ``` #### (1)解題思路 利用公式解 #### (2)判斷流程圖 ![image](https://hackmd.io/_uploads/HJmxqaLL6.png) #### (3)選擇此題之原因,我學會了甚麼? 可以順便複習公式解 ![image](https://hackmd.io/_uploads/rkyHjAJPp.png) ![image](https://hackmd.io/_uploads/SyvIjCJva.png)