\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{Jumpingjaden} \pdfinfo{ /Title (c-cs-1410-exam-1.pdf) /Creator (Cheatography) /Author (Jumpingjaden) /Subject (C++ CS 1410 Exam 1 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}{761AC7} \definecolor{LightBackground}{HTML}{F6F0FB} \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{C++ CS 1410 Exam 1 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Jumpingjaden} via \textcolor{DarkBackground}{\uline{cheatography.com/210798/cs/45543/}}} \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}Jumpingjaden \\ \uline{cheatography.com/jumpingjaden} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 26th January, 2025.\\ Updated 26th January, 2025.\\ 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{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Terminology}} \tn % Row 0 \SetRowColor{LightBackground} Cin & is the same as input \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Cout & is same as print \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textless{}\textless{} and \textgreater{}\textgreater{} & point to where the information is going to. \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} difference between the ++ being before the variable or after & ++x adds 1 to the x variable before doing the math statement, x++ adds 1 after the math statement. \tn % Row Count 10 (+ 5) % Row 4 \SetRowColor{LightBackground} setprecision(3) & cout \textless{}\textless{} setprecision(3) \textless{}\textless{} 1.23456\textless{}\textless{} endl; 3 total numbers, 2 after the decimal =1.23 \tn % Row Count 15 (+ 5) % Row 5 \SetRowColor{white} setprecision command with fixed notation & cout \textless{}\textless{} fixed \textless{}\textless{} setprecision(3) \textless{}\textless{} 1.23456 \textless{}\textless{} endl; 4 total numbers, 3 after the decimal = 1.235 \tn % Row Count 20 (+ 5) % Row 6 \SetRowColor{LightBackground} Math Libraries & ceiling goes up to next int and floor goes to the int below ceil(3.5) = 4 floor(3.5)=3 Abs(-3.5) = 3.5 \tn % Row Count 26 (+ 6) % Row 7 \SetRowColor{white} setw & sets the field witdth to be used on the display \tn % Row Count 29 (+ 3) % Row 8 \SetRowColor{LightBackground} function & a way to modularize code and make it reusable. They help us manage, reuse, and organize our code. must include return type, name, parameters and \{\}. int AddFive(int a) \{return x+5\}\} \tn % Row Count 39 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Terminology (cont)}} \tn % Row 9 \SetRowColor{LightBackground} parameter passing by value & aka pass by copy, modifies a copy of the variable so that original stays the same. int addfive(int a) \{ return a = a +5\}; int b = 5; addfive(b); shows 5 \tn % Row Count 8 (+ 8) % Row 10 \SetRowColor{white} parameter passing by reference & modifies the actual variable being passed in. void addfive(int\& a) \{ a= a+5;\} int b = 5; addfive(b); shows 10. \tn % Row Count 14 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{.h/.cpp}} \tn % Row 0 \SetRowColor{LightBackground} .h aka header file & allows us to link our program to library code \#include "main.h" \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} .cpp & source code files - methods for the definitions listed in .h file are here \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} classes & Student class \{\} within .h file, have member variable and member functions. default visibility of private \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} class scope & private: only available within that function, public: available throughout the code and protected \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} \seqsplit{Constructors} & a member function of a class that is executed whenever we create new objects of that class, it is named after the class and gives our member variables values. student(); \tn % Row Count 21 (+ 7) % Row 5 \SetRowColor{white} default constructor & creates an empty object, numeric values to 0, character and string values to blank "", and sets objects to empty. can be written in line or initialized list. Student() : id\_(0), name\_(""), email\_("")\{\} \tn % Row Count 29 (+ 8) % Row 6 \SetRowColor{LightBackground} General Constructor & creates an object with user chosen values given to the member variables. can be in line or a list but not both. Student(int id, std::string name, std::string email) : id\_(id), name\_(name),email\_(email) \{\} \tn % Row Count 37 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{.h/.cpp (cont)}} \tn % Row 7 \SetRowColor{LightBackground} Setters & gets details from contructors either general or default and add them to the variables list. void SetId(int id); \tn % Row Count 5 (+ 5) % Row 8 \SetRowColor{white} Getters & a way for the user of the class to see the values without having direct access to them. int GetId() const \{return id\_;\} \tn % Row Count 10 (+ 5) % Row 9 \SetRowColor{LightBackground} structs & similar to class but can group several related variables in one place. \tn % Row Count 13 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Loops}} \tn % Row 0 \SetRowColor{LightBackground} If statement & executes when the condition is true. double up on ifs and code executes for all true statements. if(force \textless{}10)\{\} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} else if & executes the first true statement. then skips the rest. else if(force \textless{} 25)\{\} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} for loops & (start, end, change) for(int i = 2; i \textless{} 12, i++) \{\} i-{}- for counting down \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} while loops & iterates while a condition is true. while (num \textless{}= 10)\{\} \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} do/while loops & same as while but If the condition is false to begin with it will go through at least once. It can also cut down on code. do() while(); \tn % Row Count 17 (+ 5) % Row 5 \SetRowColor{white} try/catch & try to make this block of code work, if it doesnt use the catch statement to show an error message \tn % Row Count 21 (+ 4) % Row 6 \SetRowColor{LightBackground} throw & creating an error message within a definition or within main. Any throw will work as long as catch has (…) next to it. \tn % Row Count 26 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Overloaded Operators: classes}} \tn % Row 0 \SetRowColor{LightBackground} Overloaded Function & same name different parameters, need these to be able to do basic math/comparisons on objects student1 vs int 5 \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} Member Functions - binary & Box operator+(box const \&rhs)const adding a box variable to a rhs \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} Member Functions - binary - definition & Box Box::operator+(Box const \&rhs) const \{\}. \tn % Row Count 13 (+ 3) % Row 3 \SetRowColor{white} Member functions unary & only the implicit argument is required. \tn % Row Count 15 (+ 2) % Row 4 \SetRowColor{LightBackground} Friend functions & not members of the class. given access to the private member variables. used specifically when you want to be able to use an object on the rhs rather than the lhs. friend Box operator+(Box const \&lhs, Box const \&rhs); \tn % Row Count 26 (+ 11) % Row 5 \SetRowColor{white} friend function as insertion operator & friend std::ostream\& operator\textless{}\textless{}(std::ostream\& out,Item \&item); DEFINITION: ostream\& operator\textless{}\textless{}(ostream \&out,Item \&item) \{ out \textless{}\textless{} "Name: " \textless{}\textless{} item.name\_ \textless{}\textless{} " Description: " \textless{}\textless{} item.description\_ \textless{}\textless{} " Price: " \textless{}\textless{} item.price\_; \} \tn % Row Count 38 (+ 12) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{scope}} \tn % Row 0 \SetRowColor{LightBackground} global & can be accessed from anywhere in the program, not placed in a function \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} local & also known as block scope. between {[}{]} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{function} & between \{\} of a function \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{namespace} & defined in the namespace. \tn % Row Count 9 (+ 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}{overloaded \textless{}\textless{} operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/jumpingjaden_1737923194_Screenshot 2025-01-26 132553.png}}} \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}{writing a function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/jumpingjaden_1737920376_Screenshot 2025-01-26 123655.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{std::strings}} \tn % Row 0 \SetRowColor{LightBackground} defining a string & string s1("Man"); or string s2 = "Beast"; or string s3; \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} combining strings & use the + operator. s3 += "" and "" + s2 \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Getline & reads up to an enter aka new line getline(cin, name); \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} cin & reads up to a space cin \textgreater{}\textgreater{} name; \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} fixes for getline when coming after a cin & add a cin.ignore(); before the getline statement \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} .size() and .length() & do the same thing, finds the length of the string \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} Concatenating with numbers & use to\_string. string full = str + to\_string(value); \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} comparing strings & same idea as values A is smaller in askii than B, Lower case values are larger than upper case in the askii table. \tn % Row Count 25 (+ 6) % Row 8 \SetRowColor{LightBackground} .find() & returns the position of the search item.specify a start position of search str.fing("iss); can also look for the option after the first time pos = str.find("iss"); str.find("iss", pos +1) \tn % Row Count 35 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{std::strings (cont)}} \tn % Row 9 \SetRowColor{LightBackground} string::npos & no position aka not found \tn % Row Count 2 (+ 2) % Row 10 \SetRowColor{white} substring & returns a portion of the string and specifies the end. int space = str.find(" "); string school = str.substr(0, space); \tn % Row Count 8 (+ 6) % Row 11 \SetRowColor{LightBackground} .at vs {[}{]} for iterating over strings & .at is read only where as {[}{]} is read and write, .at will terminate if you are looking for something out of range {[}{]} will display random junk \tn % Row Count 15 (+ 7) % Row 12 \SetRowColor{white} cstring vs std::string & c-string pros: fixed length and prmitive data type. cons: watch for out of bounds. std::strings more intuitive to use and checks for out of bounds. \tn % Row Count 23 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{stringstream}} \tn % Row 0 \SetRowColor{LightBackground} \#include \textless{}sstream\textgreater{} & adds strings, objects and values into a stream, parse streams and strings into values \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \textless{}\textless{} & used to add to the stringstream. .str() function converts the stream to a string. stringstream sout; sout \textless{}\textless{} "add words"; \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} parsing & string str = "one two three four"; stringstream sout; sout \textless{}\textless{} str; string temp; while(sout \textgreater{}\textgreater{} temp) \{cout \textless{}\textless{} temp \textless{}\textless{} endl;\} \tn % Row Count 14 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{class member functions example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/jumpingjaden_1737923385_Screenshot 2025-01-26 132917.png}}} \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}{example main, cpp and h files}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/jumpingjaden_1737924116_Screenshot 2025-01-26 134121.png}}} \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}{parts of a function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/jumpingjaden_1737924340_parts of a function.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}