So every time I try to compile these codes it keeps giving me these errors
Error 1 error LNK2019: unresolved external symbol "bool __cdecl CISP430_A1::operator==(class CISP430_A1::statistician const &,class CISP430_A1::statistician const &)" (??8CISP430_A1@@YA_NABVstatistician@0@0@Z) referenced in function _main C:\Users\SNX\Desktop\SNX1\SNX1\stattest.obj SNX1
Error 2 error LNK1120: 1 unresolved externals C:\Users\SNX\Desktop\SNX1\Debug\SNX1.exe 1 1 SNX1
I've been researching for hours about why it's doing it, but can't find a solution.
-I tried looking for functions that I didn't define
-functions that didn't have matching parameters from the main, header, and implementation
-Made sure it was a window32 console under c++ in VS2013
-Made sure my constructor didn't really do anything worth wild
Any help would be appreciated.
Main.cpp
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
|
#include <cctype>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include "stats.h"
using namespace SNX_A1;
using namespace std;
void print_menu()
char get_user_command();
double get_number();
void print_values(const statistician& s);
int main()
{
statistician s1, s2, s3; // Three statisticians for us to play with
char choice; // A command character entered by the user
double x; // Value for multiplication x*s1
cout << "Three statisticians s1, s2, and s3 are ready to test." << endl;
do
{
cout << endl;
print_menu();
choice = toupper(get_user_command());
switch (choice)
{
case 'R': cout << "Which one should I reset (1, 2, 3) " << endl;
choice = get_user_command();
switch (choice)
{
case '1': s1.reset();
break;
case '2': s2.reset();
break;
case '3': s3.reset();
break;
}
cout << "Reset activated for s" << choice << "." << endl;
break;
case '1': s1.next(get_number());
break;
case '2': s2.next(get_number());
break;
case '3': s3.next(get_number());
break;
case 'T': cout << "The values are given in this table:" << endl;
cout << " LENGTH SUM"
<< " MINIMUM MEAN MAXIMUM" << endl;
cout << " s1";
print_values(s1);
cout << " s2";
print_values(s2);
cout << " s3";
print_values(s3);
break;
case 'E': if (s1 == s2)
cout << "s1 and s2 are equal." << endl;
else
cout << "s1 and s2 are not equal." << endl;
break;
case '+': s3 = s1 + s2;
cout << "s3 has been set to s1 + s2" << endl;
break;
case '*': cout << "Please type a value for x: ";
cin >> x;
s3 = x * s1;
cout << "s3 has been set to " << x << " * s1" << endl;
break;
case 'Q': cout << "Ridicule is the best test of truth." << endl;
break;
default: cout << choice << " is invalid. Sorry." << endl;
}
} while ((choice != 'Q'));
return EXIT_SUCCESS;
}
void print_menu()
{
// a bunch of cout lines
}
char get_user_command()
// Library facilties used: iostream.h
{
char command;
cout << "Enter choice: ";
cin >> command;
return command;
}
double get_number()
// Library facilties used: iostream.h
{
double result;
cout << "Please enter the next real number for the sequence: ";
cin >> result;
cout << result << " has been read." << endl;
return result;
}
void print_values(const statistician& s)
// Library facilties used: iostream.h
{
cout << setw(10) << s.length();
cout << setw(10) << s.sum();
if (s.length() != 0)
{
cout << setw(10) << s.minimum();
cout << setw(10) << s.mean();
cout << setw(10) << s.maximum();
}
else
cout << " none none none";
cout << endl;
}
[output][/output]
|
stats.h(header)
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
|
#ifndef STATS_H
#define STATS_H
#include <iostream>
namespace SNX_A1
{
class statistician
{
public:
// CONSTRUCTOR
statistician();
~statistician();
// MODIFICATION MEMBER FUNCTIONS
void next(double r);
void reset( );
// CONSTANT MEMBER FUNCTIONS
int length() const;
double sum() const;
double mean( ) const;
double minimum( ) const;
double maximum( ) const;
// FRIEND FUNCTIONS
friend statistician operator +
(const statistician& s1, const statistician& s2);
friend statistician operator *
(double scale, const statistician& s);
private:
int count; // How many numbers in the sequence
double total; // The sum of all the numbers in the sequence
double tiniest; // The smallest number in the sequence
double largest; // The largest number in the sequence
};
bool operator ==(const statistician& s1, const statistician& s2);
}
#endif
|
stats.cpp
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
|
#include <cassert>
#include "stats.h"
using namespace SNX_A1;
using namespace std;
statistician::statistician()
{
}
statistician::~statistician()
{
}
void statistician::next(double x)
{
if (count == 0)
tiniest = x;
if (count == 0)
largest = x;
if (tiniest > x)
tiniest = x;
if (largest < x)
largest = x;
count++;
total = +x;
}
bool operator ==(const statistician& x1, const statistician& x2)
{
return
(x1.length() == x2.length())
&&
(x1.sum() == x2.sum())
&&
(x1.minimum() == x2.minimum())
&&
(x1.maximum() == x2.maximum());
}
namespace SNX_A1
{
statistician operator+(const statistician& x1, const statistician& x2)
{
statistician y;
y.reset();
y.count = x1.length() + x2.length();
y.total = x1.sum() + x2.sum();
y.tiniest = x1.minimum() + x2.minimum();
y.largest = x1.maximum() + x2.maximum();
return y;
}
statistician operator*(double scale, const statistician& x)
{
statistician y;
y.reset();
y.count = scale * x.length();
y.total = scale * x.sum();
y.tiniest = scale * x.minimum();
y.largest = scale * x.maximum();
return y;
}
}
void statistician::reset()
{
count = 0;
total = 0;
tiniest = 0;
largest = 0;
}
double statistician::mean() const
{
assert(length() > 0);
return(total / count);
}
double statistician::minimum() const
{
assert(length() > 0);
return tiniest;
}
double statistician::maximum() const
{
assert(length() > 0);
return largest;
}
int statistician::length() const
{
return count;
}
double statistician::sum() const
{
return total;
}
|