\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{mason} \pdfinfo{ /Title (pseudocode.pdf) /Creator (Cheatography) /Author (mason) /Subject (PseudoCode Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{PseudoCode Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{mason} via \textcolor{DarkBackground}{\uline{cheatography.com/35063/cs/11011/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}mason \\ \uline{cheatography.com/mason} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 26th February, 2017.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{STRING} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{INTEGER} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{REAL} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{BOOLEAN} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{CHARACTER} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Arithmetic Operators}} \tn % Row 0 \SetRowColor{LightBackground} Addition: + & Division: / \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Subtraction: – & Remainder: MOD \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Multiplication: * & Integer Division: DIV \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Other}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Assignment operator: = Don't confuse = with == (they're different)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{You can use true and false to check Boolean variables in your conditions (as in IF SomeBooleanVariable == true THEN …etc.)} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Variables are not loosely typed – you can't mix different types of variable They don't seem to have to be declared, although sometimes there'll be a declaration (If you're asked to declare something, you can pretty much just make it up – as long as it specifies the data type, identifier, etc…)} \tn % Row Count 12 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Sometimes a colon is used to identify the data type of a variable, e.g. SomeVariable : REAL would declare a real (decimal) variable} \tn % Row Count 15 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Keywords are in capitals in pseudocode} \tn % Row Count 16 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Arrays work as they do in most languages, but often their index starts at 1, rather than 0, and sometimes they use parenthesis ( ) instead of brackets {[} {]}} \tn % Row Count 20 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Multidimensional arrays work like this: identifier(y, x)} \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Constructs}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{IF condition THEN \newline do something \newline ELSE \newline do something else \newline END IF \newline \newline WHILE condition \newline statements \newline END WHILE \newline \newline REPEAT \newline statements \newline UNTIL condition} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The else bit is optional – you don't have to have it \newline The condition is any expression that evaluates to a Boolean \newline Notice how the statements are indented (well, hopefully they'll display indented when I publish this…) \newline When using WHILE and REPEAT loops, to count, you need to manually initialize and increment the counting variable \newline The statements inside a loop should cause a change in one of the values in the condition, otherwise you may create an infinite loop} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Procedure \& Functions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{PROCEDURE doSomething(Parameter : DATATYPE, OtherParameter: DATATYPE) \newline statements \newline END PROCEDURE \newline \newline FUNCTION doSomething(parameter: DATATYPE) : RETURNTYPE \newline statements \newline RETURN something \newline END PROCEDURE} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Procedures and functions don't have to take parameters, but the parentheses () are necessary \newline Functions must have a return type and must return something (of that type) \newline File Handling} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{For}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{FOR i = 1 to 10 \newline statements \newline NEXT i \newline END FOR} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{With a FOR loop, incrementing and initializing of the counting variable are done automatically \newline You can call the counting variable (i, in this case) anything you want, and you can also set the = something TO something values to whatever you want it to count from and to} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Relational / Comparison Operators}} \tn % Row 0 \SetRowColor{LightBackground} Equal to: == & Not equal to: != \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Not equal to: \textless{}\textgreater{} & Greater than: \textgreater{} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Less than: \textless{} & Greater than or equal to: \textgreater{}= \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} Less than or equal to: \textless{}= & Both: AND \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} One or both: OR & Invert: NOT \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Logical / Boolean Operators} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{CASE}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{CASE OF something \newline something = this: statement \newline something = that: statement \newline something = other: statement \newline default: statement \newline END CASE} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{In a case statement (that's switch statement to Java/C\# people) you can have however many options you want, but there must always be a default for if none of the options match \newline In the example above, something is the variable that is being checked, and this, that and other are things it's being compared with} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{String Manipulation}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{There are two functions that look things up in the ASCII character set table for you:} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ASCII(character) returns the ASCII value of a character, character} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{CHAR(integer) returns the character of an ASCII value, integer} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Characters may be in single or double quotes (it's another thing the examiners don't seem to have made their minds up about)} \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Strings can be concatenated using the addition operator, +} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{You sometimes have to use concatenation to output something in a friendly way} \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Mathematics can't be done on strings, but you can compare their ASCII values using the relational operators (\textless{}, \textgreater{}, \textless{}\textgreater{}, !=, ==, \textgreater{}=, \textless{}=)} \tn % Row Count 16 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{MID(string, integer1, integer2) returns the part of the string between positions integer1 and integer2} \tn % Row Count 19 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{LEFT(string, integer) RIGHT(string, integer) LENGTH(string) returns the length of the string, string} \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{LOCATE(string1, string2) returns the position of the first occurrence of string2 in string1 (0 means it starts at the beginning, -1 means it's not in there)} \tn % Row Count 25 (+ 4) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{I don't know why these functions are acting like there are official pseudocode libraries… they must just be for inspiration, and as a guide} \tn % Row Count 28 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File Handling}} \tn % Row 0 \SetRowColor{LightBackground} OPEN filename FOR MODE & (You can open as READ or WRITE only, one at a time) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} READ extractedvariable FROM filename & WRITE something TO filename \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} CLOSE filename & DELETE filename \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} RENAME filename TO something & CREATE filename \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{"filename is at end of file" can be used in the condition of loops, to iterate through all the records} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{High-Level Questions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Occasionally, you'll be asked to write something in a real language \newline I think the course does require you to be taught the basics of a high-level procedural programming language in the first year \newline Again, though, the questions are more about understanding what to do than following the correct syntax \newline Familiarise yourself with how to write the constructs above in a high-level language (i.e. not assembly…)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}