


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Answer any two questions [each 50 marks] Maximum available marks is 100.
Use appropriate comments and indentation in program code.
Examiners: Mr. P Cogan Mr. D McCartney Mr. P. O’Donnell
s
Q1. (a) With reference to the C language explain what header files are and give
examples of their use. [10 marks]
(b) Explain using appropriate examples what the ‘cast operator’ is used for in C expressions. [10 marks]
(c) Demonstrate how functions are used in C by writing a program that reads in voltage and current and which then passes these values to a function. The function should calculate resistance (R=V/I) and return the result. The main program should then display this value (R). [10 marks]
(d) Explain what each line does in each of the following two programs. [20 marks] (i) #include <stdio.h> const unsigned int SET = 0x0ff; void main ( void ) { unsigned int a, b = 5, c; float d = -251.0; b = sizeof(b); c = SET; ++c; d+=c; printf("\t%u\t%u\t%u\t%f\n",a,b,c,d); c=a=b; b=(unsigned int)(d/2.0); d*=2.0; printf("\t%u\t%u\t%4.2f\n",a,b,d); } continued overleaf ….
(ii) #include <stdio.h> void main (void) { float y[5]={10.0,11.0,12.0,13.0,14.0}; float m, p = &y[2]; register long h; h=(long) p; m=p; printf ("%lu\t%4.1f\t%f\n",h,p,m); m--; h>>=2; m=p; printf("%4.1f\t%4.1f\t%lu\t%4.1f\n",m,p, h,(p++)); }
Q2. (a) Using example programs to illustrate your answer write a note discussing any TWO of the following with reference to the C programming language; (i) The usage of the ‘break’ statement in C. (ii) Multi-dimensional arrays. (iii) Storage classes. (iv) Recursion. [20 marks]
(b) What does the following program display on the screen? Explain your answer. [12 marks] #include <stdio.h> void main () { unsigned long x= 0x10000012; long int y=2048; char z=3; printf ("3 | x = %lx\n",3 | x); printf ("0xff & y = %ld\n",0xff & y); printf ("0x07 ^ z = %x\n",0x07 ^ z); printf ("3 << 2 = %d\n",3<<2); printf ("Z >>=1 = %d\n",z>>=1); printf ("~z = %d\n",~z); }
(c) An electronic device reports an internal fault by displaying a two digit hex number on its display. Five bits in this hex number represent the type of error as indicated in the table overleaf. You are required to produce a program to assist technicians to find the type of error being reported by the device. Write a program that can be used to check the number displayed and report on the types of error. Your program should read in the hex number displayed and report on which types of error are reported. If more than one of the bits is set your program should list all of the errors. It should repeat until the user decides to quit. [18 marks] continued overleaf ….
Option 2 should call the ping command (with a TCP/IP address as the command line argument) to test if the computer addresses listed in pinglist.txt reply. The ping command will return 0 if the machine at a specific address replies or a non-zero value if it does not reply. After checking each of the addresses in the file the program should display how many addresses were tested and how many replied.
Option 3 should read in a new address from the user and add it to the pinglist.txt file.
Option 4 should cause the program to quit. [35 marks]
ooooOOOOoooo