プログラミング基礎

Similar documents
プログラミング基礎

プログラミング基礎

Microsoft PowerPoint - handout07.ppt [互換モード]

Microsoft PowerPoint - 12.ppt [互換モード]

プログラミング方法論 II 第 14,15 回 ( 担当 : 鈴木伸夫 ) 問題 17. x 座標と y 座標をメンバに持つ構造体 Point を作成せよ 但し座標 は double 型とする typedef struct{ (a) x; (b) y; } Point; 問題 18. 問題 17 の

Microsoft PowerPoint - 13.ppt [互換モード]

DVIOUT

演習課題No12

(2) 構造体変数の宣言 文法は次のとおり. struct 構造体タグ名構造体変数名 ; (1) と (2) は同時に行える. struct 構造体タグ名 { データ型変数 1; データ型変数 2;... 構造体変数名 ; 例 : struct STUDENT{ stdata; int id; do

Microsoft PowerPoint - 12.ppt [互換モード]

演算増幅器

C 言語講座 Vol 年 5 月 29 日 CISC

memo

02: 変数と標準入出力

基礎プログラミング2015

C プログラミング演習 1( 再 ) 2 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ

DVIOUT

Microsoft Word - no13.docx

02: 変数と標準入出力

今回のプログラミングの課題 ( 前回の課題で取り上げた )data.txt の要素をソートして sorted.txt というファイルに書出す ソート (sort) とは : 数の場合 小さいものから大きなもの ( 昇順 ) もしくは 大きなものから小さなもの ( 降順 ) になるよう 並び替えること

PowerPoint プレゼンテーション

Prog1_15th

講習No.12

バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科

PowerPoint プレゼンテーション

kiso2-09.key

配列, 関数, 構造体

Microsoft PowerPoint - C4(反復for).ppt

Taro-リストⅠ(公開版).jtd

JavaプログラミングⅠ

Microsoft Word - no15.docx

PowerPoint Presentation

Prog1_6th

PowerPoint プレゼンテーション

問 2 ( 型変換 ) 次のプログラムを実行しても正しい結果が得られない 何が間違いかを指摘し 正しく修正せよ ただし int サイズが 2 バイト long サイズが 4 バイトの処理系での演算を仮定する #include <stdio.h> int main( void ) { int a =

ゲームエンジンの構成要素

Microsoft PowerPoint - 12Chap16.ppt

/*Source.cpp*/ #include<stdio.h> //printf はここでインクルードして初めて使えるようになる // ここで関数 average を定義 3 つの整数の平均値を返す double 型の関数です double average(int a,int b,int c){

Microsoft PowerPoint - 13th.ppt [互換モード]

memo

Microsoft PowerPoint - 計算機言語 第7回.ppt

講習No.10

Java 基礎問題ドリル ~ メソッドを理解する ~ 次のプログラムコードに 各設問の条件にあうメソッドを追加しなさい その後 そのメソッドが正しく動作することを検証するためのプログラムコードを main メソッドの中に追加しなさい public class Practice { // ここに各設問

PowerPoint Presentation

memo

情報処理演習 B8クラス

Microsoft Word - 3new.doc

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdiu.h> #define InFile "data.txt" #define OutFile "surted.txt" #def

PowerPoint プレゼンテーション

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード]

Microsoft PowerPoint - lec10.ppt

JavaプログラミングⅠ

cp-7. 配列

Microsoft Word - no12.doc

PowerPoint Presentation

Taro-ポインタ変数Ⅰ(公開版).j

<4D F736F F D20438CBE8CEA8D758DC03389F0939A82C282AB2E646F63>

模擬試験問題(第1章~第3章)

program7app.ppt

8 / 0 1 i++ i 1 i-- i C !!! C 2

Microsoft PowerPoint - exp2-02_intro.ppt [互換モード]

memo

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdio.h> #define InFile "data.txt" #define OutFile "sorted.txt" #def

関数の動作 / printhw(); 7 printf(" n"); printhw(); printf("############ n"); 4 printhw(); 5 関数の作り方 ( 関数名 ) 戻り値 ( 後述 ) void である. 関数名 (

Microsoft Word - Cプログラミング演習(12)

Microsoft Word - Training10_プリプロセッサ.docx

Microsoft PowerPoint - prog07.ppt

PowerPoint プレゼンテーション

Microsoft PowerPoint - prog08.ppt

プログラミング実習I

PowerPoint Presentation

Microsoft Word - no204.docx

Microsoft PowerPoint - kougi9.ppt

gengo1-10

Microsoft Word - no202.docx

Microsoft PowerPoint ppt

第3回 配列とリスト

講習No.1

DVIOUT

ープのロープ長以下であれば実現可能である ケース 3: 3 本のロープの杭の位置を点 P 1 = (x 1, y 1, 0), 点 P 2 = (x 2, y 2, 0), 点 P 3 = (x 3, y 3, 0) とする 点 P 1 = (x 1, y 1, 0), 点 P 2 = (x 2,

C C UNIX C ( ) 4 1 HTML 1

Microsoft Word - Cプログラミング演習(7)

PowerPoint プレゼンテーション

データ構造

プログラミング実習I

Microsoft Word - no11.docx

目次

Microsoft PowerPoint - 09.pptx

物質工学科 田中晋

情報処理Ⅰ演習

講習No.9

スライド 1

第9回 配列(array)型の変数

Microsoft PowerPoint - kougi11.ppt

kiso2-03.key

RX ファミリ用 C/C++ コンパイラ V.1.00 Release 02 ご使用上のお願い RX ファミリ用 C/C++ コンパイラの使用上の注意事項 4 件を連絡します #pragma option 使用時の 1 または 2 バイトの整数型の関数戻り値に関する注意事項 (RXC#012) 共用

C言語7

ポインタ変数

Microsoft Word - Cプログラミング演習(1)_2012

コマンドラインから受け取った文字列の大文字と小文字を変換するプログラムを作成せよ 入力は 1 バイトの表示文字とし アルファベット文字以外は変換しない 1. #include <stdio.h> 2. #include <ctype.h> /*troupper,islower,isupper,tol

Transcription:

C プログラミング 演習 プログラミング基礎 II 演習 II 2012 年 12 月 10 日 第 11 回

今後の予定 2012/12/10 C プログラミング及びプログラミング演習 II 2 2012/12/17 期末試験 (60 分間 ) 場所 :A0542 時間 :4 時限 (15:00~16:00) 2012/12/16 課題の最終提出締切

課題の提出方法 電子メールで提出 提出先 ( 宛先 ) - hcilab@rs.kagu.tus.ac.jp メールの題名 ( 件名 ) - 後期第 回課題学籍番号例 ) 後期第 11 回課題 J123456 Jは大文字 ハイフン (-) はいらない 第 回の は及び学籍番号は半角数字 メールの本文 - 課題のプログラムをそのまま記述 2012/12/10 Cプログラミング及びプログラミング演習 II 3

2012/12/10 C プログラミング及びプログラミング演習 II 4 プログラミングの習得 プログラミング言語を学ぶ唯一の方法は プログラムを書いてみること 練習課題, 提出課題の実行 習うより慣れろ というのが経験的な習得方法

2012/12/10 Cプログラミング及びプログラミング演習 II 5 C プログラミング 演習 プログラミング基礎 II 演習 II 2012 年 12 月 10 日 第 11 回

2012/12/10 C プログラミング及びプログラミング演習 II 6 #include < stdio.h > #include < math.h > struct point int x; int y; ; double length(struct point a1, struct point a2) double xx, yy; xx = (a1.x - a2.x) * (a1.x - a2.x); yy = (a1.y - a2.y) * (a1.y - a2.y); return sqrt(xx + yy); // sqrt(x) は x の平方根を求める void main() struct point p1, p2; double a; 実行後の a の値を示せ. p1.x = 2; p1.y = 1; p2.x = 5; p2.y = -3; a = length(p1, p2); これまでの復習 1 #include < stdio.h > struct exam int a; double b; ; 2 #include < stdio.h > struct bunsu int m; int n; ; 3 struct exam set(int x, int y) struct exam result; result.a = x; result.b = (double)y/x; return result; void main() double a; struct exam hensu; hensu = set(50, 120); a = hensu.b; struct bunsu seki(struct bunsu X, struct bunsu Y) struct bunsu ans; ans.m = X.m * Y.m; ans.n = X.n * Y.n; return ans; void main() struct bunsu A = 10, 3; struct bunsu B = 6, 5; struct bunsu C = 2, 7; struct bunsu D; int a; D = seki(a, seki(b, C)); a = D.n;

2012/12/10 C プログラミング及びプログラミング演習 II 7 今日の課題の URL http://www015.upp.so-net.ne.jp /class/sec_ex11.html 復習構造体について

2012/12/10 C プログラミング及びプログラミング演習 II 8 構造体 構造体とは複数の ( 異なる型の ) 変数を1つの変数に格納することが可能な変数例 ) 構造体 health は以下の全ての情報を格納する 名前 (char 型 ) 年齢 (int 型 ) health 身長 (double 型 ) 名前 年齢 身長 体重 体重 (double 型 )

構造体の宣言 main 関数の前に構造体を宣言する struct 構造体の名前 ( 構造体タグ ) ; 構造体内部で使う変数 ( メンバ ) の宣言 例 ) struct health ; char name[100];// 名前 int age; // 年齢 double length; // 身長 double weight;// 体重 構造体 health char int double double name age length weight 2012/12/10 C プログラミング及びプログラミング演習 II 9

構造体変数の宣言 <stdio.h> struct health char name[100]; int age; double length; double weight; ; // 名前 // 年齢 // 身長 // 体重 void main() struct health konishi; struct health yamada; struct health taro, hanako;... struct 構造体タグ変数名 ; 2012/12/10 C プログラミング及びプログラミング演習 II 10

2012/12/10 C プログラミング及びプログラミング演習 II 11 構造体への値の代入と参照 struct health taro; taro.id= 13066; taro.age = 20; taro.length = 180.0; taro.weight = 70.0; struct health int id; int age; double length; double weight; ; // 学籍番号 // 年齢 // 身長 // 体重 printf( 学籍番号 :%d, 年齢 :%d n, taro.id, taro.age); printf( 身長 :%f, 体重 %f n, taro.length, taro.weight); 変数名 (taro). メンバ名 (id, age, length, weight) で参照と代入ができる

2012/12/10 C プログラミング及びプログラミング演習 II 12 構造体変数の宣言 2 struct health int id; int age; double length; double weight; ; // 学籍番号 // 年齢 // 身長 // 体重 struct health taro= 13066, 20, 180.0, 70.0 ; struct health int name[100]; int age; double length; double weight; ; // 名前 // 年齢 // 身長 // 体重 struct health taro= Taro YAMADA, 20, 180.0, 70.0 ;

構造体の配列 struct score int math; int english; double average; ; main() struct score student[100]; student[0].math = 100; student[0].english = 10; student[1].math = 50;... 宣言 :struct 構造体タグ配列変数名 [ 個数 ]; 参照及び代入 : 配列変数名 [ 番号 ]. メンバ 2012/12/10 C プログラミング及びプログラミング演習 II 13

2012/12/10 C プログラミング及びプログラミング演習 II 14 復習 1 #include < stdio.h > #include < math.h > 1 point struct point int x; int y; ; double length(struct point a1, struct point a2) double xx, yy; x y xx = (a1.x - a2.x) * (a1.x - a2.x); yy = (a1.y - a2.y) * (a1.y - a2.y); return sqrt(xx + yy); // sqrt(x) は x の平方根を求める void main() struct point p1, p2; double a; p1.x = 2; p1.y = 1; p2.x = 5; p2.y = -3; a = length(p1, p2); y p1 (2, 1) a p2 (5, -3) x a = 5

2012/12/10 C プログラミング及びプログラミング演習 II 15 復習 2 #include < stdio.h > struct exam int a; double b; ; struct exam set(int x, int y) struct exam result; 2 構造体を返す exam a b result.a = x; result.b = (double)y/x; return result; void main() double a; set(50, 120) hensu a struct exam hensu; hensu = set(50, 120); a = hensu.b; b a = hensu.b a = 2.4

2012/12/10 C プログラミング及びプログラミング演習 II 16 復習 3 #include < stdio.h > struct bunsu int m; int n; ; struct bunsu seki(struct bunsu X, struct bunsu Y) struct bunsu ans; ans.m = X.m * Y.m; ans.n = X.n * Y.n; return ans; 3 構造体を引数 構造体を返す bunsu m n A B C void main() struct bunsu A = 10, 3; struct bunsu B = 6, 5; struct bunsu C = 2, 7; struct bunsu D; int a; 10 3 6 5 2 7 D = seki(a, seki(b, C)); a = D.n; D = A (B C) a = D.n a = 105

Kadai11.txt からデータを構造体配列 UEFA[] に読み込み, 試合数 (match) や得点 (score) の平均を求める関数 UEFA_ave(), 試合数や得点の最大値及び最小値を求める関数 UEFA_MaxMin() を完成させよ 名前 (name) をアルファベットの昇順 (A Z) に並べ替える関数 UEFA_sort1(), チーム名 (team) をアルファベットの降順 (Z A) に並べ替える関数 UEFA_sort2() を完成させよ 各結果をファイル (Result11.txt) 及び通常出力するプログラムを完成させよ Kadai11.txt は名前, チーム, 試合数, 得点の順で 6 名分のデータとなっている 表示例 Messi Barcelona 14 21 Ronaldo RealMadrid 14 13 Uchida Schalke 10 1 Nagatomo InterMilan 14 0 Ibrahimovic PSG 12 13 Pirlo Juventus 13 3 提出期限 :2012/12/14( 金 )24:00 提出先 :hcilab@rs.kagu.tus.ac.jp 提出課題 平均試合数 =??? 最大値 =??, 最小値 =?? 平均得点 =??? 最大値 =??, 最小値 =?? 名前の並べ替え Ibrahimovic PSG 12 13... Uchida Schalke 10 1 チーム名の並べ替え Messi Barcelona 14 21... Uchida Schalke 10 1 2012/12/10 Cプログラミング及びプログラミング演習 II 17

課題の提出に関して 電子メールで提出 提出先 ( 宛先 ) - hcilab@rs.kagu.tus.ac.jp メールの題名 ( 件名 ) - 後期第 回課題学籍番号例 ) 後期第 11 回課題 J123456 Jは大文字 ハイフン (-) はいらない 第 回の は及び学籍番号は半角数字 メールの本文 - 課題のプログラムをそのまま記述 2012/12/10 Cプログラミング及びプログラミング演習 II 18