首页 > > 详细

代写permarray_main作业、代做C++编程设计作业、代写C/C++实验作业代做Python程序|代做Python程序

Homework 03
Link to create your repository: https://classroom.github.com/a/OTWqMgeC
Due date: Sep. 24, 2019
Points: 40 pt.
Final contents of repository (all in the root of your repository; no subdirectories;
exact filenames):
sum.c
permarray.c
permarray_main.c
README.md
.travis.yml
any test cases we've given you, or that you come up with on your own, are fine
to have in your repository, as long as they do not cause your build to fail.
.gitignore is optional.
The purpose of this homework assignment is to practice using Travis, get
comfortable making C programs, and practice with pointers.
Warning: Your filenames, their contents, and code outputs must be exactly as
described here. We have automated our grading process to have a fair and
timely feedback. Any discrepency will result in a mismatch with expected output
of a test case and you will lose the points allocated for that test case.
Your data file or outputs must not include extra characters or lines. Pay special
attention to the beginning and end of a string you print to output.
Make sure that you print messages to the expected device in each case of
standard output (stdout) and standard error (stderr).
If your code generates an output, it is expected that it goes to a new line at the
end (so that your shell prompt starts on the next line after running your
program.)
If something is not clear, ask about it. Do not make assumptions.
Task 0: Review the readings
In case you did not get to finish the assigned readings, make sure you do it
now. Remember that it is always more fun and fruitful when you actually
practice what you are reading; try examples from the readings and implement
new functionalities based on those.
Task 1: Travis setup [5 pt.]
As in the last assignment, you will need to setup a README.md file with the
Travis CI build indicator for your repository. When the homework is finished, the
build indicator should show "passed". Detailed intructions can be seen in The
hw02 assignment's repo
You will need to copy the test cases from this hw repo to your own repo
manually.
Submission: file README.md
Task 2: Sum [15 pt.]
Write a program in a single file sum.c which accepts multiple integer numbers
as command line arguments and prints their total to the standard output. You
need to use a standard library function such as strtol to convert from string to
number. The following examples explain the expected outputs depending on
input arguments.
> ./sum 1 2 5
8
> ./sum 29 74 -21 78 0
160
> ./sum
Error: Expected a list of integers as arguments!
> ./sum d29 74 -21
53
Error: d29 is not a valid integer.
> ./sum d29 74 testing -21
53
Error: d29 is not a valid integer!
Error: testing is not a valid integer!
> ./sum d29 testing
Error: d29 is not a valid integer!
Error: testing is not a valid integer!
Note that the sum must be printed to stdout, while the errors must be printed to
stderr.
Submission: file sum.c.
Task 3: Arrays and Pointers [20 pt.]
Below is the declaration of a function that performs a specific permutation of the
elements of an array of integer values. Parameter len indicates the length of the
array.
int permarray(int* arr, size_t len);
The implemented permutation must be as follows:
The non-positive values (including zero) should be moved to the beginning of
the array, while keeping their original order.
The positive values should be moved after non-positive values and sorted in
non-descending order.
The implementation must be in-place, i.e., you cannot allocate additional array
for calculating the result. For in-place sorting, you can implement simple
algorithms such as bubble sort or insertion sort.
Set the return value to be always 0, i.e., always successful.
We first show some expected inputs and outputs and then discuss about actual
format of your code. Here are examples of input/output that explains the
expected behavior.
> ./permute_array 22 1 -5 5 0 -29 2
-5 0 -29 1 2 5 22
> ./permute_array -4 29 74 -21 78 -11
-4 -21 -11 29 74 78
> ./permute_array 9 8 3 -3 -5 2 -7
-3 -5 -7 2 3 8 9
> ./permute_array
Error: Expected a list of integers as arguments!
> ./permute_array 22 3d test2 1 -5 5 0 -29 2
-5 0 -29 1 2 5 22
Error: 3d is not a valid integer!
Error: test2 is not a valid integer!
As in Task 1, the expected result goes to stdout, while the errors are printed to
stderr.
You must implement the above permarray() function in file permarray.c using the
exact signature given above. Then, create a main() function in a separate file
permarray_main.c that will receive the array as command line arguments, calls
the function in permarray.c, and produces the expected outputs. Your code must
not impose any limit on the number of arguments (beyond any restriction that
might be in place by OS).
Note that in order for your main() to be able to call permarray(), it needs to know
the signature of the permarray() function. You can simply include the signature
shown at the beginnign of this task in your permarray_main.c file (after any
#include and before main()). An alternative approach is to include a .h file that
consists of the signature declaration. Since our program is very simple here, we
skip creating an additional .h in this exercise.
You can build an executable of your code named permute_array, by running the
following command:
gcc permarray.c permarray_main.c -o permute_array
Submission: files permarray.c and permarray_main.c.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点文章
程序代写更多图片

联系我们 - QQ: 99515681 微信:codinghelp
© 2014 www.7daixie.com
程序代写网!