1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
// file Resistor.h
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Resistor
{
private:
string name;
double value;
double tolerance;
double minValue;
double maxValue;
public:
void DisplayResistor();
void GetResistance();
};
// file Resistor.cpp
#include "stdafx.h"
#include "Resistor.h"
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
void Resistor::DisplayResistor()
{
};
void Resistor::GetResistance()
{
};
// Lab 2.6.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include "Resistor.h"
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class ResistorClass
{
private:
double m_dResValue;
double m_dTolerance;
double m_dMinResistance;
double m_dMaxResistance;
public:
string m_cResistorName;
void DisplayResistor( void );
void EnterResistance (void );
void AddSeries ( ResistorClass Resistor1, ResistorClass Resistor2 );
ResistorClass( );
ResistorClass( string Name, double nominalResistance, double Tolerance );
ResistorClass( const ResistorClass &ResistorObject );
~ResistorClass( );
};
int main( void )
{
ResistorClass oResOne;
Resistor tolerance = 20%; //error occurs here!
ResistorClass oResTwo("Resistor 2",4700,20);
ResistorClass oResThree(oResTwo);
oResOne.DisplayResistor();
oResTwo.DisplayResistor();
oResThree.DisplayResistor();
system("pause");
return 0;
}
void ResistorClass:: DisplayResistor ( void )
{
cout << fixed << setprecision (2);
cout<<"Values for "<<m_cResistorName<<" are: "<<endl;
cout<<"Resistor Nominal Value = "<<m_dResValue<<endl;
cout<<"ohmsResistorTolerance = "<<m_dTolerance*100<<" %"<<endl;
cout<<"Mininimum Resistance = "<<m_dMinResistance<<" ohms"<<endl;
cout<<"Maximum Resistance = "<<m_dMaxResistance<<" ohms"<<endl;
cout<<endl;
}
void ResistorClass::EnterResistance (void)
{
m_dResValue = -1;
while (m_dResValue < 1)
{
cout << "Enter Resistor Value: " <<endl;
cin >> m_dResValue;
if (m_dResValue < 1 || m_dResValue > 10000000)
{
cout << "Input Error Resistor Value must be > 1" << endl;
cout << "Please Enter a value that is > 1: " << endl;
cin >> m_dResValue;
}
else break;
}
m_dTolerance = -1;
while (m_dTolerance < 1)
{
cout << "Enter Resistor Tolerance: " << endl;
cin >> m_dTolerance;
if (m_dTolerance < 1 || m_dTolerance > 10000000)
{
cout << "Input Error Resistor Tolerance Value must be > 1: " << endl;
cout << "Please Enter a value that is > 1: " << endl;
cin >> m_dTolerance;
}
else break;
}
m_dTolerance = m_dTolerance/100;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout<<endl;
}
void ResistorClass:: AddSeries ( ResistorClass Resistor1, ResistorClass Resistor2)
{
if( Resistor1.m_dTolerance > Resistor2.m_dTolerance )
m_dTolerance = Resistor1.m_dTolerance;
else
m_dTolerance = Resistor2.m_dTolerance;
m_dResValue = Resistor1.m_dResValue + Resistor2.m_dResValue;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout<<endl;
}
ResistorClass::ResistorClass( )
{
cout << "Enter Resistor Name <default>: " ;
getline(cin, m_cResistorName, '\n');
m_dResValue = 1000.0;
m_dTolerance = 0.10;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
cout <<endl<< "Default Constructor Called:" <<endl;
}
ResistorClass::ResistorClass( string Name, double nominalResistance, double Tolerance )
{
cout <<endl<<"Parameterized Constructor Called:" <<endl;
m_dResValue = nominalResistance;
m_dTolerance = double(Tolerance/100);
m_cResistorName = Name;
m_dMinResistance = m_dResValue - (m_dResValue * m_dTolerance);
m_dMaxResistance = m_dResValue + (m_dResValue * m_dTolerance);
}
ResistorClass::ResistorClass(const ResistorClass &ResistorObject)
{
cout<<endl <<"Enter Resister Name <copy>: ";
getline(cin, m_cResistorName, '\n');
m_dResValue=ResistorObject.m_dResValue;
m_dTolerance=ResistorObject.m_dTolerance;
m_dMaxResistance=ResistorObject.m_dMaxResistance;
m_dMinResistance=ResistorObject.m_dMinResistance;
cout <<endl<<"Copy Constructor Called:"<<endl;
}
ResistorClass:: ~ResistorClass( )
{
cout << "Destructor Called "<<endl;
}
|