讲解COSC2666编程、辅导Programming程序、C/C++程序语言调试
调试Matlab程序|调试C/C++编程
COSC2666 Programming C Programming Project Semester 2 2020
“Finding Your Way”
Assessment
This assignment contributes 20% towards your assessment for Programming and will be given a
mark out of 40.
It must be your own independent work. You may not hire another author or copy another person’s
work.
Your assignment must not be submitted as pair or group effort.
The program must be written in C, not C++ or any other language.
The due date for final submission is 15th November 2020. Late submissions will penalized at 10% per
day off the original mark.
You need to submit the C code and a working executable program (.exe or .exec).
Your submitted programs must include your name and student number in their file names.
Introduction
Despite the introduction of GPS, gyro compasses, and mobile phones, the magnetic compass is still
an important direction measuring tool for users such as yacht owners, small boat pilots, light aircraft
flyers, drivers and hikers. It is light, works day and night and does not rely on batteries, satellite or
‘phone towers.
The North seeking pole of a compass points towards the North Magnetic Pole of the Earth. This pole
does not coincide with the North Geographic Pole. The North Magnetic Pole is currently situated in
the Arctic Ocean, 500km South of the North Geographic Pole and moving towards Russia at 50 to 60
km per year.
The direction (true bearing) of an object, measured at a given point, is based on the angle between
the object and the North Geographical Pole at that point.
In order to find the true bearing of an object with respect to an observer, this difference in position
of the two poles must be accounted for. At a given point, the direction of the Magnetic North Pole
with respect to the Geographic North Pole is called variation or declination at that point.
The observer can plot the true bearing as a straight line from the observation point to the observed
object on a map. The intersection of three true bearing lines can then be used to estimate the
position of the observer in relation to other places on the Earth.
Bearings increase clockwise from 0o
(due North) through 90o
(due East), 180o
(due South), 270o
(due
West) to 360O
(due North again).
Any variation to the East of true North is recorded as positive and any variation to the West of true
North is negative.
2
Author: Russell Moon, Russell.moon@rmit.edu.au, 06/09/2020
Example
Currently, in Port Philip Bay, the variation is 11o44’ East.
A yacht pilot on Port Philip Bay measures the direction of a lighthouse at Docklands as
78o16’. Adding the current variation of +11o44’, which gives the true bearing of 90o 00’,
showing that the lighthouse is due East.
A hiker near Melbourne, measuring the bearing of a mountain top as 290o 00’ would have to
add +11o44’ to get a true bearing of 301o 44’.
In conclusion, to find the true bearing, if the variation is East of North add it (+), and, if the variation
is to the West of North(-), subtract it (add the negative number) from the compass bearing.
Boat skippers use this mnemonic “Variation East, compass least, variation West compass best.”
To make sure that you understand the concept of compass variation answer the following questions.
The variation, at a certain place on the Earth, is 20o 30’ west. A hiker’s compass measures
the bearing of a mountain top as 228o 18’. What is the true bearing of the mountain top?
Answer: 228o 18’ – 20o 30’ = 207o 48’ or 228.3o – 20.5o = 207.8o
A pilot measures the bearing of a radio beacon as due East (90o
). If the variation is -13o what
is the true bearing of the radio beacon?
Answer: The compass measurement of the bearing of the radio beacon is 90o
. The true
bearing is 90o + (– 13o
) which is 77o
.
Your Task
The application designer has provided a flowchart describing how the application should work.
You are employed to write a computer program in C that reliably calculates the true bearings of
three landmarks, given the input of the compass bearings.
You will choose six cities around the World and research, on the Internet, the magnetic variation at
each city. (Your choices should be made independently and will be recorded for authentication).
The user will enter the compass bearings (in degrees as a decimal number) of three landmarks in a
chosen city. The true bearing of each landmark will be returned.
The program will record the true bearings of three landmarks and display these bearings at the
conclusion of the program.
If the city is not listed, the tourist will have the option of entering the magnetic variation for that
unlisted city.
A description of how the tourist should use the program, will be included.
You will need to demonstrate features of C, as listed in the Marking Guide.
3
Author: Russell Moon, Russell.moon@rmit.edu.au, 06/09/2020
“Finding Your Way” Marking Guide
a. Both the C program and the executable program have been correctly named and submitted.
(2)
b. The user is prompted to enter the name of an unlisted city. Its name will be saved as a string
and displayed when the three true bearings in that city are displayed (2)
c. Your C code is neatly and logically indented. (2)
d. Your program contains at least ten comments indicating use of the code. (2)
e. Real data about the magnetic variation in each of six listed cities is coded into your program.
(2)
f. The executable program displays clear instructions to the user. (2)
g. The program does not crash if invalid data is entered, or for any other reason. (2)
h. The user can choose a listed or unlisted city for which he/she wants the true bearings. (2)
i. The user can enter the magnetic variation for an unlisted city. (2)
j. The user is warned of invalid entry of a variation. (2)
k. The user is prompted to enter the compass bearing of each of three landmarks. (2)
l. The user is warned of invalid entry of a landmark bearing. (2)
m. A function call, given the inputs, city, magnetic bearing and variation, returns the true
bearing of a landmark (2)
n. The same function returns the true magnetic bearing of a landmark in an unlisted city. (2)
o. If the function returns a negative value, the value is converted to a bearing between 0 and
360 degrees. (2)
p. Your program saves the three true bearings as data in a one-dimensional array. (2)
q. The three true bearing measurements are clearly displayed as degrees, accurate to two
decimal places, at the conclusion of the program. (2)
r. The user is prompted to repeat the whole program if they choose to, and the program will
repeat from the beginning (2)
s. You have used formatting characters to ensure that the displayed information is neatly and
clearly arranged on the screen. (2)
t. Your program returns accurate information. (2)
Total: 40 marks
4
Author: Russell Moon, Russell.moon@rmit.edu.au, 06/09/2020
“Finding Your Way” Flowchart
A. Declare and initialize
variables.
B. Description and
Instructions
C. Select a listed city name
or select the unlisted city
option.
D. Invalid input warning
E. Check validity of the
input.
F. Is input valid?
G. Is the city name listed?
H. Instruct to enter the
variation for the unlisted
‘other’ city.
I. Input the variation for the
unlisted ‘other’ city.
J. Variation validity function
call (You write this function)
K. instructions to enter a compass bearing.
L. Compass bearing
M. Bearing validity function call
(You write this function).
N. Add 1 to the Measurement counter.
O. True Bearing Calculator Function call
(You write this function)
P. Store the True Bearing in an array
Q. Value of the True Bearing
R. Have three bearings been made?
S. Values of the three bearings, unlisted city
and ask whether to repeat the program.
T. Answer
U. Is answer ‘yes’?