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

Objective: Create a C++ console application that will model the characteristics

ID: 3557286 • Letter: O

Question

Objective: Create a C++ console application that will model the characteristics of a resistor. Create a multifile project. Create and add to the project an h file containing the resistor-class definition. Create and add to the project a cpp file containing the implementation of the class-member functions. Create and add to the project a ccp file containing the main() function, which will instantiate a resistor object and test its member functions. STEP 2: Required Class Members Back to Top The resistor class will, at minimum, have members that do the following. store the nominal resistance value of a resistor store the tolerance of a resistor initialize any and all nominal-resistance values to correct, EIA, nonzero values that are greater than 0 and less than 1,000,000 ohms initialize any and all resistance-tolerance values to correct, E12, E24, E48, or E96 resistance-tolerance values allow the nominal-resistance and tolerance values of a resistor object to be changed by the user All member functions should have a test message stating the name of the function. All the test messages should be displayed or not displayed, depending on the value of a Boolean variable declared in main(). If the Boolean value = true, display the message. If the Boolean value = false, do not display the message. STEP 3: Program Operations Back to Top Function main() should instatiate two objects of class resistor. Function main() should display the current values of all resistor objects. Function main() should also calculate and display the minimum and maximum in-tolerance resistance values of each resistor object from the resistor data members. Function main() should allow the user to change the values of the nominal resistance and the resistor tolerance of both resistor objects, and it should also correctly handle out of numeric-range input. Main() is also responsible for making sure that the user can successfully enter only correct, EIA resistance and tolerance values. The user should be given the following data-entry choices: accept current EIA values for resistance and tolerance; The function main() should display the new, modified values of the resistor object, including the new min and max in-tolerance resistance values. The function main() should be executed twice: once with the test messages displayed and once without. STEP 4: Lab Questions Back to Top You are not required to copy the question text into your document, but all answers should be listed with the question number they answer. List the complete reference-source information for where you found the EIA standard resistor value and tolerance information. How was this reference discovered and where? The constructor requires the initialization values for the nominal resistance and the tolerance when an object is instantiated to be a correct E-series resistance and tolerance combination. Describe how this was accomplished in your program design and implementation. In the lab, you were required to provide mutator functions to change the nominal-resistance and tolerance values of a resistor object. Describe how this was accomplished so that the user could not enter an invalid nominal-resistance and E-series tolerance combination. Describe how this process was different and/or similar to how you implemented this validation in the class constructor.

Summary: Write a statement summarizing your predicted and actual output. Identify and explain any differences.

Conclusions: Write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.

Each lab exercise should have a separate section in the lab-report document.

Your lab grade will be based upon

Explanation / Answer


#include <iostream>
#include <iomanip>
using namespace std;


int main()
{
   char type;                                                                                  
   //declare a character type variable
   double total_resistance=0;                                                                  
   //initialize double total_resistance=0
   double resistor_value=0;                                                                  
   //initialize double resistor_value=0
   int number_of_resistors_connected=0;                                                      
   //declare number_of_resistors_connected=0
  
  


   double *r; //A pointer to hold the address of your dynamically-allocated "array"
while (true)
   {
cout << "Please input 's' for series OR 'p' for resistors parallel"
<< endl;
cin >> type;
cout << "Please enter the number of resistors connected" << endl;
cin >> number_of_resistors_connected;
if (!cin || (number_of_resistors_connected <= 0)) {
cout << "Invalid input. Must be a positive integer." << endl;

}
r = new double[number_of_resistors_connected];// Storage to hold the resistors' values
if (type == 's') {
total_resistance = 0.0;
for (int i = 0; i < number_of_resistors_connected; i++) {
cout << "Input value of series resistor number " << i + 1 << endl;
cin >> r[i];
if (!cin) {
cout << "Invalid input." << endl;
  
}
total_resistance += r[i];
}
}
       if (type == 'p') {
total_resistance = 0.0;
for (int i = 0; i < number_of_resistors_connected; i++) {
cout << "Input value of parallel resistor number " << i + 1 << endl;
cin >> r[i];
if (!cin) {
cout << "Invalid input." << endl;
  
}
total_resistance += r[i];
}
}
   }
   {
   int array [] = {1, 2, 3, 4, 5, 6};
   int length = sizeof(array) / sizeof(int);

   for(int i = 0; i < length; i++) {
   cout << "Resistor: " << length<< endl;
   }

   if (total_resistance<1000)                                                                   //if total_resistance<1000
   {
       double x=0;                                                                               //declare x=0
       x=total_resistance;                                                                      
       //declare c = total resistance
       cout<<"The total resistance is less than 1000 and its value is "<<x<<" Ohm"<<endl;       //prompt message on screen
   }
   else                                                                                       //false statement
   {
       total_resistance=total_resistance/1000;                                                  
       //total_resistance=total_resistance/1000
       cout<<fixed<<showpoint<<setprecision(3);
       cout<<"The total resistance is greater than 1000 and its value is "<<total_resistance<<" kOhm"<<endl;
       //prompt message on screen
   }


   delete [] r;
   return 0;                                                                                  
   //indicate program ended successfully


}
}