C Programming Exam for Bachelor of Engineering Students - Autumn 2006, Exams of Computer Science

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

2012/2013

Uploaded on 03/30/2013

lallit
lallit 🇮🇳

4

(27)

150 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cork Institute of Technology
Bachelor of Engineering in Communications Systems - Award
Bachelor of Engineering in Electronic Automation and Robotics - Award
Bachelor of Engineering in Applied Electronics Design - Award
(NFQ Level 7)
Autumn 2006
Computer Science
(Time: 2 Hours)
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
A
C
ε
=
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 <stdio.h>
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 ….
pf3
pf4

Partial preview of the text

Download C Programming Exam for Bachelor of Engineering Students - Autumn 2006 and more Exams Computer Science in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Engineering in Communications Systems - Award

Bachelor of Engineering in Electronic Automation and Robotics - Award

Bachelor of Engineering in Applied Electronics Design - Award

(NFQ Level 7)

Autumn 2006

Computer Science

(Time: 2 Hours)

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

A

C

ε

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