
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  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 07 - 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 3rd CodeLab assignment\\
	\vskip 1\baselineskip
	 \qquad "CodeLab Assignment-3"\\
	 \qquad Due:  23:59,  Mar 7th\\
	      \vskip 1\baselineskip
\end{itemize}
%\vspace{2in}
\end{frame} %-------------------------------------------------------------|


\section{if else}

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


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Example: if...else if...else}
  \framesubtitle{~}
\texttt{if ( grade < 80 )}\\
$\{$\\
\quad \texttt{printf("You got C");}\\
$\}$\\
\texttt{else if ( grade < 90)}\\
$\{$\\
\quad \texttt{printf("You got B");}\\
$\}$\\
\texttt{else}\\
$\{$\\
\quad \texttt{printf("You got A");}\\
$\}$\\
\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Comparison: if...if...if}
  \framesubtitle{~}
\texttt{if ( grade < 80 )}\\
$\{$\\
\quad \texttt{printf("You got C");}\\
$\}$\\
\texttt{if ( grade >= 80 $\&$$\&$ grade < 90)}\\
$\{$\\
\quad \texttt{printf("You got B");}\\
$\}$\\
\texttt{if ( grade >= 90)}\\
$\{$\\
\quad \texttt{printf("You got A");}\\
$\}$\\
\vskip 0.5\baselineskip
\large
\texttt{Deficiency: Always need to compare three times.}\\
\vspace{2in}
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Structure: Multiple condition expression}
  \framesubtitle{~}

\texttt{if ( ( logical expression 1) $\&$$\&$ ( logical expression 2) $\&$$\&$ ( logical expression 3 ) )}\\
$\{$\\
\quad \texttt{executable statement;}\\
\quad \texttt{\dots}\\
$\}$\\
\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Example: Multiple condition expression}
  \framesubtitle{~}

\texttt{if ( ( mpg > 25 ) $\&$$\&$ ( safety > 99 ) $\&$$\&$ ( price < 20000 ) )}\\
$\{$\\
\quad \texttt{printf("A nice car!");}\\
\quad \texttt{\dots}\\
$\}$\\
\vspace{2in}
\end{frame} %-------------------------------------------------------------|


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


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Nested if : Example}
  \framesubtitle{~}
  \texttt{if ( AverageTemperature > 70 ) }\\
$\{$\\
\quad \quad \texttt{ if ( NumRainDays > 150 ) }\\

\quad \qquad \qquad \texttt{printf("Tropical rainforest climate");}\\
\vskip 0.5\baselineskip
\quad \quad \texttt{else if ( NumRainDays > 50 )} \\

\quad \qquad \qquad \texttt{printf("Semi-tropical climate");}\\
\vskip 0.5\baselineskip
\quad \quad \texttt{else} \\

\quad \qquad \qquad \texttt{printf("May be tropical desert climate");}\\
$\}$\\

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


\section{switch}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{switch: structure}
  \framesubtitle{~}

\texttt{switch ( controlling\_variable ) }\\
$\{$\\
\quad \quad \texttt{ case 1:}  \\
\quad \quad \qquad \texttt{ executable group 1 ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 2:}  \\
\quad \quad \qquad \texttt{ executable group 2 ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \qquad \texttt{ \dots}  \\
\vskip 0.5\baselineskip
\quad \quad \texttt{ default:}  \\
\quad \quad \qquad \texttt{ executable group last ;}  \\
$\}$\\

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


\begin{frame} %-----------------------------------------------------------|
  \frametitle{switch: key points}
  \framesubtitle{~}
\begin{itemize}

\item \texttt{Controlling\_variable: int, char}\\
\item \texttt{char variable:  'c' ;}\\
\item \texttt{break;}\\
\item \texttt{Other cases $-$$-$ default :}\\

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





\begin{frame} %-----------------------------------------------------------|
  \frametitle{switch: example (int)}
  \framesubtitle{~}

\texttt{int courseId ; }\\

\texttt{switch ( courseId ) }\\
$\{$\\
\quad \quad \texttt{ case 101:}  \\
\quad \quad \qquad \texttt{ printf("Basics of Computing") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 351:}  \\
\quad \quad \qquad \texttt{ printf("Operating System") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 230:}  \\
\quad \quad \qquad \texttt{ printf("Computer Organizatoin") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\vskip 0.5\baselineskip
\quad \quad \texttt{ default:}  \\
\quad \quad \qquad \texttt{ printf("Not open in this semester") ;}  \\
$\}$\\

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




\begin{frame} %-----------------------------------------------------------|
  \frametitle{switch: example (int)}
  \framesubtitle{~}

\texttt{int courseId ; }\\

\texttt{switch ( courseId ) }\\
$\{$\\
\quad \quad \texttt{ case 101:}  \\
\quad \quad \qquad \texttt{ printf("Basics of Computing") ;}  \\
% \quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 351:}  \\
\quad \quad \qquad \texttt{ printf("Operating System") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 230:}  \\
% \quad \quad \qquad \texttt{ printf("Computer Organizatoin") ;}  \\
% \quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 231:}  \\
\quad \quad \qquad \texttt{ printf("Computer Organizatoin") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\vskip 0.5\baselineskip
\quad \quad \texttt{ default:}  \\
\quad \quad \qquad \texttt{ printf("Not open in this semester") ;}  \\
$\}$\\

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






\begin{frame} %-----------------------------------------------------------|
  \frametitle{switch: example (char)}
  \framesubtitle{~}

\texttt{char color ; }\\

\texttt{switch ( color ) }\\
$\{$\\
\quad \quad \texttt{ case 'r':}  \\
\quad \quad \qquad \texttt{ printf("Tricolor: Red") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 'g':}  \\
\quad \quad \qquad \texttt{ printf("Tricolor: Green") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 'b':}  \\
\quad \quad \qquad \texttt{ printf("Tricolor: Blue") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\vskip 0.5\baselineskip
\quad \quad \texttt{ default:}  \\
\quad \quad \qquad \texttt{ printf("Not belong to tricolor") ;}  \\
$\}$\\

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





\end{document} 