Jan 18, 2015 at 5:16pm Jan 18, 2015 at 5:16pm UTC
I have a lab that is do tonight and I am down to the last error and I am stuck, so any help would be awesome! I am using Visual Basic 2010 and the error is: 1>Lab 2.6.cpp(39): error C2059: syntax error : ';' and it exists in the Lab 2.cpp file. I will make it bold and underline the line where the error is occurring.
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;
}
Last edited on Jan 18, 2015 at 6:50pm Jan 18, 2015 at 6:50pm UTC
Jan 18, 2015 at 5:28pm Jan 18, 2015 at 5:28pm UTC
That line just does not make sense. Just delete it and the program will work. what is 20%. Did you mean just 20? and is tolerance an instance of Resistor?
Jan 18, 2015 at 6:42pm Jan 18, 2015 at 6:42pm UTC
Yes the tolerance should be an instance of the resistor class. From what I understand that line is supposed to set the resistor tolerance to 20%. I know that % does not mean percent in C++, but the main program (listed as Lab 2.6.cpp) was given to us by the professor.
However I deleted the line and can now run the program but I do not think it is running correctly. The program is supposed to allow the user to change the resistance and tolerance. I can list all the parameters of the program - if you would like.
I think it is something I am missing in the resistor.h or resistor.cpp file.
Last edited on Jan 18, 2015 at 6:53pm Jan 18, 2015 at 6:53pm UTC
Jan 19, 2015 at 3:29am Jan 19, 2015 at 3:29am UTC
Reading the ResistorClass code, it seems that tolerance is the tolerance expressed as a decimal. So 20% should be given as 0.20.
I don't understand the relation betweeen class Resistor and class ResistorClass. They seem to be nearly identical but your main program has no instances of class Resistor. So why set Resistor.tolerance at all?