Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROGRAMMING ENGINER C++, Please help me to write the code for this problem. Than

ID: 3794457 • Letter: P

Question

PROGRAMMING ENGINER C++, Please help me to write the code for this problem. Thanks

Problem 1. Paste the code provided below into Excel, and expand and enhance the program. Enhance this code by adding at least 8 decimals to the constants. Also, add the other constants shown in the comments sections by expanding the If statement with more ElseIf conditions. Paste your updated code into this document. Do not paste a screenshot.

Function Constant(x)

'this function is for returning values for common constants.

'The inputs are text, the output is a number

'input pi gives output 3.141...,

'input e gives output 2.718...,

'input phi gives output golden ratio 1.618...,

'input gam gives output gamma 0.577...,

'input c gives output the speed of light 2.998 x 10^8,

'input G gives output gravitational constant.

If x = "pi" Then

    Constant = 3.141

ElseIf x = "e" Then

    Constant = 2.718

Else

    Constant = "No constant"

End If

End Function

Explanation / Answer

c++ code:

#include <bits/stdc++.h>
using namespace std;

void constant(string s)
{

if(s == "pi")
{
   cout <<    "input pi gives output " << "3.141592653589793" << endl;
}
else if(s == "phi")
{
   cout <<    "input phi gives output " << "1.61803398875" << endl;
}
else if(s == "c")
{
   cout <<    "input c gives output " << "299792458 m / s" << endl;
}
else if(s == "gam")
{
   cout <<    "input gam gives output " << "0.57721566490153" << endl;  
}
else if(s == "G")
{
   cout <<    "input G gives output " << "6.67408 × 10^(-11)" << endl;
}
else
{
   cout << "Invalid constant symbol! ";
}
}

int main()
{
       string s;
       cout << "Enter symbol! ";
       getline(cin,s);
       constant(s);
       return 0;  
}

Sample Output:

Enter symbol!
pi
input pi gives output 3.141592653589793
akash@akash-SVE15116ENB:~/Desktop/chegg/bisection methode$ ./a.out
Enter symbol!
phi
input phi gives output 1.61803398875
akash@akash-SVE15116ENB:~/Desktop/chegg/bisection methode$ ./a.out
Enter symbol!
c
input c gives output 299792458 m / s
akash@akash-SVE15116ENB:~/Desktop/chegg/bisection methode$ ./a.out
Enter symbol!
gam
input gam gives output 0.57721566490153

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote