Question

Please help me with this question! It is due by midnight! I'm doing this in Visual Studio 2019. But any others are fine as long as it can compile.

Description: For this homework we will use classes to model something in the real world. In this case a resistor. The coloredColor Digit Multiplier Tolerance Black x10° 0 Brown 1 10 #1% x10 Red +2% Orange 3 10 x10 Yellow 4 *10 Green 0.5% x10 6 Blue +

I also wanted to see the results if it is compiled and QT comments as well. Please respond immediately!

Description: For this homework we will use classes to model something in the real world. In this case a resistor. The colored bands on the top-most resistor shown in the photo below indicate a resistance of 6.2 k2 #5 percent. The resistor tolerance of5 percent indicates the acceptable variation in the resistance. A 6.2 k2 #5 percent resistor could have a resistance as small as 5.89 k2 or as large as 6.51 k2. We say that 6.2 k2 is the nominal value of the resistance and that the actual value of the resistance can be any value between 5.89 k2 and 6.51 k2 Maris dkikpho The colors on the top resistor are Blue, Red, Red, and Gold. Each of the colors have a meaning. Consider another resistor Tolerance First band Second band Multiplier The first band is the first significant digit of the resistance value The second band is the second significant digit of the resistance value The third band is the decimal multiplier The fourth band indicates the tolerance For example (using the values from the table below as a key), a resistor with red, violet, green, and gold bands (left to right) will have 2 as the first digit, 7 as the second digit, a multiplier of 105, and a tolerance of+5 percent, for a resistance of 2,700 k2, plus or minus 5 percent
Color Digit Multiplier Tolerance Black x10° 0 Brown 1 10 #1% x10 Red +2% Orange 3 10 x10 Yellow 4 *10 Green 0.5% x10 6 Blue +0.25% Violet x10 7 20.1% 20 Gray 40.05% White x10 x10 Gold 45% x10 Silver +10% None 20% Specifications 1. Create an Empty C++ project 2. Add a new file to the Project called - main.cpp. 3. You will add a class resistor which will be in namespace nwacc in files resistor.h and resistor.cpp. DO NOT forget mandatory comments 4. Write a program that represents a resistor as a class 5. Provide a single constructor that accepts values for the nominal resistance, multiplier, tolerance, and then determines the actual value randomly 6. The class should provide public methods to get the nominal resistance, tolerance, and the actual resistance 7. The class should be immutable 8. Lastly, provide a method that returns a description of the "color bands" for the resistance and tolerance string. For example - a. First Band - Red as a b. Second Band - Violet Multiplier Green C. d. Tolerance Gold 9. Write a main method for the program that demonstrates that the class works properly by displaying actual resistances and description (color bands) for ten different resistors. Place your resistors in a list or vector and iterate over the container displaying the values 10. You can use the rand function from cstdlib to generate the random tolerance. 11. The program will not require any user input 12. All output should be formatted as shown with the correct symbols, spacing, and number of decimal places
1 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Ouck Launch ICb+) ResitanceMain - Micresoft Visual Studio View Praiect Analre Winsiow deepthionganattu D File Feit Ruild Dehu--------------------------------------------------------

Program

main.cpp

#include <iostream>
#include<iomanip>
#include<vector>
#include<cstdlib>
#include "Resistance.h"
using namespace std;
int main()
{
   //Create a vector for resistance
   vector<Resistance> resistances;
   //Tolerance vector
   vector<double>tolerances;
   //Add 2 tolerances randomly for check
   for (int i = 0; i < 2; i++) {
       double r = (double)rand() / RAND_MAX;
       tolerances.push_back(.05 + (fmod(r, (20 - .05 + 1))));
   }
   //Create 2 resistances
   Resistance r1(4.8,2,tolerances.at(0));
   resistances.push_back(r1);
   Resistance r2(6.2,5,tolerances.at(1));
   resistances.push_back(r2);
   //Display details
   for (int i = 0; i < 2; i++) {
       double resistance = resistances.at(i).getactualResistance();
       cout << fixed << setprecision(2) <<resistance <<"KOhm"<< endl;
       resistances.at(i).colorBand(resistance);
       cout << endl;
   }
  
}

Resistance.h

#pragma once
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;
//Craete a class Resistance
class Resistance {
//Attributes
private:
   double nominalResistance;
   int multiplier;
   double tolerance;
//Member functions
public:
   //constructor
   Resistance(double, int, double);
   //getters
   double getNominalResistance()const;
   double getTolerance()const;
   double getactualResistance()const;
   //color band description
   void colorBand(double);
};

Resistance.cpp

#include "Resistance.h"
//Constructor implementation
Resistance::Resistance(double nominal, int mult, double tol){
   nominalResistance = nominal;
   multiplier = mult;
   tolerance = tol;
}
//getters implementation
double Resistance::getNominalResistance()const {
   return nominalResistance;
}
double Resistance::getTolerance()const {
   return tolerance;
}
double Resistance::getactualResistance()const {
   double toleranceVal = nominalResistance * (double(tolerance) / 100);
   double resistance1 = nominalResistance - toleranceVal;
   double resistance2 = nominalResistance + toleranceVal;
   double r = (double)rand() / RAND_MAX;
   return resistance1 + (fmod(r, (resistance2 - resistance1 + 1)));;
}
//color band description
void Resistance::colorBand(double actualResistance) {
   int temp = actualResistance * 1000;
   int firstBand = temp / 1000;
   int secondBand = (temp / 100) % 10;
   string colors[] = { "Black","Brown","Red","Orange","Yellow","Green","Blue","Violet","Gray","White","Gold/Silver/None" };
   cout << "First Band: "<<colors[firstBand]<< endl;
   cout << "First Band: " << colors[secondBand] << endl;
   cout << "Multiplier: " << colors[multiplier] << endl;
   if (tolerance == 1) {
       cout << "Tolerance: Brown" << endl;
   }
   else if (tolerance == 2) {
       cout << "tolerance: red" << endl;
   }
   else if (tolerance == 0.5) {
       cout << "First Band: Green" << endl;
   }
   else if(tolerance == .25) {
       cout << "First Band: Blue" << endl;
   }
   else if (tolerance == .1) {
       cout << "First Band: Violet" << endl;
   }
   else if (tolerance == .05) {
       cout << "First Band: Gray" << endl;
   }
   else if (tolerance == 5) {
       cout << "First Band: Gold" << endl;
   }
   else if (tolerance == 10) {
       cout << "First Band: Silver" << endl;
   }
   else if (tolerance == 20) {
       cout << "First Band: None" << endl;
   }
   else {
       cout << "First Band: black/Orange/Yellow/White" << endl;
   }

}

--------------------------------

output

4.99KOhm
First Band: Yellow
First Band: White
Multiplier: Red
First Band: black/Orange/Yellow/White

6.97KOhm
First Band: Blue
First Band: White
Multiplier: Green
First Band: black/Orange/Yellow/White

-----------------------------------------------------

Note

Here i test only 2 values due to time limit,Please add more test values.

