25.4k views
2 votes
Coding! Please review my work! Thank you!

Instructions:

Pseudocode and Flowchart
You’ll create both pseudocode and a flowchart to design a mobile app. The app will write the device’s latitude and longitude to a file each time the device’s location changes. Use the techniques discussed in Section 3.3 and Chapter 10 of your textbook to write the latitude and longitude to the file as a record.

The mobile app is designed to effectively write the device’s latitude and longitude to a file each time the device’s location changes.

My Coding (the Coding is in Pseudocode):

//Fields
Class App
Private real latitude
Private real longitude

//Constructor
Public Module Loctaion(real lat, real long)
Set latitude = lat
Set longitude = long
End module

//Mutators
Public Module SetLatitude(real lat)
Set = lat
End Module

Public Module SetLongitude(real long)
Set = long
End Module

//Accessors
Public Real getLatitude()
Display "Device Latitude is: ",
getLatitude()
Return latitude
End Module

Public Real getLongitude()
Display "Device Longitude is: ",
getLongitude()
Return longitude
End Module

//Call module for loctaion

Call mobileApp_LocationShift()

If (mobileApp_LocationShift==true)
Open file
File write(getLatitude,getLongitude)
End if
End Class

Module mobileApp_LocationShift()
getLatitude()
getlongitude()
End Module


If I am missing anything, please let me know. thank you very much for helping me out!

2 Answers

1 vote

Answer:

correct

Step-by-step explanation:

very well wrote

User Futuregeek
by
7.3k points
3 votes

Thank you for sharing your pseudocode! Here are my suggestions:

In your constructor module, you have misspelled "Location" as "Loctaion". Make sure to correct this spelling error.

In your mutators modules, you are not setting the instance variables latitude and longitude. You should set them as follows:

Public Module SetLatitude(real lat)

Set latitude = lat

End Module

Public Module SetLongitude(real long)

Set longitude = long

End Module

In your accessors modules, you are not returning the latitude and longitude values. You should include a return statement as follows:

Public Real getLatitude()

Display "Device Latitude is: ",

getLatitude()

Return latitude

End Module

Public Real getLongitude()

Display "Device Longitude is: ",

getLongitude()

Return longitude

End Module

In your main module, you should call the constructor module to initialize the latitude and longitude values before calling the mobileApp_LocationShift module. You can do this as follows:

//Create a new instance of the App class

App myApp = new App()

//Call the Location constructor to set the initial latitude and longitude values

myApp.Location(0.0, 0.0)

//Call the mobileApp_LocationShift module to get the updated latitude and longitude values

mobileApp_LocationShift()

//Check if the location has shifted and write to file if necessary

If (mobileApp_LocationShift == true)

Open file

File write(getLatitude, getLongitude)

End if

In your mobileApp_LocationShift module, you are not actually updating the latitude and longitude values. You can update them as follows:

Module mobileApp_LocationShift()

SetLatitude(new_latitude_value)

SetLongitude(new_longitude_value)

End Module

Finally, you should add error handling to your code in case the file cannot be opened or written to. You can use try-catch blocks to handle these errors.

I hope these suggestions are helpful!

User Yangfan
by
7.9k points