I think the exam went well

Last Thursday (23rd June) I had my "Embedded" C programming exam. I think I went alright with it. 50 marks were allotted for writing actual code, and 50 marks for syntax-like stuff about the C programming language. Some of the syntax questions were a complete gift -- "what are the file handle names for the screen and keyboard in C?" and "what is the point of header files?"

The first "write me some code" question involved writing a routine to round a double to a provided number of decimal places. Now of course writing my response in the exam I was enamoured of my neat response:
double round(double number, int noOfPlaces) {

    double temp = number;

    temp \*= pow(10, noOfPlaces);
    temp += 0.5;
    return ( floor(temp) / pow(10, noOfPlaces));
}


Which was just fine until I got back to work (no rest for the wicked) and realised that I should have had some error checking in there for noOfPlaces being positive. So a more reliable or accurate version would be something like this:

double round(double number, int noOfPlaces) {

    double temp = number;

    if (noOfPlaces < 1) {
        return (number);
    }

    temp \*= pow(10, noOfPlaces);
    temp += 0.5;
    return ( floor(temp) / pow(10, noOfPlaces));
}


And of course we should have some library variable (errno equivalent) to indicate an error condition.
No matter! On with the exam....

For the life of me I can't now remember what the second question was.

The third question was about numbers which are relatively prime (they have no common factors). We had to write a whole program to determine whether two numbers were or were not relatively prime.

Some people came out and mentioned that they had only found one set of factors, rather than checking the factors for both. Of course in a 'I have to code this in real life' situation I would have put in some short-circuits (are the input numbers equal? is one prime?) but this was an exam of course so I didn't really have the mental space to think of the useful short-circuits that I'd do otherwise. But I reckon I got a decent answer written for that one too.

What I found worrisome was that one of the girls who (if I'm thinking of the right person) did really well at Electronics-n-Circuits last semester came out of this exam in tears. Of course, it could be the case that she didn't write enough code for this subject, but I don't know.

So I think I did ok. Since I was on 40/40 from the assignments I'm hoping to do fairly well overall. Have to wait until July to find out though.
Comments:

Post a Comment:
Comments are closed for this entry.
About

I work at Oracle in the Solaris group. The opinions expressed here are entirely my own, and neither Oracle nor any other party necessarily agrees with them.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today