hey guys, i got an assingment due and i was wondering if you could please help me to debug this program.

5 files,
ass1.h
ass1.cpp
main.cpp
Makefile.txt (needs to be renamed to makefile for it to be used properly)
ass1.txt(needs to be renamed ass1.dat to be used[its the database for the books])

to be compiled for a linux environment

the files to be loaded needs to change from text to binary file type, i havnt been able to work out how to do that yet

Attachments
/****************************************************************
 * ass1.cpp - CSCI124 - Ass1 - Contains the functions           *
 * <Nicholas Tsaoucis - nt647>                                  *
 ****************************************************************/
#include <iostream>
#include "ass1.h"
using namespace std;

bool Loadrecords(const char);
bool SaveRecords(const char);
bool FindRacords(const char);
void DisplayRecords(ostream& outs, int i);
void ChangeStatus(ostream& outs, int i);
void PrintAll();

bool LoadRecords(const char filename[])
{
	ifstream ins;
	
	ins.open(filename);
	
	if (ins.good())
	{
		ins >> numrecords;
	
		for (int i = 0; i < numrecords; i++)
		{
			ins >> database[i].title;
			ins >> database[i].barcode;
			ins >> database[i].runtime;
			ins >> database[i].category;
			ins >> database[i].numcopies;
		}
		ins.close();
		return true;
	}
	ins.close();
	return false;

}


bool SaveRecords(const char filename[])
{
	ofstream outs;
	
	if (numrecords == 0)
		return false;
		
	outs.open(filename);
	
	if (outs.good())
	{
		int i = 0;
		outs << numrecords << endl;
		while(i < numrecords)
		{
			PrintRecords(outs, i);
			i++;
		}
		outs.close();
		return true;
	}
	else
		return false;
}

bool FindRecord(const char key[])
{
	int i = 0;
	while (i < numrecords)
	{
		if (strcmp(key, database[i].title) == 0)
		{
			PrintRecords(cout, i);
			return true;
		}
		else
			i++;
	}
	return false;
}

void PrintRecords(ostream& outs, int i)
{
		outs << database[i].title << endl;
		outs << database[i].barcode << endl;
		outs << database[i].runtime << endl;
		outs << database[i].category << endl;
		outs << database[i].numcopies << endl;
}

void PrintAll()
{
	for (int i = 0; i < numrecords; i++)
	{
		cout << "Printing Record " << i + 1 << endl;
		cout << database[i].title << endl;
		cout << database[i].barcode << endl;
		cout << database[i].runtime << endl;
		cout << database[i].category << endl;
		cout << database[i].numcopies << endl;
		cout << endl;
	}
}
#include <iostream>
#include <fstream>
using namespace std;

const int MAXTITLE = 100;
const int MAXCATEGORY = 50;
const int MAXNAME = 100;

// data structure describing a movie

struct book
{
	char Title[MAXTITLE+1];
	char CallNumber;
	char Author;
	char category[MAXCATEGORY+1];
	int BookStatus;
	char DueDate;
	Char Borrowersname[MAXNAME+1];
};

bool Loadrecords(const char);
bool SaveRecords(const char);
bool FindRacords(const char);
void DisplayRecords(ostream& outs, int i);
void ChangeStatus(ostream& outs, int i);
void PrintAll();
001.645.2
Learning C++
Gregory	Harrison
1
001.721.3
C++ for Beginners
Quentin	Resnick
2
25 9 1999
Me
001.384.2
C++ Tools
Kieren Legrande
1
001.098.5
Learning C++ in 7 days
Yolanda	Zefirovic
1
001.491.8
C++ for C Programmers
Christopher Davenport
3
001.967.2
Effective C++ 
Xavier Williams
2
12 7 2006
Jack Murphy
001.077.4
C++ Handbook
Erica Forsythe
2
22 9 1999
Fred Flynn
001.947.2
Teach Yourself C++
Anna Baker
1
001.997.1
Borland C++
Owen Porter
2
1 10 1999
Sue Baker
001.095.3
Symantic C++
Uriah VanDenBerg
1
001.823.8
C++ Examples
Imran Jabeil
2
23 11 1998
John Jones
001.812.9
C++ Guidelines
Salvatore Torelli
1
005.920.4
C++ Development Environments
Minh Nguyen
1
/****************************************************************
 * main.cpp - CSCI124/MCS9124 - Ass1 - Contains main() for library database
 * <Name - Login - data>
 * Do not alter this file
 ****************************************************************/
#include <iostream>
#include "ass1.h"
using namespace std;

void PrintMenu();

int main()
{
	bool Proceed = true;
		
	LoadRecords();
	PrintMenu();
	while (Proceed)
	{
		char Command;
		cout << "Enter command (or m for menu): ";
		cin >> Command;
		cin.ignore();
		switch (Command)
		{
			case 'l': case 'L':
				LoadRecords();	// Loads records from data file
				break;
			case 's': case 'S':
				SaveRecords();  //Saves records to the data file 
				break;
			case 'f': case 'F':
				FindRecord();	// Asks user for book's Call number and 						// displays found record on screen
				break;
			case 'd': case 'D':
				DisplayRecords(); // Display all books on screen one at 						  // a time
				break;
			case 'c': case 'C':
				ChangeStatus();	// Asks user for book's Call number and
                            			// changes records status
                            			// If status is changed to OnLoan
                            			// the due date and borrowers name
                            			// are also requested and changed 
				break;
			case 'm': case 'M':
				PrintMenu();
				break;
			case 'q': case 'Q':
				Proceed = false;
				break;
			default:
				cerr << "Illegal command. Try again." << endl;		
		}
	}
	cout << "Quitting Program!" << endl;
	SaveRecords();
	return 0;
}

void PrintMenu()
{
 	cout << "Valid Commands:\n"
	     << "  (L)oad Records from file\n"
	     << "  (S)ave Records to file\n"
	     << "  (F)ind Book's Record\n"
	     << "  (D)isplay all Books\n"
	     << "  (C)hange Book's Status\n"
	     << "  (M)enu Display\n"
	     << "  (Q)uit\n\n";
}
CC=g++

all:	ass1

ass1:	main.o ass1.o
	$(CC) main.o ass1.o -o ass1

main.o:	main.cpp ass1.h
	$(CC) -c main.cpp

ass1.o:	ass1.cpp ass1.h
	$(CC) -c ass1.cpp

no, we're not going to do that. We're certainly not going to sheepishly compile and run your code and fix it for you.

well it was worth a try

i fixed it all now anyhow, except one thing, my makefile.

CC=g++

all:	ass1

ass1:	main.o ass1.o
	$(CC) main.o ass1.o -o ass1

main.o:	main.cpp ass1.h
	$(CC) -c main.cpp

ass1.o:	ass1.cpp ass1.h
	$(CC) -c ass1.cpp

there it is, and here is the error (im using SSH to compile with, its connected to uni servers running ubuntu)

$ make
make: Fatal error in reader: Makefile, line 3: Unexpected end of line seen

Try this

CC=g++
 
ass1:	main.o ass1.o
	$(CC) main.o ass1.o -o ass1
 
main.o:	main.cpp ass1.h
	$(CC) -c main.cpp
 
ass1.o:	ass1.cpp ass1.h
	$(CC) -c ass1.cpp

still not working, error got bigger


mksh: Warning: newline is not last character in file Makefile
Current working directory /home/ug/q/nt647
make: Fatal error in reader: Makefile, line 3: Unexpected end of line seen

Try implicit rules

CC = g++
 
ass1: main.o ass1.o
	$(CC) main.o ass1.o -o ass1
 
main.o:	main.cpp ass1.h
 
ass1.o:	ass1.cpp ass1.h

I just downloaded your files(.cpp & .h) and tried the Makefile. Makefile just works fine. The problem is with your codes.

??

that code there btw is out of date, i have almost completly re-written it all, (except the main.cpp)

i put all my code into one file and compiled it and it worked fine (my new stuff) but when i split it again, for the makefile to do its job, it didnt complie

Post your corrected codes(all .cpp and .h files). I will try them at my end with the Makefile.

ok, i got my makefile working, but there seems to still be an error that i cant find , int he code itself, if possible could you see if you could find it ?

dont forget to change the makefile.txt back to makefile (just a reminder :P )

the error im getting now is

main.cpp:1: error: stray '\239' in program
main.cpp:1: error: stray '\187' in program
main.cpp:1: error: stray '\191' in program

Attachments
/****************************************************************
 * ass1.cpp - Contains the functions                            *
 * <Nicholas Tsaoucis - nt647>                                  *
 ****************************************************************/
#include <iostream>
#include <fstream>
#include <cstring>
#include "ass1.h"
using namespace std;

char* GetBooktatus (unsigned);
void LoadRecords();
int calculateNumRecords();
void convert();
void SaveRecords();
void FindRecord();
void DisplayAllRecords();
void ChangeStatus();
void DisplaySingleRecord (Book &book);
int Seek( char *searchKey);

void convert()
{
	cout << endl;
     int i = 1;
     Book temp;
     fstream textFile;
     ofstream dataFile;
     textFile.open("ass1.txt", ios::in);
     if (textFile.fail())
     {
        cout << "Could not open \"ass1.txt\". Closing Program" << endl;
        exit(1);
     }
     
     dataFile.open("ass1.dat", ios::out | ios:: binary);
	 while(!textFile.eof() && i <100)
	{
        cout << "Writing Record Number: " << i <<endl;
        memset (&temp, '\0', sizeof (Book));
		textFile.getline ( temp.CallNo, MAX_CALL);
		if (strlen (temp.CallNo) == 0)
		{
		
			break;
		}
		textFile.getline(temp.Title, MAX_TITLE);
		textFile.getline(temp.Author, MAX_AUTHOR);
		textFile >> temp.Status;
		textFile.ignore (1);
		if (temp.Status == 2)
		{
    		textFile.getline (temp.Date, MAX_DATE);
    		textFile.getline(temp.Borrower, MAX_BORROWER);
        }
		dataFile.write((char*)&temp, sizeof(Book));
		i++;
	}
	if (i == 100)
       cout << "Limit Reached!!!" << endl;
    else
	    cout << "Finished Writing all recoreds from \"ass1.txt\" to \"ass1.dat\"." << endl << endl;
	textFile.close();
	dataFile.close();
	
	cout << endl;
     
 }

char* GetBooktatus (unsigned Status)
{
	switch (Status)
	{
	case 1: 
		return "In Library";
	case 2: 
		return "On Loan";
	case 3: 
		return "Lost";
	default:
		return "Unknown Status: ";
	}	
}

void DisplaySingleRecord (Book &book)
{
	cout << endl << "Call Number: ";
	cout << book.CallNo << endl;
	cout << "Title: ";
	cout << book.Title << endl;
	cout << "Author: ";
	cout << book.Author << endl;
	cout << "Status: ";
	cout << GetBooktatus (book.Status) << endl;
	if (2== book.Status)
	{
		cout << "Due Date: ";
		cout << book.Date << endl;
		cout << "Borrower: ";
		cout << book.Borrower << endl;
	}
	cout << endl;
}

void DisplayAllRecords()
{
	bool proceed = true;
	char option;
	for (int i = 0; i < bookToal && proceed; i++)
	{
		DisplaySingleRecord (dbBook[i]);

		do
		{
			cout << "Display next record?(y/n)" << endl;
			cin >> option;
			option = tolower (option);

			if (option == 'y')
			{
				proceed = true;
			}
			else if (option == 'n')
			{
				proceed = false;
			}
		}while(option != 'n' && option != 'y');
	}
	cout << endl << "Finished Printing" << endl;
}

void ChangeStatus()
{
	bool ok = true;
	Book temp;
	unsigned newStatus;
	fstream dataFile;

	dataFile.open("ass1.dat", ios::in | ios::out | ios::binary);
	if (dataFile.fail())
	{
		cout << "Error: failed to change Status - ass1.dat failed to open" << endl;
		return;
	}
	else
	{
		char searchKey [100];
		cout << "Enter the call number of the book for which you are searching for" << endl;
		cin.getline(searchKey, 100);
		int position = Seek(searchKey);
		if (position < 0)
		{
			cout << "" << endl;
			ok = false;
		}
		else
		{
			dataFile.seekg(position);
			dataFile.read((char*)&temp, sizeof(Book));
			if (0 == strcmp (temp.CallNo, searchKey))			{
				
				cout << "What is the new book Status? (1=In Library, 2 = On loan, 3 = Lost): ";
				cin >> newStatus;
				cin.ignore();
				if (1 == newStatus)
				{
					cout << "Status Changed to \"In Library\"." << endl;
					temp.Status = 1;
				}
				else if (2 == newStatus)
				{
					cout << " Status Changed to \"On Loan\"." << endl;
					temp.Status = 2;
					cout << "When is the book due? (DD MM YY): ";
					cin.getline(temp.Date, MAX_DATE);
					cout << "Who borrowed the book? ";
					cin.getline(temp.Borrower, MAX_BORROWER);
				}
				else if (3 == newStatus)
				{
					cout << " Status Changed to \"Lost\"." << endl;
					temp.Status = 3;
				}
				else
				{
					cout << "in valid option." << endl;
					ok = false;				}
				if (ok)
				{
					dataFile.seekg(position);
					if (dataFile.fail ())
					{
						cout << "Error: failed to find " << position << endl;
						ok = false;
					}
					else
					{
						dataFile.write((char*)&temp, sizeof(Book));

						if (dataFile.fail ())
						{
							cout << "Error: failed to upDate Status " << endl;
							ok = false;
						}
					}
				}
			}

		}
		dataFile.close();

		if (ok )
		{
			cout << "Refreshing local cache ..." << endl;
			LoadRecords();
		}
	}
}

int Seek( char *searchKey)
{
	cout << endl;
	int position;
	Book bookDB;
	bool found = false;
	fstream dataFile;
	dataFile.open("ass1.dat", ios::in | ios::binary);
	if (dataFile.fail())
	{
		cout << "Error opening \"ass1.dat\"." << endl;
		return -1;
	}

	for (int i = 0; i < bookToal && found == false; i++)
	{
		position = dataFile.tellg();
		dataFile.read((char*)&bookDB, sizeof(Book));
		if (strcmp(bookDB.CallNo, searchKey) == 0)
		{
			cout << "Record Found at position " << position << endl;
			DisplaySingleRecord (bookDB);
			found = true;
			break; 
		}

	}
	if (false == found)
	{
		cout << "Record not found." << endl;
		position = -1; // -1 means not found
	}
	dataFile.close ();
	return position;
	cout << endl;
}

void LoadRecords()
{
	cout << endl;
    fstream dataFile;
    dataFile.open("ass1.dat", ios::in | ios:: binary);
    if (dataFile.good())
    {
       int count = 0;
       int numrecords = 0;
       cout << "ass1.dat was opened successfully" << endl;

       numrecords = calculateNumRecords();
       while (count < numrecords)
       {
             dataFile.read((char*)&dbBook[count], sizeof(Book));
             count ++;
       }
	   bookToal = count;
       dataFile.close();
       
       
       
    }
    else
    {
        cout << "\"ass1.dat\" failed to open, recreating \"ass1.dat\" from \"ass1.txt\" now" << endl;
        // dataFile.close();
        convert();
    }
   	cout << endl; 
}

int calculateNumRecords()
{
	cout << endl;
     int totalSize = 0;
     int numrecords;
     fstream dataFile;
     dataFile.open("ass1.dat", ios::in | ios::binary);
     dataFile.seekg(0, ios::end);
     totalSize = dataFile.tellg();
     numrecords = totalSize / sizeof(Book);
     dataFile.close();
     cout << "Number of records is: " << numrecords <<endl;
     return numrecords;
	 cout << endl;
 }

void SaveRecords()
{
	cout << endl;
	fstream dataFile;
	dataFile.open("ass1.dat", ios::out | ios::binary);
	if (dataFile.fail())
		cout << "Error creating \"ass1.dat\". " << endl;
	else
	{
		for (int i = 0; i < bookToal; i++)
		{
			dataFile.write((char*)&dbBook[i], sizeof(Book));
			if (!dataFile)
			{
				cout << "Error writing." << endl;
				break;
			}
		}
		
		dataFile.close();
	}
	cout << endl;
}
 
void FindRecord()
{
	cout << endl;
     char searchKey[100];
     bool found = false;
     cout << "Enter the call number of the book:" << endl;
     cin.getline(searchKey, 100);

	 for (int i = 0; i < bookToal && found == false; i++)
	 {
          if (strcmp(dbBook[i].CallNo, searchKey) == 0)
          {
             cout << "Record Found:" << endl;
			  DisplaySingleRecord (dbBook[i]);
             found = true;
          }

      }
      if (false == found)
      {
         cout << "Record not found." << endl;
      }
	  cout << endl;
}
/****************************************************************
 * ass1.h - headerfile                                          *
 * <Nicholas Tsaoucis - nt647>                                  *
 ****************************************************************/
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

const int MAX_TITLE = 50;
const int MAX_AUTHOR = 50;
const int MAX_BORROWER = 50;
const int MAX_DATE = 50;
const int MAX_CALL = 50;
const char onLoan = '2';

struct Book
{
	char CallNo[MAX_CALL + 1];
	char Title[MAX_TITLE+1];
	char Author[MAX_AUTHOR+1];
	unsigned Status;
	char Date[MAX_DATE+1];
	char Borrower[MAX_BORROWER + 1];
};

static Book dbBook[100];
static int bookToal;

void PrintMenu();
char* GetBooktatus (unsigned);
void LoadRecords();
int calculateNumRecords();
void convert();
void SaveRecords();
void FindRecord();
void DisplayAllRecords();
void DisplayRecords();
void ChangeStatus();
void DisplaySingleRecord (Book &book);
int Seek( char *searchKey);
001.645.2
Learning C++
Gregory	Harrison
1
001.721.3
C++ for Beginners
Quentin	Resnick
2
25 9 1999
Me
001.384.2
C++ Tools
Kieren Legrande
1
001.098.5
Learning C++ in 7 days
Yolanda	Zefirovic
1
001.491.8
C++ for C Programmers
Christopher Davenport
3
001.967.2
Effective C++ 
Xavier Williams
2
12 7 2006
Jack Murphy
001.077.4
C++ Handbook
Erica Forsythe
2
22 9 1999
Fred Flynn
001.947.2
Teach Yourself C++
Anna Baker
1
001.997.1
Borland C++
Owen Porter
2
1 10 1999
Sue Baker
001.095.3
Symantic C++
Uriah VanDenBerg
1
001.823.8
C++ Examples
Imran Jabeil
2
23 11 1998
John Jones
001.812.9
C++ Guidelines
Salvatore Torelli
1
005.920.4
C++ Development Environments
Minh Nguyen
1
/****************************************************************
 * main.cpp - CSCI124/MCS9124 - Ass1 - Contains main() for library database
 * <Name - Login - data>
 * Do not alter this file
 ****************************************************************/
#include <iostream>
#include "ass1.h"
using namespace std;

void PrintMenu();

int main()
{
	bool Proceed = true;
		
	LoadRecords();
	PrintMenu();
	while (Proceed)
	{
		char Command;
		cout << "Enter command (or m for menu): ";
		cin >> Command;
		cin.ignore();
		switch (Command)
		{
			case 'l': case 'L':
				LoadRecords();	// Loads records from data file
				break;
			case 's': case 'S':
				SaveRecords();  //Saves records to the data file 
				break;
			case 'f': case 'F':
				FindRecord();	// Asks user for book's Call number and 						// displays found record on screen
				break;
			case 'd': case 'D':
				DisplayRecords(); // Display all books on screen one at 						  // a time
				break;
			case 'c': case 'C':
				ChangeStatus();	// Asks user for book's Call number and
                            			// changes records status
                            			// If status is changed to OnLoan
                            			// the due date and borrowers name
                            			// are also requested and changed 
				break;
			case 'm': case 'M':
				PrintMenu();
				break;
			case 'q': case 'Q':
				Proceed = false;
				break;
			default:
				cerr << "Illegal command. Try again." << endl;		
		}
	}
	cout << "Quitting Program!" << endl;
	SaveRecords();
	return 0;
}

void PrintMenu()
{
 	cout << "Valid Commands:\n"
	     << "  (L)oad Records from file\n"
	     << "  (S)ave Records to file\n"
	     << "  (F)ind Book's Record\n"
	     << "  (D)isplay all Books\n"
	     << "  (C)hange Book's Status\n"
	     << "  (M)enu Display\n"
	     << "  (Q)uit\n\n";
}
CC=g++

all:	ass1

ass1:	main.o ass1.o
	$(CC) main.o ass1.o -o ass1

main.o:	main.cpp ass1.h
	$(CC) -c main.cpp

ass1.o:	ass1.cpp ass1.h
		$(CC) -c ass1.cpp

ok, fixed, that, now this error instead :"(


$ make
g++ -c main.cpp
g++ -c ass1.cpp
g++ main.o ass1.o -o ass1
Undefined first referenced
symbol in file
DisplayRecords() main.o
ld: fatal: Symbol referencing errors. No output written to ass1
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `ass1'


use that main

Attachments
/****************************************************************
 * main.cpp - CSCI124/MCS9124 - Ass1 - Contains main() for library database
 * <Name - Login - data>
 * Do not alter this file
 ****************************************************************/
#include <iostream>
#include "ass1.h"
using namespace std;

void PrintMenu();

int main()
{
	bool Proceed = true;
		
	LoadRecords();
	PrintMenu();
	while (Proceed)
	{
		char Command;
		cout << "Enter command (or m for menu): ";
		cin >> Command;
		cin.ignore();
		switch (Command)
		{
			case 'l': case 'L':
				LoadRecords();	// Loads records from data file
				break;
			case 's': case 'S':
				SaveRecords();  //Saves records to the data file 
				break;
			case 'f': case 'F':
				FindRecord();	// Asks user for book's Call number and 						// displays found record on screen
				break;
			case 'd': case 'D':
				DisplayRecords(); // Display all books on screen one at 						  // a time
				break;
			case 'c': case 'C':
				ChangeStatus();	// Asks user for book's Call number and
                            			// changes records status
                            			// If status is changed to OnLoan
                            			// the due date and borrowers name
                            			// are also requested and changed 
				break;
			case 'm': case 'M':
				PrintMenu();
				break;
			case 'q': case 'Q':
				Proceed = false;
				break;
			default:
				cerr << "Illegal command. Try again." << endl;		
		}
	}
	cout << "Quitting Program!" << endl;
	SaveRecords();
	return 0;
}


void PrintMenu()
{
 	cout << "Valid Commands:\n"
	     << "  (L)oad Records from file\n"
	     << "  (S)ave Records to file\n"
	     << "  (F)ind Book's Record\n"
	     << "  (D)isplay all Books\n"
	     << "  (C)hange Book's Status\n"
	     << "  (M)enu Display\n"
	     << "  (Q)uit\n\n";
}

That's a linker error. It seems that you don't have defination of DisplayRecords() .

yea, i jsut had a thoroguh read of it, and found teh problem, please come and shoot me where i stand

DisplayRecord();
DisplayRecords();

i mixed it up in one spot :)

the makefile problems i was haveing seemed to be coming from invisible characters, i got my mate to retype on on his linux and send to me and i used that fine

but yea mate, thnx again for ur help

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