Computer Program Design Paper

i need some help with this homework for programing design

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Write a program to randomize an array of digits 0 to 9, for instance, 2 3 1 9 8 4 7 5 6 0. Therandom positions of the 10 digits will be generated by randomly swapping two digits in the array10 times.The program will start with an array of size 10 of elements 0 1 2 3 4 5 6 7 8 9, then use rand()function to generate 2 random positions in the range of 0 to 9 as the index of the digits andswap the two digits. For example, given the array 0 1 2 3 4 5 6 7 8 9, if the two random positionsare 2 and 8, then the resulting array of the swapping will be 0 1 8 3 4 5 6 2 9. The program willdo 10 times of generating 2 random positions and swapping.

i attached a file that descripe the hole thing

Project 3, Program Design
1. Write a program to randomize an array of digits 0 to 9, for instance, 2 3 1 9 8 4 7 5 6 0. The
random positions of the 10 digits will be generated by randomly swapping two digits in the array
10 times.
The program will start with an array of size 10 of elements 0 1 2 3 4 5 6 7 8 9, then use rand()
function to generate 2 random positions in the range of 0 to 9 as the index of the digits and
swap the two digits. For example, given the array 0 1 2 3 4 5 6 7 8 9, if the two random positions
are 2 and 8, then the resulting array of the swapping will be 0 1 8 3 4 5 6 2 9. The program will
do 10 times of generating 2 random positions and swapping.
Sample output: 6 3 4 0 9 1 2 8 5 7
The program should include the following function where a is the array and n is the size of the
array
void swap(int a[], int n);
1) Name your program key_array.c
2) The main function declares and initialized the array, calls the swap function, and then
displays the array.
3) In the swap() function, use rand() function to do 10 times of generating 2 random
positions in the range of 0 to 9 and swapping.
4) To use the rand() and time function, you need to include and .
How to use the rand() function to generate a random number:
1) With the help of rand () function, a number in range of lower to upper can be
generated as num = (rand() % (upper – lower + 1)) + lower
2) rand() function generates the same sequence again and again every time the
program runs. Use srand() function with time to set seed for rand() function so it
generates different sequences of random numbers. Include the following statement at
the beginning of the main function: srand(time(NULL));
2. A simple way to encrypt a number is to replace each digit of the number with its position (index)
in a key array. A key array is an ordering of the digits 0 – 9, such as 2 3 1 9 8 4 7 5 6 0. For
example, 831 will be encrypted as 412 with the key array 2 3 1 9 8 4 7 5 6 0 because 8 is at
position (index) 4 in the key array, 3 is at index 1, 1 is at index 2.
Write a C program that asks the user to enter a positive integer (the integer could be of any
number of digits in the range of the integer type) and encrypts the number with a key array
that’s randomly generated. A sample input/output:
Enter the number of digits of the number: 5
Enter the number: 92028
Key array: 2 3 1 9 8 4 7 5 6 0
Output: 30904
1) Name your program encrypt.c.
2) The user will enter the total number of digits before entering the number.
3) You can use format specifier “%1d” in scanf to read in a single digit into a variable (or an array
element). For example, for input 101011, scanf(“%1d”, &num) will read in 1 to num.
4) Include the swap function from part 1 to generate the key array.
5) As part of the solution, write and call the function replace() with the following prototype.
The replace() function assumes that the digits are stored in the array a and computes the
replaced digits and store them in the array b. The function uses the key array key to encrypt.
n represents the size of the array a and b.
void replace(int a[], int b[], int key[], int n);
6) The main function reads in the input and stores it in an array, calls swap function to generate
the key array, and calls the replace function, and then displays the output.
Before you submit
1. Compile both programs with –Wall. –Wall shows the warnings by the compiler. Be sure
it compiles on student cluster with no errors and no warnings.
gcc –Wall key_array.c
gcc –Wall encrypt.c
2. Be sure your Unix source file is read & write protected. Change Unix file permission on
Unix:
chmod 600 key_array.c
chmod 600 encrypt.c
3. Test your programs multiple times to check its correctness. There are no testing scripts
for this project since the key arrays are generated randomly.
4. Submit key_array.c and encrypt.c on Canvas.
Grading
Total points: 100 (50 points each problem)
1. A program that does not compile will result in a zero.
2. Runtime error and compilation warning 5%
3. Commenting and style 15%
4. Functionality 80%
-Functions implemented as required
Programming Style Guidelines
The major purpose of programming style guidelines is to make programs easy to read and
understand. Good programming style helps make it possible for a person knowledgeable in the
application area to quickly read a program and understand how it works.
1. Your program should begin with a comment that briefly summarizes what it does. This
comment should also include your name.
2. In most cases, a function should have a brief comment above its definition describing
what it does. Other than that, comments should be written only needed in order for a
reader to understand what is happening.
3. Variable names and function names should be sufficiently descriptive that a
knowledgeable reader can easily understand what the variable means and what the
function does. If this is not possible, comments should be added to make the meaning
clear.
4. Use consistent indentation to emphasize block structure.
5. Full line comments inside function bodies should conform to the indentation of the code
where they appear.
6. Macro definitions (#define) should be used for defining symbolic names for numeric
constants. For example: #define PI 3.141592
7. Use names of moderate length for variables. Most names should be between 2 and 12
letters long.
8. Use underscores to make compound names easier to read: tot_vol or
total_volumn is clearer than totalvolumn.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER