943,075 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 275
  • C++ RSS
Jan 28th, 2010
0

bloody linker error

Expand Post »
hey everyone,

so im trying hard to get this assignment done by tomorrow but after sucessfully compiling, I am now getting linker errors. I have to use Vi for this assignment but never the less here are my linker errors:

assign5.o: In function `main':
assign5.cpp:(.text+0x1026): undefined reference to `Print(cStudent (&) [30], int)'
assign5.cpp:(.text+0x103d): undefined reference to `Display(cStudent (&) [30], int)'
collect2: ld returned 1 exit status


here is the code itself:

C++ Syntax (Toggle Plain Text)
  1. //assignment 5
  2.  
  3. #include<iostream>
  4. #include<iomanip>
  5. #include<fstream>
  6. using namespace std;
  7.  
  8. const int NAMESIZE=11;
  9. const int FILENAMESIZE=51;
  10. const int ARRAYSIZE=20;
  11. int N=0;
  12. typedef char Name_t[NAMESIZE];
  13. typedef int Grade_t;
  14. typedef char Filename_t[FILENAMESIZE];
  15. typedef fstream Infile_t;
  16. typedef fstream Outfile_t;
  17.  
  18. class cStudent
  19. {
  20. private:
  21. Name_t fname;
  22. Name_t lname;
  23. Grade_t t1;
  24. Grade_t t2;
  25. Grade_t t3;
  26. Grade_t t4;
  27. Grade_t ag;
  28. Grade_t eg;
  29. public:
  30. cStudent();
  31. cStudent(Name_t NewName, Grade_t NewGrade);
  32. //set
  33. void set_fname(Name_t first)
  34. { strcpy(fname,first);}
  35. void set_lname(Name_t last)
  36. { strcpy(lname,last);}
  37. void set_t1(Grade_t a)
  38. { t1=a;}
  39. void set_t2(Grade_t b)
  40. { t2=b;}
  41. void set_t3(Grade_t c)
  42. { t3=c;}
  43. void set_t4(Grade_t d)
  44. { t4=d;}
  45. void set_ag(Grade_t e)
  46. { ag=e;}
  47. void set_eg(Grade_t f)
  48. { eg=f;}
  49. //get
  50. void get_fname(Name_t &fname)
  51. { strcpy(fname,this->fname);}
  52. void get_lname(Name_t &lname)
  53. { strcpy(lname,this->lname);}
  54. int get_t1(Grade_t &t1)
  55. { t1=this->t1; return t1;}
  56. int get_t2(Grade_t &t2)
  57. { t2=this->t2; return t2;}
  58. int get_t3(Grade_t &t3)
  59. { t3=this->t3; return t3;}
  60. int get_t4(Grade_t &t4)
  61. { t4=this->t4; return t4;}
  62. int get_ag(Grade_t &ag)
  63. { ag=this->ag; return ag;}
  64. int get_eg(Grade_t &eg)
  65. { eg=this->eg; return eg;}
  66. };// end class cStudent
  67. //cStudent Methods
  68. cStudent::cStudent()
  69. {
  70. t1=0;
  71. t2=0;
  72. t3=0;
  73. t4=0;
  74. ag=0;
  75. eg=0;
  76. };//end of cStudent::cStudent
  77.  
  78. typedef cStudent StudentArray[30];
  79. StudentArray CSCI208Class; //array of cStudent objects
  80.  
  81. void Read(StudentArray &CSCI208Class, int &N);
  82. void Sort(StudentArray &CSCI208Class, int &N);
  83. void Print(StudentArray &CSCI208Class, int N);
  84. void Display(StudentArray &CSCI208Class, int N);
  85.  
  86. //begin main
  87. int main()
  88. {
  89. Read(CSCI208Class,N);
  90. Sort(CSCI208Class,N);
  91. Print(CSCI208Class,N);
  92. Display(CSCI208Class,N);
  93.  
  94. cout<<"TERMINATING PROGRAM.........GOODBYE!"<<endl;
  95. return 0;
  96.  
  97. };//end main
  98.  
  99. void Read(StudentArray &CSCI208Class, int &N)
  100. {
  101. Filename_t Filename;
  102. Infile_t Infile;
  103. cout<<"Enter the name of the data file:"<<endl<<endl;
  104. cin>>Filename;
  105. cout<<"Opening Datafile..............."<<endl;
  106. Infile.open(Filename,ios::in);
  107.  
  108. Name_t first, last;
  109. Grade_t a,b,c,d,e,f;
  110. N=0;
  111.  
  112. Infile>>first;
  113. CSCI208Class[N].set_fname(first);
  114. while(!Infile.eof())
  115. {
  116. Infile>>last>>a>>b>>c>>d>>e>>f;
  117. CSCI208Class[N].set_lname(last);
  118. CSCI208Class[N].set_t1(a);
  119. CSCI208Class[N].set_t2(b);
  120. CSCI208Class[N].set_t3(c);
  121. CSCI208Class[N].set_t4(d);
  122. CSCI208Class[N].set_ag(e);
  123. CSCI208Class[N].set_eg(f);
  124. N=N+1;
  125. Infile>>first;
  126. CSCI208Class[N].set_fname(first);
  127. }//end while loop
  128. cout<<"READ COMPLETE..............."<<endl;
  129. cout<<"Closing Datafile..............."<<endl;
  130. cout<<"Begining Next Process..............."<<endl<<endl;
  131. Infile.close();
  132. };//end of read
  133.  
  134. void Sort(StudentArray &CSCI208Class, int &N)
  135. {
  136. int I,Pass;
  137. Name_t lname;
  138. Name_t nextlname;
  139. for(Pass=0; Pass<N-2; Pass++)
  140. {
  141. for(I=0; I<N-2; I++)
  142. {
  143. CSCI208Class[I].get_lname(lname);
  144. CSCI208Class[I+1].get_lname(nextlname);
  145. if(strcmp(lname,nextlname)>0)
  146. {
  147. StudentArray Temp;
  148. Temp[I]=CSCI208Class[I];
  149. CSCI208Class[I]=CSCI208Class[I+1];
  150. CSCI208Class[I+1]=Temp[I];
  151. }//end if
  152. }//end inside for
  153. }//end outside for
  154. };//end sort
  155.  
  156.  
  157. void Print(StudentArray CSCI208Class, int N)
  158. {
  159. Filename_t Filename;
  160. Outfile_t Outfile;
  161. cout<<"Please enter the name of the output file to be created:"<<endl<<endl;
  162. cin>>Filename;
  163. cout<<"CREATING OUTPUT FILE..............."<<endl;
  164. Outfile.open(Filename,ios::out);
  165. cout<<"BEGINING WRITE PLEASE WAIT..............."<<endl;
  166. Outfile<<"********************************************************************************************"<<endl;
  167. Outfile<<" "<<"NAME"<<" "<<"TEST GRADES"<<" "<<"ASSIGNMENT GRADE"<<" "<<"EXAM GRADE"<<endl;
  168. Outfile<<"********************************************************************************************"<<endl<<endl;
  169.  
  170. for(int I=0; I<N; I++)
  171. {
  172. Name_t fname,lname;
  173. Grade_t t1,t2,t3,t4,ag,eg;
  174. CSCI208Class[I].get_fname(fname);
  175. CSCI208Class[I].get_lname(lname);
  176. CSCI208Class[I].get_t1(t1);
  177. CSCI208Class[I].get_t2(t2);
  178. CSCI208Class[I].get_t3(t3);
  179. CSCI208Class[I].get_t4(t4);
  180. CSCI208Class[I].get_ag(ag);
  181. CSCI208Class[I].get_eg(eg);
  182. Outfile<<" "<<fname<<" "<<lname<<" "<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<" "<<ag<<" "<<eg<<endl;
  183. Outfile<<"---------------------------------------------------------------------------------------"<<endl;
  184. };//end for loop
  185. Outfile<<"********************************"<<N<<"students in this file***********************************"<<endl;
  186. Outfile<<"********************************END-OF-REPORT**************************************************"<<endl;
  187. cout<<"DATA SUCESSFULLY WRITTEN TO FILE!"<<endl;
  188. cout<<"NOW SAVING AND CLOSING OUTPUT FILE PLEASE WAIT..............."<<endl<<endl;
  189. Outfile.close();
  190. };//end of print
  191.  
  192. void Display(StudentArray CSCI208Class, int N)
  193. {
  194. char choice[5];
  195. cout<<"Would you like to preview the student records output file? (Yes/No)"<<endl;
  196. cin>>choice;
  197.  
  198. if(choice=="No"||"NO"||"no")
  199. { cout<<"TERMINATING PROGRAM.................GOODBYE"<<endl;}
  200. else
  201. if(choice=="Yes"||"YES"||"yes")
  202. {
  203. cout<<"********************************************************************************************"<<endl;
  204. cout<<" "<<"NAME"<<" "<<"TEST GRADES"<<" "<<"ASSIGNMENT GRADE"<<" "<<"EXAM GRADE"<<endl;
  205. cout<<"********************************************************************************************"<<endl<<endl;
  206.  
  207. for(int I=0; I<N; I++)
  208. {
  209. Name_t fname,lname;
  210. Grade_t t1,t2,t3,t4,ag,eg;
  211. CSCI208Class[I].get_fname(fname);
  212. CSCI208Class[I].get_lname(lname);
  213. CSCI208Class[I].get_t1(t1);
  214. CSCI208Class[I].get_t2(t2);
  215. CSCI208Class[I].get_t3(t3);
  216. CSCI208Class[I].get_t4(t4);
  217. CSCI208Class[I].get_ag(ag);
  218. CSCI208Class[I].get_eg(eg);
  219. cout<<" "<<fname<<" "<<lname<<" "<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<" "<<ag<<" "<<eg<<endl;
  220. cout<<"----------------------------------------------------------------------------------"<<endl;
  221. };//end for loop
  222. cout<<"***"<<N<<" students in this file***"<<endl;
  223. cout<<"*****************END-OF-REPORT*******************"<<endl;
  224. }
  225. else
  226. { cout<<"PLEASE ENTER EITHER YES or NO......................."<<endl;}
  227. }//end display

anyone have any ideas? whats got the linker huffing and puffing?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
atticusr5 is offline Offline
128 posts
since Jan 2010
Jan 28th, 2010
0
Re: bloody linker error
Your prototype and implementation do not match.
Team Colleague
Reputation Points: 5862
Solved Threads: 949
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jan 28th, 2010
0
Re: bloody linker error
For next time, don't necessarily start up a new thread when people might still be working on that exact same issue in your old one, it gets too confusing.
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Trouble compiling a sort program
Next Thread in C++ Forum Timeline: Help me in some questions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC