Thursday, 11 February 2016

Dealing with Data (C++ Primer Plus Sixth Edition Solution Manual) Question-3

Leave a Comment
Questions:

Write a program that asks the user to enter a latitude in degrees, minutes, and seconds
and that then displays the latitude in decimal format.There are 60 seconds of arc to a minute and 60 minutes of arc to a degree; represent these values with symbolic constants.You should use a separate variable for each input value.

A sample
run should look like this:
Enter a latitude in degrees, minutes, and seconds:
First, enter the degrees: 37
Next, enter the minutes of arc: 51
Finally, enter the seconds of arc: 19
37 degrees, 51 minutes, 19 seconds = 37.8553 degrees

Explanation:

Below mention code is compiled in Visual Studio 2015 and Code Blocks 13.12,output snap is attached.. If any problem you feel and you want some explanation feel free to contact us.

Code:

/**************************************************|
/*************C++ Programs And Projects************|
***************************************************/


#include <iostream>
using namespace std;
void main() {
       const int min2sec = 60;
       const int deg2min = 60;
       cout << "Enter a latitude in degrees, minutes, and seconds:"<< endl<< "First, enter the degrees:";
       int degree;
       cin >> degree;
       cout << "Next, enter the minutes of arc:";
       int min;
       cin >> min;
       cout << "Finally, enter the seconds of arc:";
       int sec;
       cin >> sec;
       float min_f = min + float(sec) / min2sec;
       float deg_f = degree + min_f / deg2min;
       cout << endl<< degree<< " degrees, "<< min<< " minutes, "<< sec<< " seconds = "<< deg_f<< " degrees"<< endl;
}



Output:
C++ Programs And Projects


Related Articles:

C++ Primer Plus Sixth Edition Complete Solution Manual 

C++ Books Solution


If You Enjoyed This, Take 5 Seconds To Share It