
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  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 10 - Review and Debug}

\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 5th CodeLab assignment\\
	\vskip 1\baselineskip
	 \qquad "CodeLab Assignment-5"\\
	 \qquad Due:  23:59 Apr 5\\
	      \vskip 1\baselineskip
\end{itemize}

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

\section{Data Type}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{\texttt{Data Type}}
  \framesubtitle{~}

\begin{tabular}[h]{c|c|c|c}
	Var Name & Stores & Scanf & Printf \\
	\hline
	\texttt{int} & Integers & \%d & \%d \\
	\hline
	\texttt{double} & Decimals & \%lf & \%f \\
	\hline
	\texttt{char} & Letters & \%c & \%c \\
\end{tabular}

\vspace{1em}

\begin{itemize}
  \item char grade = 'A';
  \item \%10d \qquad \%7.2f
  \item Type cast
     \begin{itemize}
     \item int i=3, j=4;
     \item double k;
     \item k=(double)i/j;
     \end{itemize}
\end{itemize}

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

\section{Operators}

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

 \begin{itemize}
 	\item Math operators: +\quad $-$\quad * \quad/ \quad\%(remainder)
 	\vskip 1\baselineskip
 	\item Relation and equality operators:\quad $<$ \quad $>$ \quad $<$$=$ \quad $>$$=$ \quad $=$$=$ \quad $!$$=$\\
 	\vskip 1\baselineskip
  \item logical operators: \quad $\&$$\&$ \quad $\mid$$\mid$ \quad $!$
  \vskip 1\baselineskip
 	\item Notes: order of operators;  using "( )". 	
 	


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


\section{Math}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{\texttt{Math}}
  \framesubtitle{~}

 \begin{itemize}
 \item Math function: abs(x),\quad fabs(x),\quad sin(x),\quad cos(x),\quad pow(x,y),\quad sqrt(x)
 \vskip 1\baselineskip
 \item \#include <math.h>
 \vskip 1\baselineskip
 \item Math expression: \\
  \vskip 1\baselineskip
 $\left|\frac{1}{\sqrt{1-x^2}}\right|$ $=>$ \texttt{fabs(1.0/sqrt(1-pow(x,2)))}\\
 \end{itemize}
\vspace{2in}
\end{frame} %-----------------------------------------------------------|

\section{Function}

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

\#include $<$stdio.h$>$\\
\vskip 1\baselineskip
\small
\texttt{double CountArea(double x, double y);} $\setminus$$\setminus$Prototype \\
\vskip 1\baselineskip
\texttt{int main(void)}\\
$\{$\\
\texttt{$\dots$}\\
\texttt{area = CountArea(x, y);} $\setminus$$\setminus$Call the function \\
\texttt{$\dots$}\\
$\}$\\
\vskip 1\baselineskip
\texttt{double CountArea(double x, double y)} $\setminus$$\setminus$Definition \\
$\{$\\
   \texttt{return (x * y);}\\
$\}$\\

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


\section{Condition}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{if... else... statements}
  \framesubtitle{~}
\texttt{if (x > 3 $\&$$\&$ y <= 4)}\\
$\{$\\
\quad \texttt{$\dots$}\\
$\}$\\
\texttt{else}\\
$\{$\\
\quad \texttt{$\dots$}\\
$\}$\\
\end{frame} %-----------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{if... else if...else...}
  \framesubtitle{~}

\texttt{if ( grade <= 80 )}\\
$\{$\\
\quad \texttt{$\dots$}\\
$\}$\\
\texttt{else if ( grade <= 90)}\\
$\{$\\
\quad \texttt{$\dots$}\\
$\}$\\
\texttt{else}\\
$\{$\\
\quad \texttt{$\dots$}\\
$\}$\\
\vspace{2in}

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

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Nested if}
  \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} %-----------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{switch}
  \framesubtitle{~}
  \small
\texttt{int windlevel ; }\\
\texttt{$\dots$}\\
  \texttt{switch ( windlevel ) }\\
$\{$\\
\quad \quad \texttt{ case 2:}  \\
\quad \quad \qquad \texttt{ printf("Level 2: Breeze") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 7:}  \\
\quad \quad \qquad \texttt{ printf("Level 7: Strong wind") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\quad \quad \texttt{ case 10:}  \\
\quad \quad \qquad \texttt{ printf("Level 10: Storm wind") ;}  \\
\quad \quad \qquad \texttt{ break ;}  \\
\vskip 0.5\baselineskip
\quad \quad \texttt{ default:}  \\
\quad \quad \qquad \texttt{ printf("More detail see our website") ;}  \\
$\}$\\

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

\section{Loops}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{While loop}
  \framesubtitle{~}

  \texttt{int i=1, total=0;}
  \vskip 0.8\baselineskip
	\texttt{while ( i <=10 )}\\
	 $\{$ \\
	 \qquad \texttt{total = total + i;}\\
	 \qquad \texttt{i++;}\\
	  $\}$\\
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Do while loop}
  \framesubtitle{~}

  \vskip 1\baselineskip	
  \texttt{int i=1, total=0;}\\
   \vskip 0.8\baselineskip
	\texttt{do}\\
	 $\{$ \\
	 \qquad \texttt{total = total + i;}\\
	 \qquad \texttt{i++;}\\
   $\}$ \texttt{while ( i <= 10 );}\\

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

\begin{frame} %-----------------------------------------------------------|
  \frametitle{For loop}
  \framesubtitle{~}

\vskip 1\baselineskip
	\texttt{for ( i = 1; i < 10; i++ )}\\
	$\{$ \\
	\qquad \texttt{total = total + i;}\\
	 $\}$\\
\vskip 1\baselineskip

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

\section{Debugging}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{\texttt{Code::Blocks}}
  \framesubtitle{~}

\vspace{1em}

\textbf{Code::Blocks instruction}

\begin{itemize}
  \item Create a new project
     \begin{itemize}
     \item New project
     \item Console Application --> Go
     \item Select "c" not "c++"
     \item Project title and saving folder.
     \item GNU GCC Compiler
     \end{itemize}
  \item Copy your desired source code into main.c
\end{itemize}

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

\begin{frame} %-----------------------------------------------------------|
  \frametitle{\texttt{Code::Blocks}}
  \framesubtitle{~}

\vspace{1em}

\textbf{Code::Blocks instruction}

\begin{itemize}

  \item Save: \quad Ctrl + S
  \item Build: \quad Ctrl + F9
  \item Build and run: \quad F9

  \item Run to Cursor \quad F4
  \item Toggle breakpoint: \quad F5
  \item Next line: \quad F7
  \item Step into: \quad Ctrl + F7
  \item Step out: \quad Shift + Ctrl + F7
  \item Open "Watches Window" to view value of variables.
\end{itemize}

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


\end{document} 