Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

STEP 1: Create a Multifile Project for the Composition Lab Back to Top Add three

ID: 3769335 • Letter: S

Question

STEP 1: Create a Multifile Project for the Composition Lab

Back to Top

Add three classes to the project: a Filter class, a Capacitor class, and a Resistor class.

You may use the Resistor class files from the Week 2 lab for this lab.

The Capacitor class should be modeled after the Resistor class for class members and operation.

STEP 2: Filter-Class Definition

Back to Top

The Filter class should have, at a minimum, the following capabilities.

a resistor-object data member

a capacitor-object data member

a cutoff frequency (in Hertz) of the RC filter

maximum and minimum cutoff frequencies, based on the maximum and minimum in-tolerance values of the capacitor and the resistor object

a filter type, either low pass or high pass

allow the user to enter new values for the filter, including

6.1. resistor tolerance and nominal resistance;
6.2. capacitor tolerance and nominal capacitance; and
6.3. filter type

provides the ability to write all capacitor, resistor, and filter data members to a formatted text file and allows the user to name the file

provides the ability to read all capacitor, resistor, and filter data members from a formatted text file and allows the user to enter the file name and correctly handles a file-not-found error

STEP 3: Test-Program Operation

Back to Top

All data-input and data-display operations (cin and cout) should be done in the function main() test program.

The test program should instantiate at least one object of the class Filter.

The user should enter values for all the data members of the Filter, Resistor, and Capacitor classes.

The Filter class should then calculate and display the correct maximum and minimum cutoff frequencies.

The test program should then display all Filter, Resistor, and Capacitor data members.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

class Capacitor
{
public:
string getName( void );
string getTolerance(void);
string getCapacitance(void);
Capacitor(string name,double tolerance,string capacitance); // This is the constructor

private:
string name;
double tolerance;
double capacitance;
};

// setter methods including constructor
Capacitor::Capacitor(string name,double tolerance,string capacitance)
{
this.name = name;
this.tolerance = tolerance;
this.capacitance = capacitance;
}


string Capacitor::getName( void )
{
return name;
}
double Capacitor::getTolerance( void )
{
return tolerance;
}
double Capacitor::getCapacitance( void )
{
return capacitance;
}

//class resistance
class Resistor
{
public:
string getName( void );
string getTolerance(void);
string getResistance(void);
Resistor(string name,double tolerance,string resistance); // This is the constructor

private:
string name;
double tolerance;
double resistance;
};

// setter methods including constructor
Resistor::Resistor(string name,double tolerance,string resistance)
{
this.name = name;
this.tolerance = tolerance;
this.resistance = resistance;
}


string Resistor::getName( void )
{
return name;
}
double Resistor::getTolerance( void )
{
return tolerance;
}
double Resistor::getResistance( void )
{
return resistance;
}

class Filter
{
public:
Filter(Resistor res,Capacitor cap,double cutOffResistance,double minimumCutoff,double maximumCutOff); // This is the constructor

private:
Resistor res;
Capacitor cap;
double cutOffResistance;
double minimumCutoff;
double maximumCutOff;
};

// setter methods including constructor
Filter::Filter(Resistor res,Capacitor cap,double cutOffResistance,double minimumCutoff,double maximumCutOff)
{
this.res = res;
this.cap= cap;
this.cutOffResistance = cutOffResistance;
this.minimumCutoff = minimumCutoff;
this.maximumCutOff = maximumCutOff;
}

// Main function for the program
int main( )
{
//creating Capacitor object
string capacitorName;
double capacitorTolerance,capacitorCapacitance;
cout<<"Enter capacitor name: ";
cin>>capacitorName;
cout<<"Enter capacitorTolerance: ";
cin>>capacitorTolerance;
cout<<"Enter capacitorCapacitance: ";
cin>>capacitorCapacitance;
Capacitor cap = new Capacitor(capacitorName,capacitorTolerance,capacitorCapacitance);

//creating Resistor object
string resistorName;
double resistorTolerance,resistorResistance;
cout<<"Enter resistance name: ";
cin>>resistorName;
cout<<"Enter resistance Tolerance: ";
cin>>resistorTolerance;
cout<<"Enter resistance resistance: ";
cin>>resistorResistance;
Resistor res = new Resistor(resistorName,resistorTolerance,resistorResistance);

//creating filter object
double cutOffResistance,minimumCutoff,maximumCutOff;
cout<<"Enter cut off resiatance: ";
cin>>cutOffResistance
cout<<"Enter minimum Cutoff frequency: ";
cin>>minimumCutoff;
cout<<"Enter maximum CutOff frequency: ";
cin>>maximumCutOff;
Filter(cap,res,cutOffResistance,minimumCutoff,maximumCutOff);

cout<<" Enter file name to write object details: ";
string filename;
cin>>filename;
ofstream out_data(filename);
out_data << "Capacitor: "<<capacitorName <<" "<< capacitorTolerance<<" "<<capacitorCapacitance;
out_data << "Resistor: "<<resistorName <<" " << resistorTolerance << " " <<resistorResistance;
out_data << "Filter: "<<cutOffResistance << " "<< minimumCutoff << " " <<maximumCutOff;

return 0;
}