/*
Sean Hodgins
Lab 5 Part 1
Visual C++ 2005 Express Edition
Purpose: To write a program that calucates various resistances, using functions
Variables: Farads, henrys, hertz- user entered numbers, resistance- calculated within the program. Void functoin- for external
functions.
*/
#include "stdafx.h"
#include
#define pi 3.1415925
using namespace std;
// Function prototype.
int inductive_reactance(float, float);
// This function computes the inductive reactance
// for a given value of inductor and frequency.
float input();
void display(float, float, float, float, float);
#define capacitive_reactance(frequency, capacitance) 1/(2 * pi * frequency * capacitance) // The capacitive reactance.
int main()
{
float farads; // Value of the capacitor.
float henrys; // Value of the inductor.
float hertz; // Value of the frequency.
float reactanceC; // Value of the capacitive reactance.
float reactanceI; // Value of the inductiive reactance.
cout << "Input value of the capacitor in farads => ";
farads = input();
cout << "Input value of the inductor in henrys => ";
henrys = input();
cout << "Input value of the frequence in hertz => ";
hertz = input();
reactanceC = capacitive_reactance(farads, hertz);
reactanceI = inductive_reactance(henrys, hertz);
display(farads, hertz, reactanceI, reactanceC, henrys);
cin.get();
cin.get();
return 0;
}
void display(float farads, float hertz, float reactanceI, float reactanceC, float henrys)
{
cout << "\n";
cout << "The reactance of a " << farads << " farad capacitor\n";
cout << "at a frequency of " << hertz << " hertz is " << reactanceC;
cout << " ohms.\n";
cout << "\n";
cout << "The reactance of a " << henrys << " henry inductor\n";
cout << "at a frequency of " << hertz << " hertz is " << reactanceI;
cout << " ohms.\n";
}
int inductive_reactance(float inductance, float frequency)
{
return(2 * pi * frequency * inductance);// The inductive reactance.
}
float input()
{ int keyinput;
cin>>keyinput;
return(keyinput);
}
/*Ran program. cin.get(); was added to see output.
Input value of the capacitor in farads => 400
Input value of the inductor in henrys => 300
Input value of the frequence in hertz => 200
The reactance of a 400 farad capacitor
at a frequency of 200 hertz is 1.98944e-006 ohms.
The reactance of a 300 henry inductor
at a frequency of 200 hertz is 376991 ohms.
a)Yes you can change inductive_resistance function to int and the program will run because the function does not
begin to run until a value has been input.
Input value of the capacitor in farads => 400
Input value of the inductor in henrys => 300
Input value of the frequence in hertz => 200
The reactance of a 400 farad capacitor
at a frequency of 200 hertz is 1.98944e-006 ohms.
The reactance of a 300 henry inductor
at a frequency of 200 hertz is 376991 ohms.
b)Input value of the capacitor in farads => 400
Input value of the inductor in henrys => 500
Input value of the frequence in hertz => 400
The reactance of a 400 farad capacitor
at a frequency of 400 hertz is 9.94719e-007 ohms.
The reactance of a 500 henry inductor
at a frequency of 400 hertz is 1.25664e+006 ohms.
c)Input value of the capacitor in farads => 40
Input value of the inductor in henrys => 30
Input value of the frequence in hertz => 20
The reactance of a 40 farad capacitor
at a frequency of 20 hertz is 0.000198944 ohms.
The reactance of a 30 henry inductor
at a frequency of 20 hertz is 3769 ohms.
d)Input value of the capacitor in farads => 400
Input value of the inductor in henrys => 300
Input value of the frequence in hertz => 400
The reactance of a 400 farad capacitor
at a frequency of 400 hertz is 9.94718e-007 ohms.
The reactance of a 300 henry inductor
at a frequency of 400 hertz is 753982 ohms.
e)Its a void function because you don't want the function to be called until there are variables available.
Input value of the capacitor in farads => 400
Input value of the inductor in henrys => 300
Input value of the frequence in hertz => 400
The reactance of a 400 farad capacitor
at a frequency of 400 hertz is 9.94718e-007 ohms.
The reactance of a 300 henry inductor
at a frequency of 400 hertz is 753982 ohms.
f)Input value of the capacitor in farads => 23
Input value of the inductor in henrys => 12
Input value of the frequence in hertz => 23
The reactance of a 23 farad capacitor
at a frequency of 23 hertz is 0.00030086 ohms.
The reactance of a 12 henry inductor
at a frequency of 23 hertz is 1734 ohms.
The type of the input variables are ints, because the program has a local variable expecting an integer.
*/