I need this C++ program to have a GUI on visual studio. I need it to take the 7 inputs (Latitude, longitude, day, month,

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

I need this C++ program to have a GUI on visual studio. I need it to take the 7 inputs (Latitude, longitude, day, month,

Post by answerhappygod »

I need this C++ program to have a GUI on visual studio.
I need it to take the 7 inputs (Latitude, longitude, day,
month, hour, minute, utc difference) from the user as mentioned in
the code and I need it to print out whatever is printed out in the
code. So the GUI will take 7 inputs from the user and it will print
out 3 outputs. I am not familiar with visual studio so please
explain your answer and write down all the necessary
codes.
Here is the C++ code:
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
float hour, UTHours, UTMinutes, UTSeconds=0;
float Lat, Lon, TZ;
int year,month,day;
void get_sun_pos(float latitude, float longitude,
float *altitude, float *azimuth){


printf("Latitude:");
scanf("%f", &latitude);

printf("Longitude:");
scanf("%f", &longitude);

printf("Day:");
scanf("%d", &day);

printf("Month:");
scanf("%d", &month);

printf("Year:");
scanf("%d", &year);

printf("Hour and Minute:");
scanf("%f %f", &hour, &UTMinutes);

printf("UTC difference of time:");
scanf("%f", &TZ);

UTHours= hour-TZ;
float zenith;
float pi =3.14159265358979323;
float twopi=(2*pi);
float rad=(pi/180);
float EarthMeanRadius=6371.01;
// In km
float AstronomicalUnit=149597890.;
// In km
float DecimalHours = UTHours + (UTMinutes +
UTSeconds / 60.0 ) / 60.0;
long liAux1 =(month-14)/12;
long liAux2=(1461*(year + 4800 + liAux1))/4 +
(367*(month - 2-12*liAux1))/12- (3*(year + 4900 +
liAux1)/100)/4+day-32075;
float JulianDate=(liAux2)-0.5+
DecimalHours/24.0;
float ElapsedJulianDays =
JulianDate-2451545.0;
float
Omega=2.1429-0.0010394594*ElapsedJulianDays;
float MeanLongitude = 4.8950630+
0.017202791698*ElapsedJulianDays; // Radians
float MeanAnomaly = 6.2400600+
0.0172019699*ElapsedJulianDays;
float EclipticLongitude = MeanLongitude +
0.03341607*sin( MeanAnomaly ) + 0.00034894*sin( 2*MeanAnomaly
)-0.0001134 -0.0000203*sin(Omega);
float EclipticObliquity = 0.4090928 -
6.2140e-9*ElapsedJulianDays +0.0000396*cos(Omega);
float Sin_EclipticLongitude= sin(
EclipticLongitude );
float Y = cos( EclipticObliquity ) *
Sin_EclipticLongitude;
float X = cos( EclipticLongitude );
float RightAscension = atan2( Y, X );
if ( RightAscension < 0.0 ) RightAscension =
RightAscension + twopi;
float Declination = asin( sin( EclipticObliquity
)* Sin_EclipticLongitude );
float GreenwichMeanSiderealTime = 6.6974243242 +
0.0657098283*ElapsedJulianDays + DecimalHours;
float LocalMeanSiderealTime =
(GreenwichMeanSiderealTime*15 + longitude)*rad;
float HourAngle = LocalMeanSiderealTime -
RightAscension;
float LatitudeInRadians = latitude*rad;
float Cos_Latitude = cos( LatitudeInRadians
);
float Sin_Latitude = sin( LatitudeInRadians
);
float Cos_HourAngle= cos( HourAngle );
float UTSunCoordinatesZenithAngle = (acos(
Cos_Latitude*Cos_HourAngle*cos(Declination) + sin( Declination
)*Sin_Latitude));
Y = -sin( HourAngle );
X = tan( Declination )*Cos_Latitude -
Sin_Latitude*Cos_HourAngle;
float UTSunCoordinatesAzimuth = atan2( Y, X
);
if ( UTSunCoordinatesAzimuth < 0.0 )
UTSunCoordinatesAzimuth =
UTSunCoordinatesAzimuth + twopi;
UTSunCoordinatesAzimuth =
UTSunCoordinatesAzimuth/rad;
float
Parallax=(EarthMeanRadius/AstronomicalUnit)*sin(UTSunCoordinatesZenithAngle);


UTSunCoordinatesZenithAngle=(UTSunCoordinatesZenithAngle +
Parallax)/rad;
*azimuth=UTSunCoordinatesAzimuth;
zenith=UTSunCoordinatesZenithAngle;
*altitude=90.-UTSunCoordinatesZenithAngle;

}
using namespace std;

struct Pt { double x, y, z; };
Pt operator + ( Pt p, Pt q ) { return { p.x + q.x,
p.y + q.y, p.z + q.z }; }
Pt operator - ( Pt p, Pt q ) { return { p.x - q.x,
p.y - q.y, p.z - q.z }; }
Pt operator * ( double r, Pt p ) { return { r * p.x,
r * p.y, r * p.z }; }
Pt operator / ( Pt p, double r ) { return { p.x / r,
p.y / r, p.z / r }; }
double dot( Pt p, Pt q ) { return p.x * q.x + p.y * q.y + p.z *
q.z; }
ostream &operator << ( ostream &out, const Pt &p
) { return out << p.x << " " << p.y << " "
<< p.z; }
istream &operator >> ( istream &in ,
Pt &p ) { return in >> p.x
>> p.y >> p.z;
}
int main()
{
float alt, az, azimrad, egim, yazim, xazim, x, y, z,
elevrad, w, q, e;
get_sun_pos(Lat, Lon, &alt, &az);

printf("UTC Date: %02i/%02i/%4i local time: %2i:%02i
\r\n",month,day,year,(int)(UTHours+TZ),(int)UTMinutes);
printf("Sun altitude = %7.2f, azimuth =
%7.2f\n",alt,az);
azimrad= (3.1415/180)*az;
elevrad= (3.1415/180)*alt;

w= -cos(azimrad)*cos(elevrad);
q= sin(azimrad)*cos(elevrad);
e= sin(elevrad);

Pt centre, origin, direction;
double radius;

centre= {0, 0, 0};
radius= 110;
origin= {0, 0, 0};
direction= {w, q, e};
double a = dot( direction, direction );
double b = 2 * dot( direction, origin - centre
);
double c = dot( origin - centre, origin - centre ) -
radius * radius;
double discriminant = b * b - 4 * a * c;
if ( discriminant < 0 )
{
cout << "No intersection.\n";
}
else if ( discriminant > 0 )
{
double t = ( -b + sqrt( discriminant ) ) / ( 2
* a );
double t2 = -b / a - t;

Pt result= origin + t *
direction;
cout << "Closest intersection at "
<< result << '\n';
}
else
{
cout << "Touches sphere at " <<
origin + (-0.5 * b / a) * direction << '\n';
}
return 0;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply