%-------------------------------------------------------
% exercise1.tex
%    Exercise 1.
%
% Sariel Har-Peled
%--------------------------------------------------------

\documentclass[12pt]{article}
%\documentclass[twocolumn]{article}
\usepackage{alltt,url,amstext,amsmath,amssymb}

\setlength{\evensidemargin}{.0in}
\setlength{\oddsidemargin}{-0.3in}
\setlength{\textwidth}{6.8in}
\setlength{\textheight}{8.7in}

\newcommand{\sep}[1]{\,\left|\, {#1} \MakeBig\right.}
\newcommand{\brc}[1]{\left\{ {#1} \right\}}
\newcommand{\pth}[1]{\left( {#1} \right)}
\newcommand{\ceil}[1]{\left\lceil {#1} \right\rceil}
\newcommand{\floor}[1]{\left\lfloor {#1} \right\rfloor}

\newcommand{\remove}[1]{}
\newtheorem{theorem}{Theorem}[section] % section
\newtheorem{lemma}[theorem]{Lemma}
%\newtheorem{example}[theorem]{Example}
\newtheorem{defn}[theorem]{Definition}
\newcommand{\ctrl}{{\symbol{'136}}}
\newcommand{\examplex}[3]{
    \vspace{0.2cm}
    \noindent{\tt #1}

    \noindent{\bf \large Input:}
    {\tt #2}
 
    \noindent{\bf \large Output:}{\tt #3}

    \vspace{0.2cm}
}
\newcommand{\exmpinp}{\noindent{\bf \large Input:}\vspace{-0.3cm}}
\newcommand{\exmpout}{\noindent{\bf \large Output:}\vspace{-0.3cm}}
\newcommand{\MakeBig}{\rule[-.2cm]{0cm}{0.6cm}}
\newcommand{\unix}{{\tt UNIX}}
\newcommand{\dos}{{\tt DOS}}

\newcommand{\exercise}[2]{\section*{Ex {#1} ~ {#2}}}

\newcommand{\tildegen}{\protect\raisebox{-0.12cm}{\symbol{'176}}}
\newcommand{\atgen}{\symbol{'100}}
\newcommand{\email}{{\tt sariel\atgen{}math.tau.ac.il}}
\newcommand{\homepage}{{\tt http://www.math.tau.ac.il/\tildegen{}sariel/}}
 

% Title
\title{Software I - Fall semester 1998/9\\
   {\tt {{Exercise}} 1}}

\author{{\bf Due:} 31/12/1998}

\date{{\bf Needed:} printf, scanf, while, int, double,
   float, getchar, putchar, basic \unix{}}

\begin{document}
\maketitle

 
{\bf \large Before doing the exercise, please read very
   carefully the ``guidelines for submission'' and make sure
   that you understand them.  If you have any questions
   about the guidelines or the exercise, please read the
   FAQ\footnote{ {\bf Course web-page:}
      {\tt http://www.math.tau.ac.il/\tildegen{}halperin/courses/soft1-fall98-9.html}\\
      $\rule[-0.01cm]{0.2in}{-0.01cm}$ {\bf Tirgul
         web-page:} {\tt
         http://www.math.tau.ac.il/\tildegen{}sariel/TA/99a/soft99a/}
      } first (located at the web page of the course's
   TIRGUL). If your question is not answered there, ask your
   teaching assistant (METARGEL).}

\vspace{0.4cm}

This exercise is to write several simple programs to familiarize
yourself with \verb|C|, \unix{}, and the compiler \verb|g++|.

Note, that if the user inputs an invalid input, your programs should
print an appropriate error message. Also, since programs are
tested automaticly as well, do NOT add ``friendly''
messages to your programs.


\exercise{1.1}{d2u}

Write a program to read text in \dos{} format from the
standard input (until reaching the end of the input), and
transform it into a \unix{} text format, which is being
output to standard output (using \verb|getchar, putchar|).
In a \dos{} text format, in the end of each line there
are two characters \verb|'\n'|, \verb|'\r'| (in this order).
While in \unix{}, in the end of each line, there is only a
single character \verb|'\n'|.

\exercise{1.2}{u2d}

This program reads text in \unix{} format from the standard input
(until reaching the end of the input), and transforms it into a
\dos{} text format.

To test your programs \verb|d2u|, \verb|u2d|, you can just
check if they work like the unix equivalent programs
\verb|dos2unix| and \verb|unix2dos|.  Take a text file (for
example a copy of your program source) and do:
\begin{verbatim}
    dos2unix < textfile > unix-file
    unix2dos < unix-file > dos-file
    ./d2u < dos-file > my-unix-file
    ./u2d < unix-file > my-dos-file
    diff unix-file my-unix-file
    diff dos-file my-dos-file
\end{verbatim}
If your program fails to work, you will get an appropriate
message about the result not being identical.

\exercise{1.3}{exp}

This program reads a real number $x$ from the input (using type \verb|double|
and\\ \verb|args = scanf( "%lg", &num )|), 
computes, and outputs $\exp(x) = e^x$.  The value $\exp(x)$
should be computed according to the formula:
\[
exp(x) = 1 + \sum_{i=1}^{20} \frac{x^i}{i!}\;\;,
\]
where $i!=1\cdot 2 \cdot 3 \cdots i$. Note that the $i$-th element in
this summation can be easily computed from the $(i-1)$-st element.


\exercise{1.4}{factorit}

The program reads an integer number from the input, and computes its
factorization. Namely, it outputs the prime numbers whose product
is the input number. For example, for the input

\begin{verbatim}
9372
\end{verbatim}

The program will output:
\begin{verbatim}
2
2
3
11
71
\end{verbatim}

since $2\cdot 2 \cdot 3 \cdot 11 \cdot 73 = 9372$. Note,
that the primes are printed in a non-decreasing order.



\exercise{1.5}{gcd}

The program reads two integer numbers, and outputs their
$\gcd$. The $\gcd$ of two numbers is the largest positive
integer that divides both numbers. The {\em greatest common
   divisor} can be computed by the following observation: If
$a>b>0$ then $\gcd(a,b) = \gcd( a \mod b, b )$, where $a
\mod b = a - \floor{\frac{a}{b}}b$. The modulo can be
computed in
\verb|C| using the \verb|%| operator; that is, \\
$a\mod b=\text{\tt a \% b}$.


\begin{center}
\Huge Good Luck!
\end{center}
 
%\newpage

~

\section*{More Information on the Submission}

\subsection*{Files Name}

Don't forget to give correct permission to your files. The
files for your exercises should be located under
{\tt \tildegen{}/soft99a/ex1/}, and their names should be:


\begin{alltt}
   \tildegen{}/soft99a/ex1/d2u.C
   \tildegen{}/soft99a/ex1/u2d.C
   \tildegen{}/soft99a/ex1/exp.C
   \tildegen{}/soft99a/ex1/factorit.C
   \tildegen{}/soft99a/ex1/gcd.C
\end{alltt}

Note that the case is important (i.e. \verb|ex1.C| is
different than \verb|ex1.c|).

\subsection*{Giving Permission to the Files}

Before submitting the exercise, please give permission to
the files so we could check them, by executing the following
command:

    {\tt chmod 705 \tildegen{}/ \tildegen{}/soft99a 
       \tildegen{}/soft99a/ex1 \tildegen{}/soft99a/ex1/*}

\subsection*{Running Example}

We have implemented the exercise. You can test/play the demo
program to verify that your programs work correctly. Note
that your program {\em must} behave exactly like the demo
program. A program that fails to behave exactly like the
demo program is considered to be incorrect, and will be
graded accordingly. 

You exercise will be checked automaticly on several inputs.
Following the above guidelines will ensure that the automatic
check will not fail.

\noindent{} The example programs are located under:
{\tt \tildegen{}sariel/TA/soft99a/ex1/}

\noindent{} Inputs example:
{\tt \tildegen{}sariel/TA/soft99a/ex1/inputs/}

Your program must work correctly for all the given input
examples.


%\section*{Information on The Web}


\end{document}



%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
