### Problem under c ++

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

10x!!!!
Last edited on

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.

Hope that helps,

Andy
Hello Andy, thank you for the advice. I give the code, but I do not know if it's true?

Code:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566`` `````` #include #include using namespace std; // A function to print the matrix. void PrintMat(int **mat, int n) { int i, j; cout<<"\n\n"<>v; // Dynamically declare graph. int **graph; graph = new int*[v]; for(i = 0; i < v; i++) { graph[i] = new int[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 "<>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); } ``````

10x !!!
Last edited on

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.

Hope that helps,

Andy
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.

thanks!!!

 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.

Andy
2. Write sorcid this is my fault...

I meant the source code.

that is, I only need the source code of the program.
Last edited on
some ideas..?

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.

 ``1234567891011121314151617`` `````` #include #include using namespace std; double lg(double a) { const double MAGIC_NUMBER = 2.302585092994045901; const int 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; }``````