User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,873 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,971 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2011 | Replies: 2
Reply
Join Date: Oct 2004
Posts: 43
Reputation: hopeolicious is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
hopeolicious hopeolicious is offline Offline
Light Poster

reading records from a file

  #1  
Apr 20th, 2005
Can someone help me to figure his out. I have to read in a file that contains employee names, numbers, payrates, and hours. Then I have to calculate the gross andsend everything to an output file. I keep getting this error message

"employee.cpp" 69 lines, 1471 characters
$ c++ employee.cpp
Undefined first referenced
symbol in file
putdata(char *, int, float) /var/tmp/cckpUsol.o
getdata(char *, int, float, int) /var/tmp/cckpUsol.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
$

this is my program

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

const int MAXNAME = 20;
const int NUMRECS = 12;
int i=0;

struct employees
{
int number, hours;
float rate, gross;
char name[MAXNAME];
}employee;

int employees[NUMRECS];

void getdata(char [], int, float, int);
void processdata(float, int);
void putdata(char [], int, float);

ifstream HopeData;
ofstream MikeData;

void main()
{


HopeData.open("personel.dat");
MikeData.open("putdata");

if(HopeData.fail())
{
	cout << "\n\nFile not successfully opened\n\n";
}
cout << "\n\nFile successfully opened\n\n";

getdata(employee.name, employee.number, employee.rate, employee.hours);

putdata(employee.name, employee.number, employee.gross); 

HopeData.close();
MikeData.close();
}

void getdata(int name[], int number, float rate, int hours)
{
		while(i < NUMRECS)
		{

HopeData >> employee.name, employee.number, employee.rate, employee.hours;
		}
processdata(employee.rate, employee.hours);
}

void processdata(float rate, int hours)
{
employee.grossddd = employee.rate * employee.hours;
}

void putdata(char name, int number, float gross)
{
cout << "\n\n              Payroll  Report" << endl;
cout << "        Name        Number        Gross Pay" << endl;    
		cout << setiosflags(ios::showpoint);
		cout << setiosflags(ios::fixed);
		cout << setprecision(2);
		cout << setw(15) << employee.name << setw(5) << "\t" << employee.number << setw(7) << "\t$" << employee.gross << endl;

}

And this is a sample of my file that i'm reading

Simmons 2242 8.00 40
Alexander 8343 5.98 40
Jenkins 6234 4.65 23
Gardiner 1009 9.34 40
Ward 2289 3.57 40
Simien 5342 3.09 40
Smith 7344 7.00 40
Fresch 2942 6.50 40
Donato 5034 8.09 40
Glasper 1276 8.32 40
Marsh 8234 7.98 40
Fontenot 2454 6.95 40
Johnson 1523 6.98 40
Deville 2212 1.45 40
Clay 1912 2.89 40
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,615
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 142
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: reading records from a file

  #2  
Apr 20th, 2005
My compiler shows something similar after fixing this oddity.
employee.grossddd = employee.rate * employee.hours;
So the linker says it can't find these functions. Let's look at what we have.
void getdata(char [], int, float, int);
void putdata(char [], int, float);
// ...
void getdata(int name[], int number, float rate, int hours)
{
   // ...
}
void putdata(char name, int number, float gross)
{
   // ...
}
Sure enough. The prototyped functions don't exist.

If employees is the destination array, don't you think you should reference it somewhere?
Reply With Quote  
Join Date: Dec 2004
Location: Allentown, PA
Posts: 60
Reputation: murschech is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
murschech murschech is offline Offline
Junior Poster in Training

Re: reading records from a file

  #3  
Apr 20th, 2005
Might it be that "employees" is ambiguous? It's both the name of the an array of integers and it's also a type that you've defined. (struct employees).
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 4:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC