finished cls12

This commit is contained in:
2026-07-12 21:27:30 +09:00
parent 54df531af1
commit 5d8dfb667f
10 changed files with 231 additions and 0 deletions
+1
View File
@@ -1 +1,2 @@
.intermediates/ .intermediates/
src/build
Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.
Binary file not shown.
+98
View File
@@ -0,0 +1,98 @@
\documentclass[xelatex,a4paper,11pt,ja=standard]{bxjsarticle}
\usepackage{tex/preamble}
\usepackage{tex/simple-title}
\usepackage{subcaption}
\reportauthor{柴田健琉}
\reporttitle{情報処理2 - 前期第12回課題}
\reportdate{2026年}{07月}{07日}
\turnindate{2026年}{07月}{12日}
\begin{document}
\simpletitle
\section{はじめに}
この課題のプログラムは以下の環境での動作が確認されている.
\begin{itemize}
\item{OS: NixOS 26.05 Yarara, Linux 7.1.2 x86\_64}
\item{CC: GCC 15.2.0}
\item{CFLAGS: \texttt{-g -O1 -Wall -Wpedantic}}
\end{itemize}
\section{課題1}
授業資料内のサンプルコードに平均点数のエントリーを追加する.
\lstinputlisting[language=C]{./src/cls12/a1.c}
\subsection{実行結果}
\begin{figure}[tbh]
\centering
\includegraphics[width=12cm]{./assets/cls12-a1.png}
\caption{課題1の実行結果}
\end{figure}
\subsection{処理の流れ}
\begin{enumerate}
\item{構造体の配列\texttt{students}を宣言・定義する}
\item{\texttt{students}に対し, それぞれの要素の\texttt{english}, \texttt{mathematics}, \texttt{japanese}エントリーから平均を求め, \texttt{average}エントリーに代入}
\item{\texttt{students}の各要素の全エントリーを所定の書式に合わせて標準出力に表示させる}
\end{enumerate}
\subsection{書く際の難点}
ただ構造体にエントリーを1つ追加し, 平均値の計算を追加しただけなので特筆すべき難点はない.
\subsection{想定されるバグ}
浮動小数点数の誤差が考えられるが, 大抵は最小位の桁での誤差であり, また, 書式で小数点以下2桁しか表示しないので, 表示される数値に大きな誤差が生まれることはほとんど無い.
\newpage
\section{課題2}
課題1から平均点数を元に"A"から"D"までランク付けを行い, それぞれのランクの人数を記録する.
\lstinputlisting[language=C]{./src/cls12/a2.c}
\subsection{実行結果}
\begin{figure}[tbh]
\centering
\begin{minipage}[t]{0.95\textwidth}
\centering
\includegraphics[width=12cm]{./assets/cls12-a2-1.png}
\subcaption{Without \texttt{-D ALT\_DATA} Option}
\end{minipage}
\begin{minipage}[t]{0.95\textwidth}
\centering
\includegraphics[width=12cm]{./assets/cls12-a2-2.png}
\subcaption{With \texttt{-D ALT\_DATA} Option}
\end{minipage}
\caption{課題2の実行結果}
\end{figure}
\subsection{処理の流れ}
\begin{enumerate}
\item{構造体の配列\texttt{students}を宣言・定義する}
\item{\texttt{students}に対し, それぞれの要素の\texttt{english}, \texttt{mathematics}, \texttt{japanese}エントリーから平均を求め, \texttt{average}エントリーに代入}
\item{各ランクに属する人数を記録する整数型配列\texttt{grades}を宣言し, 0で初期化する}
\item{\texttt{students}に対し, 各要素の\texttt{average}エントリーの値の範囲を条件分岐で確認し, 文字型変数\texttt{grade}に対応するランクを代入し, \texttt{grades}の対応要素をインクリメントする}
\item{\texttt{students}の各要素の全エントリーとランクを所定の書式に合わせて標準出力に表示させる}
\item{\texttt{grades}の各要素を所定の書式に合わせて標準出力に表示させる}
\end{enumerate}
\subsection{書く際の難点}
課題1に分岐処理を追加するだけなので特筆すべき難点はない.
\subsection{想定されるバグ}
課題1同
\end{document}
+18
View File
@@ -0,0 +1,18 @@
include ../common.mk
PROJECT_NAME:=cls12
TGTS:=$(patsubst %.c,%,$(wildcard *.c))
all: $(TGTS) a2-alt
%: %.c
@mkdir -p $(BUILD_PATH)/$(PROJECT_NAME)
$(CC) $(CFLAGS) $^ -o $(BUILD_PATH)/$(PROJECT_NAME)/$@
a2-alt: a2.c
@mkdir -p $(BUILD_PATH)/$(PROJECT_NAME)
$(CC) $(CFLAGS) -D ALT_DATA $^ -o $(BUILD_PATH)/$(PROJECT_NAME)/$@
clean:
$(RM) -drf $(BUILD_PATH)/$(PROJECT_NAME)
+41
View File
@@ -0,0 +1,41 @@
#include <stdio.h>
#define STUDENTS_NUM 4
struct student {
char name[20];
int english;
int mathematics;
int japanese;
double average;
};
int main(void) {
struct student students[] = {
{ .name = "佐藤", .english = 82, .mathematics = 72, .japanese = 58 },
{ .name = "秋山", .english = 77, .mathematics = 82, .japanese = 79 },
{ .name = "永田", .english = 52, .mathematics = 62, .japanese = 39 },
{ .name = "藤田", .english = 61, .mathematics = 82, .japanese = 88 }
};
for (int i = 0; i < STUDENTS_NUM; i++) {
students[i].average = (double)(
students[i].english +
students[i].mathematics +
students[i].japanese
) / 3.f;
}
for (int i = 0; i < STUDENTS_NUM; i++) {
printf(
"%10s: 英語=%3d\t数学=%3d\t国語=%3d\t平均=%.2lf\n",
students[i].name,
students[i].english,
students[i].mathematics,
students[i].japanese,
students[i].average
);
}
return 0;
}
+73
View File
@@ -0,0 +1,73 @@
#include <stdio.h>
#define STUDENTS_NUM 4
struct student {
char name[20];
int english;
int mathematics;
int japanese;
double average;
};
int main(void) {
#ifdef ALT_DATA
struct student students[] = {
{ .name = "佐藤", .english = 89, .mathematics = 86, .japanese = 78 },
{ .name = "秋山", .english = 78, .mathematics = 65, .japanese = 79 },
{ .name = "永田", .english = 64, .mathematics = 33, .japanese = 53 },
{ .name = "藤田", .english = 89, .mathematics = 47, .japanese = 62 }
};
#else
struct student students[] = {
{ .name = "佐藤", .english = 82, .mathematics = 72, .japanese = 58 },
{ .name = "秋山", .english = 77, .mathematics = 82, .japanese = 79 },
{ .name = "永田", .english = 52, .mathematics = 62, .japanese = 39 },
{ .name = "藤田", .english = 61, .mathematics = 82, .japanese = 88 }
};
#endif
for (int i = 0; i < STUDENTS_NUM; i++) {
students[i].average = (double)(
students[i].english +
students[i].mathematics +
students[i].japanese
) / 3.f;
}
int grades[4] = {0};
for (int i = 0; i < STUDENTS_NUM; i++) {
char grade = 0;
int avg = students[i].average;
if (avg < 60) {
grade = 'D';
grades[3]++;
} else if (avg >= 60 && avg < 70) {
grade = 'C';
grades[2]++;
} else if (avg >= 70 && avg < 80) {
grade = 'B';
grades[1]++;
} else {
grade = 'A';
grades[0]++;
}
printf(
"%10s: 英語=%3d\t数学=%3d\t国語=%3d\t平均=%.2lf\t成績=%c\n",
students[i].name,
students[i].english,
students[i].mathematics,
students[i].japanese,
students[i].average,
grade
);
}
printf("成績: ");
for (int i = 0; i < 4; i++) {
printf("%c=%d人\t", 'A' + i, grades[i]);
}
putchar('\n');
return 0;
}