Help! Another Problem

This is a discussion on Help! Another Problem within the C++ Programming forums, part of the General Programming Boards category; Hi guys. I have written the following codes: Professor.ccp Code: #include <iostream> #include <string> #include <conio.h> #include <vector> #include "Professor.h" ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    7

    Help! Another Problem

    Hi guys.
    I have written the following codes:
    Professor.ccp
    Code:
    #include <iostream>
    #include <string>
    #include <conio.h>
    #include <vector>
    #include "Professor.h"
    using namespace std;
    int Professor::lastAssignedID=0;
    class Course;
        Professor::Professor():Person()
        {}
    	Professor::Professor(string name, string ic, string gender): Person(name,ic,gender)
    	{
    	        staffID=lastAssignedID;
    	        lastAssignedID+=1;
    	}
    	int Professor::getStaffID(){
    		  	return staffID;
    	}
        Course* Professor::getCourse(string courseCode){
    		 int i=-1; 
    	 	bool check=false;
    		 while (check==false){
    	 		i=i+1;
    	 		if ((teachingCourses[i].getCourseName()).compare(courseCode)==0){
     			   check=true;
    			   }
    	 	}
    	 	return teachingCourses[i];
    	 }
    	 
         string Professor::getTeachingCourses(){
    	 	string result;
    	 	for(int i=0;i<teachingCourses.size();i++){
    	 		if (i==0)
    	 			result=result+(teachingCourses[i]).getCourseCode();
    	 		else
    	 			result=result+","+(teachingCourses.get[i]).getCourseCode();
    	 	}
    	 	return result;
    	 }
    and Course.cpp
    Code:
    #include <iostream>
    #include <string>
    #include <boost/xpressive/xpressive.hpp>
    #include "Course.h"	
    #include "Professor.h"
    using namespace std;
    using namespace boost::xpressive;
    Professor tmp;
    	Course::Course(string courseCode,string courseName,int modularCredits,Professor newProfessor)
    	{
    			setCourseCode(courseCode);
    			setCourseName(courseName);
    			setModularCredits(modularCredits);
    	        setProfessor(newProfessor);
    	}
    	void Course::setProfessor(Professor newProfessor)
    	{
    	 	 tmp.setName(newProfessor.getName());
    	 	 tmp.setGender(newProfessor.getGender());
    	 	 tmp.setIC(newProfessor.getIC());
    	 	 string line;
    	 	 line=tmp.getName();
    	 	 theProfessor.setName(line);
    	 	 line=tmp.getIC();
    	 	 theProfessor.setIC(line);
    	 	 line=tmp.getGender();
    	 	 theProfessor.setGender(line);
        }
    	string Course::getProfessor()
    	{
    	 	 string tmp;
    		 tmp=theProfessor.getName();  
             return tmp;
    	}
    	    
    	void Course::setCourseName(string newCourseName)
    	{
    	 	 courseName=newCourseName;
    	}
    	    
    	string Course::getCourseName()
    	{
    	     return courseName;
    	}
    	void Course::setCourseCode(string newCourseCode)
    	{
    	 	 sregex base=as_xpr('C')>>'S'>>(range('1','6'))>>repeat<3>(_d);
    	    	if (regex_match(newCourseCode,base)==true){
    	    		courseCode=newCourseCode;
    	    	}
    	    	else{
    	    		cout<<"Invalid new Course Code";
    	    	}
    	}
    	    
    	string Course::getCourseCode(){
    	    	return courseCode;
    	    }
    	    
    	void Course::setModularCredits(int newModularCredits)
    	{
    	    	modularCredits=newModularCredits;
    	}
    	    
    	int Course::getModularCredits()
    	{
    	    	return modularCredits;
    	}
    	    
    /*	string Course::toString()
    	{
    	    return (courseCode+","+courseName+","+modularCredits);
    	}*/
    When I compile, the following errors appear:
    19 C:\Dev-Cpp\Save\Professor.cpp prototype for `Course* Professor::getCourse(std::string)' does not match any in class `Professor'
    15 C:\Dev-Cpp\Save\Professor.h Course* Professor::getCourse(std::string*)
    C:\Dev-Cpp\Save\Professor.cpp In member function `Course* Professor::getCourse(std::string)':
    24 C:\Dev-Cpp\Save\Professor.cpp `getCourseName' has not been declared
    24 C:\Dev-Cpp\Save\Professor.cpp request for member of non-aggregate type before '(' token
    C:\Dev-Cpp\Save\Professor.cpp In member function `std::string Professor::getTeachingCourses()':
    35 C:\Dev-Cpp\Save\Professor.cpp `getCourseCode' has not been declared
    35 C:\Dev-Cpp\Save\Professor.cpp request for member of non-aggregate type before '(' token '
    37 C:\Dev-Cpp\Save\Professor.cpp 'class std::vector<Course*, std::allocator<Course*> >' has no member named 'get'
    Basically the methods of class Course cannot be used in class Professor.
    How to solve this problem?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Every function that appears in your Professor.cpp file needs to have a prototype in the class Professor definition in your Professor.h file.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    7
    So you mean I must have Course* getCourseCode() .. in my Professor.h?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by halo3 View Post
    So you mean I must have Course* getCourseCode() .. in my Professor.h?
    You don't have a function Professor::getCourseCode(), so no. You have a Course::getCourseCode(), so that needs to be in course.h.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    If you can, you might to want only to use either spaces or tabs for indentation. Otherwise the code will look messed up in the forum.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21