Hi guys

I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday

//ClientData.h
#ifndef CLIENTDATA_H
#define CLIENTDATA_H

#include <string>
using std::string;

class ClientData 
{
public:
// default ClientData constructor
inline ClientData( int = 0, string = "", string = "", string = "", string = "" );

// accessor functions for accountNumber
void setAccountNumber( int );
int getAccountNumber() const;

// accessor functions for clientName
void setClientName( string );
string getClientName() const;

// accessor functions for clientAddress
void setClientAddress( string );
string getClientAddress() const;

//accessor functions for contactName
void setContactName( string );
string getContactName() const;

//accessor functions for clientPhone
void setClientPhone( string );
string getClientPhone() const;

private:
const int accountNumber;
const char telNumber[ 11 ];
const char clientName[ 20 ];
const char clientAddress[ 20 ];
const char contactName[ 15 ];
}; // end class ClientData

#endif
//TheClient.cpp
// This program reads a random access file sequentially, updates
// data previously written to the file, creates data to be placed
// in the file, and deletes data previously in the file.

#include "ClientData.h" // ClientData class definition

#include <iostream>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::ios;
using std::left;
using std::right;
using std::showpoint;

#include <fstream>
using std::ofstream;
using std::ostream;
using std::fstream;

#include <iomanip>
using std::setw;
using std::setprecision;

//#include <cstdlib> 



int enterChoice();
void createTextFile( fstream& );
void updateRecord( fstream& );
void newRecord( fstream& );
void deleteRecord( fstream& );
void outputLine( ostream&, const ClientData & );
int getAccount( const char * const );

enum Choices { PRINT = 1, UPDATE, NEW, DELETE, END };

int main()
{
// open file for reading and writing
fstream inOutCredit( "credit.dat", ios::in | ios::out );

// exit program if fstream cannot open file
if ( !inOutCredit ) 
{
cerr << "File could not be opened." << endl;
exit ( 1 );
} // end if

int choice; // store user choice

// enable user to specify action
while ( ( choice = enterChoice() ) != END ) 
{
switch ( choice ) 
{
case PRINT: // create text file from record file
createTextFile( inOutCredit );
break;
case UPDATE: // update record
updateRecord( inOutCredit );
break;
case NEW: // create record
newRecord( inOutCredit );
break;
case DELETE: // delete existing record
deleteRecord( inOutCredit );
break;
default: // display error if user does not select valid choice
cerr << "Incorrect choice" << endl;
break;
} // end switch

inOutCredit.clear(); // reset end-of-file indicator
} // end while

return 0;
} // end main

// enable user to input menu choice
int enterChoice()
{
// display available options
cout << "\nEnter your choice" << endl
<< "1 - store a formatted text file of clients" << endl
<< " called \"print.txt\" for printing" << endl
<< "2 - update a client record" << endl
<< "3 - add a new client" << endl
<< "4 - delete a client record" << endl
<< "5 - end program\n? ";

int menuChoice;
cin >> menuChoice; // input menu selection from user
return menuChoice;
} // end function enterChoice

// create formatted text file for printing
void createTextFile( fstream &readFromFile )
{
// create text file
ofstream outPrintFile( "print.txt", ios::out );

// exit program if ofstream cannot create file
if ( !outPrintFile ) 
{
cerr << "File could not be created." << endl;
exit( 1 );
} // end if

outPrintFile << left << setw( 10 ) << "Account"<< setw( 10 ) << "Client Name" << setw( 16 )
<< "Address" << setw( 11 ) << "Contact Name" << right
<< setw( 10 ) << "Telephone No" << endl;

// set file-position pointer to beginning of readFromFile
readFromFile.seekg( 0 );

// read first record from record file
ClientData client;
readFromFile.read( reinterpret_cast< char * >( &client ),
sizeof( ClientData ) );

// copy all records from record file into text file
while ( !readFromFile.eof() ) 
{
// write single record to text file
if ( client.getAccountNumber() != 0 ) // skip empty records
outputLine( outPrintFile, client );

// read next record from record file
readFromFile.read( reinterpret_cast< char * >( &client ), 
sizeof( ClientData ) );
} // end while
} // end function createTextFile

// update balance in record
void updateRecord( fstream &updateFile )
{
// obtain number of account to update
int accountNumber = getAccount( "Enter account to update" );

// move file-position pointer to correct record in file
updateFile.seekg( ( accountNumber - 1 ) * sizeof( ClientData ) );

// read first record from file
ClientData client;
updateFile.read( reinterpret_cast< char * >( &client ), 
sizeof( ClientData ) );

// update record
if ( client.getAccountNumber() != 0 ) 
{
outputLine( cout, client ); // display the record

// move file-position pointer to correct record in file
updateFile.seekp( ( accountNumber - 1 ) * sizeof( ClientData ) );

// write updated record over old record in file
updateFile.write( reinterpret_cast< const char * >( &client ), 
sizeof( ClientData ) );
} // end if
else // display error if account does not exist
cerr << "Account #" << accountNumber 
<< " has no information." << endl;
} // end function updateRecord

// create and insert record
void newRecord( fstream &insertInFile )
{
// obtain number of account to create
int accountNumber = getAccount( "Enter new account number" );

// move file-position pointer to correct record in file
insertInFile.seekg( ( accountNumber - 1 ) * sizeof( ClientData ) );

// read record from file
ClientData client;
insertInFile.read( reinterpret_cast< char * >( &client ), 
sizeof( ClientData ) );

// create record, if record does not previously exist
if ( client.getAccountNumber() == 0 ) 
{
char telNumber[ 11 ];
char clientName[ 20 ];
char clientAddress[ 40 ];
char contactName[ 15 ];

// user enters last name, first name and balance
cout << "Enter clientname, address, contactname, telnumber\n? ";
cin >> setw( 20 ) >> clientName;
cin >> setw( 40 ) >> clientAddress;
cin >> setw( 15 ) >> contactName;
cin >> setw( 11 ) >> telNumber;
//cin >> balance;

// use values to populate account values
client.setClientName( clientName );
client.setClientAddress( clientAddress);
client.setContactName( contactName );
client.setClientPhone( telNumber );
client.setAccountNumber( accountNumber );

// move file-position pointer to correct record in file
insertInFile.seekp( ( accountNumber - 1 ) * sizeof( ClientData ) );

// insert record in file 
insertInFile.write( reinterpret_cast< const char * >( &client ),
sizeof( ClientData ) ); 
} // end if
else // display error if account already exists
cerr << "Account #" << accountNumber
<< " already contains information." << endl;
} // end function newRecord

// delete an existing record
void deleteRecord( fstream &deleteFromFile )
{
// obtain number of account to delete
int accountNumber = getAccount( "Enter account to delete" );

// move file-position pointer to correct record in file
deleteFromFile.seekg( ( accountNumber - 1 ) * sizeof( ClientData ) );

// read record from file
ClientData client;
deleteFromFile.read( reinterpret_cast< char * >( &client ), 
sizeof( ClientData ) );

// delete record, if record exists in file
if ( client.getAccountNumber() != 0 ) 
{
ClientData blankClient; // create blank record

// move file-position pointer to correct record in file
deleteFromFile.seekp( ( accountNumber - 1 ) * 
sizeof( ClientData ) );

// replace existing record with blank record
deleteFromFile.write( 
reinterpret_cast< const char * >( &blankClient ), 
sizeof( ClientData ) );

cout << "Account #" << accountNumber << " deleted.\n";
} // end if
else // display error if record does not exist
cerr << "Account #" << accountNumber << " is empty.\n";
} // end deleteRecord

// display single record
void outputLine( ostream &output, const ClientData &record )
{
output << left << setw( 10 ) << record.getAccountNumber()
<< setw( 20 ) << record.getClientName()
<< setw( 40 ) << record.getClientAddress()
<< setw( 15 ) << record.getContactName()
<< setw( 11 ) << record.getClientPhone()
<< setw( 10 ) << setprecision( 2 ) << right << fixed 
<< showpoint << endl;
} // end function outputLine

// obtain account-number value from user
int getAccount( const char * const prompt )
{
int accountNumber;

// obtain account-number value
do 
{
cout << prompt << " (1 - 100): ";
cin >> accountNumber;
} while ( accountNumber < 1 || accountNumber > 100 );

return accountNumber;
} // end function getAccount

Problem:
It compiles with 0 errors & 0 warnings in MSVisual C++ 6, but when you try and get it to build .exe, it has these errors:

Linking...
Wholesaler.obj : error LNK2005: _main already defined in TheClient.obj
TheClient.obj : error LNK2001: unresolved external symbol "public: int __thiscall ClientData::getAccountNumber(void)const " (?getAccountNumber@ClientData@@QBEHXZ)
TheClient.obj : error LNK2001: unresolved external symbol "public: __thiscall ClientData::ClientData(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<cha
r>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0ClientData@@QAE@HV?$basic_string@DU
?$char_traits@D@std@@V?$allocator@D@2@@std@@000@Z)
TheClient.obj : error LNK2001: unresolved external symbol "public: void __thiscall ClientData::setAccountNumber(int)" (?setAccountNumber@ClientData@@QAEXH@Z)
TheClient.obj : error LNK2001: unresolved external symbol "public: void __thiscall ClientData::setClientPhone(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setClientPhone@ClientData@@QAEXV?$basic_string@
DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
TheClient.obj : error LNK2001: unresolved external symbol "public: void __thiscall ClientData::setContactName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setContactName@ClientData@@QAEXV?$basic_string@
DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
TheClient.obj : error LNK2001: unresolved external symbol "public: void __thiscall ClientData::setClientAddress(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setClientAddress@ClientData@@QAEXV?$basic_str
ing@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
TheClient.obj : error LNK2001: unresolved external symbol "public: void __thiscall ClientData::setClientName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setClientName@ClientData@@QAEXV?$basic_string@DU
?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
TheClient.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ClientData::getClientName(void)const " (?getClientName@ClientData@@QBE?AV?$basic_s
tring@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
TheClient.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ClientData::getClientAddress(void)const " (?getClientAddress@ClientData@@QBE?AV?$b
asic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
TheClient.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ClientData::getContactName(void)const " (?getContactName@ClientData@@QBE?AV?$basic
_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
TheClient.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ClientData::getClientPhone(void)const " (?getClientPhone@ClientData@@QBE?AV?$basic
_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
TheRetailer.obj : error LNK2001: unresolved external symbol "public: __thiscall TheClient::TheClient(char const *,char const *,char const *)" (??0TheClient@@QAE@PBD00@Z)
TheSupplier.obj : error LNK2001: unresolved external symbol "public: __thiscall TheClient::TheClient(char const *,char const *,char const *)" (??0TheClient@@QAE@PBD00@Z)
Debug/WholesalerFinal.exe : fatal error LNK1120: 12 unresolved externals
Error executing link.exe.

WholesalerFinal.exe - 15 error(s), 0 warning(s)

Scratching my head as to why, and what all that error goobledeegook means?

Thank you in advance for your help guys.
:confused: :confused: :confused: :confused: :cheesy: :cheesy:

The functions in your header need to be defined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.