Login
Order Now
Support
theprogrammingassignmenthelp

Program - C++ header files, C++ constants, inline functions and C++ I/O

  • 13th Feb, 2020
  • 17:17 PM

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 <iostream>. This header file contains the definition of the std namespace.  

/* Convert this program into a C++ program. */
#include <stdio.h>
#include <conio.h>

#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 <stdio.h>
#include <iostream>

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 = "<<xc<<endl;

  return 0;
}

Share this post