Write the code segments based on the given descriptions: Declare a file pointer called input. Open a file called location.txt for reading using this pointer. If the file is not available, display...


Write the code segments based on the given descriptions:



  1. Declare a file pointer called
    input.
    Open a file called
    location.txt
    for reading using this  pointer.

  2. If the file is not available, display
    “File does not exist.”.

  3. The content of the text file
    location.txt
    is as shown below. It includes the
    location, latitude
    and
    longitude values.













FILE


location.txt


CONTENTS



Location>



UTM 1.5523763 103.63322


KLCC 3.153889 101.71333


UM 3.1185 101.665


UMS 6.0367 116.1186


UNIMAS 1.465174 110.4270601









Ask the user to enter a location. Check if the user’s location can be found in the text file. If found,  display the
location, latitude
and
longitude
as shown below.













SAMPLE OUTPUT



Enter a location: UM


Location : UM


Latitude : 3.1185


Longitude : 101.6650









Otherwise display
“Sorry, location could not be found”.













SAMPLE OUTPUT



Enter a location : MMU


Sorry, location could not be found









QUESTION 3<br>Write the code segments based on the given descriptions:<br>1. Declare a file pointer called input. Open a file called location.txt for reading using this<br>pointer.<br>2.<br>If the file is not available, display
UTM 1.5523763 103.63322 KLCC 3.153889 101.71333 UM 3.1185 101.665 UMS 6.0367 116.1186 UNIMAS 1. 465174 110.4270601 Ask the user to enter a location. Check if the user's location can be found in the text file. If found, display the location, latitude and longitude as shown below. SAMPLE OUTPUT Enter a location: UM Location : UM : 3.1185 : 101.6650 Latitude Longitude Otherwise display "Sorry, location could not be found". SAMPLE OUTPUT Enter a location : MMU Sorry, location could not be found "/>
Extracted text: QUESTION 3 Write the code segments based on the given descriptions: 1. Declare a file pointer called input. Open a file called location.txt for reading using this pointer. 2. If the file is not available, display "File does not exist. ". 3. The content of the text file location.txt is as shown below. It includes the location, latitude and longitude values. FILE location.txt CONTENTS UTM 1.5523763 103.63322 KLCC 3.153889 101.71333 UM 3.1185 101.665 UMS 6.0367 116.1186 UNIMAS 1. 465174 110.4270601 Ask the user to enter a location. Check if the user's location can be found in the text file. If found, display the location, latitude and longitude as shown below. SAMPLE OUTPUT Enter a location: UM Location : UM : 3.1185 : 101.6650 Latitude Longitude Otherwise display "Sorry, location could not be found". SAMPLE OUTPUT Enter a location : MMU Sorry, location could not be found
Jun 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here