PHY225 Autumn Semester 2011-12 Programming in C Examination Paper, Exams of Physics

The autumn semester 2011-12 phy225 programming in c examination paper. It includes instructions for the exam, five programming questions, and a continuation page. Students are required to answer all questions and write their answers in their answer booklets. The document also includes a pause command at the end.

Typology: Exams

2012/2013

Uploaded on 02/20/2013

saeeda
saeeda 🇮🇳

4

(4)

49 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PHY225
1
PHY225 TURN OVER
DEPARTMENT OF PHYSICS AND ASTRONOMY
Autumn Semester 2011-12
PROGRAMMING IN C 2 HOURS
Answer ALL questions
There are a total of 50 marks to be awarded for this paper. The breakdown on the
right-hand side of the paper is meant as a guide to the marks that can be obtained
from each part of the question.
Please write all answers to questions in your answer booklet and not on the
examination paper.
pf3
pf4
pf5

Partial preview of the text

Download PHY225 Autumn Semester 2011-12 Programming in C Examination Paper and more Exams Physics in PDF only on Docsity!

PHY225 TURN OVER

DEPARTMENT OF PHYSICS AND ASTRONOMY

Autumn Semester 2011-

PROGRAMMING IN C 2 HOURS

Answer ALL questions

There are a total of 50 marks to be awarded for this paper. The breakdown on the right-hand side of the paper is meant as a guide to the marks that can be obtained from each part of the question.

Please write all answers to questions in your answer booklet and not on the examination paper.

PHY225 CONTINUED

  1. a) Explain the concept of linking in the creation of an executable file. What external files may be required during the linking process?

b) What is a relational operator? Give an example of one.

c) What is the purpose of a function prototype?

d) In the statement int main(void) what does (void) signify?

e) How does the atan2() function differ from the atan() function?

f) What does the strcmp() function do?

[2]

[2]

[1]

[1]

[1]

[1]

  1. Study the following program and predict the values of r, s, t, u , k , l and m to the same precision as specified in the printf statements:

#include <stdio.h> #include <stdlib.h>

int main(void) { double r=333.45,s=3.4e-2,t=1.008,u=152.5; int i=34,j=-34,k=808,l=5034 2 ,m=0;

r = (t+r*s/u-u/r); s = s+u/t+r/t-r; t = --u; u = sqrt(abs(r-t/s)); k = (i/j)u; l += k-(i%l)j; m *= i;

printf (“r: %f s: %f t: %f u: %f\n”,r,s,t,u); printf (“k: %d l: %d m: %d\n”,k,l,m);

system(“pause”); return 0; }

[8]

PHY225 CONTINUED

  1. Study the following program and write out exactly what is written out at the printf statement:

#include<stdlib.h> #include<stdio.h>

int main(void) { int i=9, j=1; while (i>0) { if (i%3) { j+=i; j*=i; i--; } else if (i%5) i--; i--; printf("i: %d j: %d\n",i,j); }

system("pause"); return 0; }

[7]

PHY225 TURN OVER

  1. Ben works for British Gas and is writing a computer program to read customer records from a database into an array of structures. Each customer record comprises the following information:

CustomerSurname (character string, maximum 20 characters) CustomerNumber (integer, up to 10 digits) CurrentMeterReading (integer, up to 6 digits) LastBill (amount in pounds and pence)

A typical customer record would thus look like:

Brown 4382910395 001789 142.

Ben’s program is incomplete. So far it looks like this:

#include<stdlib.h> #include<stdio.h> #include<math.h>

//TODO I need to define my structure here

int main(void)

{ int NUM_CUSTOMERS; printf(“Enter the number of customers:”); scanf(“%d”,NUM_CUSTOMERS);

//TODO I need to define my array of structures here

FILE* database;

if((database = fopen("customers.db", "r"))==NULL) { printf("Could not open database file”); return 1; }

for(i=0; i<NUM_CUSTOMERS; ++i) {

//TODO This is where my fscanf command goes

} fclose(database); system(“pause”); return(0);

}

PHY225 TURN OVER

END OF EXAMINATION PAPER