Code of Academic Integrity Violations of Academic Integrity: What are the Consequences? Doing Original Work at Penn Plagiarism-what is it? Citing Sources Common Knowledge Using the Internet Evaluating Internet Information Citing Electronic Sources Quoting Paraphrasing To Quote or Paraphrase? Summarizing Writing Computer Code Collaboration Copyright Good Work Habits Study Tips and Resources Style Guides Other Links Weingarten Learning Resources Center Research Basics Office of Student Conduct University Honor Council Tutoring Center Writing Center Penn Library

Avoiding Plagiarism:  Writing Computer Code

Plagiarism can also occur when you write code.

It is still plagiarism if the student borrows the structure of an original program exactly while changing only a few details that do not affect the meaning of the program.
The following program appears on page 118 of the textbook Algorithms in C (Addison Wesley, New York. 1990).

```Source: quicksort (int a [ ], int l, int r)
{
int v, i, j, t;
if (r > l)
{
v = a [ r ]; i = l-1; j = r;

for ( ; ; )
{
while (a [++i ] < v) ;
while (a [--j] > v);
if (i >= j) break;
t = a [i]; a [i] = a [j]; a [j] = t;
}
t = a [i]; a [i] = a [r]; a [r] = t;
quicksort (a, l, i-1);
quicksort (a, i+1, r);
}
}```
Unacceptable example 1
```mysort (int data[], int x, int y){
(B)=(A);}
int pivot;
int i, j;
int temp;

if (y > x){
pivot = data[y]; i = x-1; j = r;
while (1){
while (data [++i] < pivot);
while (data [--j] > pivot);
if (i >= j) break;
temp = data [i]; data [i] = data [y]; data [y] = temp;
}
temp = data [i]; data [i] = data [y]; data [y] = temp;
mysort (data, x, i-1);
mysort (data, i + 1, y);
}
}```

Source: Examples of plagiarism. Academic Integrity at Princeton. Retrieved September 3, 2004 from http://www.princeton.edu/pr/pub/integrity/pages/plagiarism/

This example is plagiarism because the student has borrowed the structure of the original program exactly, while changing only a few details that do not affect the meaning of the program. Though the program looks different to the untrained eye, it has exactly the same meaning as the original program. The student has made the following changes:

• Changed the names of variables: a, l, r, v and t are changed to data, x, y, pivot and temp (respectively)
• Replaced the construct “for (;;)” with the equivalent construct “while (1)”
• Changed the name of the procedure from “quicksort” to “mysort”
• Changed the indentation and the division of program elements between lines
Unacceptable example 2
```#define Swap(A,B) { temp=(A); (A)=(B); (B)=A;}

void mysort (const int* data, int x, int y){
int temp;
while (y > x){
int pivot = data[y];
int i = x-1;
int j = r;
while (1){
while (data [++i] < pivot){/*do nothing*/}
while (data --j] > pivot){/*do nothing*/}
if (i >= j) break;
swap (data [i], data [y];
}
swap (data [i], data [j];
mysort (data, x, i-1);
x = i+1;
}
}```

Source: Examples of plagiarism. Academic Integrity at Princeton. Retrieved September 3, 2004 from http://www.princeton.edu/pr/pub/integrity/pages/plagiarism.html

This example is also plagiarism. The student has made more changes to the program than in the first example, and some of this student’s changes are even improvements to the program. Nevertheless, this student’s program is clearly derived from the program in the textbook. The student’s action in this case can be compared to paraphrasing a passage from a reference book.

 This guide has been adapted from one produced at MIT entitled Academic Integrity at the Massachusetts Institute of Technology:  A Handbook for Students.  We are grateful for their permission to use and revise the work for students at the University of Pennsylvania. Written by Patricia Brennecke, Lecturer in English Language Studies Edited by Professor Margery Resnick, Chair of the Committee on Discipline, and Joanne Straggas, Office of the Dean for Undergraduate Education.  Prepared with the support of Professor Robert P. Redwine, Dean for Undergraduate Education at MIT. Adapted in Fall 2006 for use by graduate students at the University of Pennsylvania and published as the Handbook for Students, Ethics and Original Research by Professor Barbara Fuchs, Romance Languages, Dr. James B. Lok, Professor of Pathobiology, School of Veterinary Medicine, Linda Meiberg, graduate student and Karen Lawrence, Assistant Director of Education. This edition edited, amended and produced by: The University Honor Council and the Office of Student Conduct University of Pennsylvania Fall 2008