
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  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 03 - Unix Basics,Pico,Gcc}

\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 and grading}
%  \framesubtitle{~}
%
%\begin{itemize}
%	\item The first CodeLab assignment\\  Directory:\quad "Week 03 -- Sep 09".\\
%	      Due time: \quad 11:59 PM Sep 09.\\
%	\item The lab grades will be sended to your CSE email account, and will not update in BB(BlackBoard). \\
%\end{itemize}
%     %\vspace{2in}
%\end{frame} %-------------------------------------------------------------|


\section{Unix Basics}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Unix Basics: Review}
  \framesubtitle{~}

\begin{itemize}
	\item pwd \quad $-$ print current working directory
	\item mkdir $<$foldername$>$ \quad $-$ create a new directory
	\item cd $<$foldername$>$ \quad $-$ enter a specific directory
	\item cd .. \quad $-$ go to the parent directory
	\item cd \quad $-$ go to the home directory
	\item touch $<$filename$>$ \quad $-$ create an empty file
	\item ls \quad \quad $-$ show all the files
	\item ls $-$l  \quad $-$ show detail information
	\item ls $<$foldername$>$ \quad $-$ show files in a specific directory
\end{itemize}
%\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Unix Basics: Pico}
  \framesubtitle{~}

\begin{itemize}
	\item pico $<$filename$>$ $-$ "Notepad" in Unix
		\begin{itemize}
		  \item Ctrl+O $-$ Save file
		  \item Ctrl+X  \& y $-$ Save file and exit
		  \item Ctrl+X  \& n $-$ Exit without saving
		  \item Ctrl+C  $-$ Show cursor position
		\end{itemize}
\end{itemize}
%\vspace{2in}
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Unix Basics: Managing Files}
  \framesubtitle{~}

\begin{itemize}
	\item Copy, Move and Rename
	\begin{itemize}
		\item cp $<$oldfile$>$ $<$newfile$>$ $-$ Copy a file to a new file
	  \item mv $<$filename$>$ $<$directory$>$ $-$ move a file to a directory
		\item mv $<$oldname$>$ $<$newname$>$ $-$ Rename a file

	\end{itemize}
	\item Delete Files
	\begin{itemize}
		\item rm $<$filename$>$ $-$ Be careful!
	\end{itemize}
\end{itemize}
%\vspace{2in}
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Unix Basics: Get Info}
  \framesubtitle{~}

\begin{itemize}
  \item Get Info
  \begin{itemize}
	  \item man $<$commandname$>$ $-$ Display the manual for command.
    \item less $<$filename$>$ $-$ Display the contents of a file.
    \item Press "q" to exit.
  \end{itemize}
\end{itemize}
%\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\section{Gcc}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Compiler: gcc}
  \framesubtitle{~}
\begin{itemize}
  \item gcc $-$ c compiler in unix system
	\item Compile:
		\[\text{\texttt{gcc filename.c}}\]
	\item Run:
		\[\text{\texttt{a.out}}\]
\end{itemize}
\vspace{1.5in}
\end{frame} %-------------------------------------------------------------|


\section{Printf}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Printf: football game}
  \framesubtitle{~}

\#include $<$stdio.h$>$\\
\vskip 1\baselineskip
/* this is a multi-line\\
comment! */\\
\vskip 1\baselineskip
// this is a single line comment.\\
\vskip 1\baselineskip

int main(void)\\
$\{$\\
\qquad printf("The football game is so cool!$\setminus$n");\\

\qquad return 0;\\
$\}$\\

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

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Printf: gcc -o}
  \framesubtitle{~}
\begin{itemize}
	\item Compile:

	\[\text{\texttt{gcc -o program file.c}}\]\\
	

	\item Run:
		\[\text{\texttt{./program}}\]
		
	\item Example:
	  \[\text{\texttt{gcc -o sayhello hello.c} $\rightarrow$ ./sayhello}\]
	
	\item Comparation:
	  \[\text{\texttt{gcc hello.c} $\rightarrow$ a.out}\]
	
	
	%\item \texttt{Careful: Miss the program, lose the file. }
\end{itemize}
\vspace{1.5in}
\end{frame} %-------------------------------------------------------------|



\section{Input}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Input: \texttt{scanf}}
  \framesubtitle{~}

\begin{itemize}
	\item \texttt{scanf("format string", \texttt{\&}variables...););}
	\begin{itemize}
		\item Use the same as $\texttt{printf}$, except for \texttt{\&} before variables.
		\[\text{\texttt{scanf("\%d \%lf", \&myInt, \&myDouble);}}\]
		\item Be sure to define variables ahead of time!
		\item Remember to keep the same format string when input.	\end{itemize}
