サンプルと下敷き


基本的なページ: basics.html
<html>
<head>
<title>題目</title>
</head>
<body>
<h1>題目</h1>

<h2>最初の節</h2>

イントロダクション。

<h2>第二節</h2>

<h3>最初の小さい節</h3>

ひとつめについては
<ol>
<li> 数字付き箇条書き
<li> その二つ目
</ol>
に対して
<ul>
<li> 単なる箇条書き
<li> その二つ目
</ul>
となる。
また,説明箇条書きは
<dl>
<dt>最初の項目
<dd>その説明や定義などを書いて説明することができる。
<a href="http://www.tohoku.ac.jp/">東北大学のホームページ</a>にも
説明があります。というのがアンカータグによるハイパーリンク。
<dt>二つ目の項目
<dd>その説明や定義などを書いて説明することができる。
長くしてもいい。
</dl>
となる。

<h3>式について</h3>

正弦関数
<pre>
f(x)=sin x
</pre>
くらいしか書けません。

<h2>授業では教えない表など</h2>

<P>
<IMG alt="仙台" src="smphoto.jpg" width="100" align="left">
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
写真を左に入れて,文章を巻き込ませることもできます。
<!--コメント行,以下の<br clear="left">は必要です.-->
<BR clear=left>
</P>

<p>
表は授業では教えませんが。
</p>

<center>
<table border="3">
<caption>2次方程式の解</caption>
<tr align="center">
<th width="30"> a </th> <th width="30"> b </th> <th width="30"> c </th> 
<th width="30"> x<sub>1</sub> </th> <th width="30"> x<sub>2</sub> </th>
</tr>
<tr align="center">
<td> 1 </td> <td> 2 </td> <td> 1 </td> <td> -1 </td> <td> -1 </td>
</tr>
<tr align="right">
<td> 1 </td> <td> -2 </td> <td> -3 </td> <td> 3 </td> <td> -1 </td>
</tr>
</table>
</center>

<p>
最後の行には署名をしましょう。
</p>

<address>
氏名 <br>
2009年5月1日
</address>
</body>
</html>

履歴書と趣味(ホームページ)未完成: vita.html
<html>
<head>
<title>略歴と趣味</title>
</head>
<body>

<h1>略歴と趣味</h1>
<p align="right">
<img src="./myface.jpg" height="130">
</p>

<h2>略歴</h2>

<dl>
<dt> 氏名:
<dd> 南野何某
<dt> 生年月日:
<dd> 1993年4月10日(○曜日)
<dt> 学歴:
<dd> 小学校以降
<dl>
<!-- 以下が略歴 -->
<dt> 2005年3月25日
<dd> ゆとり小学校卒業
<dt> 2005年4月1日
<dd> 詰め込み中学校入学
<dt> 2008年3月27日
<dd> ・・・
<!-- 以上が略歴:大学入学まで -->
</dl>
</dl>

<h2>趣味</h2>

<h3>趣味一覧</h3>

<p>
勉強をあまりしなかったこともあって,
趣味は多彩である。そのうちの代表を挙げると
<ol>
<li> 甲冑の製作と販売
<li> トライアスロン
<li> ・・・・・
</ol>
のようになる。
</p>

<h3>一番熱心な趣味について</h3>

<p>
その中で一番熱中したのが最初の「甲冑の政策と販売」である。
その訳は・・・なんたらかんたら。
</p>

<p>
これまでの成果として,○○展示コーナーに自作の・・・・
</p>

<hr>
<address>
南野何某,2011年5月27日<br>
情報基礎B宿題
</body>
</html>

履歴書と趣味(LaTeX 文書)未完成: vita.tex
\documentclass[a4paper]{jarticle}
\usepackage{graphicx}
\title{略歴と趣味}
\author{南野何某}
\begin{document}

\maketitle

\begin{flushright}
\includegraphics*[height=3cm]{myface.ps}
\end{flushright}

\section{略歴}

\begin{description}
\item[氏名:] 南野何某
\item[生年月日:] 1993年4月10日(○曜日)
\item[学歴:] 小学校以降
\begin{description}
%  以下が略歴
\item[2005年3月25日] ゆとり小学校卒業
\item[2005年4月1日] 詰め込み中学校入学
\item[2008年3月27日] ・・・
%  以上が略歴:大学入学まで
\end{description}
\end{description}

\section{趣味}

\subsection{趣味一覧}

勉強をあまりしなかったこともあって,
趣味は多彩である。そのうちの代表を挙げると
\begin{enumerate}
\item 甲冑の製作と販売
\item トライアスロン
\item ・・・・・
\end{enumerate}
のようになる。

