Beginner Having errors please help I have been working for days and am stuck!

Library.cpp

#include <iostream>
#include <fstream>
#include <iomanip>
#include "card.h"
#include "book.h"

using namespace std;

void CheckOut(Card c[], book b[], int, int);
void ShowMenu();
int CreateCard(Card cards[], int numCards);
void PrintAllCards(Card cards[], int numCards);
void PrintAllBooks ( book books[], int numBooks);
void CheckIn(Card c[],book b[], int, int);

int main()
{
int numBooks = 0;
int numCards = 0;
int i = 0, j = 0;
int command = 0;


// declare an array of 20 cards
Card cards[20];

// declare an array of 20 books
book books[20];

// declare a file pointer and open the cards file
ifstream cardInput("cards.txt");
if (!cardInput)
{
cout << "File cards.txt could not be openned. Fatal Error" << endl;
exit(1);
}
cout << "File openned. Reading cards..." << endl;

// read the next line from the file
char name[15];
char junk[5];
char phone[14];
int cardID = 0;
int temp = 0;

cardInput.getline(name, 13, ',');
while (cardInput)
{
cardInput.getline(name, 13, ',');
cardInput.getline(junk, 5, ',');
cardInput.getline(phone, 12, ',');
cardInput.getline(junk, 5, ',');
cardInput >> cardID >> temp;

Card working(name, phone, cardID);
cards[i] = working;
i++;

}
cardInput.close();
// tokenize the line to get the data for class variables
ifstream BookInput("books.txt");
if (!BookInput)
{
cout << "File books.txt could not be openned. Fatal error." << endl;
exit(1);
}

cout << "File opened. Reading Books File...." << endl;

char Title[30];
char Junk[5];
char Author[10];
int BookID = 0;
int Temp = 0;

BookInput.getline(Title, 13, ',');
while (BookInput)
{
BookInput.getline(Title, 30, ',');
BookInput.getline(Junk, 5, ' ');
BookInput.getline(Author, 10, ',');
BookInput.getline(Junk, 5, ' ');

BookInput >> BookID >> Temp;

book working(BookID, Title, Author);
books[i] = working;
i++;
}
BookInput.close();

// display main menu
do{
ShowMenu();
cin >> command;
// execute the appropriate command
switch (command){
case 0:
break;
case 1:
// call function to print all cards
PrintAllCards(cards, numCards);
break;
case 2:
// call functions to print all books
PrintAllBooks(books, numBooks);
break;
case 3:
// call to check out book
CheckOut(cards, books, numCards, numBooks);
break;
case 4:
// call to check in book
CheckIn;
break;
case 5:
// create new library cards
numCards = CreateCard(cards, numCards);
break;
default:
cout << "INVALID. Menu choices must be btween 0 and 5.";
}
ShowMenu();
while (command != 0)
{

}



void ShowMenu();
{

cout << " ------------------------------------- " << endl << endl;
cout << "1. Show all Library Cards " << endl;
cout << "2. Show all Books " << endl;
cout << "3. Check out a Book " << endl;
cout << "4. Check in a Book " << endl;
cout << "5. Create a new Library Card " << endl;
cout << "0. Exit the system " << endl << endl;
}


int CreateCard(Card cards[], int numCards);
{

char name[30];
char phone[20];
int cardID = 0;

// add 1 to CardID to get ne CardID
cout << "Enter the Card ID: ";
cin >> cardID;

// ask for name
cout << "Enter your Name: ";
cin >> name;

// ask for phone number
cout << "Enter your Phone Number: ";
cin >> phone;

// create a card
Card temp(name, phone, cardID);

// copy to arrau
cards[numCards] = temp;
numCards++;
return numCards;
}

void CheckOut(Card cards[], book books[], int numBooks, int numCards);
{
int c = 0, b = 0, nCard = 0, nBook = 0;

cout << "Enter a card to search for: ";
cin >> nCard;

while (c < numCards && nCard != cards[c].getCardID())
{
c++;
}
if (c == numCards)
{
cout << "Card not Found! Create a new card and try again" << endl;
return 0;
}

cout << "Card found for ";
cards[c].printName();
cout << "!" << endl;

if (cards[c].getCardID() != 0)
{
cout << "HOWEVER... You have not returned your last book." << endl;
return 0;
}

cout << "Enter the Book ID : ";
cin >> nBook;

while (b < numBooks && nBook != books[b].getBookID())
{
b++;
}

if (b == numBooks)
{
cout << "Book Not Found or Already Checked Out!" << endl;
return 0;
}
if (books[b].getCardID() != 0)
{
cout << "Book Found! However... Someone has it checked out." << endl;
return 0;
}

// Yay!
cards[c].setBookID(nBook);
books[b].setCardID(nCard);

cout << "Book Checked Out." << endl;
cards[c].printName();
cout << "has book ";
books[b].getBookID();
cout << " ";
books[b].printTitle();
cout << endl;
return 0;
}

void PrintAllCards(Card cards[], int numCards);
{
int i = 0;

for (i = 0; i < numCards; i++)
{
cards[i].print();
}
void PrintAllBooks(book books[], int numBooks);
{
int j = 0;

for (j = 0; j < numBooks; j++)
books[j].print();
}
}
}
}

card.cpp

#include <iostream>
#include "card.h"
using namespace std;

Card::Card()
{
CardID = 0;
BookID = 0;
}

Card::Card(char n[], char p[], int c)
{
CardID = c;
strcpy(Name, n);
strcpy(Phone, p);
BookID = 0;
}

int Card::getCardID()
{
return CardID;
}

bool Card::hasBook()
{
if (BookID == 0)
return false;
else
return true;
}
void Card::checkOut(int b)
{
BookID = b;
}

void Card::checkIn()
{
CardID = 0;
}
void Card::print()
{
cout << CardID << " "
<< Name << " "
<< Phone << " "
<< BookID << endl;
}
void Card::printName()
{
cout << Name;
}

book.cpp

#include "book.h"
using namespace std;

book::book(int b, char t[], char a[])
{
BookID = b;
strcpy(Title, t);
strcpy(Author, a);
CheckedOut = false;
CardID = 0;

}
int book::getBookID()
{
return BookID;
}
bool book::isCheckedOut()
{
return CheckedOut;
}
void book::checkOut(int c)
{
CardID = c;
CheckedOut = false;
}

void book::print()
{


}
void book::printTitle()
{
cout << Title;

card.h

#ifndef Card_H

#define Card_H



class Card
{
private:
int CardID;
char Name[30];
char Phone[20];
int BookID;

public:
Card();
Card(char n[], char p[], int c);
int getCardID();
int getBookID();
int setBookID();
int c = 0;
void printName();
bool hasBook();
void checkOut(int b);
void checkIn();
void print();
};

#endif

book.h

#ifndef Book_H
#define Book_H


#include <iostream>
#include <iomanip>

class book
{
private:
int BookID;
char Title[30];
char Author[30];
bool CheckedOut;
int CardID;

public:
book();
book(int b, char t[], char a[]);
int getBookID();
int getCardID();
int setCardID();
int nCard = 0;
void printTitle();
bool isCheckedOut();
void checkOut(int c);
void checkIn();
void print();
};
#endif


Error 2 error C2664: 'Card::Card(const Card &)' : cannot convert argument 1 from 'int' to 'char []

Error 7 error C2660: 'Card::setBookID' : function does not take 1 arguments

Error 3 error C2660: 'book::setCardID' : function does not take 1 arguments

Error 4 error C2059: syntax error : '}'

Error 7 IntelliSense: expected 'while'

Error 5 IntelliSense: too many arguments in function call

Error 6 IntelliSense: too many arguments in function call

Warning 1 warning C4551: function call missing argument list


Last edited on
Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/


1
2
3
4
5
6
7
8
class Card
{
...
int setBookID();
int c = 0; // What is this supposed to be?
void printName();
...
};


1
2
3
4
5
6
7
8
9
10
11
// display main menu
do{ // -> do/while mismatch
...
switch (command){
..
}
ShowMenu();
while (command != 0) // <- This does not match do
{

}
Last edited on

Sorry, my teacher did not show us how to use tags, and the int c = 0; is not supposed to be there. I am new to this, and my teacher is not helping! My big problem is the expecting while, and Card::setBookID' : function does 'book::setCardID' : function does not take 1 arguments

Any help is greatly appreciated!
Sorry, my teacher did not show us how to use tags
But you can go to the provided link and read the content, don't you? (this site by the way doesn't have anything to do with your school)

My big problem is the expecting while, and Card::setBookID' : function does 'book::setCardID' : function does not take 1 arguments
change the function int setBookID(); to
1
2
3
4
5
6
7
8
void setBookID(int id);

...

void Card::setBookID(int id)
{
BookID = id;
}
The change you have to do for setCardID is almost identically
Topic archived. No new replies allowed.