NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <windows.h>
#include <iomanip>
#include <vector>
#include <sstream>
#include <math.h>


using namespace std;

double precizie(double value, double precision)
{
return (round((value * pow(10, precision) + 0.5)) / pow(10, precision));
}

//Subprogramul care verifica existenta fisierului
int fisierul_exista(char* nume_fisier)
{
FILE *fis;
if(fis = fopen(nume_fisier,"r"))
{
fclose(fis);
return 1;
}
return 0;
}

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);



int main () {

char fisier_tsp[16],fisier_lungimi[16];


fisier1:
cout<<"Dati numele fisierului tsp urmat de extensia .txt "<<endl;
cin>>fisier_tsp;

if (fisierul_exista(fisier_tsp) == 0)
{
//Modificarea culorii textului in rosu
SetConsoleTextAttribute(console, 12);
cout<<"Ne pare rau, dar acest fisier nu exista. Incercati din noun";
//Modificarea culorii textului in alb
SetConsoleTextAttribute(console, 15);
goto fisier1;
}

fisier2:

cout<<"Dati numele fisierului cu lungimi urmat de extensia .txt "<<endl;
cin>>fisier_lungimi;




if (fisierul_exista(fisier_lungimi) == 0)
{
//Modificarea culorii textului in rosu
SetConsoleTextAttribute(console, 12);
cout<<"Ne pare rau, dar acest fisier nu exista. Incercati din noun";
//Modificarea culorii textului in alb
SetConsoleTextAttribute(console, 15);
goto fisier2;
}


//Modificarea culorii textului in verde
SetConsoleTextAttribute(console, 10);
cout<<"nNumele fisierelor a fost completat cu succesn";
//Modificarea culorii textului in alb
SetConsoleTextAttribute(console, 15);



vector<int> vector_nod1,vector_nod2,vector_lungime,vector_lungimi_calculate;

ifstream file1,file2;
//Deschirea fisierului tsp si de lungimi
file1.open (fisier_tsp);
file2.open(fisier_lungimi);
int nod_1,nod_2,lungime_noduri;
int contor = 0;
//Evitarea primelor 3 linii
string s;
while(contor<3)
{
getline(file1,s);
contor++;
}
//Citirea primelor 2 valori ale primului fisier
file1>>nod_1>>nod_2;
while (file1>>nod_1>>nod_2>>lungime_noduri && !file1.eof())
{
//Adaugarea variabilei nod_1 in vectorul vector_nod1
vector_nod1.push_back(nod_1);
vector_nod2.push_back(nod_2);
vector_lungime.push_back(lungime_noduri);
}

contor = 0;
//Eliminarea primelor 7 linii, dar se pare ca trebuie eliminate 14 la acest fisier
for(int i =0;i<14;i++)
{
getline(file2,s);
}


int numar_nod;
double coordonata_x,coordonata_y,minutes,latitude,longitude;
int deg;
double PI = 3.141592;
int i = 0;
static double matrice_noduri[2][2950];
//citirea din al doilea fisier
while (file2>>numar_nod>>coordonata_x>>coordonata_y)
{

//Transformarea primei coordonata din grade in radian
deg = (int)(coordonata_x + 0.5 );
if(coordonata_x - deg >= 0)
{
minutes = coordonata_x - deg;
}else
{
coordonata_x = coordonata_x - (deg-1);
minutes = 0.6 - coordonata_x;
}
latitude = PI * (deg + 5.0 * minutes / 3.0 ) / 180.0;
//Transformarea celei de a doua coordonata din grade in radian
deg =(int)(coordonata_y + 0.5);
if(coordonata_y - deg >= 0)
{
minutes = coordonata_y - deg;
}else
{
coordonata_y = coordonata_y - (deg-1);
minutes = 0.6 - coordonata_y;
}
longitude = PI * (deg + 5.0 * minutes / 3.0 ) / 180.0;
matrice_noduri[0][i]=latitude;
matrice_noduri[1][i]=longitude;
i++;

}
int nr=i;

//Inchiderea celor 2 fisiere
file1.close();
file2.close();




double RRR = 6378.388;
double q1,q2,q3;
int numar;
for(int i=0; i<vector_nod1.size(); i++)
{
q1 = cos(matrice_noduri[1][vector_nod1.at(i)] - matrice_noduri[1][vector_nod2.at(i)]);
q2 = cos(matrice_noduri[0][vector_nod1.at(i)] - matrice_noduri[0][vector_nod2.at(i)]);
q3 = cos(matrice_noduri[0][vector_nod1.at(i)] + matrice_noduri[0][vector_nod2.at(i)]);
//Adaugarea in vectorul vector_lungimi_calculate rezultatul calculat
numar = (int)(RRR *acos(0.5*((1.0+q1)*q2 - (1.0-q1)*q3) ) + 1.0);
vector_lungimi_calculate.push_back(numar);

}
int lungimea_drumului_maxim=0;
int nr_greseli_calcul =0;
ofstream file3;
file3.open("lenghts.txt");
for(int i=0;i<vector_lungimi_calculate.size();i++)
{
if(vector_lungime.at(i) != vector_lungimi_calculate.at(i))
{
nr_greseli_calcul++;
}
lungimea_drumului_maxim += vector_lungimi_calculate.at(i);
}
if(nr_greseli_calcul>0)
{
//Modificarea culorii textului in rosu
SetConsoleTextAttribute(console, 12);
cout<<"nAu rezultat "<<nr_greseli_calcul<<" diferente intre acest calcul si fisierul cu lungimin";
//Modificarea culorii textului in alb
SetConsoleTextAttribute(console, 15);
}else
{
//Modificarea culorii textului in verde
SetConsoleTextAttribute(console, 10);
cout<<"nCalculele au fost realizate cu succes!n";
//Modificarea culorii textului in alb
SetConsoleTextAttribute(console, 15);
}
//Scrierea pe prima linie a fisierului lenghts.txt lungimea drumului
file3<<lungimea_drumului_maxim<<endl;
//Scrierea in fiserul lenghts.txt a lumgimilor dintre noduri
//Parcurgem vectorul pana la size()-1 deoarece pe ultima pozitie se afla lungimea totala a drumului
for(int i=0;i<vector_lungimi_calculate.size();i++)
{
file3<<vector_lungimi_calculate.at(i)<<endl;
}
//Inchiderea fisierului file3
file3.close();
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.