Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [code]
- #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,'\n');
- 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.setResTolerance(tempValue/100.0);
- // 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();
- *****************************************************************************************************
- #define PI 3.141592654
- #include "Capacitor.h"
- #include <conio.h>
- #include "Filter.h"
- #include <iomanip>
- #include <iostream>
- #include "Resistor.h"
- #include <stdio.h>
- #include <windows.h>
- #include <fstream>
- using namespace std;
- Filter::Filter(void)
- {
- }
- Filter::~Filter(void)
- {
- }
- void Filter::getResistor()
- {
- double res;
- double tol;
- cout<<endl<<"Enter resistor's resistance: ";
- cin>>res;
- cout<<endl<<"Enter resistor tolerance : ";
- cin>>tol;
- resistor.setResistance(res);
- resistor.setResTolerance(tol);
- }
- void Filter::getCapacitor()
- {
- double cap;
- double tol;
- cout<<endl<<"Enter capacitor capacitance: ";
- cin>>cap;
- cout<<endl<<"Enter capacitor tolerance : ";
- cin>>tol;
- capacitor.setCapacitance(cap);
- capacitor.setCapTolerance(tol);
- }
- void Filter::getFilterType()
- {
- string type;
- cout<<endl<<"Enter Filter type(Low, High) : ";
- cin>>type;
- filterType=type;
- }
- void Filter::calculateFilter()
- {
- cutOffFrequency=1/(2*3.14*(resistor.getResistance()*capacitor.getCapacitance()));
- maxFrequency=1/(2*3.14*(resistor.getResistance()+resistor.getResTolerance())*(capacitor.getCapacitance()+capacitor.getCapTolerance()));
- minFrequency=1/(2*3.14*(resistor.getResistance()-resistor.getResTolerance())*(capacitor.getCapacitance()-capacitor.getCapTolerance()));
- }
- double Filter::getFilter()
- {
- return cutOffFrequency;
- }
- double Filter::getMaxFilter()
- {
- return maxFrequency;
- }
- double Filter::getMinFilter()
- {
- return minFrequency;
- }
- void Filter::writeToFile()
- {
- string filename;
- cout<<"Enter file name: ";
- cin>>filename;
- ofstream fout;
- fout.open(filename);
- fout<<"Resistor resistance: "<<resistor.getResistance();
- fout<<endl<<"Resistor tolerance: "<<resistor.getResTolerance();
- fout<<endl<<"Resistor Min resistance: "<<resistor.getMinResistance();
- fout<<endl<<"Resistor Max resistance: "<<resistor.getMaxResistance();
- fout<<endl<<"Capacitor capacitance: "<<capacitor.getCapacitance();
- fout<<endl<<"Capacitor tolerance: "<<capacitor.getCapTolerance();
- fout<<endl<<"Capacitor max capacitance: "<<capacitor.getMaxCapacitance();
- fout<<endl<<"Capacitor min capacitance: "<<capacitor.getMinCapacitance();
- fout<<endl<<"Cut off frequency: "<<cutOffFrequency;
- fout<<endl<<"Max frequency: "<<maxFrequency;
- fout<<endl<<"Min frequency: "<<minFrequency;
- fout<<endl<<"Filter Type: "<<filterType;
- fout.close();
- }
- void Filter::FilterRead(string filename)
- {
- ifstream fin;
- fin.open(filename);
- if(!fin)
- {
- cout<<"File do not exist.";
- return;
- }
- else
- {
- string line;
- while(fin)
- {
- getline(fin,line);
- cout<<line<<endl;
- }
- }
- fin.close();
- }
- // 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;
- }
- *******************************************************************************************************
- //Filter.h
- #pragma
- #include "Capacitor.h"
- #include "Resistor.h"
- class Filter
- {
- Resistor Resistor;
- Capacitor capacitor;
- private:
- double cutOffFrequency;
- double maxFrequency;
- double minFrequency;
- string filterType;
- public:
- Filter(void);
- ~Filter(void);
- void getResistor();
- void getCapacitor();
- void getFilterType();
- void calculateFilter();
- double getFilter();
- double getMinFilter();
- double getMaxFilter();
- double getFilterTol();
- double getCapacitance;
- double getCapTolerance;
- double getMaxCapacitance;
- double getMinCapacitance;
- double getResistance;
- double getResTolerance;
- double getMaxResistance;
- double getMinResistance;
- double setResistance;
- double setResTolerance;
- double setCapacitance;
- void writeToFile();
- void FilterRead(string);
- };
- ******************************************************************************************************
- #pragma
- //The Class Declaration
- class Resistor
- {
- private:
- double m_dResValue;
- double m_dTolerance;
- double m_dMinRResistance;
- double m_dMaxResistance;
- protected:
- double resValues[4];
- public:
- Resistor();
- Resistor(string Name, double resistorValue, double resistorTolerance);
- Resistor(const Resistor &resistorObject);
- string m_cResistorName;
- void DisplayResistor(void);
- void EnterResistance (void);
- // Returns minimum tolerance resistance
- double getMinResistance(void);
- // Set FiltRes nominal resistance
- void setResistance(double);
- void setResTolerance(double);
- Resistor(double nom = 1000.0, double tol = 0.10);
- ~Resistor();
- // Returns resistance value
- double getResistance(void);
- // Returns maximum tolerance resistance
- double getMaxResistance(void);
- // Returns resistor tolerance
- double getResTolerance(void);
- };
- *************************************************************************************************
- #pragma
- #include <conio.h>
- #include <iostream>
- #include <iomanip>
- #include "Resistor.h"
- #include <windows.h>
- using namespace std;
- Resistor::Resistor(double nom, double tol)
- {
- resValues[0] = nom;
- resValues[1] = tol;
- resValues[2] = nom * (1.0 + tol);
- resValues[3] = nom * (1.0 - tol);
- }
- Resistor::~Resistor()
- {
- }
- void Resistor::setResistance(double newResistance)
- {
- resValues[0] = newResistance;
- resValues[2] = resValues[0] * (1.0 - resValues[1]);
- resValues[3] = resValues[0] * (1.0 + resValues[1]);
- }
- void Resistor::setResTolerance(double newResTolerance)
- {
- resValues[1] = newResTolerance;
- resValues[2] = resValues[0] * (1.0 - resValues[1]);
- resValues[3] = resValues[0] * (1.0 + resValues[1]);
- }
- // Returns resistance value
- double Resistor::getResistance(void)
- {
- return resValues[0];
- }
- // Returns minimum tolerance resistance
- double Resistor::getMinResistance(void)
- {
- return resValues[3];
- }
- // Returns maximum tolerance resistance
- double Resistor::getMaxResistance(void)
- {
- return resValues[2];
- }
- // Returns resistor tolerance
- double Resistor::getResTolerance(void)
- {
- return resValues[1];
- }
- ***************************************************************************************************
- #pragma
- class Capacitor
- {
- public:
- // Returns capacitance value
- double getCapacitance(void);
- // Returns minimum tolerance capacitance
- double getMinCapacitance(void);
- // Returns max tolerance capacitance
- double getMaxCapacitance(void);
- // Returns capacitor tolerance
- double getCapTolerance(void);
- double getFilter;
- double getMinFilter();
- double getMaxFilter();
- double getFilterTol();
- void calculateFilter();
- int FilterRead(void);
- void setCapacitance(double);
- void setCapTolerance(double);
- Capacitor(double nom = 0.000001, double tol = 0.20);
- ~Capacitor();
- private:
- double capValues[4];
- };
- ***************************************************************************************************
- #include "Capacitor.h"
- #include <conio.h>
- #include <iostream>
- #include <iomanip>
- #include <windows.h>
- using namespace std;
- /**************************Construction/Destruction***********************************/
- Capacitor::Capacitor(double nom, double tol)
- {
- capValues[0] = nom;
- capValues[1] = tol;
- capValues[2] = nom * (1.0 + tol);
- capValues[3] = nom * (1.0 - tol);
- }
- Capacitor::~Capacitor()
- {
- }
- void Capacitor::setCapacitance(double newCapacitance)
- {
- capValues[0] = newCapacitance;
- capValues[2] = capValues[0] * (1.0 + capValues[1]);
- capValues[3] = capValues[0] * (1.0 - capValues[1]);
- }
- void Capacitor::setCapTolerance(double newCapTolerance)
- {
- capValues[1] = newCapTolerance;
- capValues[2] = capValues[0] * (1.0 + capValues[1]);
- capValues[3] = capValues[0] * (1.0 - capValues[1]);
- }
- // Returns capacitance value
- double Capacitor::getCapacitance(void)
- {
- return capValues[0];
- }
- // Returns minimum tolerance capacitance
- double Capacitor::getMinCapacitance(void)
- {
- return capValues[3];
- }
- // Returns max tolerance capacitance
- double Capacitor::getMaxCapacitance(void)
- {
- return capValues[2];
- }
- // Returns capacitor tolerance
- double Capacitor::getCapTolerance(void)
- {
- return capValues[1];
- }
- [/code]
Advertisement
Add Comment
Please, Sign In to add comment