COMP 220 ** NEED HELP WIRITING MAIN APP SO PROGRAM WILL WORK** iLAB STEPS STEP 1
ID: 3560155 • Letter: C
Question
COMP 220
** NEED HELP WIRITING MAIN APP SO PROGRAM WILL WORK**
iLAB STEPS
STEP 1: Create a Multifile Project for the Composition Lab
Back to Top
STEP 2: Filter-Class Definition
Back to Top
The Filter class should have, at a minimum, the following capabilities.
STEP 3: Test-Program Operation
Back to Top
_________________________________________________________________________________________
#pragma once
class PowerSupply
{
private:
double outputVoltage;
double powerOutput;
double maxCurrent;
public:
PowerSupply(void);
PowerSupply (double, double, double);
//getters
double getOutputVoltage(void);
double getPowerOutput(void);
double getMaxCurrent(void);
//setters
void setOuputVoltage(double);
void setPowerOutput(double);
void setMaxCurrent(double);
//behaviors
~PowerSupply(void);
};
______________________________________
#include "PowerSupply.h"
PowerSupply::PowerSupply(void)
{
outputVoltage = 0.0;
powerOutput = 0.0;
maxCurrent = 0.0;
}
PowerSupply::PowerSupply (double ov, double po, double mc)
{
setOuputVoltage(ov);
setPowerOutput(po);
setMaxCurrent(mc);
}
//getters
double PowerSupply::getOutputVoltage(void)
{
return outputVoltage;
}
double PowerSupply::getPowerOutput(void)
{
return powerOutput;
}
double PowerSupply::getMaxCurrent(void)
{
return maxCurrent;
}
//setters
void PowerSupply::setOuputVoltage(double ov)
{
outputVoltage = ov;
}
void PowerSupply::setPowerOutput(double po)
{
if(po < 0.0)
powerOutput = 0.0;
else
powerOutput = po;
}
void PowerSupply::setMaxCurrent(double mc)
{
if(mc < 0.0)
maxCurrent = 0.0;
else
maxCurrent = mc;
}
PowerSupply::~PowerSupply(void)
{
}
__________________________
#pragma once
#include
using namespace std;
class Resistor
{
private:
int resistance;
double tolerance;
public:
Resistor(void); //default constructor
Resistor(int r, double t); //fully parameterized constructor
//getters and setters
int getResistance(void);
double getTolerance(void);
void setResistance(int);
void setTolerance(double);
//behaviors
double findMinResistance(void);
double findMaxResistance(void);
void displayResistance(void);
//destructor
~Resistor();
};
____________________________
#include "Resistor.h"
Resistor::Resistor(void)
{
resistance = 1000;
tolerance = 0.1;
}
Resistor::~Resistor(void)
{
}
Resistor::Resistor(int r, double t) //fully parameterized constructor
{
setResistance(r);
setTolerance(t);
}
//getters and setters
int Resistor::getResistance(void)
{
return resistance;
}
double Resistor::getTolerance(void)
{
return tolerance;
}
void Resistor::setResistance(int r)
{
if ( r < 0 )
{
r = 0;
}
else if ( r > 1000000 )
{
r = 1000000;
}
resistance = r;
}
void Resistor::setTolerance(double tolerance)
{
do
{
if ( tolerance == .1 || tolerance == .05 || tolerance == .02 || tolerance == .01 )
this-> tolerance = tolerance;
else
{
cout << "Please enter values at 10%, 5%, 2%, and 1%.";
cin >> tolerance;
}
}while(tolerance != .1 &&
tolerance != .05 &&
tolerance != .02 &&
tolerance != .01 );
/*
while (tolerance != .1 && tolerance != .02 && tolerance != .05 && tolerance != .01)
{
cout << "You have entered a wrong input. Please enter another input. The input must be either .1, .02, .05, or .01." << endl;
cin >> tolerance;
}
this->tolerance = tolerance;
*/
}
//behaviors
double Resistor::findMinResistance(void)
{
/*double minResistance = resistance * (1.0 - tolerance );
return minResistance;*/
return (resistance * (1.0 - tolerance ));
}
double Resistor::findMaxResistance(void)
{ //1) create a variable of the return type
double z;
//2) do processing and set the variable we created in step 1
z = resistance * (1.0 + tolerance);
//3) return the variable created in step 1
return z;
}
void Resistor::displayResistance(void)
{
cout << "Details for resistor ";
cout << "Resistance: "<< getResistance();
cout << "Tolerance: "<< getTolerance();
cout << "Maximum: "<< findMaxResistance();
cout << "Minimum: " << findMinResistance();
}
____________________________________________
#pragma once
#include"PowerSupply.h"
#include"Resistor.h"
class Circuit
{
private:
Resistor R1;
Resistor R2;
PowerSupply ps;
public:
Circuit(void);
Circuit(Resistor, Resistor, PowerSupply);
Circuit(int R1Res, double R1Tol, int R2Res, double R2Tol,
double psOV, double psPO, double psMC);
//behaviors
//Calculates the equivalent resistance of R1 and R2 in series.
//Returns a new resistor, with equivalent resistance value,
//and a tolerance of the higher of the two resistors
Resistor EquivSeriesResistance();
//Calculates the current for the power supply with the two resistors in series
double CurrentInSeriesCkt();
//Calculates the total power dissipated by the series circuit
double PowerDissipated();
~Circuit(void);
};
___________________________
#include "Circuit.h"
Circuit::Circuit(void) : R1(), R2(), ps()
{
}
Circuit::Circuit(Resistor r1, Resistor r2, PowerSupply p)
{
R1 = r1;
R2 = r2;
ps = p;
}
Circuit::Circuit(int R1Res, double R1Tol, int R2Res, double R2Tol,
double psOV, double psPO, double psMC)
: R1(R1Res, R1Tol), R2(R2Res, R2Tol), ps(psOV, psPO, psMC)
{
}
//behaviors
//Calculates the equivalent resistance of R1 and R2 in series.
//Returns a new resistor, with equivalent resistance value,
//and a tolerance of the higher of the two resistors
Resistor Circuit::EquivSeriesResistance()
{
//1) create a variable/object of the return type
Resistor R3;
//2) finish processing and set the result of the processing to the
//variable created in step 1
int nr = R1.getResistance() + R2.getResistance();
R3.setResistance(nr); //set resistance of equivalent resistor object
//R3.setResistance(R1.getResistance() + R2.getResistance());
int nt = 0.0;
if(R2.getTolerance() >= R1.getTolerance())
nt = R2.getTolerance();
else
nt = R1.getTolerance();
R3.setTolerance(nt); //set tolerance of equivalent resistor object
//3) return variable/object created in step 1
return R3;
}
//Calculates the current for the power supply with the two resistors in series
double Circuit::CurrentInSeriesCkt()
{ // I = V / R;
//1) create a variable/object of the return type
double current;
//2) process and setting the variable from step 1 to result of the process
Resistor r3 = EquivSeriesResistance();
current = ps.getOutputVoltage() / r3.getResistance();
//current = ps.getOutputVoltage() / EquivSeriesResistance().getResistance();
//3) return variable
return current;
}
//Calculates the total power dissipated by the series circuit
double Circuit::PowerDissipated()
{
//P = I * V;
// Variable to return below
double power;
// Finding current to complete equation to find power disspated
power = CurrentInSeriesCkt() * ps.getOutputVoltage();
return power;
}
void Circuit::PowerDissipated(void)
{
cout << "Details for circuit ";
cout << "Resistance: "<< getResistance();
cout << "Tolerance: "<< getTolerance();
cout << "Maximum: "<< findMaxResistance();
cout << "Minimum: " << findMinResistance();
cout << "Current: " << getCurrent();
cout << "Power Dissipated: " << getPowerDissipated();
}
Circuit::~Circuit(void)
{
}
___________________________________
MAIN APP
#include "Resistor.h"
#include "Circuit.h"
#include "powerSupply.h"
#include
#include
#include
int main()
{
int resistance;
double tolerance;
int getResistor();
double getTolerance();
void setResistance();
void setTolerance();
double outputVoltage();
double powerOutput();
double maxCurrent();
system("pause");
return 0;
}
Explanation / Answer
You are required to use this int main() DRIVER / TEST FILE.
#include "Capacitor.h"
#include <conio.h>
#include "Filter.h"
#include <iostream>
#include "Resistor.h"
#include <windows.h>
#include <iomanip>
using namespace std;
void clear_screen(void);
void main(void)
{
// Local variable for text data entry
char tempName[16];
// Local variable for component value data entry
double tempValue;
cout << "Instantiate one object of class Filter" << endl << endl;
cout << "Enter a name for the new filter object: ";
cin.getline(tempName,15,' ');
Filter filt1;
// Display filter values
cout << setiosflags(ios::fixed)
<< setiosflags(ios::right)
<< setiosflags(ios::showpoint)
<< setprecision(3);
cout << endl << endl;
cout << "Nominal Filter Frequency = " << setw(10) << filt1.getFilter() << " Hertz" << endl;
cout << "Minimum Filter Frequency = " << setw(10) << filt1.getMaxFilter() << " Hertz" << endl;
cout << "Maximum Filter Frequency = " << setw(10) << filt1.getMinFilter() << " Hertz" << endl;
cout << "Filter Bandwidth Frequency = " << setw(10) << filt1.getFilterTol() << " Hertz" << endl;
// Display resistor values
cout << setiosflags(ios::fixed)
<< setiosflags(ios::right)
<< setiosflags(ios::showpoint)
<< setprecision(3);
cout << endl << endl;
cout << "Nominal Resistance Value = " << setw(10) << filt1.getResistance() << " ohms" << endl;
cout << "Resistor Tolerance Value = " << setw(10) << filt1.getResTolerance()*100 << " Percent" << endl;
cout << "Maximum Resistance Value = " << setw(10) << filt1.getMaxResistance() << " ohms" << endl;
cout << "Minimum Resistance Value = " << setw(10) << filt1.getMinResistance() << " ohms" << endl;
cout << endl << endl;
// Display capacitor values
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::left)
<< setprecision(3);
cout << "Nominal Capacitance Value = " << setw(10) << filt1.getCapacitance() *1000000<< " micro Farads" << endl;
cout << "Capacitor Tolerance Value = " << setw(10) << filt1.getCapTolerance()*100 << " Percent" << endl;
cout << "Maximum Capacitance Value = " << setw(10) << filt1.getMaxCapacitance() * 1000000 << " micro Farads" << endl;
cout << "Minimum Capacitance Value = " << setw(10) << filt1.getMinCapacitance() * 1000000<< " micro Farads" << endl;
cout << endl << endl;
//filt1.FilterSave();
cout << "Enter new nominal resistance value for filter: ";
cin >> tempValue;
filt1.setResistance(tempValue);
cout << "Enter new resistance tolerance value for filter: ";
cin >> tempValue;
filt1.setResTolerance(tempValue/100.0);
cout << "Enter new nominal micro Farad capacitance value for filter: ";
cin >> tempValue;
filt1.setCapacitance(tempValue/1000000.0);
cout << "Enter new capacitance tolerance value for filter: ";
cin >> tempValue;
filt1.setCapTolerance(tempValue/100.0); /// This line of code was fixed
// Calculate filter values based on new resistance and capacitance values
filt1.calculateFilter();
// Display filter values
cout << setiosflags(ios::fixed)
<< setiosflags(ios::right)
<< setiosflags(ios::showpoint)
<< setprecision(3);
cout << endl << endl;
cout << "Nominal Filter Frequency = " << setw(10) << filt1.getFilter() << " Hertz" << endl;
cout << "Minimum Filter Frequency = " << setw(10) << filt1.getMaxFilter() << " Hertz" << endl;
cout << "Maximum Filter Frequency = " << setw(10) << filt1.getMinFilter() << " Hertz" << endl;
cout << "Filter Bandwidth Frequency = " << setw(10) << filt1.getFilterTol() << " Hertz" << endl;
// Display resistor values
cout << setiosflags(ios::fixed)
<< resetiosflags(ios::left)
<< setiosflags(ios::right)
<< setiosflags(ios::showpoint)
<< setprecision(3);
cout << endl << endl;
cout << "Nominal Resistance Value = " << setw(10) << filt1.getResistance() << " ohms" << endl;
cout << "Resistor Tolerance Value = " << setw(10) << filt1.getResTolerance()*100 << " Percent" << endl;
cout << "Maximum Resistance Value = " << setw(10) << filt1.getMaxResistance() << " ohms" << endl;
cout << "Minimum Resistance Value = " << setw(10) << filt1.getMinResistance() << " ohms" << endl;
cout << endl << endl;
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::left)
<< setprecision(3);
cout << "Nominal Capacitance Value = " << setw(10) << filt1.getCapacitance() *1000000<< " micro Farads" << endl;
cout << "Capacitor Tolerance Value = " << setw(10) << filt1.getCapTolerance()*100 << " Percent" << endl;
cout << "Maximum Capacitance Value = " << setw(10) << filt1.getMaxCapacitance() * 1000000 << " micro Farads" << endl;
cout << "Minimum Capacitance Value = " << setw(10) << filt1.getMinCapacitance() * 1000000<< " micro Farads" << endl;
cout << endl << endl;
filt1.FilterRead();
//filt1.calculateFilter();
// Display filter values
cout << setiosflags(ios::fixed)
<< setiosflags(ios::right)
<< setiosflags(ios::showpoint)
<< setprecision(3);
cout << endl << endl;
cout << "Nominal Filter Frequency = " << setw(10) << filt1.getFilter() << " Hertz" << endl;
cout << "Minimum Filter Frequency = " << setw(10) << filt1.getMaxFilter() << " Hertz" << endl;
cout << "Maximum Filter Frequency = " << setw(10) << filt1.getMinFilter() << " Hertz" << endl;
cout << "Filter Bandwidth Frequency = " << setw(10) << filt1.getFilterTol() << " Hertz" << endl;
// Display resistor values
cout << setiosflags(ios::fixed)
<< resetiosflags(ios::left)
<< setiosflags(ios::right)
<< setiosflags(ios::showpoint)
<< setprecision(3);
cout << endl << endl;
cout << "Nominal Resistance Value = " << setw(10) << filt1.getResistance() << " ohms" << endl;
cout << "Resistor Tolerance Value = " << setw(10) << filt1.getResTolerance()*100 << " Percent" << endl;
cout << "Maximum Resistance Value = " << setw(10) << filt1.getMaxResistance() << " ohms" << endl;
cout << "Minimum Resistance Value = " << setw(10) << filt1.getMinResistance() << " ohms" << endl;
cout << endl << endl;
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::left)
<< setprecision(3);
cout << "Nominal Capacitance Value = " << setw(10) << filt1.getCapacitance() *1000000<< " micro Farads" << endl;
cout << "Capacitor Tolerance Value = " << setw(10) << filt1.getCapTolerance()*100 << " Percent" << endl;
cout << "Maximum Capacitance Value = " << setw(10) << filt1.getMaxCapacitance() * 1000000 << " micro Farads" << endl;
cout << "Minimum Capacitance Value = " << setw(10) << filt1.getMinCapacitance() * 1000000<< " micro Farads" << endl;
cout << endl << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.