Thread: Reading Course information

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    43

    Reading Course information

    im trying to read in course information where the first number is an employeeID the second is the course department, the third is the course number and the fourth is the number of students in course. I am checking the employeeID from the courses with that of the empID i read in earlier witht he professors but im not sure how to store it because im assigning the professor that class if the first number read in matches that employees ID number. But all course info must be private data in class Course but be able to access it from class Instructor. If you can help it would be appreciated.

    Code:
    void readCourses(ifstream &I, Course R,Instructor *S[])
    {
      string courseDepartment;
      int numStudents;
      string courseNumber;
      string employeeID;
    
      while(!I.eof())
       {
        I >> employeeID >> courseDepartment >> courseNumber >> numStudents;
    
        if(I.eof())
         break;
    	for(int instructorIndex = LOOP_BASE; instructorIndex < MAX_INSTRUCTORS; instructorIndex++)
    	{
    		int index=0;
    		if(S[instructorIndex]->getEmployeeID() == employeeID)
    		{
    			S[instructorIndex]->TC[index]=employeeID; 
    			S[instructorIndex]->TC[index]->courseDepartment=courseDepartment;
                               //Help inside of this statement
    			
    		}
    	}
    			
      }
    }
    Code:
    private:
    	string firstName;
    	string lastName;
    	string middleInitial;
    	string employeeID;  
    	Course *TC[4];
    
    }; // end class Instuctor
    Code:
    lass Course {
    
    public:
    	Course();	//constructor
    	~Course();
    
    
    private:
    
    	string courseDepartment;
    	string courseName;
    	string numStudents;
    	
    };
    Last edited by maloy; 09-28-2002 at 09:49 PM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You can't. "private" means "class access only". "protected" means "class and subclass access only". However, you may be able to make instructor a "friend" of the privatized class, but it may be just with "protected" variables. Not sure there. Otherwise, use access functions:

    class Foo {
    private:

    int data;

    public:

    int get_data() {
    return data;
    }
    };
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    the question is how can i store the data, I tried to make class Course a friend of class Instructor but that did not seem to work.

    when i get to the code that says:
    if(S[instructorIndex]->getEmployeeID() == employeeID)
    that works fine because it goes inside the if statement which tells me that the employee id for the first instructor matches that of the one just read in which means i should assign that class to that instructor but thats when my problem occurs because when i try to go in and assign that course number and course dept and num of students it wont let me.


    Code:
    void readCourses(ifstream &I, Course R,Instructor *S[])
    {
      string courseDepartment;
      int numStudents;
      string courseNumber;
      string employeeID;
    
      while(!I.eof())
       {
        I >> employeeID >> courseDepartment >> courseNumber >> numStudents;
    
        if(I.eof())
         break;
    	for(int instructorIndex = LOOP_BASE; instructorIndex < MAX_INSTRUCTORS; instructorIndex++)
    	{
    		int index=0;
    		if(S[instructorIndex]->getEmployeeID() == employeeID)
    		{
    			
    			
    			
    		}
    	}
    			
      }
    }

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    43
    ok this the input file i have

    Ray L. Jones 3942 6 4 1974 3 2 2001
    Alice K. Brown 8300 4 8 1969 2 1 1999
    Gill R. Alante 4301 8 2 1972 6 5 2000

    8300 CSE 1325 92
    3942 MATH 2325 18
    3942 MATH 2326 25
    4301 HIST 1311 26
    8300 CSE 1320 24
    4301 HIST 1312 25

    How can i read in the data for the instuctors and the classes and then match the classes with the instructor that is supposed to teach them?

    This is what i have:

    Code:
    void readData(ifstream &I, Instructor *S[])
     {
      string firstName;
      string lastName;
      string middleInitial;
      string employeeID;
      string bmn;
      string bdy;
      string byr;
      string hmn;
      string hdy;
      string hyr;
    
      
      
    
      for(int index = 0; index < 3; index++)
       {
    	  
        I>>firstName>>middleInitial>>lastName>>employeeID>>bmn>>bdy>>byr>>hmn>>hdy>>hyr;
    	
         S[index] = new Instructor(firstName, lastName, middleInitial, employeeID);
    
       }
     }
    /***********************************************************************/
    void readCourse(ifstream &I, Instructor *S[], Course *C[] )
    {
    
    	string courseDepartment;
    	string numStudents;
    	string courseNumber;
    	string employeeID;
    
      while(!I.eof())
       {
        I >> employeeID >> courseDepartment >> courseNumber >> numStudents;
    
        if(I.eof())
         break;
    
        for(int instructorIndex = LOOP_BASE;
                instructorIndex < MAX_INSTRUCTORS;
                instructorIndex++)
         {
          if(S[instructorIndex]->getEmployeeID() == employeeID)
           {
            for(int courseIndex = LOOP_BASE;
                    courseIndex < MAX_COURSES;
                    courseIndex++)
             {
    			C[courseIndex]= new Course(courseDepartment,
    				courseNumber, numStudents);
    		}
    	  }
    	}
      }
    }

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    class courses;//let the compiler know this class will be coming later
    
    class Instructor
    {
      public:
        string firstName;
        string lastName;
        string middleInitial;
        string employeeID;
        courses load[2];//each instructor has up to 2 courses
        int numCourses;//initialize to 0 in the constructor;
        //etc.
    };
    
    class courses
    {
      public:
        string teacherID;
        string numStuds;
        string courseNum;
        string courseDept;
        //etc.
    };
    
    void readData(ifstream &I, Instructor * S[])
     {
      string bmn;
      string bdy;
      string byr;
      string hmn;
      string hdy;
      string hyr;
    
      for(int index = 0; index < 3; index++)
       {
    	  
        I>>firstName>>middleInitial>>lastName>>employeeID>>bmn>>bdy>>byr>>hmn>>hdy>>hyr;
    	
         S[index] = new Instructor(firstName, lastName, middleInitial, employeeID);
    
       }
     }
    / **************************************************
    *********************/
    void readCourse(ifstream &I, Instructor *S[])
    {
    
    	string courseDepartment;
    	string numStudents;
    	string courseNumber;
    	string employeeID;
    
      while(!I.eof())
       {
        I >> employeeID >> courseDepartment >> courseNumber >> numStudents;
    
        if(I.eof())
         break;
    
        for(int instructorIndex = LOOP_BASE;
                instructorIndex < MAX_INSTRUCTORS;
                instructorIndex++)
         {
          if(S[instructorIndex]->getEmployeeID() == employeeID)
           {
              C = new Course(courseDepartment,
    	courseNumber, numStudents);
              S[instructorIndex]->load[numCourses++] = *C;
           }
         }
       }
      }
    no real need to pass array of courses(like a catalog) to readCourse() if the array of courses for each instructor is a member of the Instructor class. Since you are reading course information from a file in readCourse(), I presume you don't have a courses array already read in someplace else. If you want to construct a course catalog and then pass that to readCourse(), of course you may, but you don't need to. You should give some thought to writing your own assignment operator for the courses class, although, depending on the members in the courses class, the default assignment operator supplied by the compiler may be adequate.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-28-2008, 03:07 AM
  2. reading information from cd
    By jverkoey in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2004, 07:31 PM
  3. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  4. Getting information on system
    By sean in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2003, 03:36 PM
  5. Replies: 4
    Last Post: 04-01-2003, 12:49 AM