Thread: Problem understanding how to use memberwise assignment

  1. #1
    Registered User
    Join Date
    Sep 2011

    Problem understanding how to use memberwise assignment

    The problem that I have is that in CourseSchedule.cpp's function "void AddCourse (Course)" I am not able to find any way to copy the passed "Course a"'s "Date startDate" into "courses[numCourses].startDate"

    What does member wise assignment mean? Do I need to make "CourseSchedule" class a child class for "Course"? I think I could add public set functions to "Date" and "Time" and make it work, but I do not think my professor wants me to do that.

    The instructions were to:
    "Create a function named AddCourse that takes a Course as an argument and adds this course to the ClassSchedule array. You do NOT need to allocate any new memory since we allocated a max size for our ClassSchedule array. As long as you didnít make any of the Course member variables const you should be able to use memberwise assignment to add the course to the proper element of the array (numCourses is the current element) Ė you should add one to numCourses when you add a new Course to the ClassSchedule."

    Here are the source files. I am extremely extremely sorry for not being able to shorten this for you just to address the problem at hand, I simply do not have the time as I am running low on laptop battery. Any help towards how to solve this without adding public set functions would be greatly appreciated!

    #include <iostream> #include "Time.h" #include "Date.h" #include "Course.h" -

    #include <iostream> #include <iomanip> using namespace std; #include "Time. -

    //Time Class Definition with const member functions #ifndef TIME_H #define TIM -

    #include <iostream> using namespace std; #include "Date.h" ostream& opera -

    #ifndef DATE_H #define DATE_H class Date { friend ostream& operator<<( -

    #include <iostream> using namespace std; #include "Course.h" ostream& ope -

    #ifndef COURSE_H #define COURSE_H #include "Date.h" #include "Time.h" cl -

    #include "CourseSchedule.h" ostream& operator<< (ostream &output, const Cours -

    #ifndef COURSESCHEDULE_H #define COURSESCHEDULE_H #include <iostream> using -
    My Ctrl+S addiction gets in the way when using Code Blocks...

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    I am not able to find any way to copy the passed "Course a"'s "Date startDate" into "courses[numCourses].startDate"
    You shouldn't, it's private. You made accessor functions for all other privates, I'd suggest you write one for dates, too

    While I'm in no way clairvoyant and cannot possible know what your professor wants you to do, you may want to write an assignment operator for your Course class and use that in the AddCourse method.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble Understanding the assignment given.
    By AlbyRang in forum C Programming
    Replies: 3
    Last Post: 03-30-2012, 01:51 AM
  2. Replies: 11
    Last Post: 09-25-2010, 02:00 PM
  3. Problem Understanding this
    By RA-3000 in forum C Programming
    Replies: 9
    Last Post: 06-13-2010, 04:07 AM
  4. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  5. facing problem in understanding this....
    By enggabhinandan in forum C Programming
    Replies: 10
    Last Post: 10-25-2006, 05:30 AM