0% found this document useful (0 votes)
29 views2 pages

Programming Assignment

The document outlines a programming assignment for the course CS445, focusing on implementing the Cantor Pairing Function. Students are required to create two functions for encoding and decoding natural numbers, ensuring input validation for positive integers. Additionally, a report detailing the program's functionalities and a screenshot of its execution must be submitted by the due date on Google Classroom.

Uploaded by

Chadi Mohammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Programming Assignment

The document outlines a programming assignment for the course CS445, focusing on implementing the Cantor Pairing Function. Students are required to create two functions for encoding and decoding natural numbers, ensuring input validation for positive integers. Additionally, a report detailing the program's functionalities and a screenshot of its execution must be submitted by the due date on Google Classroom.

Uploaded by

Chadi Mohammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Arab Academy for Science and Technology and Maritime Transport

College of Computing and Information Technology


Course Structure of Programming Languages (CS445)
Lecturer Dr. Yasser Fouad
TA Mahmoud ElMorshedy

Programming Assignment
Implement a Cantor Pairing Function program using the language assigned to you.
Description:
Pairing function is a process to uniquely encode two natural numbers into a single
natural number. https://en.wikipedia.org/wiki/Pairing_function

The Cantor Pairing Function:

For example, to calculate 𝜋(47, 32):


47 + 32 = 79,
79 + 1 = 80,
79 × 80 = 6320,
6320 ÷ 2 = 3160,
3160 + 32 = 3192,
So, 𝜋(47, 32) = 3192.

The inverse of Cantor Pairing function:


To calculate x and y from z, we do:

1
For example, to find x and y such that 𝜋(𝑥, 𝑦) = 3192:
√8 ∗ 3192 + 1 − 1
𝑤=⌊ ⌋ = 79
2
792 + 79
𝑡= = 3160
2
𝑦 = 3192 − 3160 = 32
𝑥 = 79 − 32 = 47
thus 𝜋(47, 32) = 3192.

Functionalities:
You are required to implement two functions:
1. A function that takes two positive integers as arguments and calculates and returns the
encoded result 𝑧.
2. A function that takes a positive integer as an argument and calculates and returns the two
decoded numbers.
3. The functions should check if the passed arguments are positive integers, otherwise,
displays an error message and keep taking input from the user while the input is invalid.
Rubric:
• Program Functionalities [Total: 3 Points]
o Each of the three program functionalities will be evaluated using the
following criteria:

(0) (0.5) (1)

Functionality: Not implemented or Implemented but Implemented and


plagiarized. gives incorrect result. gives correct result.
Gives an error. Implemented without Implemented using
using functions. functions.

• Report [Total: 2 Points]


1- Correct Report Format (A Cover-page containing your name & RegID)
2- Explanation of each function handling each operation [1 Points]
3- Screenshot of the program run with a sample input and output [1 Point]

- Due: Check due date on Classroom


- Submit on Google Classroom.
- Attach the following:
o Source code files.
o Report document.

You might also like