\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{Lavirsis} \pdfinfo{ /Title (c-class-objects.pdf) /Creator (Cheatography) /Author (Lavirsis) /Subject (C++ Class Objects 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}{3E74A3} \definecolor{LightBackground}{HTML}{F2F6F9} \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++ Class Objects Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Lavirsis} via \textcolor{DarkBackground}{\uline{cheatography.com/152835/cs/32904/}}} \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}Lavirsis \\ \uline{cheatography.com/lavirsis} \\ \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 29th June, 2022.\\ 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*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Headers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{ac\}\}\#include \textless{}iostream\textgreater{}\{\{nl\}\}\#using namespace std;} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Structure Example}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Declare Structure} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{struct Order \{\{\{nl\}\}~~~~int modelNumber; \{\{nl\}\}~~~~string phone; \{\{nl\}\}~~~~float cost; \{\{nl\}\}\};} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Main Function, define the structure variable} \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{int main( ) \{ \{\{nl\}\}~~~~Order item1;} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Give values to structure variables} \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{~~~~item1.modelNumber = 10;\{\{nl\}\}~~~~item1.phone = "Samsung Galaxy S"; \{\{nl\}\}~~~~item1.cost = 1099.99;} \tn % Row Count 13 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Display/Output structure members} \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{~~~~cout \textless{}\textless{} "Order, " \textless{}\textless{} item1.phone \textless{}\textless{} item1.modelNumber; \{\{nl\}\}~~~~cout \textless{}\textless{} "This item costs: \$" \textless{}\textless{} part1.cost \textless{}\textless{} endl;\{\{nl\}\}\}} \tn % Row Count 18 (+ 4) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Output: \{\{nl\}\} Order, Samsung Galaxy S10 \{\{nl\}\}This item costs: \$1099.99} \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Whenever finished with output or line, \newline place 'end line' indicator: endl} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Class Example: point.h}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declare class with the class name}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{class Point\{\{nl\}\} \{ ~~~~} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Provide the class specifiers, set as private}}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{private: \{\{nl\}\}~~~~double x; \{\{nl\}\}~~~~double y;} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Set x as the first variable, y as the second variable} \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{void set (double first, double second)\{\{nl\}\}\{\{\{nl\}\}~~~~x = first;\{\{nl\}\}~~~~y = second; \{\{nl\}\}\}} \tn % Row Count 10 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Provide the class properties and methods, set as public}}\{\{nl\}\}No-parameter constructor, when an object for this class is created, the Point class values (x and y) will be set to 0} \tn % Row Count 14 (+ 4) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{public:\{\{nl\}\}\{\{nl\}\}~~~~Point( ) : x(0.0), y(0.0)\{\{nl\}\}~~~~\{\{\{nl\}\}~~~~~~~~cout \textless{}\textless{} "New Point object created/instantiated." \textless{}\textless{} endl; \{\{nl\}\}~~~~\}} \tn % Row Count 19 (+ 5) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Alternatively, the above constructor can also be written as:} \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{~~~~Point( )\{\{nl\}\}~~~~\{\{\{nl\}\}~~~~~~~~x = 0.0; \{\{nl\}\}~~~~~~~~y = 0.0;\{\{nl\}\}~~~~\}} \tn % Row Count 26 (+ 5) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A two parameter constructor, set the x and y values} \tn % Row Count 28 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{~~~~Point (double first, double second) : x(first), y(second)\{\{nl\}\}~~~~\{\{\{nl\}\}~~~~~~~~cout \textless{}\textless{} "New object, values (x,y) are \textless{}\textless{} x \textless{}\textless{} "," \textless{}\textless{} y \textless{}\textless{} endl;\{\{nl\}\}~~~~\}} \tn % Row Count 34 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Class Example: point.h (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{For returning individual values of x and y} \tn % Row Count 1 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{~~~~double getX( ) \{ return x; \} \{\{nl\}\}~~~~double getY( ) \{ return y; \}} \tn % Row Count 4 (+ 3) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Display the current values of x and y} \tn % Row Count 5 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{~~~~void display ( ) \{ \{\{nl\}\}~~~~~~~~cout \textless{}\textless{} x \textless{}\textless{} "," \textless{}\textless{} y \textless{}\textless{} endl; \}} \tn % Row Count 8 (+ 3) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Overloading the function with two new doubles as input parameters} \tn % Row Count 10 (+ 2) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{void add(double first, double second) \{ \{\{nl\}\}~~~~x += first; \{\{nl\}\}~~~~y += second; \}} \tn % Row Count 13 (+ 3) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Overloading the function with another Point object as the input} \tn % Row Count 15 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{void minus(Point pp) \{ \{\{nl\}\}~~~~x = x - pp.x; \{\{nl\}\}~~~~y = y - pp.y ; \}} \tn % Row Count 18 (+ 3) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Add the destructor} \tn % Row Count 19 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\textasciitilde{}Point ( ) \{ \{\{nl\}\} ~~~~cout \textless{}\textless{} "Point object for x,y values of " \textless{}\textless{} x \textless{}\textless{} "," \textless{}\textless{} y \textless{}\textless{} "destroyed." \textless{}\textless{} endl; \}} \tn % Row Count 22 (+ 3) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Overload the function with another Point object and return the result} \tn % Row Count 24 (+ 2) % Row 23 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Point mult(Point pp1) \{ \{\{nl\}\}~~~~Point pp2; \{\{nl\}\}~~~~pp2.x = x * pp2.x; \{\{nl\}\}~~~~pp2.y = y * pp2.y; \{\{nl\}\}~~~~return p2; \{\{nl\}\}\}} \tn % Row Count 29 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Class Example: point.cpp}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include "point.h"} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Main Function} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int main( ) \{ \{\{nl\}\}~~~~Point ptA; \{\{nl\}\}~~~~Point ptB(1.0, 3.0), ptC (5.0, 8.0);\{\{nl\}\}~~~~ptB.add(6.0,2.0);\{\{nl\}\}~~~~ptC.minus(ptB);\{\{nl\}\}~~~~ptA = ptC; \{\{nl\}\}~~~~Point ptD = ptB.mult(ptA); \{\{nl\}\}~~~~ptA.display( );\{\{nl\}\}~~~~return 0; \{\{nl\}\}\}} \tn % Row Count 11 (+ 9) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Object Values: \{\{nl\}\}ptA = (0.0,0.0); ptB(1.0, 3.0); ptC(5.0,8.0); \{\{nl\}\}ptB.add(6.0,2.0)= (1.0+6.0, 3.0+2.0); \{\{nl\}\}ptC.minus(ptB)= ((5.0-1.0),(8.0-3.0)) = (4.0,5.0); \{\{nl\}\}ptA = new ptC value = (4.0,5.0); \{\{nl\}\}ptD = ptB.mult(ptA) = ((4x7),(5x5)) = (28, 25);} \tn % Row Count 17 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Note:}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{About Properties and Classes} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A {\bf{property}} is a defined attribute of the object, for example properties for object Point include 'x' and 'y' \newline A {\bf{member}}, often a function, is an action that is performed on the object and its properties. \newline \newline class myClass \{ \newline ~~~~private: property = value; \newline ~~~~public: method \{ (action on value); \} \newline \} \newline main \{ myClass newObject; \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Internal and External Class Methods}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{If the Class methods are written externally, a prototype must be declared within the class first.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Point (double first, double second) : x(first), y(second); \{\{nl\}\}double getX( ); \{\{nl\}\}double getY( ); \{\{nl\}\}void display ( );} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{External syntax for returning class:}} \{\{nl\}\}className :: className(any parameters) \{ \}} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Point :: Point (double first, double second) : x(first), y(second) \{ \{\{nl\}\}~~~~cout \textless{}\textless{} "Object made with values x,y of " \textless{}\textless{} x \textless{}\textless{} "," \textless{}\textless{} y \textless{}\textless{} endl;\{\{nl\}\} \}} \tn % Row Count 11 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{External syntax for returning variable (or void):}} \{\{nl\}\} returnDataType className :: methodName(any parameters) \{ \}} \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{double Point :: getX( ) \{ return x; \} \{\{nl\}\}double Point :: getY \{ return y; \} \{\{nl\}\} void Point :: display ( ) \{ \{\{nl\}\}~~~~cout \textless{}\textless{} "point x,y : " \textless{}\textless{} x \textless{}\textless{} "," \textless{}\textless{} y \textless{}\textless{} endl; \}} \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Class Operator Overloading: Vector.h}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Declare class with private array variable as property} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{class Vector \{ \{\{nl\}\}private: \{\{nl\}\}~~~~double num{[}3{]};} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Set initialization values for class property} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{public: \{\{nl\}\}~~~~Vector ( ) : num\{0.0, 0.0, 0.0 \} \{\} \{\{nl\}\}~~~~Vector (double no1, double no2, double no3) \{ \{\{nl\}\}~~~~~~~~num{[}0{]} = no1; num{[}1{]} = no2; num{[}2{]} = no3; \}\{\{nl\}\}~~~~void display ( ) \{ \{\{nl\}\} ~~~~~~~~cout \textless{}\textless{} "{[}" \textless{}\textless{} num{[}0{]} \textless{}\textless{} ", " \textless{}\textless{} num{[}1{]} \textless{}\textless{} ", " \textless{}\textless{} num{[}2{]} \textless{}\textless{} "{]}" \textless{}\textless{} endl; \}} \tn % Row Count 14 (+ 9) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Create prototypes for external class methods} \tn % Row Count 15 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{~~~~Vector operator++();\{\{nl\}\}~~~~Vector operator++(int);\{\{nl\}\}~~~~Vector operator-{}-();\{\{nl\}\}~~~~Vector operator+(Vector);\{\{nl\}\}~~~~Vector operator-(Vector\&);\{\{nl\}\}~~~~friend Vector operator *(Vector\&, Vector\&);\{\{nl\}\}~~~~double\& operator{[}{]}(int);} \tn % Row Count 23 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Class Operator Overloading: Vector.cpp}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include "Vector.h"} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Vector Vector :: operator ++()\{ \{\{nl\}\}~~~~return Vector((num{[}0{]} + 1), (num{[}1{]} + 1), (num{[}2{]} + 1)); \} \{\{nl\}\} Vector Vector :: operator++(int) \{ \{\{nl\}\} \{\{nl\}\}~~~~num{[}0{]}++; \{\{nl\}\}~~~~num{[}1{]}++; \{\{nl\}\}~~~~num{[}2{]}++; \{\{nl\}\}~~~~return Vector(num{[}0{]}, num{[}1{]}, num{[}2{]}); \} \{\{nl\}\} \{\{nl\}\}Vector Vector :: operator-{}-()\{ \{\{nl\}\}~~~~return Vector((num{[}0{]}-1), (num{[}1{]}-1), (num{[}2{]}-1)); \} \{\{nl\}\} \{\{nl\}\}Vector Vector :: operator + (Vector v) \{ \{\{nl\}\} ~~~~return Vector((num{[}0{]} + v.num{[}0{]}), (num{[}1{]} + v.num{[}1{]}), (num{[}2{]} + v.num{[}2{]})); \} \{\{nl\}\} \{\{nl\}\}Vector Vector :: operator - (Vector\& v) \{ \{\{nl\}\}~~~~return Vector((num{[}0{]} - v.num{[}0{]}), (num{[}1{]} - v.num{[}1{]}), (num{[}2{]} - v.num{[}2{]})); \{\{nl\}\}\} \{\{nl\}\} \{\{nl\}\}Vector operator*(Vector\& v1, Vector\& v2) \{ \{\{nl\}\}~~~~return Vector((v1.num{[}1{]} * v2.num{[}2{]}) - (v1.num{[}2{]} * v2.num{[}1{]}), (v1.num{[}2{]} * v2.num{[}0{]}) - (v1.num{[}0{]} * v2.num{[}2{]}), ((v1.num{[}0{]} * v2.num{[}1{]}) - (v1.num{[}1{]} * v2.num{[}0{]}))); \}\{\{nl\}\} \{\{nl\}\}double\& Vector::operator{[}{]}(int index) //friend operator \{ \{\{nl\}\}~~~~if (index \textgreater{}= 3) \{ \{\{nl\}\}~~~~~~~~cout \textless{}\textless{} "Array index is out of bounds, exiting the program" \textless{}\textless{} endl; \{\{nl\}\}~~~~~~~~exit(1); \{\{nl\}\}~~~~\} \{\{nl\}\}~~~~return num{[}index{]}; \}} \tn % Row Count 32 (+ 31) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Class Operator Overloading: Main.cpp}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Create Object and use class methods} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{int main(void) \{ \{\{nl\}\} ~~~~Vector a, b(3.0, 4.0, 5.0); \{\{nl\}\} \{\{nl\}\} ~~~~a{[}0{]} = 11.0; \{\{nl\}\} ~~~~a{[}1{]} = -15.0; \{\{nl\}\} ~~~~a{[}2{]} = 3.0; \{\{nl\}\} \{\{nl\}\} ~~~~Vector c(2.0,4.0,7.0); \{\{nl\}\} \{\{nl\}\} ~~~~(++c).display(); \{\{nl\}\} ~~~~(c++).display(); \{\{nl\}\} ~~~~(-{}-c).display(); \{\{nl\}\} \{\{nl\}\} ~~~~Vector d = a + b; \{\{nl\}\} ~~~~d.display(); \{\{nl\}\} ~~~~d = a - b; \{\{nl\}\} ~~~~d.display(); \{\{nl\}\} ~~~~d = a * b; \{\{nl\}\} ~~~~d.display(); \{\{nl\}\} ~~~~d{[}5{]} = 5.0; \{\{nl\}\} \{\{nl\}\} ~~~~return 0; \{\{nl\}\}\}} \tn % Row Count 18 (+ 17) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Inheritance}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}