• 検索結果がありません。

–â‘èPDF N‰Èî•ñƒlƒbƒgƒ[ƒN“±“üƒ†ƒjƒbƒg‡UiCŒ¾Œê‡Uj

N/A
N/A
Protected

Academic year: 2018

シェア "–â‘èPDF N‰Èî•ñƒlƒbƒgƒ[ƒN“±“üƒ†ƒjƒbƒg‡UiCŒ¾Œê‡Uj"

Copied!
3
0
0

読み込み中.... (全文を見る)

全文

(1)

C言語Ⅱ 総合演習(3) 文字列, インタ,フ イル,構造体 ~ 1

C

言語Ⅱ

総合演習

(3)

文字列,ポインタ,ファイル,構造体

以下 問題 関 るプログラムを作成し,ソースプログラムを入力後,ビルド,実行し 実行結果を確認し さい.

実行 正しく確認 たら,プログラムをレポート用紙 写し,教員あるい TA 確認を受け 提出し さい.

お,レポート用紙 問題番号,学籍番号,氏名を必 書くこ .

問題1. 構造体 宣言

以 プログラ 動く う 部 追記 data型 配

列変数soft ンバ char型配列 int型 構

造体 タグ 省略 配列要素数 最 小さい こ

#include<stdio.h> //

int main(void){

data soft[2] = {{"FinalFantasy", 13}, {"Mingol", 5}}; int i;

printf("ソフ | 最新バー ョン¥n"); printf("---¥n");

for(i=0; i<2; i++){

printf(" %12s | %14d¥n", soft[i].name, soft[i].version); }

return 0; }

実行結果例

ソフト 名 | 最新バージョン

--- FinalFantasy | 13 Mingol | 5

問題 . 構造体 typedef宣言、構造体 配列

次 ンバ 持 構造体 typedef宣言 使用 data型

準備 さい typedef宣言 い 構造体タグ 省略

さい

char型 配列変数id 配列要素数:8

int型 変数age double型 変数eval

こ data型 配列変数player 要素数2 宣言 続い 右

実行結果 示 う キーボー 入力 2 情報 player

代入 後 2 情報 表示 プログラ 作成 さい

実行結果例

ID番号:0210001 年齢:19

評価:8.2

ID番号:0130002 年齢:20

評価:8.5

ID番号=0210001 年齢=19[歳] 評価=8.2[点]

ID番号=0130002 年齢=20[歳] 評価=8.5[点]

(2)

C言語Ⅱ 総合演習(3) 文字列, インタ,フ イル,構造体 ~ 2

問題 . 構造体 typedef宣言、メンバ 設定、ファイル

4 ID番号 年齢 評価 次 内容 test813.txtフ イル 作成

さい(半角 ペー 区 )

0210001 19 8.2 0130002 20 8.5 0210001 19 9.7 0320012 18 7.8

ID番号(7桁) 年齢(3桁) 評価(0.0~10.0点) 3種類 ータ 格納

構造体 typedef宣言 用い data型 作成 さい( ンバ 型 左

順 char型 int型 double型 ンバ 自由 決 い)

続い 4 情報 格納 配列変数 student data 型 宣 言 test813.txtフ イル 4 情報 配列変数student 要素 読 込

後 4 情報 右 う 表示 プログラ 作成 さい

実行結果例

ID番号 年齢 評価

(3)

C言語Ⅱ 総合演習(3) 文字列, インタ,フ イル,構造体 ~ 3

問題 . 構造体 型宣言(応用)、構造体 配列、メンバ 初期化

構造体 使 プログラ あ こ プログラ 中

示 5行 次 1行 置 換え さい

double point[5]; //

こ プログラ 正常 動作 う 5行 削除

for文 書 換え さい for文 カ ン 変数

追記 こ プログラ 書 換え 前 実行

結果 書 換え 後 結果 う こ

#include<stdio.h>

struct data { char name[20]; double point0; // double point1; // double point2; // double point3; // double point4; // int seq;

};

int main(void){ int i; //

struct data list[3]={{"Tanaka", 9.2, 8.5, 9.0, 8.2, 9.1, 1}, {"Kawata", 9.0, 8.8, 9.3, 9.0, 8.7, 2}, {"Koyama", 8.5, 9.2, 9.1, 8.9, 9.3, 3} };

for(i=0; i<3; i++){

printf("%s", list[i].name); printf(", %.1f", list[i].point0); // printf(", %.1f", list[i].point1); // printf(", %.1f", list[i].point2); // printf(", %.1f", list[i].point3); // printf(", %.1f", list[i].point4); // printf(", %d¥n", list[i].seq); }

return 0; }

実行結果例

Tanaka, 9.2, 8.5, 9.0, 8.2, 9.1, 1 Kawata, 9.0, 8.8, 9.3, 9.0, 8.7, 2 Koyama, 8.5, 9.2, 9.1, 8.9, 9.3, 3

※ 部はキー ート入力です。

参照

関連したドキュメント

Theorem 3 implies strong asymptotic stability results: the energy of strong solutions decays to zero, with an explicit decay rate

There is a bijection between left cosets of S n in the affine group and certain types of partitions (see Bjorner and Brenti (1996) and Eriksson and Eriksson (1998)).. In B-B,

Actually a similar property shall be first de- rived for a general class of first order systems including the transport equation and Schr¨odinger equations.. Then we shall consider

Hence, the degree theory constructed in [1] is an extension of the classical Leray–Schauder degree in Hilbert space.. It is unique, single-valued and has the usual properties of

Lair and Shaker [10] proved the existence of large solutions in bounded domains and entire large solutions in R N for g(x,u) = p(x)f (u), allowing p to be zero on large parts of Ω..

We prove a continuous embedding that allows us to obtain a boundary trace imbedding result for anisotropic Musielak-Orlicz spaces, which we then apply to obtain an existence result

This concludes the proof that the Riemann problem (1.6) admits a weak solution satisfying the boundary condition in the relaxed sense (1.6c).... The two manifolds are transverse and

This paper is a sequel to [1] where the existence of homoclinic solutions was proved for a family of singular Hamiltonian systems which were subjected to almost periodic forcing...