


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A past exam paper for students pursuing bachelor of engineering degrees in communications systems, electronic automation and robotics, and applied electronics design at cork institute of technology. The exam focuses on computer science and the c programming language. It includes two hours of multiple-choice questions, each worth 50 marks, on topics such as global variables, preprocessor directives, functions, arrays, and pointers.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



(NFQ Level 7)
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. J. Berry Dr. R. O Dubhghaill
Q1. (a) Explain why the use of global variables is normally avoided in program development. [10 marks]
(b) Explain using appropriate examples what the ‘#define’ directive is used for in the C language. [10 marks]
(c) Demonstrate how functions are used in C by writing a program that reads in permittivity (ε), area (A) and distance (d) and which then passes these values to a function. The function should calculate capacitance (C) using;
d
and return the result. The main program should then display this value (C). [10 marks]
(d) Explain what each line does in each of the following two programs. [20 marks] (i)#include void main (void) { signed int a = 2, b = 4, c = 0x8; float d = 1e1; a==b; b-=c++; printf ("%d\t%d\t%d\n",a,b,c); a+= c = 5*(int)d; fprintf (stdout,"%d\t%4.2f\t%d\n",a,d,c); }
continued overleaf ….
(ii)#include main () { float i[5]={10.0,11.0,12.0,13.0,14.0}; float p = &i[1]; int h; h=(int)i[2]; h<<=1; printf ("%d\t%4.1f\n",h,p); printf("%d\t%4.1f\t%u\t%u\n",--h,*p,p,(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 ‘continue’ statement in C. (ii) The use of arrays. (iii) Storage classes. (iv) Pass by reference. [20 marks]
(b) What does the following program display on the screen? Explain your answer. [12 marks] #include const unsigned long MASK=0x10000002; void main () { unsigned long y= MASK; long int z=256; char c='M'; printf ("131 ^ y = %lx\n",131^y); printf ("0x07 | MASK = %x\n",0x07|MASK); printf ("c += 2 = %c\n",c += 2); printf ("c+('a'-'A')=%c\n",c +('a'-'A')); printf ("Z >>=3 = %d\n",z>>=3); printf ("~y = %lx\n",~y); }
(c) The Type Of Service (TOS) bits are a set of four-bit flags in the IP header of a packet of network data (datagram). When any one of these bit flags is set, routers may handle the datagram differently to datagrams without any TOS bits set. Produce a program to find the type of service being requested in the IP header. The program should allow a technician to check the byte that the TOS bits are in by reading in the hexadecimal number that this byte contains. Your program should report on which type of service (if any) is requested using the table overleaf and repeat until the user decides to quit. continued overleaf ….
(i) To read in the name of the file to display.
(ii) If an invalid name was supplied, your program should insist on the
user entering a valid filename.
(iii) The program should display the contents of the file neatly on screen
as ASCII characters.
(iv) The program should offer the user the option of saving the file
contents in ASCII format to a text file.
(v) If the source file contents were saved in a text file, the program
should report on how many values were written to the text file. [35 marks]
ooooOOOOoooo