Add a comment
Know the answer?
Add Answer to:
Please help me with this question! It is due by midnight! I'm doing this in Visual...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help. Part 3: Using the color coding for resistors, determine the resistance and the tolerance...

    Please help. Part 3: Using the color coding for resistors, determine the resistance and the tolerance for the following 3 resistors: exornn Rbolor coding: brown, black, yellow, gold Rgcolor coding: red, violet, orange, gold Rocolor coding: orange, orange, orange, gold The chage nowng thonuh a sece is every themes Find out the outest throsgh the sistance is diven e well se the colot code fur esch of the resistors 4-Band-Code 2%, 5%, 10% 560k Ω 5% 1ST BAND | 2ND...

  • of 1 m of string: Class Section Length of the string H029 L-1552 gm M (g)...

    of 1 m of string: Class Section Length of the string H029 L-1552 gm M (g) kg/m A (cm) Prelab Section Class Name Turn in the prelab at the beginning of class to get credit. Identify your resistances according to the figure below Black Brown Red Fourth Band 2nd Digt No of Zes None 120% Silver 110% Gold 15% t2% Ist Digit- Tolerance Orange Yellow Rod X axis. Green Bloe Violet Gray Whise 9 oints) ar alculate 1. What is...

  • Figure 1(a) shows a combination of series and parallel circuit while Table 1 lists the colour...

    Figure 1(a) shows a combination of series and parallel circuit while Table 1 lists the colour code of 4-band resistor. The voltage source, vs is indicated in Figure 1(b). (a) Find the nominal value of resistor Rand the range of its actual resistance. (2 marks) (b) Using the nominal value of RL, compute the effective voltage across Rt. (6 marks) (c) Using the nominal value of Ru, calculate the average power dissipated in RL. (2 marks) 350 22 ş 150...

  • Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 an...

    Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 and 3. It is important to answer the exercises correctly in each labl you should include the appropriate prefix for the unit in the Numerical Value We will not be Volt using the Volt-Ohm meter (VOM) for this lab, so skip the parts that ask for VOM measurements. The parts we You do need to complete Exercises1 Note that in...

  • Pease answer questions 4 and 5! Thank you so much! 4. Connect the 2nd resistor in...

    Pease answer questions 4 and 5! Thank you so much! 4. Connect the 2nd resistor in parallel with the 1st resistor and connect that combination to the battery.          Measure the following:               The current passing through the R1, I1 = ___0.0058____ A               The current passing through the R2, I2 = ___0.0031____ A               The current supplied by the battery, I = ___0.0092____ A              Calculate I1 + I2 = ____________ A                     Is the following statement true? I = I1 +...

  • Need #8 attached a cleared picture of the graph Nomina Measured Part 1: Loop Method- Calculations...

    Need #8 attached a cleared picture of the graph Nomina Measured Part 1: Loop Method- Calculations Ri 13. 3. Determine the nominal resistance and tolerance of each resistor by reading its color code. They should have the following approximate resistances: (5 pts) R1-10 Ω R2-12Ω 3 R 22 R4 = 18 Ω R-22 Ω 4. Measure the resistance of each resistor using an ohm- meter. (5 pts) 5. Measure e of the two batteries using a voltmeter They should be...

  • Hello, Can you answer the following question using the charts and picture I've provided? Thank You...

    Hello, Can you answer the following question using the charts and picture I've provided? Thank You so Much! Information Needed to Solve the Question (2) The two resistors, Ri and R2, shown at the top of Figure 3(a) will be used in Experımehl i. Using the colour code in Table 1, write the corresponding colour and the digit in the t below for each resistor. See the example in Figure 10. Record the values of Ri and R2 with their...

  • The following code must be written and run with no errors in java eclipse Description of...

    The following code must be written and run with no errors in java eclipse Description of the code to be written: A resistor is an electronic part colour-coded with three coloured bands to indicate its resistance value. This program returns the resistance of a Resistor object instantiated with three Strings, representing the three colour bands of a real resistor. Start by creating an abstract class 'AbstractResistor' that implements the Comparable interface. This class should have the following three private methods:...

  • Answer 4 & 5 please! thank you! R values = Resistor value, R1 = 990 Ohms...

    Answer 4 & 5 please! thank you! R values = Resistor value, R1 = 990 Ohms Resistor value, R2 = 2050 Ohms 4. Connect the 2nd resistor in parallel with the 1st resistor and connect that combination to the battery.          Measure the following:               The current passing through the R1, I1 = ___0.0058____ A               The current passing through the R2, I2 = ___0.0031____ A               The current supplied by the battery, I = ___0.0092____ A              Calculate I1 + I2 =...

  • 15 Electrical Circuits rou have hund that greater ' esistance in a creur results is lower...

    15 Electrical Circuits rou have hund that greater ' esistance in a creur results is lower ement A ate resistaace to is a naisance. 1 currest, Teo nuch euerent could easily the circuits in your caleulatee Band one. 1T example in ohms (2) the resistor 4-band hat yields 2 significant figures of precision, is shown belew, seme resisters utt 5 bands for 3 sig figs Put the first two digits sogether and Indicabes Resistor Acouracw then muhiply by Band 3...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT