Week 04 Weekly Test Questions

Test Conditions

These questions must be completed under self-administered exam-like conditions. You must time the test yourself and ensure you comply with the conditions below.

You may access this language documentation while attempting this test:

You may also access manual entries (the man command).

Any violation of the test conditions will results in a mark of zero for the entire weekly test component.


weekly test question:
Print The Middle Integer of 3 Integers

Write a C program middle3.c that reads 3 integers and prints the middle integer.

You are not permitted to use loops or arrays (use if statements).

Your program should behave exactly like this example:

./middle3
Enter integer: 23
Enter integer: 5
Enter integer: 27
Middle: 23
./middle3
Enter integer: 3
Enter integer: 6
Enter integer: 27
Middle: 6
./middle3
Enter integer: 9
Enter integer: 7
Enter integer: 8
Middle: 8
You can assume the user supplies 3 integers. You do not have to check the return value from scanf.

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest middle3
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test04_middle3 middle3.c

weekly test question:
Loop Sum

Write a program called loop_sum.c that reads an integer n from standard input, and then scans in n integers from standard input, adds them together, then prints the sum.

You can assume that n is non-negative (≥ 0).

You can assume that you are given exactly n+1 integers.

You can assume that scanf succeeds (you do not need to check for errors).

Make your program match the examples below exactly.

Note: you are not permitted to use an array in this exercise.

dcc loop_sum.c -o loop_sum
./loop_sum 
How many numbers: 2
1
2
The sum is: 3
How many numbers: 3
-3
4
13
The sum is: 14
How many numbers: 5
-2
-1
0
1
2
The sum is: 0

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest loop_sum
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test04_loop_sum loop_sum.c

weekly test question:
Print A Hollow Triangle

Write a program called hollow_triangle.c that reads an integer n from standard input. and prints a pattern of asterisks forming a hollow triangle.

You can assume n is greater than 3.

Make your program match the examples below exactly.

Note: you are not permitted to use an array in this exercise.

dcc hollow_triangle.c -o hollow_triangle
./hollow_triangle 
Enter size: 4
*
**
* *
****
./hollow_triangle 
Enter size: 5
*
**
* *
*  *
*****
./hollow_triangle
Enter size: 8
*
**
* *
*  *
*   *
*    *
*     *
********
./hollow_triangle
Enter size: 11
*
**
* *
*  *
*   *
*    *
*     *
*      *
*       *
*        *
***********

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest hollow_triangle
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test04_hollow_triangle hollow_triangle.c

Submission

When you are finished each exercise make sure you submit your work by running give.

You can run give multiple times. Only your last submission will be marked.

Don't submit any exercises you haven't attempted.

If you are working at home, you may find it more convenient to upload your work via give's web interface.

Remember you have until Week 6 Monday 17:00 to complete this test.

Automarking will be run by the lecturer several days after the submission deadline for the test, using test cases that you haven't seen: different to the test cases autotest runs for you.

(Hint: do your own testing as well as running autotest)

Test Marks

After automarking is run by the lecturer you can view it here the resulting mark will also be available via via give's web interface or by running this command on a CSE machine:

1511 classrun -sturec

The test exercises for each week are worth in total 1 marks.

The best 7 of your 8 test marks for weeks 3-10 will be summed to give you a mark out of 7.