\end{itemize}
\vskip 1\baselineskip

	\begin{center}
	\begin{tabular}[h]{c|c}
		Placeholder & Variable Type\\
		\hline
		\texttt{\%d} & \texttt{int}\\
		\hline
		\texttt{\%lf} & \texttt{double}\\
		\hline
		\texttt{\%c} & \texttt{char}\\
	\end{tabular}\end{center}

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



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Input: Example Program}
  \framesubtitle{~}

\#include $<$stdio.h$>$\\
int main(void)\\
$\{$\\
\qquad int myID;\\
\qquad printf("Please input your student ID: ");\\
\qquad scanf("\%d", \&myID);\\
\qquad printf("Your ID is \%d, welcome to CSCE150A.$\setminus$n", myID);\\
\qquad return 0;\\
$\}$\\

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




\section{Data Type}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Int: integer numbers}
  \framesubtitle{~}

	\large
\vskip 3\baselineskip
 \begin{itemize}
	\item \texttt{int variablename = (integral)number;}
	\vskip 1\baselineskip
	\item Examples:
	 \begin{itemize}
	   \item int PriceIPhone = 199;
	   \item int NumCar = 3000;
	 \end{itemize}
	 \vskip 1\baselineskip
	\item Takes 4 bytes.
	\item ANSI C range:  -32767 to 32767
\end{itemize}
\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Double: real numbers}
  \framesubtitle{~}

	\large
\vskip 3\baselineskip
 \begin{itemize}
	\item \texttt{double variablename = number(.decimals);}
	\vskip 1\baselineskip
	\item Examples:
	 \begin{itemize}
	   \item double PriceCasoline = 2.39;
	   \item double MinTime = 0.12321237;	
	 \end{itemize}
	 \vskip 1\baselineskip
	\item Takes 8 bytes.
\end{itemize}
\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Char: characters}
  \framesubtitle{~}
	\large
\vskip 3\baselineskip
 \begin{itemize}
	\item \texttt{char variablename = 'c'(a letter or symbol);}
	\vskip 1\baselineskip
\item Examples:
	 \begin{itemize}
	   \item char grade = 'A';
	   \item char SymbolMoney = '$\$$';
	 \end{itemize}
	 \vskip 1\baselineskip
	\item Takes 1 byte.
	\item ASCII code
\end{itemize}
\vspace{2in}
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Printing}
  \framesubtitle{~}
	\large

 \begin{itemize}
	\item \texttt{printf("format string", variable list );}
	\item Outputs ``string" with a few variable replacements.\\
	\begin{center}
	\begin{tabular}[h]{c|c}
		Placeholder & Variable Type\\
		\hline
		\texttt{\%d} & \texttt{int}\\
		\hline
		\texttt{\%f} & \texttt{double}\\
		\hline
		\texttt{\%c} & \texttt{char}\\
		\hline
		\vdots & \vdots
	\end{tabular}\end{center}
\end{itemize}
\end{frame} %-------------------------------------------------------------|


\begin{frame} %-----------------------------------------------------------|
  \frametitle{Printf Examples}
  \framesubtitle{~}

\large
\vskip 3\baselineskip
 \begin{itemize}
    \item \texttt{printf("Michael Jackson leaves us in the year of \%d.$\setminus$n",2009);}
    \vskip 1\baselineskip
    \item \texttt{printf("My puppy weighs \%f pounds.$\setminus$n", 23.75 );}
    \vskip 1\baselineskip
    \item \texttt{printf("Hope you get \%c in this semester.$\setminus$n", 'A' );}

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



\begin{frame} %-----------------------------------------------------------|
  \frametitle{Printf: Another example}
  \framesubtitle{~}

\large

 %\begin{itemize}
  %  \item int NumA=10;
   % \item int NumB=90;
    %\item int NumC=2;
    %\item \texttt{printf("There are totally \%d of A and \%d of B and \%d of C in this semester.$\setminus$n"), NumA,NumB,NumC);}

 %\end{itemize}


\#include $<$stdio.h$>$\\
int main(void)\\
$\{$\\
\qquad  int NumCourse=5;\\
\qquad  double Average=95.50;\\
\qquad  char Grade='A';\\
 \vskip 1\baselineskip
\qquad printf("This semester I select \%d courses. \\
\qquad My average score is \%.2f. I get all \%c.$\setminus$n",\\
\qquad NumCourse, Average, Grade);\\

\qquad return 0;\\
$\}$\\

Output:\\

 This semester I select 5 courses. My average score is 95.50. I get all A.

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


\end{document}
