プログラミング実習II (2025) 課題
[T11] 第9章 構造体とユーザ定義型
struct roll { |
struct roll { |
struct roll my_data; |
//構造体 struct roll 型の宣言 |
(T11_1) [リスト 9.1] を入力し,コンパイル・実行せよ.その上で,上で記した注意に従ってプログラムを書き替えてコンパイル・実行せよ.
(T11_2) 次の手順に沿ってプログラムを完成せよ.
#include <stdio.h> /* ここで構造体を宣言 */ int main(void) { /* ここで構造体変数を定義 */ /* ここで構造体変数のメンバに値を代入 */ /* ここで日付の表示を行う */ return 0; } |
#include <stdio.h> /* ここで構造体を宣言 */ void print_day( struct date hiduke ){ /* ここで日付の表示 */ } int main(void) { /* ここで構造体変数を定義 */ /* ここで構造体変数のメンバに値を代入 */ print_day( myday ); return 0; } |
(T11_3) 次の手順に沿ってテストの点数から判定を行うプログラムを完成せよ.
(プログラム)
#include <stdio.h> void print_pass_fail( struct score a, struct score b ){ } int main( void ){ struct score myscore; struct score border; border.eng = 70; border.math = 55; myscore.eng = ??; myscore.math = ??; print_pass_fail( myscore, border ); myscore.eng = ??; myscore.math = ??; print_pass_fail( myscore, border ); myscore.eng = ??; myscore.math = ??; print_pass_fail( myscore, border ); myscore.eng = ??; myscore.math = ??; print_pass_fail( myscore, border ); return 0; } |
(T11_4) 次の手順に沿ってテストの点数を処理するプログラムを完成せよ.
(プログラム)
#include <stdio.h> #define N 10 int main(void) { struct student person[ N ] = { { 1005, 86, 75, 66, 0 }, { 1012, 65, 91, 70, 0 }, { 1043, 45, 75, 92, 0 }, { 1173, 97, 75, 76, 0 }, { 1224, 77, 77, 42, 0 }, { 1397, 27, 62, 54, 0 }, { 1500, 58, 85, 77, 0 }, { 1734, 80, 52, 66, 0 }, { 1888, 98, 93, 85, 0 }, { 1920, 60, 60, 70, 0 }, }; return 0; } |
(T11_5) 教科書 9.5.1項,およびキックオフC言語 10.1 節で説明されている typedef により,既存のデータ型(int など)に
対して別名をつけることができる.
例えば,
typedef unsigned int score_t; |
score_t a; |
unsigned int a; |
(T11_6)
前問で見た通り,typedef により,ユーザは新たに型名を定義できる.
typedef struct{ int y; int m; int d; } date_t; |