Question

Given the following C program, rewrite the program and use C++ header files, C++ constants, inline...

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;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

code:

include <iostream>

using namespace std;

const float PI=3.141592;

inline float reactance(float c,float f)

{

return 1/(2*PI*f*c);

}

int main()

{

float frq,cap,xc;

cout<<"Enter frequency => ";

cin>>frq;

cout<<"Enter capacitance => ";

cin>>cap;

xc=reactance(cap,frq);

cout<<"XC="<<xc<<" Ohm"<<endl;
return 0;

}

OUTPUT:

Enter frequency => 58.36
Enter capacitance => 2.1
XC=0.00129863 Ohm


Add a comment
Know the answer?
Add Answer to:
Given the following C program, rewrite the program and use C++ header files, C++ constants, inline...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following program has some syntax errors. Enumerate the errors then rewrite, compile and run the...

    The following program has some syntax errors. Enumerate the errors then rewrite, compile and run the program after correction. #include <stdio.h> int Main( ); { float w ; float wk ; printf ("Enter your weight in pounds "); scanf["%d" weight];    wk=w x 0.45359237 ; printf('Your weight in kilograms is %d',wk); }

  • Using the code below, Complete the C program main.c to stop execution if the user attempts...

    Using the code below, Complete the C program main.c to stop execution if the user attempts a divide by 0. #include <stdio.h> int main() { float a, b; printf("Input two integers to divide the first by the second\n"); scanf("%f%f", &a, &b); printf("%f/%f = %.2f\n", a, b, a/b);    return 0; }

  • Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include...

    Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include <stdio.h> #define PI 3.14 typedef struct cylinder{    float r,h;    float areacircle=2*PI*r;    float areacylinder;    float volumecylinder;    areacylinder=2*PI*r*h+2*PI*r*r;    volumecylinder=PI*r*r*h; }; int main() {    float start,numcyls;    printf("How many cylinders do you want? Enter a positive integer.\n");    scanf("%f",&numcyls);    if(numcyls<1||ceilf(numcyls)!=numcyls)    while()    {printf("The number you have entered is not a positive integer. Please try again.\n");        printf("Remember,...

  • Program Description Write a program that calculates the distance between two places on Earth, based on...

    Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earth’s mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed: Program must have header comments stating the author of the Program, date, and Program Description. Include the math.h header file Initialize a...

  • #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x)...

    #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x + 7\n"); printf ("q: quit\n"); } void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); } // end function a void b(float x) { float v = x*x*x; printf (" a(%.2f) = %.2f^3 = %.2f\n", x, x, v); } // end function b void c(float x)...

  • What to do Write a C program that computes Pi with the approximation algorithm that I...

    What to do Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

  • C program Classwork_3.3: Correct the program below that will read two numbers: number of drinks and...

    C program Classwork_3.3: Correct the program below that will read two numbers: number of drinks and number of sandwiches, and display the total bill calculated as: Total bill = Number of Drinks X 5.50 + Number of Sandwiches X 10.00 Answer the questions below. C-Program with error: Write the correct program here: #include<stdio.h> int main (void) floats numberofDrinks, numberofSandwiches; float totalBilling: printf("Enter number of Drinks \n"); scanf("%d",&numberofdrinks); printf("Enter number of Sandwiches\n") scanf("%f",&numberofSandwiches); totalbilling = numberofDrinks *5.50 + numberofsandwiches/10.00; printf("Total bill...

  • C program. Using do-while loop for this question. Question: write a program to calculate the average...

    C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() {     int num;     int count =0;     int sum=0;     float avg;      printf("Enter the value of n: ");    ...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT