Creating an object in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nano2
    New Member
    • Jan 2007
    • 41

    Creating an object in C++

    Does anyone know how i could create an object1 (init) and pass it in to another object to do some analysis in c++
    where by object1 initailises 4 differnt structures


    at start up time the init object1 is initilised by passing in the appropriate values to each structure below.

    The following structures will have the following types

    structure 1 - startDateTime : unix timestamp.
    endDateTime : unix timestamp


    structure 2 - startDate : unix timestamp.
    endDate : unix timestamp.
    bandStartTime : offset from 00:00:00 in seconds.
    bandEndTime : offset from 00:00:00 in seconds.


    structure 3 - startDay : a string (Mon, Tue, Wed, etc).
    endDay : a string (Mon, Tue, Wed, etc).
    startTime : offset from 00:00:00 in seconds.
    endTime : offset from 00:00:00 in seconds.


    structure 4 - startDay : a string (Mon, Tue, Wed, etc).
    endDay : a string (Mon, Tue, Wed, etc).
    startTime : offset from 00:00:00 in seconds.
    endTime : offset from 00:00:00 in seconds.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by nano2
    Does anyone know how i could create an object1 (init) and pass it in to another object to do some analysis in c++
    where by object1 initailises 4 differnt structures


    at start up time the init object1 is initilised by passing in the appropriate values to each structure below.

    The following structures will have the following types

    structure 1 - startDateTime : unix timestamp.
    endDateTime : unix timestamp


    structure 2 - startDate : unix timestamp.
    endDate : unix timestamp.
    bandStartTime : offset from 00:00:00 in seconds.
    bandEndTime : offset from 00:00:00 in seconds.


    structure 3 - startDay : a string (Mon, Tue, Wed, etc).
    endDay : a string (Mon, Tue, Wed, etc).
    startTime : offset from 00:00:00 in seconds.
    endTime : offset from 00:00:00 in seconds.


    structure 4 - startDay : a string (Mon, Tue, Wed, etc).
    endDay : a string (Mon, Tue, Wed, etc).
    startTime : offset from 00:00:00 in seconds.
    endTime : offset from 00:00:00 in seconds.
    Create the object, and then pass it to the next.

    What have you tried on this?

    Comment

    • nano2
      New Member
      • Jan 2007
      • 41

      #3
      Originally posted by sicarie
      Create the object, and then pass it to the next.

      What have you tried on this?
      What do you mean with the above ?

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        [QUOTE=nano2]
        Originally posted by sicarie

        What have you tried on this?[/QUOTO]

        What do you mean with the above ?
        I mean what have you done to try to solve the problem yourself.

        Our FAQ:

        Originally posted by FAQ
        Posting Homework or Coursework Questions and Answers
        This site is not a place where you can get your homework and course work done for you. Ignoring the questionable morals of getting someone else to do your work towards a formal qualification you will learn a lot more by attempting the problem yourself, then asking for help with the bits that are not working. You will be more likely to get help if you appear to have made an attempt at the problem yourself.
        If it appears that the question has just been pasted directly from a text book or coursework assignment our moderators have been instructed to meet this with a set response. This is a pre-written message asking you to make some attempt at the assignment yourself before asking questions about specific problems and referring you to this FAQ.
        Do NOT post your complete source code. Remember, you found this site, so can your professors and tutors and they are likely to take a dim view if you hand in something that appears to be copied from this site. In most academic institutes the minimum response to copying of assignments is a 0 mark for the assignment in question. If you post your entire code your professor will not know it was your work, you may be penalised for copying from yourself.
        If an expert requests that you provide more of your code then you can PM it to them, however please do not PM them your code unless requested.
        Acceptable questions that students can ask are on functionality and theory or syntax corrections in small posted code snippets.
        Please make sure you have asked an actual question worded in English outside of the text of your assignment that you have posted.

        Comment

        • nano2
          New Member
          • Jan 2007
          • 41

          #5
          [QUOTE=sicarie]
          Originally posted by nano2

          I mean what have you done to try to solve the problem yourself.

          Our FAQ:
          Oh sorry yes i have written it in C. it's not home work it's just another approach i am taken to it so that i can have more effecient api.

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            [QUOTE=nano2]
            Originally posted by sicarie
            Oh sorry yes i have written it in C. it's not home work it's just another approach i am taken to it so that i can have more effecient api.
            Ok, so what have you tried?

            Comment

            • nano2
              New Member
              • Jan 2007
              • 41

              #7
              [QUOTE=sicarie]
              Originally posted by nano2

              Ok, so what have you tried?
              for structure 1 building it up

              This is the pseudo code :

              method_createDa teTime {startDateTime endDateTime } {
              struct datetimeStruct

              assign datetimeStruct( "type") = "0"
              assign datetimeStruct( "startDateTime" ) =startDateTime
              assign datetimeStruct( "endDateTim e") = endDateTime
              return $datetimeStruct
              }

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                Originally posted by nano2
                object1 is initilised by passing in the appropriate values to each structure below.
                Ok, you're getting the right idea, but not entirely, and not with the correct implementation. You don't need to create a new struct - there are 4 you are going to create with your initalization. You need to figure out how to create that oject, which will in turn create those structs, and then set the values in them. You ahve the right idea to create structs and intialize them, but you first need to create this object1.

                If you just create this object (with no parameters - don't worry about it creating the structs yet), that's the first step. Once you get that completed, you can either use the constructor, or create methods to create those 4 structs (I would recommend both, along with a default constructor). Once you get it to create them (not set them at all, just create them), then you can worry about passing them variables.

                Does that make sense?

                Comment

                • nano2
                  New Member
                  • Jan 2007
                  • 41

                  #9
                  Originally posted by sicarie
                  Ok, you're getting the right idea, but not entirely, and not with the correct implementation. You don't need to create a new struct - there are 4 you are going to create with your initalization. You need to figure out how to create that oject, which will in turn create those structs, and then set the values in them. You ahve the right idea to create structs and intialize them, but you first need to create this object1.

                  If you just create this object (with no parameters - don't worry about it creating the structs yet), that's the first step. Once you get that completed, you can either use the constructor, or create methods to create those 4 structs (I would recommend both, along with a default constructor). Once you get it to create them (not set them at all, just create them), then you can worry about passing them variables.

                  Does that make sense?

                  Can you have a look at this implementation please as I feel there is a better approach to this implementation:

                  thanks

                  class classificationS et
                  {
                  public:
                  ClassifictaionS et( int startDateTime = 4712548, int endDateTime=124 556, char * classBandType = NULL)
                  : m_classBandSet( NULL)

                  {
                  }
                  ~classification Set()
                  {
                  delete m_classBandSet;
                  }

                  value_t * getClassBandSet s() { return m_classBandSet; }

                  }

                  CreateClass(){

                  classificationS et *ptr = 0;

                  ptr * = new ClassificationS et();

                  char *classBandSetty pe = ptr->getclassBandSe ts();

                  }

                  What i am trying to do here is build up a classification structure where the user will call the object like so


                  Createprog 24214155, 154151555435, "type0"

                  // I need to extend the class to hold startday, endday starttime endtime values
                  Createprog Monday Sunday 0 86400 "type1"

                  Createprog Monday Friday 28800 64801 "type3"

                  Comment

                  Working...