For Using Stringstream: Freq1 Freq2 Freq3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

#include <bits/stdc++.

h>
#include <locale>
#include<string>
#include<sstream> // for using stringstream
#include <iostream>
#include <stdio.h>
#include <fstream>
using namespace std;
float freq1;
float freq2;
float freq3;

string str1;
string str2;
string str3;

using std::cout; using std::cin;


using std::endl; using std::string;

void freqCalc()
{

cout << "Dimensão total dos elementos em metros:" << endl;


cout << "Obs. Os comprimentos variam conforme a quantidade de elementos, bem como o material condutor ser
isolado ou não." << endl;
cout << endl;
cout << freq1;
cout << "MHZ";
cout << endl;
cout << "Refletor =>";
cout << 313/freq1;
cout << "m" << endl;
cout << "Irradiante =>";
cout << 306/freq1;
cout << "m" << endl;
cout << "Diretor =>";
cout << 297/freq1;
cout << "m" << endl;
cout << endl;

cout << freq2;


cout << "MHZ";
cout << endl;
cout << "Refletor =>";
cout << 313/freq2;
cout << "m" << endl;
cout << "Irradiante =>";
cout << 306/freq2;
cout << "m" << endl;
cout << "Diretor =>";
cout << 297/freq2;
cout << "m" << endl;
cout << endl;

cout << freq3;


cout << "MHZ";
cout << endl;
cout << "Refletor =>";
cout << 313/freq3;
cout << "m" << endl;
cout << "Irradiante =>";
cout << 306/freq3;
cout << "m" << endl;
cout << "Diretor =>";
cout << 297/freq3;
cout << "m" << endl;
cout << endl;
cout << "-------------------------------------------------------------------------------------------";
cout << endl;
cout << "Dimensão cada lado em metros:" << endl;
cout << endl;
cout << freq1;
cout << "MHZ";
cout << endl;
cout << "Refletor =>";
cout << 313/freq1/4;
cout << "m" << endl;
cout << "Irradiante =>";
cout << 306/freq1/4;
cout << "m" << endl;
cout << "Diretor =>";
cout << 297/freq1/4;
cout << "m" << endl;
cout << endl;

cout << freq2;


cout << "MHZ";
cout << endl;
cout << "Refletor =>";
cout << 313/freq2/4;
cout << "m" << endl;
cout << "Irradiante =>";
cout << 306/freq2/4;
cout << "m" << endl;
cout << "Diretor =>";
cout << 297/freq2/4;
cout << "m" << endl;
cout << endl;

cout << freq3;


cout << "MHZ";
cout << endl;
cout << "Refletor =>";
cout << 313/freq3/4;
cout << "m" << endl;
cout << "Irradiante =>";
cout << 306/freq3/4;
cout << "m" << endl;
cout << "Diretor =>";
cout << 297/freq3/4;
cout << "m" << endl;
cout << endl;
cout << "-------------------------------------------------------------------------------------------";
cout << endl;
}

// Function to convert the floating


// values into fraction
void findFraction(string s)
{
// Initialize variables
string be_deci = "",
af_deci = "",
reccu = "";

bool x = true, y = false,


z = false;

// Traverse the floating string


for (int i = 0; i < s.size(); ++i) {
// Check if decimal part exist
if (s[i] == '.') {
x = false;
y = true;
continue;
}

// Check if recurrence
// sequence exist
if (s[i] == '(') {
z = true;
y = false;
continue;
}

// Retrive decimal part


// and recurrence resquence
if (x)
be_deci += s[i];

if (y)
af_deci += s[i];

if (z) {

// Traverse the string


for (; i < s.size()
&& s[i] != ')';
++i)
reccu += s[i];
break;
}
}

// Convert string to integer


int num_be_deci = stoi(be_deci);
int num_af_deci = 0;

// If no recurrence sequence exist


if (af_deci.size() != 0)
num_af_deci = stoi(af_deci);

// Initialize numerator & denominator


int numr = num_be_deci
* pow(10, af_deci.size())
+ num_af_deci;

int deno = pow(10, af_deci.size());

// No reccuring term
if (reccu.size() == 0) {
int gd = __gcd(numr, deno);

// Print the result


//cout << numr / gd << " / "
// << deno / gd;
//cout << "" << endl;
//cout << "Marcação na haste em : ";
cout << numr / gd * sin((45*3.1415)/180)/ (deno/gd) / sin((90*3.1415)/180);
//cout << " m" << endl;

// If reccuring term exist


else {
// Convert reccuring term to integer
int reccu_num = stoi(reccu);

// reccu.size() is num of
// digit in reccur term
int numr1
= numr
* pow(10, reccu.size())
+ reccu_num;

int deno1 = deno


* pow(10, reccu.size());

// eq 2 - eq 1
int res_numr = numr1 - numr,
res_deno = deno1 - deno;

int gd = __gcd(res_numr,
res_deno);

// Print the result


// cout << res_numr / gd << " / "
// << res_deno / gd;
//cout << res_numr/gd *sin(45)/res_deno/gd;
}
}

// Driver Code
int main()
{

// Given string str

setlocale(LC_ALL, "portuguese");
cout << " ANTENA QUADRA\n\n";
cout << " Agoritmo para cálculo de antena quadra\n\n";
cout << "************************PY2ADA v1.0******************************\n\n";
cout << "=> Insira as 03 frequências de cobertura da antena em MHZ:";
cout << endl;
cout << "=> Primeira frequência:";
cin >> freq1;
cout << endl;
cout << "=> Segunda frequência:";
cin >> freq2;
cout << endl;
cout << "=> Terceira frequência:";
cin >> freq3;
cout << endl;
//cout << "=> Insira o comprimento desejado para marcação em metros (1/4 total):";
//cin >> nr;
cout << endl;
freqCalc();
//findFraction(nr);
//string str1(std::to_string((313/freq)/4));
//findFraction(str1);

cout << "Ponto na haste para ancoragem do condutor em metros:" << endl;
cout << freq1;
cout << "MHZ";
cout << endl;
cout << "Refletor =>";
std::ostringstream ss1;
ss1 << 313/freq1/4;
std::string str1(ss1.str());
findFraction(str1);
cout << "m" << endl;

cout << "Irradiante =>";


std::ostringstream ss2;
ss2 << 306/freq1/4;
std::string str2(ss2.str());
findFraction(str2);
cout << "m" << endl;

cout << "Diretor =>";


std::ostringstream ss3;
ss3 << 297/freq1/4;
std::string str3(ss3.str());
findFraction(str3);
cout << "m" << endl;
cout << endl;

cout << freq2;


cout << "MHZ";
cout << endl;
cout << "Refletor =>";
std::ostringstream ss4;
ss4 << 313/freq2/4;
std::string str4(ss4.str());
findFraction(str4);
cout << "m" << endl;

cout << "Irradiante =>";


std::ostringstream ss5;
ss5 << 306/freq2/4;
std::string str5(ss5.str());
findFraction(str5);
cout << "m" << endl;

cout << "Diretor =>";


std::ostringstream ss6;
ss6 << 297/freq2/4;
std::string str6(ss6.str());
findFraction(str6);
cout << "m" << endl;
cout << endl;
cout << freq3;
cout << "MHZ";
cout << endl;
cout << "Refletor =>";
std::ostringstream ss7;
ss7 << 313/freq3/4;
std::string str7(ss7.str());
findFraction(str7);
cout << "m" << endl;

cout << "Irradiante =>";


std::ostringstream ss8;
ss8 << 306/freq3/4;
std::string str8(ss8.str());
findFraction(str8);
cout << "m" << endl;

cout << "Diretor =>";


std::ostringstream ss9;
ss9 << 297/freq3/4;
std::string str9(ss9.str());
findFraction(str9);
cout << "m" << endl;
cout << "-------------------------------------------------------------------------------------------";

cout << endl;

return 0;
}

You might also like