\subsection{一番熱心な趣味について}

その中で一番熱中したのが最初の「甲冑の政策と販売」である。
その訳は・・・なんたらかんたら。

これまでの成果として,○○展示コーナーに自作の・・・・

\end{document}

四則計算(未完成): Arithmetic.java
import java.io.*;
import java.math.*;
class Arithmetic
{
    public static void main(String[] args) throws IOException
    {
    int a, b, add, sub, mul, div, rem;
    String strx;
    BufferedReader br = // 何かキーボードから入力した文字のバッファ
        new BufferedReader(new InputStreamReader(System.in));

    System.out.println("Arithmetic of a and b");

    System.out.print("Enter a: ");
    strx = br.readLine();
    a = Integer.parseInt(strx);

    System.out.print("Enter b: ");
    strx = br.readLine();
    b = Integer.parseInt(strx);

    System.out.println("a = " + a + ": b = " + b);

    add = a + b;
    sub = ....; // 引き算・掛け算・割り算・余り計算は自分で入力

    System.out.println(" addition = " + add);
    System.out.println(" subtraction = " + sub);
    System.out.println(" multiplication = " + mul);
    System.out.println(" division = " + div);
    System.out.println(" remainder = " + rem);
    }
}

蛇馬源吾君のお小遣い計算: Allowance.java
import java.io.*;
import java.math.*;
class Allowance
{
    public static void main(String[] args) throws IOException
    {
    int i, total;
    total = 0;

    for(i=1; i<=30; i++)
        {
        total = total + i;
        System.out.println("Saving at " + i + "-th date is " + total + "yen.");
        }
    }
}

蛇馬源吾君のお小遣い計算:5日置きにたくさんもらえるバージョン: Allowance2.java
import java.io.*;
import java.math.*;
class Allowance2
{
    public static void main(String[] args) throws IOException
    {
    int i, total;
    total = 0;

    for(i=1; i<=30; i++)
        {
        if (i % 5 == 0) { // 5 で割り切れた日だけ
        total = total + 50;
            } else {
        total = total + i;
            }
        System.out.println("Saving at " + i + "-th date is " + total + "yen.");
        }
    }
}

階数の計算(未完成): Factorial.java
// これは,蛇馬源吾君のお小遣いプログラムを下敷きにすればできます。
import java.io.*;
import java.math.*;
class Factorial
{
    public static void main(String[] args) throws IOException
    {
    int i, fact;
    fact = ????; // 初期値ですよ

    for(i=1; i<=10; i++)
        {
        ..... // ここらへんを考えましょう
        System.out.println(i + "! = " + fact);
        }
    }
}

数字を分類する: Na beats you!(未完成): Nabeatsu.java
import java.io.*;
import java.math.*;
class Nabeatsu
{
    public static void main(String[] args) throws IOException
    {
    int i, total;
    total = 0;

    for(i=1; i<=50; i++)
        {
        if (i % 5 == 0) { // 5 で割り切れ
            .....
            System.out.println(i + ": [gee]");
            .....
             // 3 や 15 で割り切れる?
            }
        }
    }
}

ハイローゲーム(未完成): Hilo.java
import java.io.*;
import java.math.*;
class Hilo
{
    public static void main(String[] args) throws IOException
    {
    int i, target, guess;
    String strx;

    target = (int) (100. * Math.random());
    guess = -10;

    BufferedReader br = // 何かキーボードから入力した文字のバッファ
        new BufferedReader(new InputStreamReader(System.in));

    for(i=1; i<=10; i++)
        {
            System.out.print("Enter your guess: ");
            strx = br.readLine();
            guess = Integer.parseInt(strx);

        .... if (guess == target) とか guess < target とかで分岐
        }
        // この 10 回以内のループで大小をおしえてもらって,最後に

        // 例えば・・・
    if (guess == target) {
        System.out.println("You win!");
        } else {
        System.out.println("You lose!");
        }
    }
}

素数を取り出す(未完成): Primenumber.java

宿題にはしないが,ぜひとも自分で作ってみて欲しい。

import java.io.*;
import java.math.*;
class Primenumber
{
    public static void main(String[] args) throws IOException
    {
    int i, j, max, judge;

    for(i=3; i<=50; i++)
        {
        max = i-1;
        judge = 0;
        for(j=2; j<=max; j++)
            {
            if (i % j == 0) { // no prime number
                ..... ; // 何かする。1 行とは限らない
                }
            }
        if (judge == 0) System.out.println(i + " is a prime number.");
        }
    }
}

