Home   MosaicPresentation format
<http://cnfolio.com/B142LCW20100419>
Introduction to Computing – B142L

B142L Coursework assignment 1 – Referral

Academic year 2009/10



COURSEWORK DUE DATE

6pm April 19, 2010



COURSEWORK DESCRIPTION

Students are required to submit their coursework online using their individual coursework pages on the Mosaic website.

Answer all questions. This assessment has a total of 20 marks. Each question will be marked according to the following criteria:
MarksCriteria
5Source code uses an effective design to answer the question, compiles without errors and includes informative comments.
4Source code answers the question, compiles without errors and includes informative comments.
3Source code answers the question and compiles without errors.
2Source code is relevant to the question, but does not compile.
1Source code is incorrect or not relevant to the question.




COURSEWORK QUESTIONS

QUESTION 1
[5 Marks]

Write a C program that accepts 10 input integers. For each input number, display an output message according to its value:
  • Display message British Airways if the input value is 145
  • Display message American Airlines if the input value is 245
  • Display message Singapore Airlines if the input value is 345
  • Display message Airline not recognized if the input value is not 145, 245 or 345



QUESTION 2
[5 Marks]

In the same program as question 1, add a function that accepts an integer input and returns the result based on the following formula:
output = ( input * 20 ) - input
For example, if the input integer was 145, then the function would return 2755 and if the input integer was 45, then the function would return 855.



QUESTION 3
[5 Marks]

In the same program as question 1, add a while loop to iterate through all 10 input integers and display the result of calling the function written for question 2.



QUESTION 4
[5 Marks]

In the same program as question 1, add a for loop to iterate through all 10 input integers and find the lowest number and the highest number. Display an output message to indicate both numbers.
#include <stdio.h>

int calculate( int );

int main( void )
{
   int numbers[ 10 ];
   int highest, lowest, counter;
   
   /* Required output for question 1 */
   for ( counter = 0; counter < 10; counter++ )
   {
      scanf( "%d", &numbers[ counter] );
      switch( numbers[ counter ] )
      {
         case 145 : printf( "British Airways\n" ); break;
         case 245 : printf( "American Airlines\n" ); break;
         case 345 : printf( "Singapore Airlines\n" ); break;
         default  : printf( "Airline not recognized\n" );
      }
   }

   /* Required output for question 3 */
   counter = 0;
   while ( counter < 10 )
   {
      printf( "The input is %d and the calculated output is %d\n", numbers[ counter ], calculate( numbers[ counter ] ) );
      counter++;
   }

   /* Required output for question 4 */
   for ( lowest = numbers[ 0 ], highest = lowest, counter = 1; counter < 10; counter++ )
   {
      if ( numbers[ counter ] < lowest ) lowest = numbers[ counter ];
      else if ( numbers[ counter ] > highest ) highest = numbers[ counter ];
   }
   printf( "The lowest number is %d and the highest number is %d", lowest, highest );
}

/* Requirement for question 2 */   
int calculate( int input )
{
   return ( ( input * 20 ) - input );
}