How to Implement Aggregation concept in C++

R

Rajen

I have an Account class in which Date object is a member of it.
When I created an account class:
These errors are coming up:
////////
:!g++ Account.cpp Account_main.cpp
/tmp/cclWe0e4.o(.text+0x17): In function
`Account::Account[not-in-charge]()':
: undefined reference to `Date::Date[in-charge](int, int, int)'
/tmp/cclWe0e4.o(.text+0x7d): In function
`Account::Account[in-charge]()':
: undefined reference to `Date::Date[in-charge](int, int, int)'
/tmp/ccGYfdzi.o(.text+0x20): In function `main':
: undefined reference to `Date::Date[in-charge](char*)'
/tmp/ccGYfdzi.o(.text+0x16f): In function `main':
: undefined reference to `Date::ToString(char*)'
collect2: ld returned 1 exit status

shell returned 1
////////

Account_main.cpp is place where I create an Account object.
Also please help in understanding these errors!!

********************************Account_main.cpp***************************
#include <iostream>
#include "Account.h"
using namespace std;

int main(int argc, char **argv)
{
char acAccDate[11];
char acAccType[2];

//Account oA1;
//Date myDate("13-02-1988");
Account oA1(1322,23432,"SB",1000.00,Date("15-5-1999"));
//oA1.SetAccount(1322,23432,"SB",1000.00) : m_oDate("13-02-1988");

cout << "Account Details:" << endl;
cout << "No:" << oA1.GetAccNo() << endl;
oA1.GetAccType(acAccType);
cout << "Type:" << acAccType << endl;
cout << "Balance:" << oA1.GetBalance() << endl;
oA1.GetAccDate().ToString(acAccDate);
cout << "Date:" << acAccDate << endl;

return 0;
}

********************************Account.cpp***********************************
#include "Account.h"
#include <cstring>
Account::Account()
{
m_iCustId=0;
SetAccNo(0);
SetAccType("SB");
SetBalance(1000.00);
}

Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance, Date oDate): m_oDate(oDate)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
/*m_oDate.m_iDay = oDate.m_iDay;
m_oDate.m_iMonth= oDate.m_iMonth;
m_oDate.m_iYear= oDate.m_iYear;*/
}
/*
Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance) : m_oDate(Date sDate)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
}
*/

void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance, Date oDate)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
/*
m_oDate.m_iDay = oDate.m_iDay;
m_oDate.m_iMonth= oDate.m_iMonth;
m_oDate.m_iYear= oDate.m_iYear;
*/
}

void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
}

void Account::SetAccNo(unsigned long ulAccNo)
{
m_ulAccNo = ulAccNo;
}

/*Set the account type as given. By default set it as "SB"*/
void Account::SetAccType(char *acAccType)
{
( (strcasecmp(acAccType, "SB") == 0) && (strcasecmp(acAccType,
"CA")==0) && (strcasecmp(acAccType, "RD")==0) && (strcasecmp(acAccType,
"FD")==0) )
? strcpy(m_acAccType, acAccType) : strcpy(m_acAccType , "SB");
}

void Account::SetBalance(double dBalance)
{
m_dBalance = ( dBalance > 1000.00) ? dBalance : 1000.00;
}

unsigned long Account::GetAccNo() const
{
return m_ulAccNo;
}

void Account::GetAccType( char *sType ) const
{
strcpy(sType, m_acAccType);
}

double Account::GetBalance() const
{
return m_dBalance;
}

Date Account::GetAccDate() const
{
return this->m_oDate;
}

*************************************Account.h******************************
#include "Date.h"
#ifndef _ACCOUNT_H
#define _ACCOUNT_H

class Account
{
private:
int m_iCustId;
unsigned long m_ulAccNo;
char m_acAccType[3];
double m_dBalance;
Date m_oDate;

public:
/*Constructor*/
Account();
Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance, Date oDate);
Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance);

/*Set Methods*/
void SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance, Date oDate);
void SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance);
void SetCustId(int iCustId);
void SetAccNo(unsigned long ulAccNo);
void SetAccType( char *acAccType );
void SetBalance(double dBalance);

/*Get Methods*/
//int GetCustId() const;
unsigned long GetAccNo() const;
void GetAccType( char *sType ) const;
double GetBalance() const;
Date GetAccDate() const;

};

#endif
******************************************************************************************
That was the code.
Please helpme!!
 
V

Victor Bazarov

Rajen said:
I have an Account class in which Date object is a member of it.
When I created an account class:
These errors are coming up:
////////
:!g++ Account.cpp Account_main.cpp
/tmp/cclWe0e4.o(.text+0x17): In function
`Account::Account[not-in-charge]()':
undefined reference to `Date::Date[in-charge](int, int, int)'
[...]

"Undefined reference" usually means the compiler can see that you use
a function, but it can't see the function itself (the definition, the
body, the implementation). 'Date::Date' is a constructor. Did you
show your compiler where the implemenation of 'Date' class is located?

V
 
R

Rolf Magnus

Rajen said:
I have an Account class in which Date object is a member of it.
When I created an account class:
These errors are coming up:
////////
:!g++ Account.cpp Account_main.cpp

Try it the other way round.
/tmp/cclWe0e4.o(.text+0x17): In function
`Account::Account[not-in-charge]()':
: undefined reference to `Date::Date[in-charge](int, int, int)'
/tmp/cclWe0e4.o(.text+0x7d): In function
`Account::Account[in-charge]()':
: undefined reference to `Date::Date[in-charge](int, int, int)'
/tmp/ccGYfdzi.o(.text+0x20): In function `main':
: undefined reference to `Date::Date[in-charge](char*)'
/tmp/ccGYfdzi.o(.text+0x16f): In function `main':
: undefined reference to `Date::ToString(char*)'
collect2: ld returned 1 exit status

shell returned 1
////////

Account_main.cpp is place where I create an Account object.
Also please help in understanding these errors!!

********************************Account_main.cpp***************************
#include <iostream>
#include "Account.h"
using namespace std;

int main(int argc, char **argv)
{
char acAccDate[11];
char acAccType[2];

//Account oA1;
//Date myDate("13-02-1988");
Account oA1(1322,23432,"SB",1000.00,Date("15-5-1999"));
//oA1.SetAccount(1322,23432,"SB",1000.00) : m_oDate("13-02-1988");

cout << "Account Details:" << endl;
cout << "No:" << oA1.GetAccNo() << endl;
oA1.GetAccType(acAccType);
cout << "Type:" << acAccType << endl;
cout << "Balance:" << oA1.GetBalance() << endl;
oA1.GetAccDate().ToString(acAccDate);
cout << "Date:" << acAccDate << endl;

return 0;
}

********************************Account.cpp***********************************
#include "Account.h"
#include <cstring>
Account::Account()
{
m_iCustId=0;
SetAccNo(0);
SetAccType("SB");
SetBalance(1000.00);
}

Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance, Date oDate): m_oDate(oDate)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
/*m_oDate.m_iDay = oDate.m_iDay;
m_oDate.m_iMonth= oDate.m_iMonth;
m_oDate.m_iYear= oDate.m_iYear;*/
}
/*
Account::Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance) : m_oDate(Date sDate)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
}
*/

void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance, Date oDate)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
/*
m_oDate.m_iDay = oDate.m_iDay;
m_oDate.m_iMonth= oDate.m_iMonth;
m_oDate.m_iYear= oDate.m_iYear;
*/
}

void Account::SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance)
{
m_iCustId = iCustId;
SetAccNo(ulAccNo);
SetAccType(acAccType);
SetBalance(dBalance);
}

void Account::SetAccNo(unsigned long ulAccNo)
{
m_ulAccNo = ulAccNo;
}

/*Set the account type as given. By default set it as "SB"*/
void Account::SetAccType(char *acAccType)
{
( (strcasecmp(acAccType, "SB") == 0) && (strcasecmp(acAccType,
"CA")==0) && (strcasecmp(acAccType, "RD")==0) && (strcasecmp(acAccType,
"FD")==0) )
? strcpy(m_acAccType, acAccType) : strcpy(m_acAccType , "SB");
}

void Account::SetBalance(double dBalance)
{
m_dBalance = ( dBalance > 1000.00) ? dBalance : 1000.00;
}

unsigned long Account::GetAccNo() const
{
return m_ulAccNo;
}

void Account::GetAccType( char *sType ) const
{
strcpy(sType, m_acAccType);
}

double Account::GetBalance() const
{
return m_dBalance;
}

Date Account::GetAccDate() const
{
return this->m_oDate;
}

*************************************Account.h******************************
#include "Date.h"
#ifndef _ACCOUNT_H
#define _ACCOUNT_H

class Account
{
private:
int m_iCustId;
unsigned long m_ulAccNo;
char m_acAccType[3];
double m_dBalance;
Date m_oDate;

public:
/*Constructor*/
Account();
Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance, Date oDate);
Account(int iCustId, unsigned long ulAccNo, char *acAccType,
double dBalance);

/*Set Methods*/
void SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance, Date oDate);
void SetAccount(int iCustId, unsigned long ulAccNo, char
*acAccType, double dBalance);
void SetCustId(int iCustId);
void SetAccNo(unsigned long ulAccNo);
void SetAccType( char *acAccType );
void SetBalance(double dBalance);

/*Get Methods*/
//int GetCustId() const;
unsigned long GetAccNo() const;
void GetAccType( char *sType ) const;
double GetBalance() const;
Date GetAccDate() const;

};

#endif
******************************************************************************************
That was the code.
Please helpme!!
 
V

Victor Bazarov

Rolf said:
Rajen said:
I have an Account class in which Date object is a member of it.
When I created an account class:
These errors are coming up:
////////
:!g++ Account.cpp Account_main.cpp

Try it the other way round.

Did you *have* to quote the whole thing just to add one line?
 
R

Rolf Magnus

Victor said:
Rolf said:
Rajen said:
I have an Account class in which Date object is a member of it.
When I created an account class:
These errors are coming up:
////////
:!g++ Account.cpp Account_main.cpp

Try it the other way round.

Did you *have* to quote the whole thing just to add one line?

Definitely! No, just kidding. I was in a rush and forget to cut out the
source code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top