| | |
Trouble getting code to compile
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
I'm a newie and am in the process of trying to develop a book store as part of a class project. I would greatly appreciate any assistance that may be offered my way. Please do not give me any answers, but if you have any suggestions that may nudge me in the right direction I would be thankful. I must store the inventory of the books in an array of classes. Here is the code I have written so far.
As of now, I'm not able to get it to compile, because of the 4 errors listed below.
(80) : error C2660: 'CBooks::inputBooks' : function does not take 0 arguments
(100) : error C2660: 'CBooks::displayBooks' : function does not take 0 arguments
(155) : error C2511: 'void CBooks::inputBooks(void)' : overloaded member function not found in 'CBooks'
d:\My Documents\Visual Studio Projects\Book Store\Test.cpp(9) : see declaration of 'CBooks'
(177) : error C2511: 'void CBooks::displayBooks(void)' : overloaded member function not found in 'CBooks'
d:\My Documents\Visual Studio Projects\Book Store\Test.cpp(9) : see declaration of 'CBooks'
Thanks in advance for any guidance offered.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include <string> #define MAX 100 //Maximum number of books in inventory array using namespace std; class CBooks //Class definition { public: //Constructor CBooks(string bookName = "0", string author = "0", int isbn = 000000000, float price = 0.00): _bookName(bookName), _author(author), _isbn(isbn), _price(price){} //Destructor ~CBooks(){}; //Functions void inputBooks(string bookName, string author, int isbn, float price); void displayBooks(string bookName, string author, int isbn, float price); private: string _bookName; //Name of book string _author; //Author of book int _isbn; //ISBN of book float _price; //Price of book }inventory[MAX]; //Array of class objects //Functions double getProfit(double doublePrice); void viewProfit(); int current; //Used to count number of books in inventory double netProfit = 0; //Main Function int main() { //Declare variables int x = 0, transaction, another = 2, choice; double bookProfit, priceArray[99]; string seller, password, bookInfo[99]; while (another != 1) { system("CLS"); //display section header cout << "***********************\n"; cout << "*Team A Book Inventory*\n"; cout << "***********************\n\n"; cout << "Please type the number of the desired action and press <ENTER>:\n" ; cout << "1. Buy\n"; cout << "2. Sell\n"; cout << "3. View Profit\n"; cin >> transaction; cin.ignore(); //statement is necessary in order to make cin.getline() to work properly. //Tells cin to ignore the line feed at the end of input //code to view profit if (transaction == 3) { viewProfit(); } // code to sell a textbook if (transaction == 2) { if (x<=99) { system("CLS"); //display section header cout << "***********\n"; cout << "*Sell Book*\n"; cout << "***********\n\n"; CBooks::inputBooks(); x++; } else { cout << "I'm sorry, the database cannot hold any more books.\n"; //print if more then 100 books in inventory } } //code to buy book if (transaction == 1) { system("CLS"); //clear screen //display section header cout << "**********\n"; cout << "*Buy Book*\n"; cout << "**********\n\n"; cout << "Book Name " << "Book Author " << "ISBN " << "Price\n"; //print buy header cout << "--------- " << "----------- " << "---- " << "-----\n\n"; //print buy header CBooks::displayBooks(); cout << "\nPlease enter the number of the book you would like to buy:\n"; cin >> choice; //the number choosen cout << "Thank you for your purchase!\n\n"; bookProfit = getProfit(priceArray[choice-1]); //call function to figure out profit of the book netProfit += bookProfit; //add book profit to total profit bookInfo[choice-1] = "SOLD"; //over write selection with the word SOLD priceArray[choice-1] = 0; //right 0 to element } cout << "\nPlease type the number of the desired action and press <ENTER>:\n"; //print option make another trans cout << "1. Quit program\n"; //quit program cout << "2. Make another transaction\n"; //make another trans cin >> another; //get answer if (another == 1) //check if user selected exit { cout << "WARNING!! Data will be lost if program is exited. Are you sure you want to exit?\n"; //print warning about loosing data cout << "1. Yes, please exit.\n"; cout << "2. No, stay in program.\n"; cin >> another; //get answer again } } return 0; } //Checks password and diplays profit void viewProfit() { string password; system("CLS"); //display header section cout << "*************\n"; cout << "*View Profit*\n"; cout << "*************\n\n"; cout << "Please type your password:\n"; cin >> password; if (password == "upwd") //check password { cout << "Profit = $" << netProfit << "\n"; } else { cout << "Invalid password.\n"; } system("PAUSE"); } //Input books into inventory function void CBooks::inputBooks() { cout << "Please enter the book's name: \n"; cin.getline(bookName, 64); _bookName = bookName; cout << "Please enter the book's author: \n"; cin.getline(author, 64); _author = author; cout << "Please enter the book's ISBN: \n"; cin.getline(isbn, 10); cin.ignore(); _isbn = isbn; cout << "Please enter the desired price: \n"; cin >> price; cin.ignore(); _price = price; //Increments the number of books entered into inventory current++; cout << "There are now " << current << "books for in our inventory."; } //Diplay books in inventory function void CBooks::displayBooks(void) { int loop; //Display all of the books in inventory for (loop = 0; loop < 99; loop++) { cout << inventory[loop].bookName; cout << inventory[loop].author; cout << inventory[loop].isbn; cout << inventory[loop].price; } } //Calculates the 10% profit and pass to called instance double getProfit(double doublePrice) { return doublePrice*.1; }
As of now, I'm not able to get it to compile, because of the 4 errors listed below.
(80) : error C2660: 'CBooks::inputBooks' : function does not take 0 arguments
(100) : error C2660: 'CBooks::displayBooks' : function does not take 0 arguments
(155) : error C2511: 'void CBooks::inputBooks(void)' : overloaded member function not found in 'CBooks'
d:\My Documents\Visual Studio Projects\Book Store\Test.cpp(9) : see declaration of 'CBooks'
(177) : error C2511: 'void CBooks::displayBooks(void)' : overloaded member function not found in 'CBooks'
d:\My Documents\Visual Studio Projects\Book Store\Test.cpp(9) : see declaration of 'CBooks'
Thanks in advance for any guidance offered.
Change
to
in the Class declaration.
C++ Syntax (Toggle Plain Text)
//Functions void inputBooks(string bookName, string author, int isbn, float price); void displayBooks(string bookName, string author, int isbn, float price);
to
C++ Syntax (Toggle Plain Text)
//Functions void inputBooks(); void displayBooks();
Well, I've made some progress. At least, I think I have since I'm finally able to get it to compile. Now I'm getting two lnk errors that I don't have a clue what to do with. This is my code now that I've made some alterations to it.
The two errors I'm receiving now are:
Linking...
Test.obj : error LNK2019: unresolved external symbol "public: __thiscall CBooks::CBooks(void)" (??0CBooks@@QAE@XZ) referenced in function _$E1
Debug/Book Store.exe : fatal error LNK1120: 1 unresolved externals
I've been scouring the message boards trying to find some guidance on these error codes, but haven't come up with anything useful yet. Any suggestions would be greatly appreciated. Thanks.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include <string> #define MAX 100 //Maximum number of books in inventory array using namespace std; class CBooks //Class definition { public: //Constructor CBooks(); //Destructor ~CBooks(){}; //Functions void inputBooks(void); void displayBooks(void); private: string m_bookName; //Name of book string m_author; //Author of book int m_isbn; //ISBN of book float m_price; //Price of book }inventory[MAX]; //Array of class objects //Functions double getProfit(double doublePrice); void viewProfit(); int current; //Used to count number of books in inventory double netProfit = 0; //Main Function int main() { //Declare variables int x = 0, transaction, another = 2, choice; double bookProfit, priceArray[99]; string seller, password, bookInfo[99]; while (another != 1) { system("CLS"); //display section header cout << "***********************\n"; cout << "*Team A Book Inventory*\n"; cout << "***********************\n\n"; cout << "Please type the number of the desired action and press <ENTER>:\n" ; cout << "1. Buy\n"; cout << "2. Sell\n"; cout << "3. View Profit\n"; cin >> transaction; cin.ignore(); //statement is necessary in order to make cin.getline() to work properly. //Tells cin to ignore the line feed at the end of input //code to view profit if (transaction == 3) { viewProfit(); } // code to sell a textbook if (transaction == 2) { if (x<=99) { system("CLS"); //display section header cout << "***********\n"; cout << "*Sell Book*\n"; cout << "***********\n\n"; inventory[x].inputBooks(); x++; } else { cout << "I'm sorry, the database cannot hold any more books.\n"; //print if more then 100 books in inventory } } //code to buy book if (transaction == 1) { system("CLS"); //clear screen //display section header cout << "**********\n"; cout << "*Buy Book*\n"; cout << "**********\n\n"; cout << "Book Name " << "Book Author " << "ISBN " << "Price\n"; //print buy header cout << "--------- " << "----------- " << "---- " << "-----\n\n"; //print buy header inventory[x].displayBooks(); cout << "\nPlease enter the number of the book you would like to buy:\n"; cin >> choice; //the number choosen cout << "Thank you for your purchase!\n\n"; bookProfit = getProfit(priceArray[choice-1]); //call function to figure out profit of the book netProfit += bookProfit; //add book profit to total profit bookInfo[choice-1] = "SOLD"; //over write selection with the word SOLD priceArray[choice-1] = 0; //right 0 to element } cout << "\nPlease type the number of the desired action and press <ENTER>:\n"; //print option make another trans cout << "1. Quit program\n"; //quit program cout << "2. Make another transaction\n"; //make another trans cin >> another; //get answer if (another == 1) //check if user selected exit { cout << "WARNING!! Data will be lost if program is exited. Are you sure you want to exit?\n"; //print warning about loosing data cout << "1. Yes, please exit.\n"; cout << "2. No, stay in program.\n"; cin >> another; //get answer again } } return 0; } //Checks password and diplays profit void viewProfit() { string password; system("CLS"); //display header section cout << "*************\n"; cout << "*View Profit*\n"; cout << "*************\n\n"; cout << "Please type your password:\n"; cin >> password; if (password == "upwd") //check password { cout << "Profit = $" << netProfit << "\n"; } else { cout << "Invalid password.\n"; } system("PAUSE"); } //Input books into inventory function void CBooks::inputBooks(void) { cout << "Please enter the book's name: \n"; cin >> m_bookName; cout << "Please enter the book's author: \n"; cin >> m_author; cout << "Please enter the book's ISBN: \n"; cin >> m_isbn; cin.ignore(); cout << "Please enter the desired price: \n"; cin >> m_price; cin.ignore(); //Increments the number of books entered into inventory current++; cout << "There are now " << current << "books for in our inventory."; } //Diplay books in inventory function void CBooks::displayBooks(void) { int loop; //Display all of the books in inventory for (loop = 0; loop < 99; loop++) { cout << inventory[loop].m_bookName; cout << inventory[loop].m_author; cout << inventory[loop].m_isbn; cout << inventory[loop].m_price; } } //Calculates the 10% profit and pass to called instance double getProfit(double doublePrice) { return doublePrice*.1; }
The two errors I'm receiving now are:
Linking...
Test.obj : error LNK2019: unresolved external symbol "public: __thiscall CBooks::CBooks(void)" (??0CBooks@@QAE@XZ) referenced in function _$E1
Debug/Book Store.exe : fatal error LNK1120: 1 unresolved externals
I've been scouring the message boards trying to find some guidance on these error codes, but haven't come up with anything useful yet. Any suggestions would be greatly appreciated. Thanks.
•
•
•
•
Originally Posted by WolfPack
Do this
//Constructor CBooks(){};
You hadn't defined the Constructor. Only declared it.
CBooks(){};[/CODE]
![]() |
Similar Threads
- visual c++ strange compile error... (C++)
- Odd/Even Code (Java)
- LC3 Calculator (Assembly)
- trouble with c++ code (C++)
Other Threads in the C++ Forum
- Previous Thread: Getline help!
- Next Thread: Global Variables
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






