0% found this document useful (0 votes)
7 views

Basic Programming

Uploaded by

Nizam Azhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Basic Programming

Uploaded by

Nizam Azhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

COMPUTER

PROGRAMMING
REPORT

POSITIONING
INTERSECTION
INTRODUCTION
FLOWCHART
C++
MATLAB
DISCUSSION

MOHAMMAD NIZAM BIN AZHAN


UTM HYDRO II
HYDROGRAPHIC SURVEYING II PROGRAMME
FIG/IHO/ICA CATEGORY A
UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

INSTRUCTION
1. Understand the calculation procedure show in the assignment given.
2. Compute Step 5 to check the answer [Hint: compute distance BP]
3. Develop a flowchart of the computer program.
4. Develop a computer program using C++ and MATLAB/Phyton

INTRODUCTION OF C++

C++ is a cross-platform language that can be used to create high-performance applications


developed by Bjarne Stroustrup, as an extension to the C language. C++ gives programmers
a high level of control over system resources and memory where can be found in today's
operating systems, Graphical User Interfaces, and embedded systems.

C++ is one of the world's most popular programming languages. C++ is an object-oriented
programming language which gives a clear structure to programs and allows code to be
reused, lowering development costs. C++ is portable and can be used to develop
applications that can be adapted to multiple platforms.

C++ was developed as an extension of C, and both languages have almost the same syntax.
The main difference between C and C++ is that C++ support classes and objects, while C
does not.

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

INTRODUCTION OF MATLAB

MATLAB is a programming platform designed specifically for engineers and scientists to


analyze and design systems and products that transform our world. The heart of MATLAB is
the MATLAB language, a matrix-based language allowing the most natural expression of
computational mathematics.

MATLAB is a computing platform with its own programming language, whereas Python is a
general-purpose programming language with frameworks and libraries to extend its
functionality. MATLAB is a programming and numeric computing platform used by millions
of engineers and scientists to analyze data, develop algorithms, and create models.

FLOWCHART
A programming flowchart is a visualization tool programmers use when creating new
applications to understand a process,
workflow or algorithm. It typically uses
geometric shapes to represent steps and
arrows to communicate the flow of data.
Flowchart symbols are used to show the
steps, order and choices in a process.

A flowchart is a graphical representations


of steps. It was originated from computer
science as a tool for representing
algorithms and programming logic.

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

THE WORK FLOW CHART


Problem Statement:
START

DECLARATION
OF VARIABLES

DATA
INPUT

PROCESS COMPUTATION: First, we start by understanding the problem statement


STEP 1 given in Figure 1, assuming the following information is
known for two lines, compute coordinate Xp and Yp of the
intersection point.

PROCESS COMPUTATION:
1. Install Dev-C++
STEP 2
As a beginner and for learning in class, we start with Dev-C++
installation where we can download from this link:

PROCESS COMPUTATION:
https://dev-c1.software.informer.com/download/#downloading
STEP 3

2. Install GNU Octave

PROCESS COMPUTATION:
GNU Octave is a high-level language, primarily intended for
STEP 4 numerical computations. It provides a convenient command
line interface for solving linear and nonlinear problems
numerically, and for performing other numerical experiments
PROCESS COMPUTATION: using a language that is mostly compatible with Matlab. It may
STEP 5 also be used as a batch-oriented language.

It is easily extensible and customizable via user-defined


functions written in Octave’s own language, or using
dynamically loaded modules written in C++, C, Fortran, or other
DATA
languages.
OUTPUT
GNU Octave is also freely redistributable software where we
can download from here:
END
https://octave.org/download

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

flowchart continue... 2. Declaration of Variables


// Declaration of variables
START double pi = 3.14159265;
double DifX, DifY;
double DistanceAB, DistanceAP, DistanceBP;
double AzimuthAB , AzimuthAP , AzimuthBP;
DECLARATION double Angle_A , Angle_B , Angle_P;
double Px , Py;
OF VARIABLES
int Degree , Minute, Second;
int DegreeAB , MinuteAB , SecondAB;
int DegreeA , MinuteA , SecondA;
int DegreeB , MinuteB , SecondB;
int DegreeP , MinuteP , SecondP;
DATA
INPUT 3. Data Input
We have three method for inputting the data where we can choose
to be inside on our script:
a. Input data/value by programmer. We ourself put the value
PROCESS COMPUTATION: inside the script.
STEP 1 double XA=1425.07, YA=1971.28;
double XB=7484.80, YB=5209.64;
double AzAP_d=76, AzAP_m=04, AzAP_s=24;
double AzBP_d=141, AzBP_m=30, AzBP_s=16;
PROCESS COMPUTATION:
b. Input data/value by user define.User Data Input for
STEP 2 coordinate and azimuth angle.
cout << " Enter Coordinate of Stn A(x): " ;
cin >> XA;
cout << " Enter Coordinate of Stn A(y): " ;
PROCESS COMPUTATION: cin >> YA;
// User Input for STN B
STEP 3 cout << " Enter Coordinate of Stn B(x): " ;
cin >> XB;
cout << " Enter Coordinate of Stn B(y): " ;
cin >> YB;
// User Input for Azimuth AP
PROCESS COMPUTATION: cout <<"Enter Azimuth/Direction from StnA - StnP
STEP 4 [Degree]: " ;
cin >> AzAP_d;
cout << " Enter Azimuth/Direction from StnA - StnP
[Minutes]: " ;
cin >> AzAP_m;
PROCESS COMPUTATION: cout << " Enter Azimuth/Direction from StnA - StnP
[Second]: " ;
STEP 5 cin >> AzAP_s;
// User Input for Azimuth BP
cout << " Enter Azimuth/Direction from StnB - StnP
[Degree]: " ;
cin >> AzBP_d;
DATA cout << " Enter Azimuth/Direction from StnB - StnP
[Minutes]: " ;
OUTPUT cin >> AzBP_m;
cout << " Enter Azimuth/Direction from StnB - StnP
[Second]: " ;
cin >> AzBP_s;

END

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

flowchart continue...

c. Input data/value from text file. Data Input using File by


START inserting the name and directory of your text file.

fstream InputFile; //
InputFile.open("C:\\Users\\nizamazhan\\Desktop\
DECLARATION \UTM Cat A\\Computer
Programming\\DataInput.txt");
OF VARIABLES InputFile >> XA;
InputFile >> YA;
InputFile >> XB;
InputFile >> YB;
InputFile >> AzAP_d >> AzAP_m >> AzAP_s;
DATA InputFile >> AzBP_d >> AzBP_m >> AzBP_s;
INPUT

Process Computation:
PROCESS COMPUTATION:
STEP 1 Step 1:

PROCESS COMPUTATION:
STEP 2

PROCESS COMPUTATION: // STEP 1 : TO COMPUTE THE DISTANCE & AZIMUTH FROM


STN A - STN B
STEP 3
// Distance of side AB

DifX = XB - XA ;
PROCESS COMPUTATION: DifY = YB - YA ;
STEP 4 DistanceAB = sqrt(pow (DifX,2) + pow (DifY,2));

// Azimuth of AB

AzimuthAB = atan(DifX / DifY) * 180/pi;


PROCESS COMPUTATION:
STEP 5 // Convert DecimalDegree (DD) to Degree Minute
Second (DMS)

DegreeAB = int (AzimuthAB);


MinuteAB = int ((AzimuthAB-DegreeAB)*60);
DATA SecondAB = ((AzimuthAB - DegreeAB)*60)-MinuteAB)*60;
OUTPUT

END

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

flowchart continue...

Process Computation:
START
Step 2:
Compute the three angles of triangle ABP are
A = (76°04’24) - (61°52’46.8) = 14°11’37.2’’
DECLARATION
OF VARIABLES B = (180° + 61°52’46.8) - 141°30’16 = 100°22’.8”
C = 180° + 14°11’.2-100°22’30.8 = 65°25’52.0”

// STEP 2 : TO COMPUTE THE THREE ANGLES OF TRIANGLE


ABP
DATA
INPUT // Convert AzAP in DMS to DD
AzimuthAP = AzAP_d + (AzAP_m / 60) + (AzAP_s / 60);

PROCESS COMPUTATION: // Convert AzBP in DMS to DD


AzimuthBP = AzBP_d + (AzBP_m / 60) + (AzBP_s / 60);
STEP 1
// Angle A in DMS
Angle_A = AzimuthAP - AzimuthAB;
DegreeA = int (Angle_A);
PROCESS COMPUTATION: MinuteA = int ((Angle_A - DegreeA) * 60);
STEP 2 SecondA = (((Angle_A - DegreeA) * 60) - MinuteA) *
60;

// Angle B in DMS
Angle_B = (180 + AzimuthAB) - AzimuthBP;
PROCESS COMPUTATION:
DegreeB = int (Angle_B);
STEP 3 MinuteB = int ((Angle_B - DegreeB) * 60);
SecondB = (((Angle_B - DegreeB) * 60) - MinuteB) *
60;

PROCESS COMPUTATION: // Angle P in DMS


Angle_P = 180 - (Angle_A + Angle_B);
STEP 4
DegreeP = int (Angle_P);
MinuteP= int ((Angle_P - DegreeP) * 60);
SecondP = (((Angle_P - DegreeP) * 60) - MinuteP) *
60;
PROCESS COMPUTATION:
STEP 5 Step 3:

Compute distance of AP

DATA AP = AB x (sin (B) / sin (P)


= 6870.757 x (sin 100°22’30.8”/sin 65°25’52”)
OUTPUT = 7431.224m

// STEP 3 : to compute the dictance of AP


DistanceAP = DistanceAB*(sin (Angle_B*pi/180)/sin
END (Angle_P*pi/180));

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

flowchart continue...

Process Computation:
START

Step 4:
DECLARATION Compute the coordinates of station P are
OF VARIABLES Xp = 1425.07 + 7421.224 sin 76°04’24” = 8627.85m
Yp = 1971.28 + 7431.224 cos 76°04’24” = 3759.83m

// STEP 4 : to compute the coordinates of station P


DATA Px = XA + DistanceAP * (sin(AzimuthAP * pi/180));
INPUT Py = XA + DistanceAP * (cos(AzimuthAP * pi/180));

Step 5:
Check the answer? Apply side of BP
STEP 1
// STEP 5 : to compute the distance of BP

DistanceBP = DistanceAB*(sin (Angle_A*pi/180)/sin


(Angle_P*pi/180));
STEP 2

STEP 3

STEP 4

STEP 5

DATA
OUTPUT

END

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

flowchart continue...
4. Data Output:
START
a. Print output using ‘cout’:
cout << "STEP 1: The distance and azimuth of side AB
are:" << endl;
DECLARATION cout << endl;
cout << "Distance AB: "<< DistanceAB << " meter" << endl;
OF VARIABLES cout << "Azimuth AB [Degree]: " << AzimuthAB << "\370"
<<endl;
cout << "Azimuth AB [DMS]:" << DegreeAB << "\370" <<
MinuteAB << "'" << SecondAB <<"''"<<endl;cout << endl;

DATA cout << "STEP 2: The three angles of ABP triangle:" <<
endl;
INPUT cout << endl;
cout << "Azimuth AP [Degree]:" << AzimuthAP << "\370"
<<endl;
cout << "Azimuth BP [Degree]:" << AzimuthBP << "\370"
<<endl;
cout << endl;
STEP 1 cout << "Angle A [Degree]:" << Angle_A << Degree <<
"\370" <<endl;
cout << "Angle A [DMS]:" << DegreeA << "\370" << MinuteA
<< "'" << SecondA <<"''"<<endl;cout << endl;
cout << "Angle B [Degree]:" << Angle_B << Degree <<
"\370" <<endl;
STEP 2 cout << "Angle B [DMS]:" << DegreeB << "\370" << MinuteB
<< "'" << SecondB <<"''"<<endl; cout << endl;
cout << "Angle P [Degree]:" << Angle_P << Degree <<
"\370" <<endl;
cout << "Angle P [DMS]:" << DegreeP << "\370" << MinuteP
<< "'" << SecondP <<"''"<<endl; cout << endl;

STEP 3 cout << "STEP 3: The distance of AP:" << endl;


cout << endl;
cout << "Distance AP:" << DistanceAP << " meter" <<
endl;

cout << "STEP 4: The coordinates of station P:" << endl;


STEP 4 cout << endl;
cout << "Latitude P:" << Px << " meter" << endl;
cout << "Longitude P:" << Py << " meter" << endl;

cout << "STEP 5: The distance of BP:" << endl;


cout << endl;
cout << "Distance BP:"<< DistanceBP << " meter" << endl;
STEP 5
b. Print output using ‘outputfile’ – convert into text file. Similiar to
cout steps but changed the the word ‘cout’ to ‘outputfile’ but first
to indicate file directory to store the .txt file
DATA
ofstream outputfile;
OUTPUT outputfile.open("C:\\Users\\nizamazhan\\Desktop\\UTM Cat
A\\Computer Programming\\IntersectionOutput.txt");

outpufile << example;


outpuffile << end;
END

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

C++ SCRIPT
#include <iostream> //standard library for i/o [input from keyboard, output to monitor -
cin/cout]
#include <cmath> //standard library for mathematical function
#include <fstream> //standard librady for input/output to text file

using namespace std;

int main ()

{
// ################### INPUT ###################
// Declaration of variables

double pi = 3.14159265;
double DifX, DifY, DistanceAB, DistanceAP, DistanceBP;
double AzimuthAB, AzimuthAP, AzimuthBP, Angle_A, Angle_B, Angle_P;
double Px , Py;

int Degree, Minute, Second, DegreeAB, MinuteAB, SecondAB ;


int DegreeA , MinuteA , SecondA ;
int DegreeB , MinuteB , SecondB ;
int DegreeP , MinuteP , SecondP ;

// INPUT DATA METHOD 1 : PROGRAMMER DEFINE

double XA = 1425.07 , YA = 1971.28 , XB = 7484.80 , YB = 5209.64 ;


double AzAP_d=76 , AzAP_m=04 , AzAP_s=24 ;
double AzBP_d=141 , AzBP_m=30 , AzBP_s=16 ;

// INPUT DATA METHOD 2 : USER DEFINE


/*
//declaration of variable
double XA, YA, XB, YB;
double AzAP_d, AzAP_m, AzAP_s;
double AzBP_d, AzBP_m, AzBP_s;

// User Input for STN A


cout << " Enter Coordinate of Stn A(x): " ;
cin >> XA;
cout << " Enter Coordinate of Stn A(y): " ;
cin >> YA;
// User Input for STN B
cout << " Enter Coordinate of Stn B(x): " ;
cin >> XB;
cout << " Enter Coordinate of Stn B(y): " ;
cin >> YB;
// User Input for Azimuth AP
cout << " Enter Azimuth/Direction from StnA - StnP [Degree]: " ;
cin >> AzAP_d;
cout << " Enter Azimuth/Direction from StnA - StnP [Minutes]: " ;
cin >> AzAP_m;
cout << " Enter Azimuth/Direction from StnA - StnP [Second]: " ;

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

cin >> AzAP_s;


// User Input for Azimuth BP
cout << " Enter Azimuth/Direction from StnB - StnP [Degree]: " ;
cin >> AzBP_d;
cout << " Enter Azimuth/Direction from StnB - StnP [Minutes]: " ;
cin >> AzBP_m;
cout << " Enter Azimuth/Direction from StnB - StnP [Second]: " ;
cin >> AzBP_s;
*/

// INPUT DATA METHOD 3 : READ DATA FROM TEXT FILE


/*
//declaration of variable
double XA, YA, XB, YB;
double AzAP_d, AzAP_m, AzAP_s;
double AzBP_d, AzBP_m, AzBP_s;

ifstream InputFile; //
InputFile.open("C:\\Users\\nizamazhan\\Desktop\\UTM Cat A\\Computer Programming\\DataInput.txt");
InputFile >> XA;
InputFile >> YA;
InputFile >> XB;
InputFile >> YB;
InputFile >> AzAP_d >> AzAP_m >> AzAP_s;
InputFile >> AzBP_d >> AzBP_m >> AzBP_s;
*/

// ################### PROCESS-COMPUTATION ###################

// STEP 1 : TO COMPUTE THE DISTANCE & AZIMUTH FROM STN A - STN B


DifX = XB - XA ;
DifY = YB - YA ;
DistanceAB = sqrt(pow (DifX,2) + pow (DifY,2)) ;
AzimuthAB = atan(DifX / DifY) * 180/pi ;

// Convert DecimalDegree (DD) to Degree Minute Second (DMS)


DegreeAB = int (AzimuthAB) ;
MinuteAB = int ((AzimuthAB - DegreeAB) * 60) ;
SecondAB = (((AzimuthAB - DegreeAB) * 60) - MinuteAB) * 60 ;

// STEP 2 : TO COMPUTE THE THREE ANGLES OF TRIANGLE ABP


// Convert AzAP in DMS to DD
AzimuthAP = AzAP_d + (AzAP_m / 60) + (AzAP_s / 60);

// Convert AzBP in DMS to DD


AzimuthBP = AzBP_d + (AzBP_m / 60) + (AzBP_s / 60);

// Angle A in DMS
Angle_A = AzimuthAP - AzimuthAB;
DegreeA = int (Angle_A);
MinuteA = int ((Angle_A - DegreeA) * 60);
SecondA = (((Angle_A - DegreeA) * 60) - MinuteA) * 60;

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

// Angle B in DMS
Angle_B = (180 + AzimuthAB) - AzimuthBP;
DegreeB = int (Angle_B);
MinuteB = int ((Angle_B - DegreeB) * 60);
SecondB = (((Angle_B - DegreeB) * 60) - MinuteB) * 60;

// Angle P in DMS
Angle_P = 180 - (Angle_A + Angle_B);
DegreeP = int (Angle_P);
MinuteP= int ((Angle_P - DegreeP) * 60);
SecondP = (((Angle_P - DegreeP) * 60) - MinuteP) * 60;

// STEP 3 : to compute the dictance of AP


DistanceAP = DistanceAB * (sin (Angle_B*pi/180) / sin (Angle_P*pi/180));

// STEP 4 : to compute the coordinates of station P


Px = XA + DistanceAP * (sin(AzimuthAP * pi/180));
Py = YA + DistanceAP * (cos(AzimuthAP * pi/180));

// STEP 5 : to compute the distance of BP


DistanceBP = DistanceAB * (sin (Angle_A*pi/180) / sin (Angle_P*pi/180));

// ################## FINAL OUTPUT #################

cout << "MOHAMMAD NIZAM BIN AZHAN";


cout << endl;
cout << "UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A";
cout << endl;
cout << "IN CLASS ASSIGNMENT";
cout << endl;
cout << "POSITIONING INTERSECTION";
cout << endl;
cout << endl;
cout << "Intersection of two lines where both having known directions.";
cout << endl;
cout << endl;
cout << "Refer to Figure 1 in assignment given, assuming the following information is known for
two lines.";
cout << endl;
cout << "Compute coordinate latitude/longitude at station P and check the answer by applying to
the side of BP.";
cout << endl;
cout << endl;
cout << "Given:";cout << endl;
cout << "PSN A (1425.07,1971.28)" ;cout << endl;
cout << "PSN B (7484.80,5209.64)" ;cout << endl;
cout << "Azimuth AP = 76'04'24''" ;cout << endl;
cout << "Azimuth BP = 141'30'16'' ";cout << endl;
cout << endl;
cout << endl;
cout << "**********************************************************";
cout << endl;
cout << "STEP 1: The distance and azimuth of side AB are:" << endl;

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

cout << endl;


cout << "Distance AB :" << DistanceAB << " meter" << endl;
cout << "Azimuth AB [Degree] :" << AzimuthAB << "\370" <<endl;
cout << "Azimuth AB [DMS] :" << DegreeAB << "\370" << MinuteAB << "'" << SecondAB
<<"''"<<endl; cout << endl;
cout << endl;
cout << "**********************************************************";
cout << endl;
cout << "STEP 2: The three angles of ABP triangle:" << endl;
cout << endl;
cout << "Azimuth AP [Degree] :" << AzimuthAP << "\370" <<endl;
cout << "Azimuth BP [Degree] :" << AzimuthBP << "\370" <<endl;
cout << endl;
cout << "Angle A [Degree] :" << Angle_A << Degree << "\370" <<endl;
cout << "Angle A [DMS] :" << DegreeA << "\370" << MinuteA << "'" << SecondA
<<"''"<<endl; cout << endl;
cout << "Angle B [Degree] :" << Angle_B << Degree << "\370" <<endl;
cout << "Angle B [DMS] :" << DegreeB << "\370" << MinuteB << "'" << SecondB
<<"''"<<endl; cout << endl;
cout << "Angle P [Degree] :" << Angle_P << Degree << "\370" <<endl;
cout << "Angle P [DMS] :" << DegreeP << "\370" << MinuteP << "'" << SecondP
<<"''"<<endl; cout << endl;
cout << endl;
cout << "**********************************************************";
cout << endl;
cout << "STEP 3: The distance of AP:" << endl;
cout << endl;
cout << "Distance AP :" << DistanceAP << " meter" << endl;
cout << endl;
cout << endl;
cout << "**********************************************************";
cout << endl;
cout << "STEP 4: The coordinates of station P:" << endl;
cout << endl;
cout << "Xp :" << Px << " meter" << endl;
cout << "Yp :" << Py << " meter" << endl;
cout << endl;
cout << endl;
cout << "**********************************************************";
cout << endl;
cout << "STEP 5: The distance of BP:" << endl;
cout << endl;
cout << "Distance BP :" << DistanceBP << " meter" << endl;

//###################OUTPUT TO TEXT FILE###################


//similiar to cout
ofstream outputfile;
outputfile.open("C:\\Users\\nizamazhan\\Desktop\\UTM Cat A\\Computer
Programming\\IntersectionOutput.txt");

outputfile << "MOHAMMAD NIZAM BIN AZHAN";


outputfile << endl;
outputfile << "UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A";

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

outputfile << endl;


outputfile << "IN CLASS ASSIGNMENT";
outputfile << endl;
outputfile << "POSITIONING INTERSECTION";
outputfile << endl;
outputfile << endl;
outputfile << "Intersection of two lines where both having known directions.";
outputfile << endl;
outputfile << endl;
outputfile << "Refer to Figure 1 in assignment given, assuming the following information is known
for two lines.";
outputfile << endl;
outputfile << "Compute coordinate latitude/longitude at station P and check the answer by
applying to the side of BP.";
outputfile << endl;
outputfile << endl;
outputfile << "Given:";outputfile << endl;
outputfile << "PSN A (1425.07,1971.28)" ;outputfile << endl;
outputfile << "PSN B (7484.80,5209.64)" ;outputfile << endl;
outputfile << "Azimuth AP = 76'04'24''" ;outputfile << endl;
outputfile << "Azimuth BP = 141'30'16'' ";outputfile << endl;
outputfile << endl;
outputfile << endl;
outputfile << "**********************************************************";
outputfile << endl;
outputfile << "STEP 1: The distance and azimuth of side AB are:" << endl;
outputfile << endl;
outputfile << "Distance AB :" << DistanceAB << " meter" << endl;
outputfile << "Azimuth AB [Degree] :" << AzimuthAB << "\370" <<endl;
outputfile << "Azimuth AB [DMS] :" << DegreeAB << "\370" << MinuteAB << "'" << SecondAB
<<"''"<<endl; outputfile << endl;
outputfile << endl;
outputfile << "**********************************************************";
outputfile << endl;
outputfile << "STEP 2: The three angles of ABP triangle:" << endl;
outputfile << endl;
outputfile << "Azimuth AP [Degree] :" << AzimuthAP << "\370" <<endl;
outputfile << "Azimuth BP [Degree] :" << AzimuthBP << "\370" <<endl;
outputfile << endl;
outputfile << "Angle A [Degree] :" << Angle_A << Degree << "\370" <<endl;
outputfile << "Angle A [DMS] :" << DegreeA << "\370" << MinuteA << "'" << SecondA
<<"''"<<endl; outputfile << endl;
outputfile << "Angle B [Degree] :" << Angle_B << Degree << "\370" <<endl;
outputfile << "Angle B [DMS] :" << DegreeB << "\370" << MinuteB << "'" << SecondB
<<"''"<<endl; outputfile << endl;
outputfile << "Angle P [Degree] :" << Angle_P << Degree << "\370" <<endl;
outputfile << "Angle P [DMS] :" << DegreeP << "\370" << MinuteP << "'" << SecondP
<<"''"<<endl; outputfile << endl;
outputfile << endl;
outputfile << "**********************************************************";
outputfile << endl;
outputfile << "STEP 3: The distance of AP:" << endl;
outputfile << endl;

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

outputfile << "Distance AP :" << DistanceAP << " meter" << endl;
outputfile << endl;
outputfile << endl;
outputfile << "**********************************************************";
outputfile << endl;
outputfile << "STEP 4: The coordinates of station P:" << endl;
outputfile << endl;
outputfile << "Xp :" << Px << " meter" << endl;
outputfile << "Yp :" << Py << " meter" << endl;
outputfile << endl;
outputfile << endl;
outputfile << "**********************************************************";
outputfile << endl;
outputfile << "STEP 5: The distance of BP:" << endl;
outputfile << endl;
outputfile << "Distance BP :" << DistanceBP << " meter" << endl;
return 0;
}

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

MATLAB SCRIPT
% MATLAB script for positioning intersection

% ################### INPUT ###################

% DATA INPUT
XA = 1425.07; YA = 1971.28; XB = 7484.80; YB = 5209.64;
AzAP_d = 76; AzAP_m = 04; AzAP_s = 24;
AzBP_d = 141; AzBP_m = 30; AzBP_s = 16;

% ################### PROCESS-COMPUTATION ###################

% STEP 1 : TO COMPUTE THE DISTANCE & AZIMUTH FROM STN A - STN B


DifX = XB - XA;
DifY = YB - YA;
DistanceAB = sqrt(DifX^2 + DifY^2);
AzimuthAB = atan(DifX / DifY) * 180 / pi;

% Convert DecimalDegree (DD) to Degree Minute Second (DMS)


DegreeAB = floor(AzimuthAB);
MinuteAB = floor((AzimuthAB - DegreeAB) * 60);
SecondAB = (((AzimuthAB - DegreeAB) * 60) - MinuteAB) * 60;

% STEP 2 : TO COMPUTE THE THREE ANGLES OF TRIANGLE ABP

% Convert AzAP in DMS to DD


AzimuthAP = AzAP_d + (AzAP_m / 60) + (AzAP_s / 3600);

% Convert AzBP in DMS to DD


AzimuthBP = AzBP_d + (AzBP_m / 60) + (AzBP_s / 3600);

% Angle A in DMS
Angle_A = AzimuthAP - AzimuthAB;
DegreeA = floor(Angle_A);
MinuteA = floor((Angle_A - DegreeA) * 60);
SecondA = (((Angle_A - DegreeA) * 60) - MinuteA) * 60;

% Angle B in DMS
Angle_B = (180 + AzimuthAB) - AzimuthBP;
DegreeB = floor(Angle_B);
MinuteB = floor((Angle_B - DegreeB) * 60);
SecondB = (((Angle_B - DegreeB) * 60) - MinuteB) * 60;

% Angle P in DMS
Angle_P = 180 - (Angle_A + Angle_B);
DegreeP = floor(Angle_P);
MinuteP = floor((Angle_P - DegreeP) * 60);
SecondP = (((Angle_P - DegreeP) * 60) - MinuteP) * 60;

% STEP 3 : to compute the distance of AP


DistanceAP = DistanceAB * (sin(Angle_B * pi / 180) / sin(Angle_P * pi / 180));

% STEP 4 : to compute the coordinates of station P


Px = XA + DistanceAP * (sin(AzimuthAP * pi / 180));
Py = YA + DistanceAP * (cos(AzimuthAP * pi / 180));

% STEP 5 : to compute the distance of BP


DistanceBP = DistanceAB * (sin(Angle_A * pi / 180) / sin(Angle_P * pi / 180));

% ################## FINAL OUTPUT #################

fprintf('Compute coordinate at station P and check the answer by applying to


the side of BP.\n\n');

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

fprintf('Given:\n');
fprintf('PSN A (1425.07,1971.28)\n');
fprintf('PSN B (7484.80,5209.64)\n');
fprintf('Azimuth AP = 76''04''24''''\n');
fprintf('Azimuth BP = 141''30''16''''\n\n');
fprintf('**********************************************************\n');

fprintf('STEP 1: The distance and azimuth of side AB are:\n\n');


fprintf('Distance AB: %.2f meter\n', DistanceAB);
fprintf('Azimuth AB [Degree]: %.2f°\n', AzimuthAB);
fprintf('Azimuth AB [DMS]: %d°%d''%.2f''''\n\n', DegreeAB, MinuteAB, SecondAB);

fprintf('**********************************************************\n');
fprintf('STEP 2: The three angles of ABP triangle:\n\n');
fprintf('Azimuth AP [Degree]: %.2f°\n', AzimuthAP);
fprintf('Azimuth BP [Degree]: %.2f°\n\n', AzimuthBP);
fprintf('Angle A [Degree]: %.2f°\n', Angle_A);
fprintf('Angle A [DMS]: %d°%d''%.2f''''\n\n', DegreeA, MinuteA, SecondA);
fprintf('Angle B [Degree]: %.2f°\n', Angle_B);
fprintf('Angle B [DMS]: %d°%d''%.2f''''\n\n', DegreeB, MinuteB, SecondB);
fprintf('Angle P [Degree]: %.2f°\n', Angle_P);
fprintf('Angle P [DMS]: %d°%d''%.2f''''\n\n', DegreeP, MinuteP, SecondP);

fprintf('**********************************************************\n');
fprintf('STEP 3: The distance of AP:\n\n');
fprintf('Distance AP: %.2f meter\n\n', DistanceAP);

fprintf('**********************************************************\n');
fprintf('STEP 4: The coordinates of station P:\n\n');
fprintf('Xp: %.2f meter\n', Px);
fprintf('Yp: %.2f meter\n\n', Py);

fprintf('**********************************************************\n');
fprintf('STEP 5: The distance of BP:\n\n');
fprintf('Distance BP: %.2f meter\n', DistanceBP);

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A


UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

DISCUSSION

C++ and MATLAB are two distinct programming languages used for different purposes, and
each has its advantages and disadvantages for beginners.

COMPARISON C++ MATLAB


General-purpose, for software Focused on mathematical
development, games, systems computations, data analysis, and
Purpose programming. Good for high- engineering applications
performance needs.
Complex syntax, requires Simple syntax, intuitive for
understanding memory mathematical operations, easier
Ease of Learning management and object- for beginners, especially in
oriented programming. Steeper science and engineering
learning curve

Faster, compiled language with Slower, interpreted language but


Performance better control over hardware optimized for matrix operations
and memory and quick prototyping
Requires external IDEs (e.g., Built-in IDE with integrated tools
Development Visual Studio), debugging can for visualization and debugging
Environment be complex
Free and open-source Paid software, though often
Cost provided by universities
Software development, games, Data analysis, scientific
Use Cases system-level programming research, engineering

For learning programming concepts and working on software development or


performance-critical applications, C++ might be the better choice.

But to more focused on mathematical modeling, data analysis, or engineering


applications and prefer an easier start, MATLAB is the more suitable option.

UTM HYDRO II (HYDROGRAPHIC SURVEYING II PROGRAMME) FIG/IHO/ICA CATEGORY A

You might also like