Hello fellow I have the following problem to solve ..
I will be grateful to someone who can help with the solution ..
Write a program that inputs values V1, V2 from the keyboard and calculates the ratio of V1 / V2 in dB by the formula
dB = 20 lg (V2 / V1) for V2> 0; V1> 0
1. Create a block diagram of the algorithm.
2. source code
3. Test it
Verification
A) Example Input V2 / V1> 1
B) Example Input V2 / V1 <1
C) Example input V2 = V1
F) Example output dB> 0
F) Example output dB <0
D) Example output dB = 0
It has been my experience that a post like yours tends to be ignored because most people here will not do your work for you.
Write some code and post it, point out where you are having a problem and then you can get some help.
I will suggest that "db", "V1" and "V2"be defined as doubles because of the division and you will need "db" as a floating point number. Also I would check that "V1" is not zero because of the divide by zero problem you would eventually come to.
You may also want to research how to calculate "db". I think your formula that you posted is a little light.
#include<iostream>
#include<iomanip>
usingnamespace std;
// A function to print the matrix.
void PrintMat(int **mat, int n)
{
int i, j;
cout<<"\n\n"<<setw(4)<<"";
for(i = 0; i < n; i++)
cout<<setw(3)<<"("<<i+1<<")";
cout<<"\n\n";
// Print 1 if the corresponding vertexes are connected otherwise 0.
for(i = 0; i < n; i++)
{
cout<<setw(3)<<"("<<i+1<<")";
for(j = 0; j < n; j++)
{
cout<<setw(4)<<mat[i][j];
}
cout<<"\n\n";
}
}
int main()
{
int i, v, e, j, v1, v2;
// take the input of the number of edges.
cout<<"Enter the number of vertexes of the graph: ";
cin>>v;
// Dynamically declare graph.
int **graph;
graph = newint*[v];
for(i = 0; i < v; i++)
{
graph[i] = newint[v];
for(j = 0; j < v; j++)graph[i][j] = 0;
}
cout<<"\nEnter the number of edges of the graph: ";
cin>>e;
// Take the input of the adjacent vertex pairs of the given graph.
for(i = 0; i < e; i++)
{
cout<<"\nEnter the vertex pair for edge "<<i+1;
cout<<"\nV(1): ";
cin>>v1;
cout<<"V(2): ";
cin>>v2;
graph[v1-1][v2-1] = 1;
graph[v2-1][v1-1] = 1;
}
// Print the 2D array representation of the graph.
PrintMat(graph, v);
}
This is a very nice program even great full that it compiles with no errors, but what does it have to do with figuring the dB of a given input?
Unless I am entering the wrong values for "V1" and "V2" I believe that you are using the wrong subscripts for lines 59 and 60.
If there is some test data that you are using that has a known result it is helpful to include that with you code so that a known input will produce a known output.
Hi andy, you definitely help me, but lines 50 and 60 with what I would replace them and if only they are wrong with the condition I gave. Оr I need to change the whole code if I want to perform the functions of the topic.
Write a program that inputs values V1, V2 from the keyboard and calculates the ratio of V1 / V2 in dB by the formula dB = 20 lg (V2 / V1) for V2> 0; V1> 0
Your program is in totally different direction.
If this is what you want to use you will have to tell me what the (graph/table/array) is for and how you want to use it? Using "v1" and "v2" as your subscript for the array could put an element outside the boundaries of the array. This would not good and would have unknown results.
You have me at a loss, because I in-visioned a much different program that did not include an array or having to store the results of the calculation.
A possibility would be to store the results of the calculation of dB in the array and later use those numbers to print something out. Just a guess at this point.
While I am thinking about it, what is
2. Write sorcid
I do not understand what "sorcid" is? If this in not a language difference then it is something I have not seen before and I am not sure what it means.
The code that you have presented has nothing remotely to do with the statement of your problem.
It appears to be something you have cut-and-pasted from elsewhere to try to demonstrate that you have made some attempt at the problem. In fact it appears to be this one: http://www.sanfoundry.com/cpp-program-represent-graph-using-2d-array/
but there are several other sources on the web.
I don't think that is very clever.
Please present a genuine attempt of your own at solving your particular problem. Then someone might offer assistance.
here's what I figured out but it returns my mistake.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include<iostream>
#include<iomanip>
usingnamespace std;
double lg(double a) {
constdouble MAGIC_NUMBER = 2.302585092994045901;
constint LUCKY_SEVEN = 7;
double sum = 0, x = a-1;
int i;
for (i = LUCKY_SEVEN; i; --i) {
sum += 1.0/(i*(1-((!(i&1))<<1)));
sum *= x;
}
return sum / MAGIC_NUMBER;
}