\documentclass{beamer} \usepackage{verbatim} \usepackage[english]{babel} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage{listings} \usepackage[T1]{fontenc} \usepackage{graphicx} \usepackage{xcolor,colortbl} \newcommand{\mc}[2]{\multicolumn{#1}{c}{#2}} \definecolor{Gray}{gray}{0.85} \definecolor{LightCyan}{rgb}{0.88,1,1} \newcolumntype{a}{>{\columncolor{Gray}}c} \newcolumntype{b}{>{\columncolor{white}}c} \newenvironment<>{varblock}[2][.9\textwidth]{% \setlength{\textwidth}{#1} \begin{actionenv}#3% \def\insertblocktitle{#2}% \par% \usebeamertemplate{block begin}} {\par% \usebeamertemplate{block end}% \end{actionenv}} \usetheme{Frankfurt} \usepackage{movie15} \title{programming in C++} \author{Jonas Vejlin} \date{} \begin{document} \maketitle \section{Introduction} \begin{frame} \frametitle{Who I am} \subsection{Who I am} \begin{itemize} \item Background: M.Sc in software engineering at AAU in 2009 \item IT developer: Working with modeling at Foulum 2009-20?? \item Working with FASSET, Animal Change, Nitroscape, C-tool \item Java, C++, C\# \item VBA, R, Matlab \end{itemize} \end{frame} \subsection{Goal} \begin{frame} \frametitle{Goal} \begin{itemize} \pause \item <2->\alert<2>{Automate some task } \pause \item <2->\alert<3>{Implement some statistic method to analyst data} \pause \item <2->\alert<4>{Extract the necessary information from file} \pause \item <2->\alert<5>{Modifier larger models such as Daisy or Fasset} \end{itemize} \end{frame} \subsection{Parsts} \begin{frame} \frametitle{Parts} \begin{block}{Part 1 (Today)} Basic programming \end{block} \begin{block}{Part 2} Control structure such as loops and if-else \end{block} \begin{block}{Part 3} Vector, Files and Functions \end{block} \end{frame} \subsection{C++} \begin{frame} \frametitle{C++} \begin{itemize} \pause \item <2->\alert<2>{General purpose programming language} \pause \item <2->\alert<3>{Both high-level and low-level language features} \pause \item <2->\alert<4>{Provide possibility for Object-oriented programming} \pause \item <2->\alert<5>{Needs to compiled} \pause \item <2->\alert<6>{Created by Bjarne Stroustrup at Aarhus Uni} \end{itemize} \end{frame} \subsection{Programming} \begin{frame} \frametitle{Programming} \begin{itemize} \pause \item <2->\alert<2>{Define the problem} \pause \item <2->\alert<3>{Write algorithm that solves the problem} \pause \item <2->\alert<4>{Program the algorithm} \pause \item <2->\alert<5>{Test the program} \pause \item <2->\alert<6>{Make the computer do all the hard work} \end{itemize} \end{frame} \subsection{Termologi} \begin{frame} \frametitle{Termologi} \begin{itemize} \pause \item <2->\alert<2>{Programs have to be translated to the target computers machine language} \begin{itemize} \pause \item <2->\alert<2>{Compiler: the program that translates} \pause \item <2->\alert<2>{Source file: input to the compiler} \pause \item <2->\alert<2>{If the program is syntactically correct, the compiler will save the machine language instructions in an object file} \end{itemize} \pause \item <2->\alert<3>{The linker combines an object file with already existing libraries of functions and procedures in an executable file} \end{itemize} \end{frame} \section{Our first program} \subsection{Hallo World} \begin{frame} \frametitle{Hallo World} \begin{columns}[T] \begin{column}{0.45\textwidth} \begin{varblock}[6cm]{Source Code} \setbeamercolor{alerted text}{fg=blue} \setbeamerfont{alerted text}{series=\bfseries,family=\ttfamily} \begin{semiverbatim} \small {\alert<1>{// my first program in C++\newline}} {\alert<2>{\#include \newline}} {\alert<3>{using namespace std;\newline}} {\alert<4>{int main()}\newline} {\alert<5>{\{\newline}} {\alert<6>{\hspace*{2em}cout $<<$ "Hallo World!";\newline}} {\alert<7>{\hspace*{2em}cin.get();\newline}} {\alert<5>{\}\newline}} \end{semiverbatim} \end{varblock} \end{column} \begin{column}{0.45\textwidth} \setbeamercolor{alerted text}{fg=blue} \begin{varblock}[2cm]{Output} {\alt<1-5>{\hspace*{2em}\newline}{\alert<6> { Hallo world!}}}\newline \end{varblock} \end{column} \end{columns} \end{frame} \section{Types} \subsection{Basic Types} \begin{frame} \frametitle{Basic Types} \begin{center} \begin{tabular}{|r|l|} \hline Group & Type names\\ \hline \hline & (signed) \textbf{int} \\ \cline{2-2} Integer types & unsigned int \\ \cline{2-2} & long \\ \cline{2-2} \hline &(signed) \textbf{double} \\ \cline{2-2} Floating-point& unsigned double \\ \cline{2-2} & long double \\ \cline{2-2} \hline Character types&char \\ \cline{2-2} \hline \end{tabular} \end{center} \end{frame} \subsection{Declare And Assign} \begin{frame} \frametitle{Declare And Assign} \begin{center} \includegraphics<1>[width=.60\textwidth]{assignAndDeclare.png} \end{center} \end{frame} \begin{frame} \frametitle{Declare And Assign} \begin{columns}[T] \begin{column}{0.45\textwidth} \begin{varblock}[6cm]{Source Code} \setbeamercolor{alerted text}{fg=blue} \setbeamerfont{alerted text}{series=\bfseries,family=\ttfamily} \begin{semiverbatim} \small \#include \newline using namespace std;\newline int main()\newline \{\newline {\alert<1>{\hspace*{2em}double decimalPoint;}}\newline {\alert<2>{\hspace*{2em}decimalPoint = 0.7;}}\newline {\alert<3>{\hspace*{2em}int interger=0;}}\newline {\alert<4>{\hspace*{2em}interger=2;}}\newline {\alert<5>{\hspace*{2em}cout $<<$"the value of decimalPoint"$<<$endl;}}\newline {\alert<6>{\hspace*{2em}cout $<<$ decimalPoint$<<$endl;}}\newline {\alert<7>{\hspace*{2em}cout $<<$ interger$<<$endl;}}\newline cin.get();\newline \} \end{semiverbatim} \end{varblock} \end{column} \begin{column}{0.45\textwidth} \setbeamercolor{alerted text}{fg=blue} \begin{varblock}[4cm]{Output} {\alt<1-4>{ \hspace*{2em}\newline}{\alert<5>{the value of decimalPoint}}}\newline {\alt<1-5>{ \hspace*{2em}\newline}{\alert<6>{0.7}}}\newline {\alt<1-6>{ \hspace*{2em}\newline}{\alert<7>{2}}}\newline \end{varblock} \setbeamercolor{alerted text}{fg=blue} \begin{varblock}[4cm]{data} \alt<0-0>{ \hspace*{2em}\newline}{\alt<1-1>{\alert<1>{decimalPoint}}{\alert<2>{decimalPoint=0.7}}}\newline \alt<0-2>{ \hspace*{2em}\newline}{\alt<3-3>{\alert<3>{interger=0}}{\alert<4>{interger=2}}}\newline \end{varblock} \end{column} \end{columns} \end{frame} \section{Statements} \subsection{Statements} \begin{frame} \frametitle{Statements} 3 different kinds \begin{itemize} \item Expression statement \item Compound statement \item Control statement \end{itemize} \end{frame} \subsection{Expression statements} \begin{frame} \frametitle{Expression statements} \begin{itemize} \item An expression statement consists of an expression followed by a semi colon \item The execution of such an expression implies the evaluation of the related expression \item Eg: \begin{itemize} \item a = 6; \item c = a + b; \item ; (empty statement) \end{itemize} \end{itemize} \end{frame} \subsection{Compound statements} \begin{frame} \frametitle{Compound statements} \begin{itemize} \item Consists of several individual statements enclosed by \{ \} \item Whatever lies inside \{ \} is to be interpreted as a single statement \item Also called scope \item variables declared inside a Scope cannot be seen from the outside \item Eg: \begin{description} \item \{ \item \hspace*{2em}{ statements1;} \item \hspace*{2em}{ statements2;} \item \} \end{description} \end{itemize} \end{frame} \subsection{Compound statements} \begin{frame} \frametitle{Control statements} \begin{itemize} \item These control the flow of execution in a program or a function \item 2 kinds \begin{itemize} \pause \item <2-> Selection \begin{itemize} \item if, if-else, switch \end{itemize} \pause \item <3-> Repetition \begin{itemize} \item for, while, do-while \end{itemize} \end{itemize} \end{itemize} \end{frame} \subsection{Expression statements} \begin{frame} \frametitle{Operator Precedence} \begin{center} \begin{tabular}{| l | c| } \hline\hline \rowcolor{LightCyan} Operators & How to write them \\ \hline\hline multiplicative & * / \% \\\hline additive types & + - \\\hline relational & < > <= >= \\\hline equality & == != \\\hline logical AND & \&\& \\\hline logical OR & $||$ \\\hline assignment & = += -= *= /= \%= \\\hline \end{tabular} \end{center} \end{frame} \begin{frame} \frametitle{Operators} \begin{columns}[T] \begin{column}{0.45\textwidth} \begin{varblock}[6cm]{Source Code} \setbeamercolor{alerted text}{fg=blue} \setbeamerfont{alerted text}{series=\bfseries,family=\ttfamily} \begin{semiverbatim} \small \#include \newline using namespace std;\newline int main()\newline \{\newline {\alert<1>{\hspace*{2em}double i = 10;}}\newline {\alert<2>{\hspace*{2em}double j = 20;}}\newline {\alert<3>{\hspace*{2em}double result;}}\newline {\alert<4>{\hspace*{2em}cout$<<$"Adding";}}\newline {\alert<6>{\hspace*{2em}result=\alert<5>{i + j;}}}\newline {\alert<7>{\hspace*{2em}cout$<<$" i + j = ";}}\newline {\alert<8>{\hspace*{2em}cout$<<$result$<<$endl;}}\newline cin.get();\newline \} \end{semiverbatim} \end{varblock} \end{column} \begin{column}{0.45\textwidth} \setbeamercolor{alerted text}{fg=blue} \begin{varblock}[4cm]{Output} \alt<0-3>{ \hspace*{2em}}{\alt<4-6>{\alert<4>{Adding}}{\alt<7-7>{Adding\alert<7>{ i + j = }}{{Adding i + j = \alert<8>{30}}}}}\newline \end{varblock} \setbeamercolor{alerted text}{fg=blue} \begin{varblock}[4cm]{data} \alt<0-0>{ \hspace*{2em}\newline}{\alert<1>{i=10}}\newline \alt<0-1>{ \hspace*{2em}\newline}{\alert<2>{j=20}}\newline \alt<0-2>{ \hspace*{2em}\newline}{\alt<3-5>{\alert<3>{result}}{\alert<6>{result=30}}}\newline \end{varblock} \end{column} \end{columns} \end{frame} \begin{frame} \frametitle{Operators} \begin{columns}[T] \begin{column}{0.45\textwidth} \begin{varblock}[6cm]{Source Code} \setbeamercolor{alerted text}{fg=blue} \setbeamerfont{alerted text}{series=\bfseries,family=\ttfamily} \begin{semiverbatim} \small \#include \newline using namespace std;\newline int main()\newline \{\newline {\alert<1>{\hspace*{2em}double i = 10;}}\newline {\alert<2>{\hspace*{2em}double j = 20;}}\newline {\alert<3>{\hspace*{2em}double result;}}\newline {\alert<6>{\hspace*{2em}result=\alert<5>{\alert<4>{i / j}+1;}}}\newline {\alert<7>{\hspace*{2em}cout$<<$" i / j+1 = " $<<$ result$<<$endl;}}\newline {\alert<10>{\hspace*{2em}result=\alert<9>{i / \alert<8>{(j+1);}}}}\newline {\alert<11>{\hspace*{2em}cout$<<$" i / (j+1) = "$<<$ result$<<$endl;}}\newline cin.get();\newline \} \end{semiverbatim} \end{varblock} \end{column} \begin{column}{0.45\textwidth} \setbeamercolor{alerted text}{fg=blue} \begin{varblock}[4cm]{Output} \alt<0-6>{ \hspace*{2em}\newline}{\alert<7>{ i / j+1 = 1.5}}\newline \alt<0-10>{ \hspace*{2em}\newline}{\alert<11>{ i / (j+1) = 0.47619}}\newline \end{varblock} \setbeamercolor{alerted text}{fg=blue} \begin{varblock}[4cm]{data} \alt<0-0>{ \hspace*{2em}\newline}{\alert<1>{i=10}}\newline \alt<0-1>{ \hspace*{2em}\newline}{\alert<2>{j=20}}\newline \alt<0-2>{ \hspace*{2em}\newline}{\alt<3-5>{\alert<3>{result}}{\alert<6>{result=30}}}\newline \end{varblock} \end{column} \end{columns} \end{frame} \section{Problems} \subsection{Problems} \begin{frame} \frametitle{Problems} \begin{varblock}[6cm]{Source Code} \setbeamercolor{alerted text}{fg=blue} \setbeamerfont{alerted text}{series=\bfseries,family=\ttfamily} \begin{semiverbatim} \small {\#include \newline} {int main()\newline} {\{\newline} {\hspace*{2em}int a=5;} {\hspace*{2em}int a=0;} {\hspace*{2em}int result=a/b;\newline} {\hspace*{2em}co ut$<<$result$<<$endl\newline} {\hspace*{2em}cout$<<$"hel lo world"$<<$endl;\newline} {\hspace*{2em}int sum=2-2;\newline} {\hspace*{2em}cout$<<$"the sum of 2+2 is: ";\newline} {\hspace*{2em}cout$<<$sum$<<$endl;} \end{semiverbatim} \end{varblock} \end{frame} \end{document}