Basic Programming
Basic Programming
PROGRAMMING
REPORT
POSITIONING
INTERSECTION
INTRODUCTION
FLOWCHART
C++
MATLAB
DISCUSSION
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 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.
INTRODUCTION OF MATLAB
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.
DECLARATION
OF VARIABLES
DATA
INPUT
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
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.
END
flowchart continue...
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
DifX = XB - XA ;
PROCESS COMPUTATION: DifY = YB - YA ;
STEP 4 DistanceAB = sqrt(pow (DifX,2) + pow (DifY,2));
// Azimuth of AB
END
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”
// 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;
Compute distance of AP
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 5:
Check the answer? Apply side of BP
STEP 1
// STEP 5 : to compute the distance of BP
STEP 3
STEP 4
STEP 5
DATA
OUTPUT
END
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;
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
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;
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;
*/
// 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;
// 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;
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;
}
MATLAB SCRIPT
% MATLAB script for positioning intersection
% 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;
% 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;
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('**********************************************************\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);
DISCUSSION
C++ and MATLAB are two distinct programming languages used for different purposes, and
each has its advantages and disadvantages for beginners.