diff --git a/assets/cls09-a1.png b/assets/cls09-a1.png new file mode 100644 index 0000000..cf0ad81 Binary files /dev/null and b/assets/cls09-a1.png differ diff --git a/assets/cls09-a2.png b/assets/cls09-a2.png new file mode 100644 index 0000000..10b289c Binary files /dev/null and b/assets/cls09-a2.png differ diff --git a/assets/cls09-a3.png b/assets/cls09-a3.png new file mode 100644 index 0000000..e72df43 Binary files /dev/null and b/assets/cls09-a3.png differ diff --git a/out/report-cls09.pdf b/out/report-cls09.pdf new file mode 100644 index 0000000..d84e400 Binary files /dev/null and b/out/report-cls09.pdf differ diff --git a/out/report-cls09.synctex.gz b/out/report-cls09.synctex.gz new file mode 100644 index 0000000..91d6fc2 Binary files /dev/null and b/out/report-cls09.synctex.gz differ diff --git a/report-cls09.tex b/report-cls09.tex new file mode 100644 index 0000000..a9d2549 --- /dev/null +++ b/report-cls09.tex @@ -0,0 +1,68 @@ +\documentclass[xelatex,a4paper,11pt,ja=standard]{bxjsarticle} + +\usepackage{tex/preamble} +\usepackage{tex/simple-title} + +\reportauthor{柴田健琉} +\reporttitle{情報処理2 - 前期第9回課題} +\reportdate{2026年}{06月}{16日} +\turnindate{2026年}{06月}{16日} + +\begin{document} + \simpletitle + + \section{はじめに} + + この課題のプログラムは以下の環境での動作が確認されている: + + \begin{itemize} + \item{OS: NixOS 26.05 Yarara, Linux 7.0.12 x86\_64} + \item{CC: GCC 15.2.0} + \item{CFLAGS: \texttt{-g -O1 -Wall -Wpedantic}} + \item{デバッガ: GNU gdb (GDB) 17.1} + \end{itemize} + + \section{課題1 - 演習10-1} + + 教科書の演習10-1の\texttt{adjust\_point}関数を作成する. + + \lstinputlisting[language=C,caption={課題1のプログラム}]{./src/cls09/a1.c} + + \newpage + + \subsection{実行結果} + + \begin{figure}[tbh] + \centering + \includegraphics[width=10cm]{./assets/cls09-a1.png} + \caption{課題1の実行結果} + \end{figure} + + \section{課題2 - 演習10-2} + + 教科書の演習10-2の\texttt{increment\_date}と\texttt{decrement\_date}関数を作成する. なお, 閏年は考慮しないものとする. + + \lstinputlisting[language=C,caption={課題2のプログラム}]{./src/cls09/a2.c} + + \subsection{実行結果} + + \begin{figure}[tbh] + \centering + \includegraphics[width=10cm]{./assets/cls09-a2.png} + \caption{課題2の実行結果} + \end{figure} + + \section{課題3 - 演習10-3} + + 教科書の演習10-3の\texttt{sort3}関数を作成する. + + \lstinputlisting[language=C,caption={課題3のプログラム}]{./src/cls09/a3.c} + + \subsection{実行結果} + + \begin{figure}[tbh] + \centering + \includegraphics[width=10cm]{./assets/cls09-a3.png} + \caption{課題3の実行結果} + \end{figure} +\end{document} diff --git a/src/cls09/Makefile b/src/cls09/Makefile new file mode 100644 index 0000000..feb36c8 --- /dev/null +++ b/src/cls09/Makefile @@ -0,0 +1,14 @@ +include ../common.mk + +PROJECT_NAME:=cls09 + +TGTS:=$(patsubst %.c,%,$(wildcard *.c)) + +all: $(TGTS) + +%: %.c + @mkdir -p $(BUILD_PATH)/$(PROJECT_NAME) + $(CC) $(CFLAGS) $^ -o $(BUILD_PATH)/$(PROJECT_NAME)/$@ + +clean: + $(RM) -drf $(BUILD_PATH)/$(PROJECT_NAME) diff --git a/src/cls09/a1.c b/src/cls09/a1.c new file mode 100644 index 0000000..3f268cc --- /dev/null +++ b/src/cls09/a1.c @@ -0,0 +1,21 @@ +#include + +void adjust_point(int *n) { + if (*n < 0) { + *n = 0; + } else if (*n > 100) { + *n = 100; + } +} + +int main(void) { + int d = 0; + + printf("Input integer: "); + scanf("%d", &d); + + adjust_point(&d); + printf("Result: %d\n", d); + + return 0; +} diff --git a/src/cls09/a2.c b/src/cls09/a2.c new file mode 100644 index 0000000..fe2f0cf --- /dev/null +++ b/src/cls09/a2.c @@ -0,0 +1,76 @@ +#include +#include + +#define BUFFSZ 32 + +const int DAYS_IN_MONTH[12] = { + 31, + 28, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31 +}; + +void increment_date(int *year, int *month, int *day) { + (*day)++; + + if (*day > DAYS_IN_MONTH[*month - 1]) { + *day = 1; + (*month)++; + } + + if (*month > 12) { + *month = 1; + (*year)++; + } +} + +void decrement_date(int *year, int *month, int *day) { + (*day)--; + + if (*day < 1) { + (*month)--; + if (*month < 1) { + *month = 12; + (*year)--; + } + *day = DAYS_IN_MONTH[*month - 1]; + } +} + +int main(void) { + char *buff = (char*)malloc(sizeof(char) * BUFFSZ); + + int m, d, y; + printf("Input date in mm/dd/yyyy: "); + fgets(buff, BUFFSZ, stdin); + sscanf(buff, "%d/%d/%d", &m, &d, &y); + + + char opr_in; + while (1) { + printf("Select operation [+/-]: "); + opr_in = getc(stdin); + if (opr_in == '+') { + increment_date(&y, &m, &d); + printf("Tomorrow is %02d/%02d/%4d\n", m, d, y); + break; + } else if (opr_in == '-') { + decrement_date(&y, &m, &d); + printf("Yesterday was %02d/%02d/%4d\n", m, d, y); + break; + } else { + printf("Error: Please input correct operation mode.\n"); + } + } + + + return 0; +} diff --git a/src/cls09/a3.c b/src/cls09/a3.c new file mode 100644 index 0000000..f312f78 --- /dev/null +++ b/src/cls09/a3.c @@ -0,0 +1,26 @@ +#include + +void swap(int *a, int *b) { + int t = *a; + *a = *b; + *b = t; +} + +void sort3(int *x, int *y, int *z) { + if (*x > *y) swap(x, y); + if (*y > *z) swap(y, z); + if (*x > *y) swap(x, y); +} + +int main(void) { + int a,b,c; + + printf("Input 3 integers separated by ',': "); + scanf("%d,%d,%d", &a, &b, &c); + + sort3(&a, &b, &c); + + printf("Result: %d, %d, %d\n", a, b, c); + + return 0; +}