lab04
by typing:
mkdir lab04Change to this directory by typing:
cd lab04
Unfortunately it is incomplete. Your task is to complete it.
Its main function is complete. Do not main function change. The three functions to change are>
double area(double radius); double circumference(double radius); double diameter(double radius);
Hint use the constant M_PI
defined in math.h
dcc -o circle_facts circle_facts.c ./circle_facts Enter circle radius: 1 Area = 3.141593 Circumference = 6.283185 Diameter = 2.000000 ./circle_facts Enter circle radius: 17 Area = 907.920277 Circumference = 106.814150 Diameter = 34.000000 ./circle_facts Enter circle radius: 0.0125 Area = 0.000491 Circumference = 0.078540 Diameter = 0.025000
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest circle_factsWhen you are finished on this exercise you and your lab partner must both submit your work by running give:
give cs1511 wk04_circle_facts circle_facts.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise.
We use loops in C to do things multiple times. Here is an example of a loop that prints all the numbers from 1 to 17 on a new line in ascending order:
int counter = 1; //initialise counter to 1
while (counter <= 17) { // loop until not <= 17
printf("%d\n", counter); // print counter
counter = counter + 1; // increment counter
}
In this exercise you will use a loop to print a countdown from 10 to 0.
Start by creating a file called countdown.c
in your week 4 directory, and copying
the above code. Modify this code so that the loop counts down from 10 until 0.
./countdown 10 9 8 7 6 5 4 3 2 1 0
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest countdownWhen you are finished on this exercise you and your lab partner must both submit your work by running give:
give cs1511 wk04_countdown countdown.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise.
For example:
./three_five Enter number: 10 3 5 6 9 ./three_five Enter number: 30 3 5 6 9 10 12 15 18 20 21 24 25 27
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest three_fiveWhen you are finished on this exercise you and your lab partner must both submit your work by running give:
give cs1511 wk04_three_five three_five.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise.
perfect.c
that reads a positive integer n
from standard input and prints all the factors of n, their sum and if
indicates if n is a perfect number.
./perfect Enter number: 6 The factors of 6 are: 1 2 3 6 Sum of factors = 12 6 is a perfect number ./perfect Enter number: 1001 The factors of 1001 are: 1 7 11 13 77 91 143 1001 Sum of factors = 1344 1001 is not a perfect number
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest perfectWhen you are finished on this exercise you and your lab partner must both submit your work by running give:
give cs1511 wk04_perfect perfect.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise.
x.c
that reads an integer n from standard input.
and prints an nxn pattern of asterisks and dashes in the shape of an "X".
You can assume n is odd and >= 5.
Make your program match the examples below exactly.
You are not permitted to use an array in this exercise.
./x Enter size: 5 *---* -*-*- --*-- -*-*- *---* ./x Enter size: 9 *-------* -*-----*- --*---*-- ---*-*--- ----*---- ---*-*--- --*---*-- -*-----*- *-------* ./x Enter size: 15 *-------------* -*-----------*- --*---------*-- ---*-------*--- ----*-----*---- -----*---*----- ------*-*------ -------*------- ------*-*------ -----*---*----- ----*-----*---- ---*-------*--- --*---------*-- -*-----------*- *-------------*
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest xWhen you are finished on this exercise you and your lab partner must both submit your work by running give:
give cs1511 wk04_x x.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise.
In this task,
you will create a program
called danish_flag.c
which will read in a size
and display a Danish Flag
of that size
using the following algorithm
and the #
character.
The Danish Flag
is made up of 6 blocks.
It is 3 blocks wide,
and 2 blocks high.
To display it using empty spaces
and the character #
,
we will read in a value called size
.
Each block will be 3 times size
wide,
and 2 times size
high.
#
character.See the diagram below for details.
For example
dcc -o danish_flag danish_flag.c ./danish_flag Enter the flag size: 1 ## ##### ## #####
./danish_flag Enter the flag size: 2 ##### ########### ##### ########### ##### ########### ##### ########### ##### ########### ##### ###########
./danish_flag Enter the flag size: 3 ######## ################# ######## ################# ######## ################# ######## ################# ######## ################# ######## ################# ######## ################# ######## ################# ######## ################# ######## #################
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest danish_flagWhen you are finished on this exercise you and your lab partner must both submit your work by running give:
give cs1511 wk04_danish_flag danish_flag.cNote, even though this is a pair exercise, you both must run give from your own account before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise.
For this challenge,
make a program called boxes.c
which reads in a number
and then draws that many square boxes
inside each other
using the character #
.
For example:
./boxes How many boxes: 1 ### # # ###
./boxes How many boxes: 2 ####### # # # ### # # # # # # ### # # # #######
./boxes How many boxes: 5 ################### # # # ############### # # # # # # # ########### # # # # # # # # # # # ####### # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # # # ####### # # # # # # # # # # # ########### # # # # # # # ############### # # # ###################
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest boxesWhen you are finished working on this exercise you must submit your work by running give:
give cs1511 wk04_boxes boxes.cYou must run give before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
spiral.c
that reads an integer n from standard input.
and prints an nxn pattern of asterisks and dashes in the shape of a spiral.
You can assume n is odd and >= 5.
You are only permitted to use C language features covered in weeks 1-3 lectures. In particular, you are not permitted to use array(s).
Make your program match the examples below exactly.
You are not permitted to use an array in this exercise.
./spiral Enter size: 5 ***** ----* ***-* *---* ***** ./spiral Enter size: 7 ******* ------* *****-* *---*-* *-***-* *-----* ******* ./spiral Enter size: 9 ********* --------* *******-* *-----*-* *-***-*-* *-*---*-* *-*****-* *-------* ********* ./spiral Enter size: 17 ***************** ----------------* ***************-* *-------------*-* *-***********-*-* *-*---------*-*-* *-*-*******-*-*-* *-*-*-----*-*-*-* *-*-*-***-*-*-*-* *-*-*-*---*-*-*-* *-*-*-*****-*-*-* *-*-*-------*-*-* *-*-*********-*-* *-*-----------*-* *-*************-* *---------------* *****************
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest spiralWhen you are finished working on this exercise you must submit your work by running give:
give cs1511 wk04_spiral spiral.cYou must run give before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
decimal_spiral.c
that reads an integer n from standard input.
and prints an nxn pattern of decimal digits and dashes in the shape of a spiral.
You can assume n is odd and >= 5.
You are only permitted to use C language features covered in weeks 1-3 lectures. In particular, you are not permitted to use array(s).
Make your program match the examples below exactly.
You are not permitted to use an array in this exercise.
./decimal_spiral Enter size: 5 65432 ----1 210-0 3---9 45678 ./decimal_spiral Enter size: 7 0987654 ------3 87654-2 9---3-1 0-012-0 1-----9 2345678 ./decimal_spiral Enter size: 9 876543210 --------9 8765432-8 9-----1-7 0-210-0-6 1-3---9-5 2-45678-4 3-------3 456789012 ./decimal_spiral Enter size: 15 654321098765432 --------------1 2109876543210-0 3-----------9-9 4-210987654-8-8 5-3-------3-7-7 6-4-87654-2-6-6 7-5-9---3-1-5-5 8-6-0-012-0-4-4 9-7-1-----9-3-3 0-8-2345678-2-2 1-9---------1-1 2-01234567890-0 3-------------9 456789012345678
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest decimal_spiralWhen you are finished working on this exercise you must submit your work by running give:
give cs1511 wk04_decimal_spiral decimal_spiral.cYou must run give before Sunday 25 March 23:59:59 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
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 Sunday 25 March 23:59:59 to submit your work.
Automarking will be run several days after the submission deadline for the test. When complete you can view automarking here and you can view the the resulting mark via give's web interface
You can read more about lab assessment here