CSC1109_Tutorials/Week10_Lab/Submission/CSC1109_Lab11_2200624.tex

166 lines
3.4 KiB
TeX

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\renewcommand\familydefault{\sfdefault}
\usepackage{tgheros}
\usepackage[defaultmono]{droidsansmono}
\usepackage{amsmath,amssymb,amsthm,textcomp}
\usepackage{enumerate}
\usepackage{multicol}
\usepackage{tikz}
\usepackage{geometry}
\geometry{left=25mm,right=25mm,%
bindingoffset=0mm, top=20mm,bottom=20mm}
% Image path
\graphicspath{{images/}}
\linespread{1.3}
\newcommand{\linia}{\rule{\linewidth}{0.5pt}}
% custom theorems if needed
\newtheoremstyle{mytheor}
{1ex}{1ex}{\normalfont}{0pt}{\scshape}{.}{1ex}
{{\thmname{#1 }}{\thmnumber{#2}}{\thmnote{ (#3)}}}
\theoremstyle{mytheor}
\newtheorem{defi}{Definition}
% my own titles
\makeatletter
\renewcommand{\maketitle}{
\begin{center}
\vspace{2ex}
{\huge \textsc{\@title}}
\vspace{1ex}
\\
\linia\\
\@author \hfill \@date
\vspace{4ex}
\end{center}
}
\makeatother
%%%
% custom footers and headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{}
\lfoot{CSC 1109 Lab 11}
\cfoot{}
\rfoot{Page \thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
%
% code listing settings
\usepackage{listings}
\lstset{
language=python,
basicstyle=\ttfamily\small,
aboveskip={1.0\baselineskip},
belowskip={1.0\baselineskip},
columns=fixed,
extendedchars=true,
breaklines=true,
tabsize=4,
prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
frame=lines,
showtabs=false,
showspaces=false,
showstringspaces=false,
keywordstyle=\color[rgb]{0.627,0.126,0.941},
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{01,0,0},
numbers=left,
numberstyle=\small,
stepnumber=1,
numbersep=10pt,
captionpos=t,
escapeinside={\%*}{*)}
}
%%%----------%%%----------%%%----------%%%----------%%%
\begin{document}
\title{CSC 1109 Lab 11}
\author{Woon Jun Wei, 2200624}
\date{\today}
\maketitle
\section*{Question 1}
\begin{lstlisting}[label={list:calculator},caption=calculator.py]
class calculator:
def __init__(self, x, y):
self.x = x
self.y = y
def adder(self):
print("The sum is: " + str(self.x + self.y))
return self.x + self.y
def subtractor(self):
print("The difference is: " + str(self.x - self.y))
return self.x - self.y
def multiplier(self):
print("The multiplication is: " + str(self.x * self.y))
return self.x * self.y
def divider(self):
print("The quotient is: " + str(self.x / self.y))
return self.x / self.y
def clear(self):
self.x = 0
self.y = 0
print("Numbers are reset to be zero")
return self.x, self.y
if __name__ == "__main__":
x = int(input("Enter the first number: "))
y = int(input("Enter the second number: "))
calc = calculator(x, y)
calc.adder()
calc.subtractor()
calc.multiplier()
calc.divider()
calc.clear()
\end{lstlisting}
\begin{lstlisting}[label={list:calculator_output},caption=calculator.py output]
# Output 1
Enter the first number: 10
Enter the second number: 5
The sum is: 15
The difference is: 5
The multiplication is: 50
The quotient is: 2.0
Numbers are reset to be zero
# Output 2
Enter the first number: 100
Enter the second number: 5
The sum is: 105
The difference is: 95
The multiplication is: 500
The quotient is: 20.0
Numbers are reset to be zero
\end{lstlisting}
\end{document}