need help with reading from a file with classes.

Reply

Join Date: May 2008
Posts: 14
Reputation: blackhawk9876 is an unknown quantity at this point 
Solved Threads: 0
blackhawk9876 blackhawk9876 is offline Offline
Newbie Poster

need help with reading from a file with classes.

 
0
  #1
Oct 30th, 2008
  1. // SPECIFICATION FILE (sList.h)
  2. // This file gives the specification of a sorted ADT
  3. // The list components are maintained in ascending order of value
  4. //******************************************************************
  5. #ifndef SLIST_H
  6. #define SLIST_H
  7. const int MAX_LENGTH = 50;// Maximum possible number of components needed
  8. typedef int ItemType; // Type of each component
  9.  
  10. class SortedList {
  11. public:
  12. SortedList();
  13. bool IsEmpty() const;
  14. bool IsFull() const;
  15. void MakeEmpty();
  16. int Length() const;
  17. void Insert(ItemType item);
  18. void Delete(ItemType item);
  19. bool IsPresent(ItemType item) const;
  20. void Print() const;
  21. void Mergelist();
  22. private:
  23. int length;
  24. ItemType data[MAX_LENGTH];
  25. void BinSearch(ItemType item, bool& found, int& position) const;
  26. };
  27. #endif
  28.  
  29. // IMPLEMENTATION FILE (sList.cpp)
  30. // This file implements the SortedList class member functions
  31. // List representation: a one-dimensional array and a length
  32. // Private members of class:
  33. // int length;
  34. // ItemType data[MAX_LENGTH];
  35. // void BinSearch( ItemType, bool&, int& ) const;
  36. //******************************************************************
  37. #include "sList.h"
  38. #include <iostream>
  39. #include<fstream>
  40. #include<cstdlib>
  41. #include<iomanip>
  42. using namespace std;
  43.  
  44. SortedList::SortedList() {
  45. length = 0;
  46. }
  47.  
  48. bool SortedList::IsEmpty() const {
  49. return (length == 0);
  50. }
  51.  
  52. bool SortedList::IsFull() const {
  53. return (length == MAX_LENGTH);
  54. }
  55.  
  56. void SortedList::MakeEmpty(){
  57. length = 0;
  58. }
  59.  
  60. int SortedList::Length() const {
  61. return length;
  62. }
  63.  
  64. void SortedList::Insert(ItemType item) {
  65. int index;
  66. index = length - 1;
  67. while (index >= 0 && item < data[index]) {
  68. data[index+1] = data[index];
  69. index--;
  70. }
  71. data[index+1] = item; // Insert item
  72. length++;
  73. }
  74.  
  75. void SortedList::BinSearch(ItemType item, bool& found, int& position ) const {
  76. int first = 0;
  77. int last = length - 1;
  78. int middle;
  79. found = false;
  80. while (last >= first && !found) {
  81. middle = (first + last) / 2;
  82. if (item < data[middle])
  83. last = middle - 1;
  84. else if (item > data[middle])
  85. first = middle + 1;
  86. else
  87. found = true;
  88. }
  89. if (found)
  90. position = middle;
  91. }
  92.  
  93. void SortedList::Delete(ItemType item ) {
  94. bool found; // True if item is found
  95. int position; // Position of item, if found
  96. int index;
  97. BinSearch(item, found, position);
  98. if (found) {
  99. // Shift data[position..length-1] up one position
  100. for (index = position; index < length - 1; index++)
  101. data[index] = data[index+1];
  102. length--;
  103. }
  104. }
  105.  
  106. bool SortedList::IsPresent(ItemType item ) const {
  107. bool found; // True if item is found
  108. int position; // Used in the call to BinSearch
  109. BinSearch(item, found, position);
  110. return found;
  111. }
  112.  
  113. void SortedList::Print() const {
  114. for (int index = 0; index < length; index++)
  115. cout << data[index] << " ";
  116. }
  117. void SortedList::Mergelist()
  118. {
  119. }
  120. #include "sList.h"
  121. #include<iostream>
  122. #include<fstream>
  123. #include<cstdlib>
  124. #include<iomanip>
  125. #include<string>
  126. using namespace std;
  127.  
  128. void input_list1(ifstream& input);
  129. void get_input(SortedList& , ifstream& );
  130.  
  131.  
  132. int main()
  133. {
  134. SortedList list_1;
  135. SortedList list_2;
  136. ifstream next;
  137. input_list1(next);
  138. get_input(list_1,next);
  139.  
  140.  
  141. return 0;
  142. }
  143.  
  144. void input_list1(ifstream& in_stream)
  145. {
  146. string filename1;
  147. cout<< "Input file name:";
  148. cin>>filename1;
  149. in_stream.open("c:\\Program Files\\list1.txt");
  150. if(in_stream.fail())
  151. {
  152. cout<< "cannot open file"<<endl;
  153. exit(1);
  154. }
  155. }
  156. void get_input1(SortedList& list_1, ifstream& list1 )
  157. {
  158. int number;
  159. list1>>number;
  160. cout<<number;
  161. while(number)
  162. {
  163. list_1.Insert(number);
  164. list1>>number;
  165. }
  166. }



my problem is when i compile it up to this point i get this error message:sListclient.obj : error LNK2019: unresolved external symbol "void __cdecl get_input(class SortedList &,class std::basic_ifstream<char,struct std::char_traits<char> > &)" (?get_input@@YAXAAVSortedList@@AAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main

and:
C:\Documents and Settings\Krystian\My Documents\Visual Studio 2005\Projects\SLIST_H\Debug\SLIST_H.exe : fatal error LNK1120: 1 unresolved externals

what am I doing wrong?
thank you for your help
Last edited by cscgal; Oct 30th, 2008 at 7:54 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,522
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 127
William Hemsworth William Hemsworth is offline Offline
Posting Virtuoso

Re: need help with reading from a file with classes.

 
0
  #2
Oct 30th, 2008
Perhaps if you had read the rules and used code tags, I would be a little more encouraged to help.. Read This Before Posting
Last edited by William Hemsworth; Oct 30th, 2008 at 7:04 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 320 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC