Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. creating methods/functions in a seperate file

creating methods/functions in a seperate file

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benjamin yap
    wrote on last edited by
    #1

    Hi all, i am very very new to c++ hope u guys can pardon me. I have a file called "newclass.h" which declares a few methods.

    //newclass.h, the specification file for the class NewClass

    #ifndef _NEWCLASS_H
    #define _NEWCLASS_H
    #include <string>

    using namespace std;

    class NewClass {
    public:

    string symbol; //variable to store the symbol (e.g.: Nasdaq)
    double lastTrade; //variable to store the last traded value
    double changeValue(); //variable to store the change in value
    double changePercentage(); //variable to store the change in percentage

    //function to get the respective values
    //the word const at the end of the member functions specify that these functions cannot modify the member variables of a variable
    void getDow(string symbol, double, double, double) const;
    void getNasdaq(string symbol, double, double, double) const;
    void getSP_500(string symbol, double, double, double) const;
    void getFTSE_100(string symbol, double, double, double) const;
    void getDAX(string symbol, double, double, double) const;
    void getNikkei_225(string symbol, double, double, double) const;
    void getHang_Seng(string symbol, double, double, double) const;
    void getStraits_Times_Index(string symbol, double, double, double) const;
    };
    #endif

    and the other file i have is "newclass.cpp"

    //newclass.cpp, the implementation file
    #include #include "newclass.h"

    using namespace std;

    how do i continue writing the main function of the method in newclass.cpp thanks

    C M N 3 Replies Last reply
    0
    • B benjamin yap

      Hi all, i am very very new to c++ hope u guys can pardon me. I have a file called "newclass.h" which declares a few methods.

      //newclass.h, the specification file for the class NewClass

      #ifndef _NEWCLASS_H
      #define _NEWCLASS_H
      #include <string>

      using namespace std;

      class NewClass {
      public:

      string symbol; //variable to store the symbol (e.g.: Nasdaq)
      double lastTrade; //variable to store the last traded value
      double changeValue(); //variable to store the change in value
      double changePercentage(); //variable to store the change in percentage

      //function to get the respective values
      //the word const at the end of the member functions specify that these functions cannot modify the member variables of a variable
      void getDow(string symbol, double, double, double) const;
      void getNasdaq(string symbol, double, double, double) const;
      void getSP_500(string symbol, double, double, double) const;
      void getFTSE_100(string symbol, double, double, double) const;
      void getDAX(string symbol, double, double, double) const;
      void getNikkei_225(string symbol, double, double, double) const;
      void getHang_Seng(string symbol, double, double, double) const;
      void getStraits_Times_Index(string symbol, double, double, double) const;
      };
      #endif

      and the other file i have is "newclass.cpp"

      //newclass.cpp, the implementation file
      #include #include "newclass.h"

      using namespace std;

      how do i continue writing the main function of the method in newclass.cpp thanks

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      You seem to be really confused about a lot of basic concepts in C++. I strongly suggest you start by reading a book (from the begining) about the C++ language first.

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • B benjamin yap

        Hi all, i am very very new to c++ hope u guys can pardon me. I have a file called "newclass.h" which declares a few methods.

        //newclass.h, the specification file for the class NewClass

        #ifndef _NEWCLASS_H
        #define _NEWCLASS_H
        #include <string>

        using namespace std;

        class NewClass {
        public:

        string symbol; //variable to store the symbol (e.g.: Nasdaq)
        double lastTrade; //variable to store the last traded value
        double changeValue(); //variable to store the change in value
        double changePercentage(); //variable to store the change in percentage

        //function to get the respective values
        //the word const at the end of the member functions specify that these functions cannot modify the member variables of a variable
        void getDow(string symbol, double, double, double) const;
        void getNasdaq(string symbol, double, double, double) const;
        void getSP_500(string symbol, double, double, double) const;
        void getFTSE_100(string symbol, double, double, double) const;
        void getDAX(string symbol, double, double, double) const;
        void getNikkei_225(string symbol, double, double, double) const;
        void getHang_Seng(string symbol, double, double, double) const;
        void getStraits_Times_Index(string symbol, double, double, double) const;
        };
        #endif

        and the other file i have is "newclass.cpp"

        //newclass.cpp, the implementation file
        #include #include "newclass.h"

        using namespace std;

        how do i continue writing the main function of the method in newclass.cpp thanks

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        something like :

        void NewClass::getDow(string symbol, double value1, double value2, double value3) const
        {
        // ... do the code to get the Dow values for the supplied symbol.
        }

        use the same pattern for the other methods. Since I do not know what the 3 double variables are, I simply called them value1, value2, value3; I assume that they really mean something; and if they are "returned" values (i.e. variables that you will assign something to them), you better make them either references (prefered) or pointers. good luck.

        This signature was proudly tested on animals.

        1 Reply Last reply
        0
        • B benjamin yap

          Hi all, i am very very new to c++ hope u guys can pardon me. I have a file called "newclass.h" which declares a few methods.

          //newclass.h, the specification file for the class NewClass

          #ifndef _NEWCLASS_H
          #define _NEWCLASS_H
          #include <string>

          using namespace std;

          class NewClass {
          public:

          string symbol; //variable to store the symbol (e.g.: Nasdaq)
          double lastTrade; //variable to store the last traded value
          double changeValue(); //variable to store the change in value
          double changePercentage(); //variable to store the change in percentage

          //function to get the respective values
          //the word const at the end of the member functions specify that these functions cannot modify the member variables of a variable
          void getDow(string symbol, double, double, double) const;
          void getNasdaq(string symbol, double, double, double) const;
          void getSP_500(string symbol, double, double, double) const;
          void getFTSE_100(string symbol, double, double, double) const;
          void getDAX(string symbol, double, double, double) const;
          void getNikkei_225(string symbol, double, double, double) const;
          void getHang_Seng(string symbol, double, double, double) const;
          void getStraits_Times_Index(string symbol, double, double, double) const;
          };
          #endif

          and the other file i have is "newclass.cpp"

          //newclass.cpp, the implementation file
          #include #include "newclass.h"

          using namespace std;

          how do i continue writing the main function of the method in newclass.cpp thanks

          N Offline
          N Offline
          Nemanja Trifunovic
          wrote on last edited by
          #4

          A friendly piece of advice: never use double (or float) for currency values[^]

          utf8-cpp

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups