I'm beginner with c++ and want some help
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(SUMxxSUMyy) 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?

#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());
    }
    }

}

Edited 2 Years Ago by loldafuq

I only took a quick glance at your code. However I did notice one likely bug in your program, particularly in the CCalcCorr class. The issue is that everything in the class is private, which means it would be very difficult to actually call anything from it. You probably meant to include public: somewhere. Remember, by default things in a class will always be private.

EDIT:

Also note that your CCalcCorr class could just be a normal function, with everything local instead. This may make it easier to use in your main function.

Just in case you are unfamiliar, your main function must be in the global scope (not wrapped in any class or namespace) and should be either int main() or int main(int argc, char *argv[]).

Edited 2 Years Ago by Labdabeta: more info

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