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

My class creates Resistors. I have the following created pResistor[0] points to

ID: 1927590 • Letter: M

Question

My class creates Resistors. I have the following created

pResistor[0] points to value "Res1", 1000, .05
pResistor[1] points to value"Res2", 3000, .10
pResistor[2] points to value"Res3", 500, .2

This is what I need done. I need to sort the pointers above based on the Nominal Value (1000, 3000, 500)

4. Write a new, nonclass function called in function main() to sort the pointers to the Resistor objects in order from lowest nominal resistance value to highest, passing a pointer to the Resistor-object pointer as the only passed data argument.
5. Display the sorted Resistor objects according to the nominal resistance value, from lowest to highest.
6. Within the sorting function, use pointer arithmetic to access the individual Resistor objects.

Explanation / Answer

#include 018 #include 019 #include 020 021 using namespace std; 022 023 // 024 //CLASS DECLARATION SECTION 025 // 026 class ResistorClass { 027 protected: 028 double *m_dptrRes; 029 char *m_sptrResName; 030 public: 031 static int m_istResCounter; 032 void DisplayResistor(void); 033 void EnterResistance(void); 034 ResistorClass(); 035 ResistorClass(char Name [], double nominalResistance, double Tolerance); 036 ~ResistorClass(); 037 enum resistorValues {NOMINAL, TOLERANCE, MAX, MIN}; 038 }; 039 040 int ResistorClass::m_istResCounter = 0; //intialize static counter 041 042 043 class FancyResistorClass:public ResistorClass { 044 protected: 045 char *m_sptrResType; 046 public: 047 void DisplayResistor(void); 048 FancyResistorClass(char Name[],double nominalResistance,double Tolerance); 049 ~FancyResistorClass(); 050 }; 051 052 053 int main() { 054 //Create the first resistor using the default constructor 055 ResistorClass oResOne; 056 oResOne.DisplayResistor(); 057 //Create the second resistor using the parameterized constructor 058 ResistorClass oResTwo("RESISTOR2", 4700, .20); 059 oResTwo.DisplayResistor(); 060 //Create a fancy Resistor 061 cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote