- 13th Feb 2020
- 04:47 am
- Ali Akavis
C++ Assignment Question
Given the following C program, rewrite the program and use C++ header files, C++ constants, inline functions and C++ I/O. Please note that the standard C++ library header file, which defines the I/O functions is named . This header file contains the definition of the std namespace.
/* Convert this program into a C++ program. */
#include
#include
#define PI 3.141592
float reactance(float c,float f)
{
return 1/(2*PI*f*c);
}
int main()
{
float frq,cap,xc;
printf("Enter frequency => ");
scanf("%f",&frq);
printf("Enter capacitance => ");
scanf("%f",&cap);
xc=reactance(cap,frq);
printf("XC=%.2f Ohm",xc);
getch();
return 0;
}
C++ Assignment Solution
/* Convert this program into a C++ program. */
#include
#include
using namespace std;
#define PI 3.141592
float reactance(float c,float f)
{
return 1/(2*PI*f*c);
}
int main()
{
float frq,cap,xc;
cout<<"Enter frequency => ";
cin>>frq;
cout<<"\nEnter capacitance => ";
cin>>cap;
xc=reactance(cap,frq);
cout<<"C = "<
return 0;
}