Skip to content

Commit 4fc1fb2

Browse files
committed
Adicionando formatação para algoritmos
- Linguagens: C e Java
1 parent 09cf8a3 commit 4fc1fb2

File tree

6 files changed

+116
-11
lines changed

6 files changed

+116
-11
lines changed

codigos/codigo-c.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#define N 10
3+
4+
/**
5+
* Block
6+
* Comment
7+
*
8+
**/
9+
10+
int main()
11+
{
12+
// line comment
13+
int i, x;
14+
15+
scanf("%d", &x);
16+
17+
if (x == 0) {
18+
return -1;
19+
}
20+
21+
while (x--) {
22+
for (i = 0; i < x; i++) {
23+
printf("%d ", i);
24+
}
25+
}
26+
27+
return 0;
28+
}

codigos/codigo-java.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Block comment
3+
*
4+
**/
5+
class Dog {
6+
7+
// line comment
8+
int age;
9+
10+
public Dog(int age) {
11+
this.age = age;
12+
}
13+
14+
private static String sound() {
15+
return "Au";
16+
}
17+
18+
public final void say() {
19+
System.out.println(Dog.bark());
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "{DOG}";
25+
}
26+
27+
public void setAge(int age) {
28+
this.age = age;
29+
}
30+
31+
public int getAge() {
32+
return this.age;
33+
}
34+
}

codigos/codigo.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

elementos-textuais/topico-2.tex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ \section{Equations}\label{sec:LABEL_CHP_2_SEC_C}
3838
\label{eq:LABEL_EQ_1}
3939
\end{equation}
4040

41-
\section{References}\label{sec:LABEL_CHP_2_SEC_D}
41+
\section{Listings}\label{sec:LABEL_CHP_2_SEC_D}
42+
Reference: \url{http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings}
43+
44+
\codec{C}{alg:LABEL_CODE_1}{codigos/codigo-c.txt}
45+
46+
\codejava{Java}{alg:LABEL_CODE_2}{codigos/codigo-java.txt}
47+
48+
\section{References}\label{sec:LABEL_CHP_2_SEC_E}
4249
\begin{itemize}
4350
\item Referencing \refchapter{chp:LABEL_CHP_1}
4451
\item Referencing \refsection{sec:LABEL_CHP_1_SEC_A}
4552
\item Referencing \refsection{sec:LABEL_CHP_1_SEC_C}
4653
\item Referencing \reftable{tab:LABEL_TAB_1}
4754
\item Referencing \reffigure{fig:LABEL_FIG_1}
4855
\item Referencing \refequation{eq:LABEL_EQ_1}
56+
\item Referencing \reflisting{alg:LABEL_CODE_1}
4957
\item Article \cite{art:REF_ART_1}
5058
\item Referencing \refappendix{chp:LABEL_APP_1}
5159
\end{itemize}

main.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
\maketablespage
6767

6868
% Algoritmos
69-
%\makelistingspage
69+
\makelistingspage
7070

7171
% Abreviaturas (devem estar em ordem alfabética)
7272
\makeabrevpage{\input{elementos-pretextuais/abreviaturas}}

projetofinal-dcc.cls

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,50 @@
2929
\RequirePackage{amsmath} %formulas matemáticas
3030
\RequirePackage{hyperref} %referências
3131
\RequirePackage{fancyhdr} %manipulação de header e footer
32-
\RequirePackage{iidefs} %especifico para ufrj/im/dcc
32+
\RequirePackage{iidefs} %especifico para ufrj/im/dcc
33+
34+
\RequirePackage{color}
35+
\RequirePackage{listings}
36+
37+
%==============================================================================
38+
% Códigos
39+
%==============================================================================
40+
\definecolor{dkgreen}{rgb}{0,0.6,0}
41+
\definecolor{gray}{rgb}{0.5,0.5,0.5}
42+
\definecolor{black}{rgb}{0,0,0}
43+
\definecolor{blue}{rgb}{0,0,0.4}
44+
\definecolor{purple}{rgb}{0.8,0,0.3}
45+
\definecolor{orange}{rgb}{1,0.4,0}
46+
47+
\newcommand{\codejava}[3]{
48+
\mbox{
49+
\lstset{framexleftmargin=5mm, frame=shadowbox, rulesepcolor=\color{gray}}
50+
\lstinputlisting[language=Java,
51+
breaklines=true,
52+
basicstyle=\footnotesize\ttfamily,
53+
keywordstyle=\bfseries\color{purple},
54+
commentstyle=\itshape\color{dkgreen},
55+
stringstyle=\color{orange},
56+
showstringspaces=false,
57+
rulecolor=\color{black},
58+
caption=#1,label=#2]{#3}
59+
}
60+
}
61+
62+
\newcommand{\codec}[3]{
63+
\mbox{
64+
\lstset{framexleftmargin=5mm, frame=shadowbox, rulesepcolor=\color{gray}}
65+
\lstinputlisting[language=C,
66+
breaklines=true,
67+
basicstyle=\footnotesize\ttfamily,
68+
keywordstyle=\bfseries\color{dkgreen},
69+
commentstyle=\itshape\color{purple},
70+
identifierstyle=\color{blue},
71+
stringstyle=\color{orange},
72+
showstringspaces=false,
73+
caption=#1,label=#2]{#3}
74+
}
75+
}
3376

3477
%=====================================================================
3578
% Referências

0 commit comments

Comments
 (0)