Trouble getting code to compile

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2004
Posts: 12
Reputation: moznmar is an unknown quantity at this point 
Solved Threads: 0
moznmar's Avatar
moznmar moznmar is offline Offline
Newbie Poster

Trouble getting code to compile

 
0
  #1
Jan 15th, 2006
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.

  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #define MAX 100 //Maximum number of books in inventory array
  5.  
  6. using namespace std;
  7.  
  8. class CBooks //Class definition
  9. {
  10. public:
  11.  
  12. //Constructor
  13. CBooks(string bookName = "0", string author = "0", int isbn = 000000000,
  14. float price = 0.00): _bookName(bookName), _author(author),
  15. _isbn(isbn), _price(price){}
  16.  
  17. //Destructor
  18. ~CBooks(){};
  19.  
  20. //Functions
  21. void inputBooks(string bookName, string author, int isbn, float price);
  22. void displayBooks(string bookName, string author, int isbn, float price);
  23.  
  24. private:
  25. string _bookName; //Name of book
  26. string _author; //Author of book
  27. int _isbn; //ISBN of book
  28. float _price; //Price of book
  29. }inventory[MAX]; //Array of class objects
  30.  
  31. //Functions
  32. double getProfit(double doublePrice);
  33. void viewProfit();
  34.  
  35.  
  36. int current; //Used to count number of books in inventory
  37. double netProfit = 0;
  38.  
  39. //Main Function
  40. int main()
  41. {
  42.  
  43. //Declare variables
  44. int x = 0, transaction, another = 2, choice;
  45. double bookProfit, priceArray[99];
  46. string seller, password, bookInfo[99];
  47.  
  48. while (another != 1)
  49. {
  50. system("CLS");
  51. //display section header
  52. cout << "***********************\n";
  53. cout << "*Team A Book Inventory*\n";
  54. cout << "***********************\n\n";
  55.  
  56. cout << "Please type the number of the desired action and press <ENTER>:\n" ;
  57. cout << "1. Buy\n";
  58. cout << "2. Sell\n";
  59. cout << "3. View Profit\n";
  60. cin >> transaction;
  61. cin.ignore(); //statement is necessary in order to make cin.getline() to work properly.
  62. //Tells cin to ignore the line feed at the end of input
  63.  
  64. //code to view profit
  65. if (transaction == 3)
  66. {
  67. viewProfit();
  68. }
  69. // code to sell a textbook
  70. if (transaction == 2)
  71. {
  72. if (x<=99)
  73. {
  74. system("CLS");
  75. //display section header
  76. cout << "***********\n";
  77. cout << "*Sell Book*\n";
  78. cout << "***********\n\n";
  79.  
  80. CBooks::inputBooks();
  81. x++;
  82. }
  83. else
  84. {
  85. cout << "I'm sorry, the database cannot hold any more books.\n"; //print if more then 100 books in inventory
  86. }
  87. }
  88. //code to buy book
  89. if (transaction == 1)
  90. {
  91. system("CLS"); //clear screen
  92. //display section header
  93. cout << "**********\n";
  94. cout << "*Buy Book*\n";
  95. cout << "**********\n\n";
  96.  
  97. cout << "Book Name " << "Book Author " << "ISBN " << "Price\n"; //print buy header
  98. cout << "--------- " << "----------- " << "---- " << "-----\n\n"; //print buy header
  99.  
  100. CBooks::displayBooks();
  101.  
  102. cout << "\nPlease enter the number of the book you would like to buy:\n";
  103. cin >> choice; //the number choosen
  104. cout << "Thank you for your purchase!\n\n";
  105.  
  106. bookProfit = getProfit(priceArray[choice-1]); //call function to figure out profit of the book
  107. netProfit += bookProfit; //add book profit to total profit
  108. bookInfo[choice-1] = "SOLD"; //over write selection with the word SOLD
  109. priceArray[choice-1] = 0; //right 0 to element
  110. }
  111.  
  112. cout << "\nPlease type the number of the desired action and press <ENTER>:\n"; //print option make another trans
  113. cout << "1. Quit program\n"; //quit program
  114. cout << "2. Make another transaction\n"; //make another trans
  115. cin >> another; //get answer
  116.  
  117. if (another == 1) //check if user selected exit
  118. {
  119. cout << "WARNING!! Data will be lost if program is exited. Are you sure you want to exit?\n"; //print warning about loosing data
  120. cout << "1. Yes, please exit.\n";
  121. cout << "2. No, stay in program.\n";
  122. cin >> another; //get answer again
  123. }
  124. }
  125.  
  126. return 0;
  127. }
  128.  
  129. //Checks password and diplays profit
  130. void viewProfit()
  131. {
  132. string password;
  133.  
  134. system("CLS");
  135. //display header section
  136. cout << "*************\n";
  137. cout << "*View Profit*\n";
  138. cout << "*************\n\n";
  139.  
  140. cout << "Please type your password:\n";
  141. cin >> password;
  142. if (password == "upwd") //check password
  143. {
  144. cout << "Profit = $" << netProfit << "\n";
  145. }
  146. else
  147. {
  148. cout << "Invalid password.\n";
  149. }
  150. system("PAUSE");
  151. }
  152.  
  153. //Input books into inventory function
  154. void CBooks::inputBooks()
  155. {
  156. cout << "Please enter the book's name: \n";
  157. cin.getline(bookName, 64);
  158. _bookName = bookName;
  159. cout << "Please enter the book's author: \n";
  160. cin.getline(author, 64);
  161. _author = author;
  162. cout << "Please enter the book's ISBN: \n";
  163. cin.getline(isbn, 10);
  164. cin.ignore();
  165. _isbn = isbn;
  166. cout << "Please enter the desired price: \n";
  167. cin >> price;
  168. cin.ignore();
  169. _price = price;
  170. //Increments the number of books entered into inventory
  171. current++;
  172. cout << "There are now " << current << "books for in our inventory.";
  173. }
  174.  
  175. //Diplay books in inventory function
  176. void CBooks::displayBooks(void)
  177. {
  178. int loop;
  179.  
  180. //Display all of the books in inventory
  181. for (loop = 0; loop < 99; loop++)
  182. {
  183. cout << inventory[loop].bookName;
  184. cout << inventory[loop].author;
  185. cout << inventory[loop].isbn;
  186. cout << inventory[loop].price;
  187. }
  188. }
  189.  
  190. //Calculates the 10% profit and pass to called instance
  191. double getProfit(double doublePrice)
  192. {
  193. return doublePrice*.1;
  194. }

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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: Trouble getting code to compile

 
0
  #2
Jan 15th, 2006
1.Prototype of functions inputbooks and displaybooks differs from their call.
2.Call with the object instead of class name
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Trouble getting code to compile

 
0
  #3
Jan 15th, 2006
Change
  1. //Functions
  2. void inputBooks(string bookName, string author, int isbn, float price);
  3. void displayBooks(string bookName, string author, int isbn, float price);

to
  1. //Functions
  2. void inputBooks();
  3. void displayBooks();
in the Class declaration.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 12
Reputation: moznmar is an unknown quantity at this point 
Solved Threads: 0
moznmar's Avatar
moznmar moznmar is offline Offline
Newbie Poster

Re: Trouble getting code to compile

 
0
  #4
Jan 16th, 2006
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.

  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #define MAX 100 //Maximum number of books in inventory array
  5.  
  6. using namespace std;
  7.  
  8. class CBooks //Class definition
  9. {
  10. public:
  11.  
  12. //Constructor
  13. CBooks();
  14.  
  15. //Destructor
  16. ~CBooks(){};
  17.  
  18. //Functions
  19. void inputBooks(void);
  20. void displayBooks(void);
  21.  
  22. private:
  23. string m_bookName; //Name of book
  24. string m_author; //Author of book
  25. int m_isbn; //ISBN of book
  26. float m_price; //Price of book
  27. }inventory[MAX]; //Array of class objects
  28.  
  29. //Functions
  30. double getProfit(double doublePrice);
  31. void viewProfit();
  32.  
  33.  
  34. int current; //Used to count number of books in inventory
  35. double netProfit = 0;
  36.  
  37. //Main Function
  38. int main()
  39. {
  40.  
  41. //Declare variables
  42. int x = 0, transaction, another = 2, choice;
  43. double bookProfit, priceArray[99];
  44. string seller, password, bookInfo[99];
  45.  
  46. while (another != 1)
  47. {
  48. system("CLS");
  49. //display section header
  50. cout << "***********************\n";
  51. cout << "*Team A Book Inventory*\n";
  52. cout << "***********************\n\n";
  53.  
  54. cout << "Please type the number of the desired action and press <ENTER>:\n" ;
  55. cout << "1. Buy\n";
  56. cout << "2. Sell\n";
  57. cout << "3. View Profit\n";
  58. cin >> transaction;
  59. cin.ignore(); //statement is necessary in order to make cin.getline() to work properly.
  60. //Tells cin to ignore the line feed at the end of input
  61.  
  62. //code to view profit
  63. if (transaction == 3)
  64. {
  65. viewProfit();
  66. }
  67. // code to sell a textbook
  68. if (transaction == 2)
  69. {
  70. if (x<=99)
  71. {
  72. system("CLS");
  73. //display section header
  74. cout << "***********\n";
  75. cout << "*Sell Book*\n";
  76. cout << "***********\n\n";
  77.  
  78. inventory[x].inputBooks();
  79. x++;
  80. }
  81. else
  82. {
  83. cout << "I'm sorry, the database cannot hold any more books.\n"; //print if more then 100 books in inventory
  84. }
  85. }
  86. //code to buy book
  87. if (transaction == 1)
  88. {
  89. system("CLS"); //clear screen
  90. //display section header
  91. cout << "**********\n";
  92. cout << "*Buy Book*\n";
  93. cout << "**********\n\n";
  94.  
  95. cout << "Book Name " << "Book Author " << "ISBN " << "Price\n"; //print buy header
  96. cout << "--------- " << "----------- " << "---- " << "-----\n\n"; //print buy header
  97.  
  98. inventory[x].displayBooks();
  99.  
  100. cout << "\nPlease enter the number of the book you would like to buy:\n";
  101. cin >> choice; //the number choosen
  102. cout << "Thank you for your purchase!\n\n";
  103.  
  104. bookProfit = getProfit(priceArray[choice-1]); //call function to figure out profit of the book
  105. netProfit += bookProfit; //add book profit to total profit
  106. bookInfo[choice-1] = "SOLD"; //over write selection with the word SOLD
  107. priceArray[choice-1] = 0; //right 0 to element
  108. }
  109.  
  110. cout << "\nPlease type the number of the desired action and press <ENTER>:\n"; //print option make another trans
  111. cout << "1. Quit program\n"; //quit program
  112. cout << "2. Make another transaction\n"; //make another trans
  113. cin >> another; //get answer
  114.  
  115. if (another == 1) //check if user selected exit
  116. {
  117. cout << "WARNING!! Data will be lost if program is exited. Are you sure you want to exit?\n"; //print warning about loosing data
  118. cout << "1. Yes, please exit.\n";
  119. cout << "2. No, stay in program.\n";
  120. cin >> another; //get answer again
  121. }
  122. }
  123.  
  124. return 0;
  125. }
  126.  
  127. //Checks password and diplays profit
  128. void viewProfit()
  129. {
  130. string password;
  131.  
  132. system("CLS");
  133. //display header section
  134. cout << "*************\n";
  135. cout << "*View Profit*\n";
  136. cout << "*************\n\n";
  137.  
  138. cout << "Please type your password:\n";
  139. cin >> password;
  140. if (password == "upwd") //check password
  141. {
  142. cout << "Profit = $" << netProfit << "\n";
  143. }
  144. else
  145. {
  146. cout << "Invalid password.\n";
  147. }
  148. system("PAUSE");
  149. }
  150.  
  151. //Input books into inventory function
  152. void CBooks::inputBooks(void)
  153. {
  154. cout << "Please enter the book's name: \n";
  155. cin >> m_bookName;
  156. cout << "Please enter the book's author: \n";
  157. cin >> m_author;
  158. cout << "Please enter the book's ISBN: \n";
  159. cin >> m_isbn;
  160. cin.ignore();
  161. cout << "Please enter the desired price: \n";
  162. cin >> m_price;
  163. cin.ignore();
  164.  
  165. //Increments the number of books entered into inventory
  166. current++;
  167. cout << "There are now " << current << "books for in our inventory.";
  168. }
  169.  
  170. //Diplay books in inventory function
  171. void CBooks::displayBooks(void)
  172. {
  173. int loop;
  174.  
  175. //Display all of the books in inventory
  176. for (loop = 0; loop < 99; loop++)
  177. {
  178. cout << inventory[loop].m_bookName;
  179. cout << inventory[loop].m_author;
  180. cout << inventory[loop].m_isbn;
  181. cout << inventory[loop].m_price;
  182. }
  183. }
  184.  
  185. //Calculates the 10% profit and pass to called instance
  186. double getProfit(double doublePrice)
  187. {
  188. return doublePrice*.1;
  189. }

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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Trouble getting code to compile

 
0
  #5
Jan 16th, 2006
Do this
//Constructor
	CBooks(){};

You hadn't defined the Constructor. Only declared it.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: Trouble getting code to compile

 
0
  #6
Jan 16th, 2006
Originally Posted by WolfPack
Do this
//Constructor
	CBooks(){};

You hadn't defined the Constructor. Only declared it.
And remove the semicolon:
CBooks(){};[/CODE]
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 12
Reputation: moznmar is an unknown quantity at this point 
Solved Threads: 0
moznmar's Avatar
moznmar moznmar is offline Offline
Newbie Poster

Re: Trouble getting code to compile

 
0
  #7
Jan 16th, 2006
I just want to thank those of you who provided me some assistance on this thread. I appreciate it.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC