Question #39674

Write a C++ program to read each line of the input file, calculate the degrees in decimal for latitude and longitude and write the results to the output file.

Expert's answer

Answer on Question #39674- Programming, C++

1. Write a C++ program to read each line of the input file, calculate the degrees in decimal for latitude and longitude and write the results to the output file.

Solution.


#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void outputf(double a);
int main()
{
    double a, b;
    cout << "\n Enter the number: ";
    cin >> a;
    b = pow(a, 2);
    cout << "\n >>=" << b;
    cout << "\n Enter the file name for the record number: \n";
    outputf(b);
    cout << endl;
    return 0;
}
void outputf(double a)
{
    ofstream f1;
    f1.open("D:\\filename.txt");
    if (!f1.fail())
    {
        f1 << a;
        f1.close();
    }
    else
    {
        cout << "\n Error opening file";
        return;
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS