Question 5 (a) A council has decided to charge dog registration fees with a base
ID: 3910178 • Letter: Q
Question
Question 5 (a) A council has decided to charge dog registration fees with a base fee of $100. If the dog is trained, a $20 discount applies, and if the dog is de- sexed, a $15 discount applies as well. Due to recent attacks, a dog classified as dangerous that has NOT been trained will attract a $40 penalty fee. Assuming boolean variables trained, desexed, dangerous are set to the cor- rect value for a new dog, write a C code fragment that calculates its dog registration fee. [6 marks] (b) Your friend Harry has written the body of a C program which prompts the user for a positive integer, N and then prints the result of the sum of the first N terms of the following series: Harry sent you the 10-line program, one line at a time. However the net- work connection was unreliable so the lines have arrived out of order as listed below. int i, N; B. double term -1; C. term-term/2 D. for (i-1; iExplanation / Answer
(A) required C code segment is given below:
int regFee(bool trained, bool desexed, bool dangerous)
{
int basefee=100;
int regfee=basefee;
if(trained)
regfee-=20;
if(desexed)
regfee-=15;
if(dangerous)
regfee+=40;
return regfee;
}
(B) The reordered sequence of lines will be:
A. int i, N;
B. double term=1;
#. double sum=0;
E. printf(" Enter a number: ");
H. scanf("%i", &N);
D. for(i=1; i<=N; i++){
C. term=term/2;
F. sum = sum + term;
I. }
G. printf("Series sum is %f ", sum);
missing term is given by #. double sum=0;
//If you have any doubt regarding the answer please ask in the comment section. Sorry I could not solve the last question.
//Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.