2分法(未完成): Bisection.java
import java.io.*;
import java.math.*;
class Bisection
{
    public static void main(String[] args) throws IOException
    {
        double xl = 3., xh = 4., fl, fh, x = 0., f, eps = 0.000001;
        int n;
        fl = Math.sin(xl);
        fh = Math.sin(xh);
        for(n=1; n<=1000; n++)
            {
            x = ( xl + xh ) / 2.; // ..... 中間の値
            if (( x - xl ) / xl < eps) {
                break; // 式(K.7) の判定で所定の精度が得られたので探索を中断!
            }
            f = Math.sin(x); // ..... 式(K.5)
            // 次の(n+1) ループ用のxl, xh, fl, fh を式(K.6) で求めて次の探索!
            if (fl * f > 0.) { // 小さい方のx を変更
                .....
            } else { // 大きい方のx を変更
                .....
            }
        System.out.println("At " + n + "-th step: x = " + x);
        }
        System.out.println("Answer: x = " + x );
        System.out.println(" Exact Pi = " + Math.PI);
    }
}

公式で桁落ちしない2次方程式の求根(未完成): Betterquad.java
import java.io.*;
class Betterquad
{
    public static void main(String[] args) throws IOException
    {
        double a, b, c, d, x, y; // 倍精度にしよう
        String strx;
        BufferedReader br =
            new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Solutions of a quadratic equation: a*x*x + b*x + c = 0");
        System.out.print("Enter a: "); // x-loop
        strx = br.readLine();
        a = Double.parseDouble(strx);
        System.out.print("Enter b: "); // x-loop
        strx = br.readLine();
        b = Double.parseDouble(strx);
        System.out.print("Enter c: "); // x-loop
        strx = br.readLine();
        c = Double.parseDouble(strx);

        d = b * b - 4.0 * a * c; // 判別式,実は4.0 は倍精度
        d = Math.sqrt(d); // 判別式が正の場合だけ計算できる

        .... ここで工夫をして二つの根 x, y を求める。
           そして表示する。

        System.out.println("Solutions by the formula:" + "\t" + x + "\t" + y);
    }
}

複素根も求める(未完成): Quadx.java
ここは自分で考えてください。

最後の宿題を作るのに必要な Fsine.java
import java.io.*;
class Fsine
{
    public static void main(String[] args) throws IOException
    {
        int i, n;
        double x, y, np, cn;
        for(i=0; i <= 300; i++)
        {
            x = i / 300.;
            y = 0.;
            for(n=1; n <= 30; n++)
            {
                np = n * Math.PI;
                cn = 2. / np * ( 2. * Math.cos(np / 2.) - 1. - Math.cos(np) );
                y = y + cn * Math.sin(np * x);
            }
            System.out.println(x + " " + y);
        }
    }
}

最後の宿題を作るのに必要な Esine.java
import java.io.*;
class Esine
{
    public static void main(String[] args) throws IOException
    {
        int i;
        double x, y;
        for(i=0; i <= 100; i++)
        {
            x = i / 100.;
            y = Math.sin(6.*Math.PI*x) * Math.exp(-x);
            System.out.println(x + " " + y);
        }
    }
}

最後の総合課題:図入りの LaTeX 文書(未完成): sample.tex
\documentclass[a4paper]{jarticle}
% これはgnuplot で作ったグラフのファイルを読み込んだ文書sample.tex
\usepackage{graphicx}
\title{最後の宿題レポート}
\author{南野何某}
\begin{document}

\maketitle

\section{Fourier級数で計算した例}

ある関数
\begin{displaymath}
y=-1, \mbox{ if } 0 < x < \frac12, \quad\mbox{and}\quad
+1, \mbox{ if } \frac12 \leq x < 1
\end{displaymath}
のFourier-sine 級数の近似を計算し, gnuplot を使って
グラフにし,それをPostScript ファイルにしたのが次の図。
\begin{center}
\includegraphics*{sample.eps}
\end{center}

\section{授業での達成度}

今回,新しく知ったことは
\begin{itemize}
\item HTMLでホームページを作るのは意外と簡単だ。
\item \LaTeX はよくわからないが出力は綺麗だ。
\item 初めて,プログラミングをして・・・
\end{itemize}
といったことであった。
この授業は何かを身に付けるのではなく,コンピュータには
何ができて何ができないかを知るのが目的であると
先生は最初に宣言したが,そういう意味では,僕は・・・
もっと・・・について練習してみようと思う。

\end{document}

岩熊哲夫
2011年3月22日 宇宙暦 [-28]4626.12