0% found this document useful (0 votes)
19 views2 pages

BCSE 1102 INTRODUCTION TO PROGRAMMING CAT2 G1 Marking Scheme

Uploaded by

sunil24.mathias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

BCSE 1102 INTRODUCTION TO PROGRAMMING CAT2 G1 Marking Scheme

Uploaded by

sunil24.mathias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

The Co-operative University of Kenya

CAT 1

UNIT CODE: BCSC 1102

UNIT TITLE: INTRODUCTION TO PROGRAMMI


BSDS, BIT

DATE: 8th December, 2022 TIME: 40 Minutes

INSTRUCTIONS:
 Attempt All Questions

a) What is the output of the following program


1. #include <stdio.h>
2. int main(void)
3. {
4. int a = 4, b = 5, c;
5. a = (a-- > 3) + (b++ == 5);
6. b = (a != 3) + ((b-2) >= 3);
7. c = (b != 1);
8. printf("%d %d %d\n", ++a, b, c);
9. return 0;
10. }
SOLUTION
321 [3 Marks]

b) What is the output of the following program?


1. #include <stdio.h>
2. int main(void)
3. {
int* myPtr;
int a=54; //the memory address of a is 234
myPtr=&a;
printf(“%p , %p”, *myPtr, myPtr++);

4. {
SOLUTION [2 marks]
54 234

c) To qualify to participate at the Freshers Night, you need to meet the following
requirements:
a. Be either 18years old or Female
b. Can afford to pay 500 if alone at the entrance or free if you are accompanied
by a fresher
c. Be a student at CUK
The program should ask the potential participant to fill in this information at the
entrance. Only successful persons will gain entry. Use a single relational
operators’ statement to evaluate eligibility.
Required :
1
Use a function call void eligibility()
This function receives all the information captured from the user and displays
whether the user is eligible or not. [10 marks]

SOLUTION
Important : ELIGIBILITY CRITERIA IS COMPUTED AND DISPLAYED IN THE
FUNCTION CALLED void eligibility() but all the data to be used in the
computation should be captured in the main()
1. #include <stdio.h>
2. void elibility(int YoB, int age, int currentYear,int gender, int rGender,int
bill, int areAccompanied, int accompanied, int areStudent, int student);
3. int main(void)
4. {
5. int YoB=0, age=0, currentYear=2022;
6. int gender=0, rGender=0;
7. int bill=0;
8. int areAccompanied=0,accompanied=0;
9. int areStudent=0, student=0;

10. printf("Are you alone or accompanied?(Enter 1 for Alone and 2 for


accompanied)");
11. scanf(" %d",&areAccompanied);
12. printf("Enter your gender, 1 for Female and 2 for Male: ");
13. scanf(" %d", &gender);
14. printf("Are you a student at CUK? (Enter 1 for Yes and 2 for No)");
15. scanf(" %d",&areStudent);
16. printf("Enter your Year of Birth; ");
17. scanf(" %d", &YoB);
18. age=currentYear-YoB;
19. printf("Can you pay 500? (Enter 1 for Yes and 2 for No): ");
20. scanf(" %d", &bill);
21. elibility(YoB, age, currentYear, gender,rGender, bill, areAccompanied,
accompanied, areStudent, student);
22. return 0;
23. }
24. elibility(int YoB, int age, int currentYear,int gender, int rGender,int bill,
int areAccompanied, int accompanied, int areStudent, int student)
25. {
26. if (areStudent==1)
27. {
28. student=1;
29. }
30. else
31. {
32. student=2;
33. }
34. if(gender==1)
35. {
36. rGender=1;//female
37. }
38. else
39. {
40. rGender=2;//male
41. }
42. if (areAccompanied==2)
43. {
44. accompanied=2;
45. }
46. else
47. {
48. accompanied=1;//female
49. }
50. if((age==18||rGender==1)&&(bill==1||accompanied==2)&&(student==1))
51. {
52. printf("You are eligible");
53. }
54. else
55. {
56. printf("You should be arrested!");
57. }
58. }

You might also like