universiti teknikal malaysia melaka benc 1133 programming

BENC1133 – Tutorial 2
UNIVERSITI TEKNIKAL MALAYSIA MELAKA
BENC 1133
PROGRAMMING LANGUAGE
TUTORIAL 2
PART A.
1. Transfer the coding given in C Free and fill in the missing statements.
Compile and run the program. What is the output?
a) if else statement
/*This program prompt for upper-case letter and display it*/
#include <stdio.h>
main()
{
char letter = 0;
printf("\nEnter an upper-case latter: \n");
scanf("%c", &letter);
if(………………………)//----------------------------- missing statement
{
letter = letter - 'A'+ 'a';
printf(………………………);//------------------- missing statement
}
else
printf("\nTry using the shift key, Bud! I want a capital
letter.");
return 0;
}
Sem. II 2010/2011
1
PSMW/Sayuthi
BENC1133 – Tutorial 2
b) while
/*This program convert degrees values to radians*/
#include <stdio.h>
#define PI 3.141593
int main ()
{
int degree=0;
double radians;
printf("Degree to Radians\n");
…………………………. //------------------- missing statement
{
radians = degree*PI/180;
printf("%6i %9.6f\n ",degree,radians);
degree +=10;
}
return 0;
}
c) do-while
/*This program convert degrees values to radians*/
#include <stdio.h>
#define PI 3.141593
int main()
{
int degree=0;
double radians;
printf("Degree to Radians\n");
…………….. //------------------- missing statement
{
radians = degree*PI/180;
printf("%6i %9.6f\n", degree, radians);
degree +=10;
} ………. //------------------- missing statement
return 0;
}
Sem. II 2010/2011
2
PSMW/Sayuthi
BENC1133 – Tutorial 2
2. Self-test exercise
By using the same program that you have done in part (b) and( c) , try to
convert degree to radian using for loop. The output must same as in part
(b) and (c).
Sem. II 2010/2011
3
PSMW/Sayuthi
BENC1133 – Tutorial 2
TASK B
While spending summer as surveyor’s assistant, you decide to write a program
that automates transform compass headings in degrees (0-360 degrees) to
compass bearing. When we enter any compass heading in degree (eg 110
degree), the program should display the corresponding bearing, (eg south 70
degree east) as illustrate in below figure
Enter a compass heading > (input =example 110.0)
The bearing is south 70.0 Degree
Hint:
Heading in degree
0-89.999……
90-179.999……
180-269.999….
270 – 360
Bearing compass
North (heading) east
South (180 – heading) east
South (heading – 180.0)
North (360 – heading)
You should do this step before you transfer to program.




Analysis
Design, use pseudocode and flowchart
Write program
Check input versus expected output.
Sem. II 2010/2011
4
PSMW/Sayuthi
BENC1133 – Tutorial 2
TASK C(self-test exercise).
Extra exercise
Please do this exercise on your own. If any question, please refer to your lecturer
or teaching engineer. Please follow exactly as shown in method TASK B
(including analysis, design, write program and check input versus expected
output).
Implement a program that prompt for noise loudness in decibels. Then, you need
to associate the noise value given with the effect of the noise. The following table
shows the relationship between noise level and human perceptions of noises.
Loudness in Decibels (dB)
50 or lower
51 to 70
71 to 90
91 to 110
more than 110
Sem. II 2010/2011
Perceptions
Quiet
Intrusive
Annoying
Very annoying
Uncomfortable
5
PSMW/Sayuthi
BENC1133 – Tutorial 2
Sem. II 2010/2011
6
PSMW/Sayuthi