I want C++ code forCreate method inside Principal mentor class called assignAssociates to assign associate mentors from faculty.txt to a course. Create a file named associates.txt store CourseId,FacultyId,Role. Overload assignAssociates function with arguments. Overloading Method1 with three arguments courseId,FacultyId,Role. Overloading Method2 with two arguments courseId,FacultyId. ( Section 6.17 from chapter 6. ) Overload methods compactly and conveniently by using function templates. Create function template for assignAssociates method

Questions by souji1425

Showing Answers 1 - 3 of 3 Answers

Indrajit

  • Jul 22nd, 2007
 

Your question is in incorrect english, unclear ( how does the two assignAssociate functions differ? which parameter should we templatise?) and overall very confusing.

Which is probably why there is no previous comment on it before this one.

However to make a bleak attempt at what you are looking for:


class Principal_mentor{


public:

    Principal_mentor(<pass container for course>); 

  ~Principal_mentor(); // destructor


private, public or protected( as you would want it to be):

     template <class A, classB...(however many template parameters you'd like)> void assignAssociate(A courseId, B FacultyId, C role);  //Method1

     template <class A, class B> void  assignAssociate(A courseId, B FacultyId);  //Method2
private:

     File * faculty;

     File * associates;

     <declaration of container for course>;
}

Principal_mentor::Principal_mentor(<argument which is container for course>):<instantiate container for course member in the initializer list>

{

   faculty = fopen(faculty.txt, "r");  //please check the correct syntax for the fopen

   associates = fopen(associates.txt, "w");  // --do--


}

Principal_mentor::~Principal_mentor()

{

   fclose(faculty); 

   fclose(associates);

}

template <class A, classB...(however many template parameters you'd like)> void assignAssociate(A courseId, B FacultyId, C role)
{
    //read one faculty name from file handle faculty
    //assign it to  a course.
    //determine the role however you want to
    //write courseId,FacultyId,role line into associates file handle using write or fwrite properly.     
}

// construct Method2 in similar fashion.

Hope this helps you.

-Indrajit


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions