| | |
need help with reading from a file with classes.
![]() |
•
•
Join Date: May 2008
Posts: 14
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
// SPECIFICATION FILE (sList.h) // This file gives the specification of a sorted ADT // The list components are maintained in ascending order of value //****************************************************************** #ifndef SLIST_H #define SLIST_H const int MAX_LENGTH = 50;// Maximum possible number of components needed typedef int ItemType; // Type of each component class SortedList { public: SortedList(); bool IsEmpty() const; bool IsFull() const; void MakeEmpty(); int Length() const; void Insert(ItemType item); void Delete(ItemType item); bool IsPresent(ItemType item) const; void Print() const; void Mergelist(); private: int length; ItemType data[MAX_LENGTH]; void BinSearch(ItemType item, bool& found, int& position) const; }; #endif // IMPLEMENTATION FILE (sList.cpp) // This file implements the SortedList class member functions // List representation: a one-dimensional array and a length // Private members of class: // int length; // ItemType data[MAX_LENGTH]; // void BinSearch( ItemType, bool&, int& ) const; //****************************************************************** #include "sList.h" #include <iostream> #include<fstream> #include<cstdlib> #include<iomanip> using namespace std; SortedList::SortedList() { length = 0; } bool SortedList::IsEmpty() const { return (length == 0); } bool SortedList::IsFull() const { return (length == MAX_LENGTH); } void SortedList::MakeEmpty(){ length = 0; } int SortedList::Length() const { return length; } void SortedList::Insert(ItemType item) { int index; index = length - 1; while (index >= 0 && item < data[index]) { data[index+1] = data[index]; index--; } data[index+1] = item; // Insert item length++; } void SortedList::BinSearch(ItemType item, bool& found, int& position ) const { int first = 0; int last = length - 1; int middle; found = false; while (last >= first && !found) { middle = (first + last) / 2; if (item < data[middle]) last = middle - 1; else if (item > data[middle]) first = middle + 1; else found = true; } if (found) position = middle; } void SortedList::Delete(ItemType item ) { bool found; // True if item is found int position; // Position of item, if found int index; BinSearch(item, found, position); if (found) { // Shift data[position..length-1] up one position for (index = position; index < length - 1; index++) data[index] = data[index+1]; length--; } } bool SortedList::IsPresent(ItemType item ) const { bool found; // True if item is found int position; // Used in the call to BinSearch BinSearch(item, found, position); return found; } void SortedList::Print() const { for (int index = 0; index < length; index++) cout << data[index] << " "; } void SortedList::Mergelist() { } #include "sList.h" #include<iostream> #include<fstream> #include<cstdlib> #include<iomanip> #include<string> using namespace std; void input_list1(ifstream& input); void get_input(SortedList& , ifstream& ); int main() { SortedList list_1; SortedList list_2; ifstream next; input_list1(next); get_input(list_1,next); return 0; } void input_list1(ifstream& in_stream) { string filename1; cout<< "Input file name:"; cin>>filename1; in_stream.open("c:\\Program Files\\list1.txt"); if(in_stream.fail()) { cout<< "cannot open file"<<endl; exit(1); } } void get_input1(SortedList& list_1, ifstream& list1 ) { int number; list1>>number; cout<<number; while(number) { list_1.Insert(number); list1>>number; } }
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
•
•
Join Date: Mar 2008
Posts: 1,522
Reputation:
Solved Threads: 127
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.
![]() |
Similar Threads
- fstream Tutorial (C++)
- reading from file (Java)
- Reading out to a file/Null String Troubles (C++)
- How to include txt into jar file? (Java)
- First year assigment on reading file, sorting and outputting invoice (C++)
- Please I need help formatting an output file and sorting the names! (C++)
- header file/ classes (C++)
- Error Message Concerning Reading File From A Drive (C++)
Other Threads in the C++ Forum
- Previous Thread: C++ OpenCV avi player - Help Needed
- Next Thread: ls Vs sort algorithm in Scan Directory test program
Views: 320 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary browser c++ c++borland c/c++ calculator char class classes code compile compiler constructor conversion convert count data delete desktop display dll dynamic encryption error file files form fstream function functions game givemetehcodez graph gui homework i/o iamthwee input int integer lazy library linker list loop loops map math matrix member memory newbie news number object objects opengl output parameter pointer pointers problem program programming project random read recursion recursive reference return sort sorting spoonfeeding string strings struct student studio template templates text time tree undefined variable vc++ vector video visual win32 window windows winsock






