
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  CSCE 150A -- Problem Solving Using Computers
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[pdftex]{beamer}

\input{beamerPreamble}
\usepackage[T1]{fontenc}
%\usepackage{tikz}\text
%\usetikzlibrary{shapes.callout}

\title[CSCE150A]{Computer Science \& Engineering 150A\\
    Problem Solving Using Computers -- Laboratory}
\subtitle{Lecture 12 - Functions}

\author[~]{Shuai Xie\vskip 1\baselineskip (Adapted from Derrick Stolee, Lin Liu \& Shuai Xie )} %

\date{Spring 2010}
%\usepackage{listings}
\usepackage{multicol}
\begin{document}
%\lstset{language=C}
\begin{frame}
  \titlepage
  \begin{center}
     \vfill
     \email{sxie@cse.unl.edu}
  \end{center}
\end{frame}

\section{Assignment}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Announcement: CodeLab assignment}
  \framesubtitle{~}

\begin{itemize}
	\item The 6th CodeLab assignment\\
	\vskip 1\baselineskip
	 \qquad "CodeLab Assignment-6"\\
	 \qquad Due:  23:59 Apr 13\\
	      \vskip 1\baselineskip
\end{itemize}

\end{frame} %-------------------------------------------------------------|


\section{Function}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Function: \texttt{Basics}}
  \framesubtitle{~}

\quad \texttt{Three steps to design your own function:}

\begin{itemize}
	\item \texttt{Prototype $-$ Declaration}
	\item \texttt{Definition $-$ Implementation}
	\item \texttt{Call $-$ Usage}
\end{itemize}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Function: \texttt{Prototype}}
  \framesubtitle{~}
\#include $<$stdio.h$>$\\
\vskip 0.4\baselineskip
\quad \texttt{void PrintAlarm(void);}\\
\quad \texttt{int Cube(int x);}\\
\quad \texttt{double EllipseArea(int x, int y);}\\
\vskip 0.4\baselineskip
int main(void)\\
$\{$ \dots
\vskip 0.5\baselineskip
\begin{itemize}
  \item \texttt{Between preprocessor directive and main function }
	\item \texttt{Returntype $-$ void, int, double, char, etc}
	\item \texttt{Argument $-$ void, single, multiple}
	\item \texttt{";"}
\end{itemize}
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Function: \texttt{Definition}}
  \framesubtitle{~}

\texttt{ReturnType FuncName(type Arg 1,\dots)}\\
$\{$\\
   \texttt{local variable declarations;}\\
   \texttt{executable statements;}\\
   \texttt{return statement;}\\
$\}$\\

\begin{itemize}
  \item \texttt{After the main funciton}
  \item \texttt{$\approx$ prototype, without ";"}
	\item "$\{$", "$\}$" $-$ scope
	\item \texttt{Local variables disappear outside scope}
	\item \texttt{Output}
	\begin{itemize}
	    \item \texttt{Return statement}
	    \item \texttt{Match returntype}
	\end{itemize}
\end{itemize}
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Function Definition: \texttt{Example 1}}
  \framesubtitle{~}
\#include $<$stdio.h$>$\\
\texttt{void PrintAlarm(void);}\\
\texttt{void PrintReminder(void);}\\
\vskip 0.4\baselineskip
int main(void)\\
$\{$ \\
\quad \texttt{PrintAlarm();} \\
\quad \texttt{PrintAlarm();} \\
$\}$ \\
\texttt{void PrintAlarm( void )}\\
$\{$\\
\quad \texttt{printf("The message you input is wrong");}\\
$\}$\\
\texttt{void PrintReminder( void )}\\
$\{$\\
\quad \texttt{printf("The message you input is correct");}\\
$\}$\\
\end{frame} %-------------------------------------------------------------|




\begin{frame} %-----------------------------------------------------------|
  \frametitle{Function Definition: \texttt{Example 2}}
  \framesubtitle{~}
\#include $<$stdio.h$>$\\
\texttt{int Cube(int x);}\\
\texttt{double EllipseArea(int a, int b);}\\
int main(void)\\
$\{$ \\
\quad \texttt{int x = 4, y=3, c, z ;}\\
\quad \texttt{c = Cube(x) ; }\\
\quad \texttt{z = EllipseArea(x,y) ; }\\
$\}$ \\
\vskip 1\baselineskip
\texttt{int Cube(int x)}\\
$\{$\\
\quad \texttt{int y;}\\
\quad \texttt{y = x * x * x ;}\\
\quad \texttt{return y;}\\
$\}$\\

\end{frame} %-------------------------------------------------------------|}\\


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Function Definition: \texttt{Example 2}}
  \framesubtitle{~}

\texttt{double EllipseArea(int a, int b)}\\
$\{$\\
\quad \texttt{double c ;}\\
\quad \texttt{c = 3.14159 * a * b ;}\\
\quad \texttt{return c ;}\\
$\}$\\

\end{frame} %-------------------------------------------------------------|}\\





\end{document}
