
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  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 06 - Conditions}

\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{Announcement}

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

\begin{itemize}
	\item The 2nd CodeLab assignment\\
	\vskip 1\baselineskip
	 \qquad "CodeLab Assignment-2"\\
	 \qquad Due:  23:59 Feb 24\\
	      \vskip 1\baselineskip
\end{itemize}
%\vspace{2in}
\end{frame} %-------------------------------------------------------------|


\section{Function}

\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}}
  \framesubtitle{~}
\#include $<$stdio.h$>$\\
\vskip 0.4\baselineskip
\texttt{double EllipseArea(int x, int y);}
\vskip 0.4\baselineskip
int main(void)\\
$\{$ \\
\quad \texttt{int x = 4, y = 5, z;}\\
\quad \texttt{z = EllipseArea(x, y);}\\
$\}$ \\
\vskip 1\baselineskip

\texttt{double EllipseArea(int x, int y)}\\
$\{$\\
\quad \texttt{return 3.14159 * x * y ;}\\
$\}$\\

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

\section{if else}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Operators: Relation and Equality Operators}
  \framesubtitle{~}

	\large

 \begin{itemize}
  \item relation and equality operators
\vskip 1\baselineskip
  \begin{itemize}
    \item "$<$" \quad "$>$" \quad  "$<$$=$" \quad "$>$$=$"
    \item "$=$$=$" \quad "$!$$=$"\\
  \end{itemize}
  \vskip 1\baselineskip
  \item Example:  x $=$ 3, y $=$ 7
  \vskip 1\baselineskip
  \begin{itemize}
    \item x $<$ y  \qquad value: 1(true)
    \item x $<=$ y  \qquad value: 1(true)
    \item x $==$ y  \qquad value: 0(false)
    \item x $!=$ 4  \qquad value: 1(true)
  \end{itemize}
\end{itemize}
\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Operators: Logical Operators}
  \framesubtitle{~}

	\large
  \texttt{Logical operators}
  \vskip 1\baselineskip
  \begin{itemize}
    \item "$\&$$\&$" $-$AND
    \item "$\mid$$\mid$" $-$OR
    \item "$!$" $-$NOT
  \end{itemize}
  \vskip 1\baselineskip
  \texttt{Example:  x $=$ 3,  y $=$ 7}
  \vskip 0.5\baselineskip
  \begin{itemize}
    \item (x $<=$ y)$\&$$\&$(x $>$ 4) \qquad  Value: 0(false)
    \item (x $>$ 4)$\mid$$\mid$(x $!=$ y) \qquad  Value: 1(true)
    \item $!$(x $==$ y) \qquad  Value: 1(true)
  \end{itemize}

\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Condition: If else statement}
  \framesubtitle{~}

\texttt{Basic idea: Decision Making} \\
\vskip 1\baselineskip
\texttt{If logical expression is true (nonzero), single or block of executable statements are executed, otherwise, skipped.}\\
\vskip 0.5\baselineskip

\vskip 0.5\baselineskip

\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Condition: Example 1}
  \framesubtitle{~}
\texttt{if ( logical expression )}\\
\quad \texttt{executable statement;}\\
\vskip 1.5\baselineskip
\texttt{Example:}\\
\vskip 0.5\baselineskip
int month ;\\
scanf("\%d", \&month ) ;\\
\vskip 0.5\baselineskip
\texttt{if (( month $>$ 12 )$\|$( month $<$ 0))}\\
\quad \texttt{printf("You input an invalid month" ) ;}\\

\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Condition: Example 2}
  \framesubtitle{~}
\texttt{if ( logical expression )}\\
$\{$\\
\quad \texttt{executable statement;}\\
\quad \texttt{\dots}\\
$\}$\\
\vskip 1\baselineskip
\texttt{Example:}\\
\vskip 0.8\baselineskip
int month, isHoliday ;\\
scanf("\%d", \&month ) ;\\
\vskip 0.5\baselineskip
\texttt{if (( month $>=$ 5 )$\&$$\&$(month $<=$ 8))}\\
$\{$\\
\quad isHoliday = 1;\\
\quad \texttt{printf("Now is Summer Vocation!" ) ;}\\

$\}$\\

\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Condition: if else}
  \framesubtitle{~}
\texttt{if ( logical expression )}\\
$\{$\\
\quad \texttt{executable statement 1;}\\
\quad \texttt{\dots}\\
$\}$\\
\texttt{else}\\
$\{$\\
\quad \texttt{executable statement 2;}\\
\quad \texttt{\dots}\\
$\}$\\
\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Condition: Example 3}
  \framesubtitle{~}

\texttt{if (( month $>=$ 5 )$\&$$\&$(month $<=$ 8))}\\
$\{$\\
\quad isHoliday = 1;\\
\quad \texttt{printf("Now is Summer Vocation!" ) ;}\\
$\}$\\
\texttt{else}\\
$\{$\\
\quad isHoliday = 0;\\
\quad \texttt{printf("It's time for studying!" ) ;}\\
$\}$\\


\vskip 0.5\baselineskip
\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\end{document}
