Anda di halaman 1dari 5

Engineering Programming 100, Semester 1, 2008

CURTIN UNIVERSITY OF TECHNOLOGY


Examinations
June 2008
MOCK EXAM
Internal Students
Unit Name: Engineering Programming 100
Unit Number and Version:
Duration:

TWO (2) HOURS, preceded by a 10 minute reading period.


Supervisor will indicate when answering of the exam may begin. If
you wish to make notes, please use the back of your exam paper,
or write on the edge columns.

Total Marks: 90.


Aids to be supplied by the University: None.
Aids to be supplied by the Student: None.
Calculator: Not allowed.
THIS IS A CLOSED BOOK EXAM
Mobile phones or any other device capable of communicating information are
prohibited from use during examinations.
Electronic Organisers/PDAs or any other devices capable of storing text or
other restricted information are prohibited.
Any breaches of this policy will be considered cheating and appropriate action
will be taken as per University policy.
Answer ALL questions. The examination paper has 5 pages. Page 1 is the
cover page. Pages 2-5 contain 4 questions. Mark allocations for individual
questions are as stated below:
Question 1:
Question 2:
Question 3:
Question 4:

20 marks.
25 marks.
25 marks.
20 marks.

Page 1 of 5

Engineering Programming 100, Semester 1, 2008


Question 1 [20 marks]
1(a) The following segment of code contains at least three (3) syntax errors that will
cause compilation to fail with errors. Identify each of these errors and specify the
solution. [2 marks each, 6 marks in total]
#include <stdio.h>
void main(void)
{
float height;
float area;
printf( "input height of the rectangle: " );
scanf( "%f", &height);
printf( "input length of the rectangle: " )
scanf( "%", &length );
area = height * length;
printf( area of rectangle %f high and %f long is
%f\n", height, length, area );
}

1(b) The following segment of code reads in numbers from the console, computes the
running maximum and prints to the screen. For example, if the use enters 3 8 6 10, one
value on each line, the program should output 3 8 8 10. The code contains at least three
(3) logical errors that will not result in the intended operation of the code. Identify each
of the errors and specify the solution. [3 marks each, 9 marks in total]
#include <stdio.h>
#define FALSE 0
#define TRUE !FALSE
void main( void )
{
int maximum;
int value;
int firstNumber = TRUE;
printf( "input numbers to compute the maximum as each is
entered\n" );
printf( "end by inputting ^C\n" );
do {
printf( "input next number: " );
scanf( "%d", value );
if ( firstNumber == FALSE )
{
maximum = value;
firstNumber = FALSE;
}
else if ( value > maximum )
maximum = value;
printf( "current maximum: %d\n", maximum );
} while ( 1 );
}

Page 2 of 5

Engineering Programming 100, Semester 1, 2008


1(c) Which of the following variables are legal or illegal. [0.5 marks each, 5 marks in
total]
(a)
(b)
(c)
(d)

float %fred;
double float;
int answer;
int x_coord;

(f)
(g)
(h)
(i)

long int z;
char country of origin[100];
char hair_colour[10];
int *y;

Question 2 [25 marks]


2(a) Define an array called days in which each element contains the number of days in
each of the 12 months such that days[0] contains the number of days in January, days[1]
contains the number of days in February and so on. Use a switch/case statement to
assign the right number of days to each element of the array. The days in each month
for January to December are: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31. [8 marks]
2(b) Explain why you have to pass by reference when you want a function to modify the
calling parameters. Use an example in your answer. [3 marks]
2(c) Define a structure to represent a complex number. [3 marks]
2(d) State the three C looping constructs. Explain, with examples, how you would use
each of them. [3 marks each, 9 marks in total]
2(e) Give an example of how to create a two dimensional float array of 20 rows and 50
columns [2 marks]

Page 3 of 5

Engineering Programming 100, Semester 1, 2008


Question 3 [25 marks]
3(a) Write a complete C program called stats that computes the maximum, minimum
and average of a sequence of integers held in a file. The file consists of one integer per
line with the first line containing a number stating the number of integers in the file. For
example, a file consisting of 100 integers would have the first line containing the
number 99. The next 99 lines would contain the numbers of interest. The program is to
read the numbers from the file and output the results to another file. The file is called
stats.dat. [15 marks]
3(b) Given an array float colours[5][5] write two complete C functions:
1. Write the array to the screen. A possible call to the function is:
print_array(colours[][5],5,5);
2. Multiply each of the entries in the array by a scale factor scale=2.5. A
possible call to the function is:
scale_array(colours[][5], 5, 5, scale);
[5 marks each, 10 marks in total]

Page 4 of 5

Engineering Programming 100, Semester 1, 2008


Question 4 [20 marks]
Write a C program that will read from the keyboard legal vales of the inner and outer
radii, and the length of a cylindrical tube and output some results to a CSV file
The inner radius must be greater than 20.0mm and the outer radius must be less than
50.0mm. The outer radius must be greater that the inner radius and the difference
between the two must be less than 20% You should repeatedly prompt the user to give
legal values and only allow the program to progress if these occur.
Once legal entries have been inputted, compute the volume of the material in mm3 and
the mass for a range of densities from 0.1 to 10.0 grams/mm3 in increments of 0.2.
Output the values of inner and outer radii, length, volume and mass to a file in CSV
format i.e. each value separated by a comma. You will need to create and open the file,
and close it after writing.
[10 marks for the prompting and inputting of data from the user, 10 marks for the
calculations and outputting to a file in CSV format]

END OF EXAMINATION

Page 5 of 5

Anda mungkin juga menyukai