Note: see lines 26-28 in ResistorMain.cpp file this is pertaining to my question
Note: driver file ResistorMain.cpp was given to me as well as some of the functions in Resisitor.cpp.
I keep running around this and cannot seem to get this one part to compile correctly.
This code requires a class header file and two .cpp files.

the errors I receive when floating my cursor on the value is: Error no instance of constructor "CResistor::CResistor" matches the argument list.

The complied Error I get for all three(yes There are three: line 26 4700.0 line 27 330.0 line 28 10000.0 ) values where the error is states \resistormain.cpp(26): error C2661: 'CResistor::CResistor' : no overloaded function takes 4 arguments.

My question is how can I resolve this error and what do I need to add to the header file or the secondary cpp file to accomplish this?

A point in the right Direction or an addition to my files given is much appreciated.
I am so close I just need help on this one part!

// file name Resistor.h
class CResistor
{
public:
	
	double getNominal(double);
	double getTolerance(double);
	char getResName(char);
	double setTolerance(double, double);
	double setNominal(double , double);
	double getRes1();
	void DisplayResistance(void);
	void EnterResistance(void);
	 CResistor (CResistor Res1, CResistor Res2, CResistor Res3);
	CResistor();
	CResistor(double Name, double Nominal , double Tolerance);
	CResistor(const CResistor &resObj);

	~CResistor();
	
	
private:
	string name;
	double nom;
	double tol;
	double min;
	double max;
	
};
//Filename:  ResistorMain.cpp
//Description: Contains CResistor class test function
//Class:  COMP 220
//Student Name:    Antonio Moreno


#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <math.h>
#include <string>
using namespace std;
#include "Resistor.h"



void DisplayResistance(CResistor &, bool );
void EnterResistance(CResistor &, bool);

void main(void)
{

 //Control variable to display function names when called
 bool fnDisp = false;

 CResistor Res1(4700.0, 0.10, "Res1", fnDisp); //focus is in these parts
 CResistor Res2(330.0, 0.10, "Res2", fnDisp);
 CResistor Res3(10000.0,0.10, "Res3", fnDisp);

 DisplayResistance(Res1, fnDisp);
 DisplayResistance(Res2, fnDisp);
 DisplayResistance(Res3, fnDisp);
  
 EnterResistance(Res1, fnDisp);
 DisplayResistance(Res1, fnDisp);

 system("pause");

 cin.ignore(2);

 
}
//file Resistor.cpp
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "Resistor.h"
//EIA Standard array element sizes per tolerance class
const int E12 = 12;
const int E24 = 24;
const int E48 = 48;
const int E96 = 96;

//EIA Standard Resistor Values
//E12   10% tolerance
//E24     5% tolerance
//E48     2% tolerance
//E96     1% tolerance

//10% standard values
const int nominalE12Values[E12] =
 { 100, 120, 150, 180, 220, 270,
  330, 390, 470, 560, 680, 820};

//5% standard values
const int nominalE24Values[E24] =
 { 100, 110, 120, 130, 150, 160, 180, 200, 220, 240,
  270, 300, 330, 360, 390, 430, 470, 510, 560, 620,
  680, 750, 820, 910};

//2% standard values
const int nominalE48Values[E48] =
 { 100, 105, 110, 115, 121, 127, 133, 140, 147, 154,
  162, 169, 178, 187, 196, 205, 215, 226, 237, 249,
  261, 274, 287, 301, 316, 332, 348, 365, 383, 402,
  422, 442, 464, 487, 511, 536, 562, 590, 619, 649,
  681, 715, 750, 787, 825, 866, 909, 953};

//1% standard values
const int nominalE96Values[E96] =
 { 100, 102, 105, 107, 110, 113, 115, 118, 121, 124,
  127, 130, 133, 137, 140, 143, 147, 150, 154, 158,
  162, 165, 169, 174, 178, 182, 187, 191, 196, 200,
  205, 210, 215, 221, 226, 232, 237, 243, 249, 255,
  261, 267, 274, 280, 287, 294, 301, 309, 316, 324,
  332, 340, 348, 357, 365, 374, 383, 392, 402, 412,
  422, 432, 442, 453, 464, 475, 487, 499, 511, 523,
  536, 549, 562, 576, 590, 604, 619, 634, 649, 665,
  681, 698, 715, 732, 750, 768, 787, 806, 825, 845,
  866, 887, 909, 931, 953, 976};
// Function displays all data member values of a CResistor object
void  DisplayResistance(CResistor & resObj, bool fnDisplay)
{
 //Local variables to hold CResistor data copies
 double nom, tol, min, max;
 nom = resObj.getNominal(fnDisplay);
 tol = resObj.getTolerance(fnDisplay);
 min = nom * (1.0 - tol);
 max = nom * (1.0 + tol);
 cout << endl << "Resistor object name is " << resObj.getResName(fnDisplay) << endl;
 cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint)
  << setprecision(3);
 cout << endl << "Nominal resistance value = " << setw(15) << nom << " ohms ";
 cout << endl << "Tolerance =                " << setw(15) << tol * 100 << " %";
 cout << endl << "Minimum Resistance =       " << setw(15) << min << " ohms";
 cout << endl << "Maximum Resistance =       " << setw(15) << max << " ohms";
 cout << endl << endl;
}
// Function allows user to enter new values for CResistor data members
void EnterResistance(CResistor & resObj, bool fnDisplay)
{
 //Local variables to hold CResistor data copies
 double nom, tol;
 string name;
 
 //Local variable for user data entry
 int nomEdit = 0;
 int tolEdit = 0;
 int powerOfTen = 0;

 //Valid EIA entry value check boolean
 bool validEIA = false;

 //Local loop counter
 int i = 0;

 nom = resObj.getNominal(fnDisplay);
 tol = resObj.getTolerance(fnDisplay);
 name = resObj.getResName(fnDisplay);
 cout << endl << endl;
 cout << "Resistor being edited:  " << name << endl << endl;

 do
 {
  cout << "Current resistance tolerance = " << tol * 100 << " %" << endl;
  cout << "Valid tolerances are 1%, 2%, 5% or 10%" << endl << endl;
  cout << "Enter 1, 2, 5 or 10:  ";
  cin >> tolEdit;
  cout << endl;
 }
 while(tolEdit != 1 && tolEdit != 2 && tolEdit != 5 && tolEdit != 10);

 cout << "Tolerance set to " << tolEdit << " %" << endl << endl;
 resObj.setTolerance((double)tolEdit*0.01, fnDisplay);

 do
 {
  cout << "Current nomimal resistance = " << nom << " ohms" << endl;
  cout << "Standard 10% Resistance Values, First Three Digits" << endl << endl;

  if(tolEdit == 10)
  {
   for( i = 0; i < E12; i++)
   {
    if(!(i % 10))
     cout << endl;
    cout << nominalE12Values[i] << "   ";
   }
  }
  else if(tolEdit == 5)
  {
   for( i = 0; i < E24; i++)
   {
    if(!(i % 10))
     cout << endl;
    cout << nominalE24Values[i] << "   ";
   }
  }
  else if(tolEdit == 2)
  {
   for( i = 0; i < E48; i++)
   {
    if(!(i % 10))
     cout << endl;
    cout << nominalE48Values[i] << "   ";
   }
  }
  else
  {
   for( i = 0; i < E96; i++)
   {
    if(!(i % 10))
     cout << endl;
    cout << nominalE96Values[i] << "   ";
   }
  }

  cout << endl << endl << "Enter first three digits:  ";
  cin >> nomEdit;
  cout << "You entered " << nomEdit << endl;
  validEIA = false;

  if(tolEdit == 10)
  {
   for( i = 0; i < E12; i++)
   {
    if(nomEdit == nominalE12Values[i])
    {
     validEIA = true;
     cout << "Valid EIA value entered" << endl;
    }
   }
  }
  else if(tolEdit == 5)
  {
   for( i = 0; i < E24; i++)
   {
    if(nomEdit == nominalE24Values[i])
    {
     validEIA = true;
     cout << "Valid EIA value entered" << endl;
    }
   }
  }
  else if(tolEdit == 2)
  {
   for( i = 0; i < E48; i++)
    {
    if(nomEdit == nominalE48Values[i])
    {
     validEIA = true;
     cout << "Valid EIA value entered" << endl;
    }
   }
  }
  else
  {
   for( i = 0; i < E96; i++)
    {
    if(nomEdit == nominalE96Values[i])
    {
     validEIA = true;
     cout << "Valid EIA value entered" << endl;
    }
   }
  }

  if (validEIA == false)
   {
    cout << "Invalid EIA value entered, try again" << endl;
   }
 }
 while(validEIA == false);

 do
 {
  cout << endl << "Enter a power of ten multiplier between -2 (0.01) and 3 (1000):  ";
  cin >> powerOfTen;
  cout << "You entered " << powerOfTen << endl;
 }
 while(powerOfTen < -2 || powerOfTen > 3);

 resObj.setNominal((double)nomEdit * pow(10.0,(double)powerOfTen), fnDisplay);
}

If you read the class description in Resistor.h you will notice that none of the three constructors takes 4 arguments. If you are not allowed to change that, then your only alternative is to change the lines in ResistorMain.cpp by removing one of the arguments so that they match the argument list in the class constructor, probably by removing the 3d argument in lines 26,27 and 28 because none of the 3 constructors have a char* parameter.

Edited 4 Years Ago by Ancient Dragon: n/a

If you read the class description in Resistor.h you will notice that none of the three constructors takes 4 arguments. If you are not allowed to change that, then your only alternative is to change the lines in ResistorMain.cpp by removing one of the arguments so that they match the argument list in the class constructor, probably by removing the 3d argument in lines 26,27 and 28 because none of the 3 constructors have a char* parameter.

thank you for the response as I stated that the ResistorMain.cpp was a given.
If changes are to be made I would like them to be in either the Resistor.h header or the Resistor.cpp file as these can be changed.

I understand that however I am still confused on which to change do I just define the value or is there more. Please remember I am still new at this and this part of the code is all I need in order to compile without errors.

I don't see where you implement the methods sepcified in Resistor.h. Instead, you've implemented two standalone functions, and then provided prototypes for them in ResistorMain.cpp.

Meanwhile, you have code that tries to create a new resistor object by passing what appears to be a nominal-resistance, a percentage tolerance, a name C-string, and a flag for whether to display the name. So Resistor.h needs a line (maybe after 17) that looks like:

CResistor(float nominal_resistance, float tolerance, const char *name, bool display);

and Resistor.cpp needs a method-body for it that starts with

CResistor::CResistor(float nominal_resistance, float tolerance, const char *name, bool display)
{
    // ininitialize members here
}

(and so on for each of the other methods specified).

I don't see where you implement the methods sepcified in Resistor.h. Instead, you've implemented two standalone functions, and then provided prototypes for them in ResistorMain.cpp.

Meanwhile, you have code that tries to create a new resistor object by passing what appears to be a nominal-resistance, a percentage tolerance, a name C-string, and a flag for whether to display the name. So Resistor.h needs a line (maybe after 17) that looks like:

CResistor(float nominal_resistance, float tolerance, const char *name, bool display);

and Resistor.cpp needs a method-body for it that starts with

CResistor::CResistor(float nominal_resistance, float tolerance, const char *name, bool display)
{
    // ininitialize members here
}

(and so on for each of the other methods specified).

so basically all I need to do is initializes the variables however once I added
the constructor I get an error: warning C4305: 'argument' : truncation from 'double' to 'float' is there something else I need to do?

This article has been dead for over six months. Start a new discussion instead.