I need this in C please Using FUNCTIONAL DECOMPOSITION do th

I need this in C++ please.

Using FUNCTIONAL DECOMPOSITION, do this task.

A resistor is a circuit device designed to have a specific resistance value between its ends. Resistance values are expressed in ohm (?) or kilo-ohms (k?). Resistors are frequently marked with colored bands that encode their resistance values, as shown below.

The first three bands are digits, the fourth is a power of ten multiplier and the fifth is the tolerance.

In the resistor above, the first band is green (value 5), the second band is blue (value 6), the third band is black ( value 0) and fourth band – the multiplier is orange (value 3) and the fifth band is silver (value 10%).

Hence the value of this resistor is 560 x 103 with a 10% tolerance. That is 560,000 ohms of 560 kilo-ohms with 10% tolerance.

Using functional decomposition, write a C++ program that will prompt user for the all the color bands of a resistor and then calculate the value of the resistor.

A sample program run may be like this:

Enter color for band 1 : > green
Enter color for band 2 : > blue
Enter color for band 3 : > black
Enter color for Multiplier : > orange
Enter color for Tolerance : > silver

This resistor has 560000 ohms with 10 % tolerance.

The color codes can either be defined as a 2-dimensional array of char OR a 1-dimensional array of string.

Note: If you type upper case or mixture of upper cases and lower cases, your program should still work.

Solution

#include<iostream>
#include<string>
#include <algorithm>
#include <iomanip>

using namespace std;

const int SILVER = 10,GOLD =1;

int main()
{
   string registor[10]={\"BLACK\",\"BROWN\",\"RED\",\"ORANGE\",\"YELLOW\",\"GREEN\",\"BLUE\",\"VIOLET\",\"GRAY\",\"WHITE\"};
   int values[10] = { 0,1,2,3,4,5,6,7,8,9};
   string band[5], multiplier, tolerence;
   int Band[5]={0};
   int total = 0;

   cout<<\"Enter color for band 1 : >\";
   cin>>band[0];
   cout<<\"Enter color for band 2 : >\";
   cin>>band[1];
   cout<<\"Enter color for band 3 : >\";
   cin>>band[2];
   cout<<\"Enter color for Multiplier : >\";
   cin>>band[3];
   cout<<\"Enter color for Tolerance : >\";
   cin>>band[4];

   for( int i = 0; i < 5 ; i++)
   {
       transform(band[i].begin(), band[i].end(), band[i].begin(), toupper);
       cout<<\"band\"<<\"i+1\"<<\" = \"<<band[i]<<endl;
   }


   int k = 0;
   for( int i = 0 ; i < 5 ; i++ )
   {
               for( int j = 0; j < 10 ; j++ )
               {
      
                   if( band[i].compare(registor[j]) == 0 )
                   {
                       Band[k++] = values[j] ;
                       break;
                   }
                   if( band[i].compare(\"SILVER\") == 0)
                   {
                       band[4] = SILVER;
                   }
      
              
               }
   }

   int exp=2;
   for( int i = 0 ; i < 3 ; i++)
   {
       cout<<\"band = \"<<Band[i]<<\"exp \" << exp<<endl;
       total+=Band[i]*pow((long double)10,exp);
      
       exp-=1;
   }

   Band[3]+=100;
   std::cout << std::setprecision(1) <<endl;

   //Band[3]= Band[3] - Band[3]*SILVER/100;
   total*= Band[3] ;
  

   cout<<\"This resistor has \"<<total<<\" ohms with\"<<Band[4]<<\" % tolerance.\"<<endl;

}

I need this in C++ please. Using FUNCTIONAL DECOMPOSITION, do this task. A resistor is a circuit device designed to have a specific resistance value between its
I need this in C++ please. Using FUNCTIONAL DECOMPOSITION, do this task. A resistor is a circuit device designed to have a specific resistance value between its

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site