Help for some functions

Create Class CSalary with private member variables
string m_strProfession
double m_dSalary
Constructors:Default,Copy,Explicit
Functions:
1/string GetProf(void),double GetSalary(void)
2/SetProf(const string val),SetSalary(const double val)
3/Output(ostream&) and Input(istram&)
4/Operators:<<,>>,=,==,<,double operator*(const CSalary&obj)
Create Class CCalcCorr with private member variables:
vector<CSalary>m_vCity1//data for city 1
vector<CSalary>m_vCity2//data for city 2
double m_dCorr//correlation coefficient
Constructors:
Explicit by data filenames string fNmae1,string fName2
CCalcCorr(const string& strFileName1,const string& strFileName2)

<profession> <salary>
Web Developer 5000

Functions:/I want help for these functions/
Colculate correlation coefficient btw 2 vectors in m_dCorr and return it in dCorr.Return false if can't calculate

Formulas:
Corr=SUMxy/sqrt(SUMxx*SUMyy) where :
SUMxx = SUM(City1*City1)-SUM(City1)*SUM(City1)/n
SUMxy = SUM(City1*City2)-SUM(City1)*SUM(City2)/n
SUMyy = SUM(City2'City2)-SUM(City2)*SUM(City2)/n where:
City1 - current value m_dSalary from m_vCityl
City2 - current value m_dSalary from m_vCity2
n- size of m_vCityl and m_vCity2


-return correlation
-change data for profession/write dCity1,dCity2/
-read data/return dCity1,dCity2/
-void WriteTo()-write stream data
<Prof,Salary1(m_vCity1),Salary2(m_vCity2)>
-input/output operators
Main function-read data from input files,create CCalcCorr,testing functions


here is my code and i don't know how to continue and if code is right?
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
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<algorithm>
#include<iterator>


using namespace std;

class CSalary{
    string m_strProfession; 
	double m_dSalary;
public:
CSalary(){};

CSalary(const string& strProfession,const double& dSalary){
	m_strProfession=strProfession;
    m_dSalary=dSalary;
}

CSalary(const CSalary &ob){
	m_strProfession=ob.m_strProfession;
	m_dSalary=ob.m_dSalary;
}

string getProf(void)const{
	return m_strProfession;
}

double getSalary(void)const{
	return m_dSalary;
}

void setProf(const string&strProfession){
	m_strProfession=strProfession;
}

void setSalary(const double&dSalary){
	m_dSalary=dSalary;
}

friend ostream&operator<<(ostream&os,const CSalary&s){
	os<<s.m_strProfession<<" "<<s.m_dSalary<<endl;
return os;
}

friend istream&operator>>(istream&is,CSalary&s){
	is>>s.m_strProfession;
	is>>s.m_dSalary;
	return is;
}

CSalary&operator=(const CSalary&ob){
	m_strProfession=ob.m_strProfession;
	m_dSalary=ob.m_dSalary;
	return *this;
}

bool operator<(const CSalary&s)const{
	return(m_strProfession<s.m_strProfession);
}

bool operator==(const CSalary&s)const{
	return(m_strProfession==s.m_strProfession);
}
double operator *(const CSalary&obj)
{
	return m_dSalary*obj.m_dSalary;
}
}

class CCalcCorr
{
    vector<CSalary*>m_vCity1;
    vector<CSalary*>m_vCity2;

	double m_dCorr;
	 
	CCalcCorr(const string& strFileName1,const string& strFileName2)
	{
	ifstream f(strFileName2.c_str());
	if(!f.is_open())
		throw "File Not Found!";
	else
	{
		f>>m_dCorr;
		copy(istream_iterator<CCalcCorr>(f),istream_iterator<CCalcCorr>(),back_inserter(m_vCity1));
		sort(m_vCity1.begin(),m_vCity1.end());
	}
	ifstream ff(strFileName2.c_str());
    if(!ff.is_open())
		throw "File Not Found!";
	else
	{
		ff>>m_dCorr;
		copy(istream_iterator<CCalcCorr>(ff),istream_iterator<CCalcCorr>(),back_inserter(m_vCity2));
		sort(m_vCity2.begin(),m_vCity2.end());
    }
	}

}

	





Your equality comparison operator is only checking the m_strProfession member for equality. Are you sure that's correct? Can two CSalary objects be considered equal if the values of m_dSalary are different?

Your less-than operator is comparing the m_strProfession members. Are you sure that's the most appropriate way to compare two salary objects? If I told you that my salary was less than yours, would you think that I meant the name of my profession comes before yours in the alphabet? Or would you think I meant something else?
Last edited on
Topic archived. No new replies allowed.