Dev c++ header problems!!

This is a discussion on Dev c++ header problems!! within the C++ Programming forums, part of the General Programming Boards category; I've read and used examples from a programming structure's book by D.S Malik, and according to him i should be ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    14

    Dev c++ header problems!!

    I've read and used examples from a programming structure's book by D.S Malik, and according to him i should be able to divide my other files besides main file into a header file and implementation file, but when i paste everything into a file, the program will run but when i separate them into a header and implementation file, it doesn't work??!!the error always points to the #include "headerFileName.h" ...WHY?
    I also try the same thing with visual C++ 6.0...and i've got the same result.. below is the file that i have combined together..
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string> 
    using namespace std;
    
    class JenisProduk
    {
      public:
        void setMaklumatProduk(string,string,float,float); 
        //setkan nilai awal supaya merujuk kepada parameter
        void setBilPesanan(int bilP);
        //setkan nilai awal untuk bilPesanan
        void paparProduk();  
        //memaparkan maklumat produk yang dipilih
        float getJumlahHarga();
        //memulangkan jumlah harga untuk produk tersebut
        float getBilPesanan();
        //memulangkan bilangan pesanan untuk produk tersebut 
        string getKodProduk();
        //memulangkan kod produk untuk produk tersebut
        string getNamaProduk();
        //memulangkan nama produk untuk produk tersebut
        JenisProduk();
        //constructors
    
      private:
         string kodProduk;
         string namaProduk;
         float  hargaProduk;
         float  diskaunProduk;   
         int    bilPesanan;
    };
      
    struct nodeType
    {
      nodeType *link;
      JenisProduk info;
    }; 
    
    int main(int argc, char *argv[])
    {
      JenisProduk x;
      x.setMaklumatProduk("kod","nama",1,2);
      x.paparProduk();
      x.setBilPesanan(3);
      x.paparProduk();
      
      system("PAUSE");	
      return 0;
    }
    
    void JenisProduk::setMaklumatProduk
                      (string kod,string nama,float harga,float diskaun)
    {
       kodProduk     = kod;
       namaProduk    = nama;
       hargaProduk   = harga;
       diskaunProduk = diskaun;
    
    }
    
    void JenisProduk::setBilPesanan(int bilP)
    {
        bilPesanan = bilP;
    }
    
    void JenisProduk::paparProduk()
    {
      
              cout<<"Produk wujud dalam inventori."<<endl;
              cout<<"Kod     Produk: "<<kodProduk<<endl
                  <<"Nama    Produk: "<<namaProduk<<endl
                  <<"Harga   Produk: "<<hargaProduk<<endl
                  <<"Diskaun Produk: "<<diskaunProduk<<endl;
              if(bilPesanan>0)    
              cout<<"Bilangan Pesanan: "<<bilPesanan<<endl;
                                   
    }
    
    float JenisProduk::getJumlahHarga()
    {
       return(hargaProduk*bilPesanan);
    }
    
    float JenisProduk::getBilPesanan()
    {
       return(bilPesanan);
    }
    
    string JenisProduk::getKodProduk()
    {
       return(kodProduk);
    }
    
    string JenisProduk::getNamaProduk()
    {
       return(namaProduk);
    }
       
    JenisProduk::JenisProduk()
    {    kodProduk    = " ";
        namaProduk    = " ";
        hargaProduk   = 0;
        diskaunProduk = 0;
        bilPesanan    = 0;
       
    }

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Well if you are only getting the errors when they are separated, why are you a) showing us the merged version, and b) not giving us error messages?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    Seems easy enough

    This is what it should look like
    Code:
    /* this is hello.cpp */
    #include <iostream>
    #include <stdlib.h>
    #include "jenis.h"
    using namespace std;
    
    int main(int argc, char *argv[])
    {
      JenisProduk x;
      x.setMaklumatProduk("kod","nama",1,2);
      x.paparProduk();
      x.setBilPesanan(3);
      x.paparProduk();
    
      system("PAUSE");
      return 0;
    }
    Code:
    /* this is jenis.h */
    #ifndef JENIS_H_INCLUDED
    #define JENIS_H_INCLUDED
    #include <string>
    using namespace std;
    
    class JenisProduk
    {
      public:
        void setMaklumatProduk(string,string,float,float);
        //setkan nilai awal supaya merujuk kepada parameter
        void setBilPesanan(int bilP);
        //setkan nilai awal untuk bilPesanan
        void paparProduk();
        //memaparkan maklumat produk yang dipilih
        float getJumlahHarga();
        //memulangkan jumlah harga untuk produk tersebut
        float getBilPesanan();
        //memulangkan bilangan pesanan untuk produk tersebut
        string getKodProduk();
        //memulangkan kod produk untuk produk tersebut
        string getNamaProduk();
        //memulangkan nama produk untuk produk tersebut
        JenisProduk();
        //constructors
    
      private:
         string kodProduk;
         string namaProduk;
         float  hargaProduk;
         float  diskaunProduk;
         int    bilPesanan;
    };
    
    struct nodeType
    {
      nodeType *link;
      JenisProduk info;
    };
    #endif
    Code:
    /* this is jenis.cpp */
    #include <iostream>
    #include <string>
    #include "jenis.h"
    using namespace std;
    
    void JenisProduk::setMaklumatProduk
                      (string kod,string nama,float harga,float diskaun)
    {
       kodProduk     = kod;
       namaProduk    = nama;
       hargaProduk   = harga;
       diskaunProduk = diskaun;
    
    }
    
    void JenisProduk::setBilPesanan(int bilP)
    {
        bilPesanan = bilP;
    }
    
    void JenisProduk::paparProduk()
    {
    
              cout<<"Produk wujud dalam inventori."<<endl;
              cout<<"Kod     Produk: "<<kodProduk<<endl
                  <<"Nama    Produk: "<<namaProduk<<endl
                  <<"Harga   Produk: "<<hargaProduk<<endl
                  <<"Diskaun Produk: "<<diskaunProduk<<endl;
              if(bilPesanan>0)
              cout<<"Bilangan Pesanan: "<<bilPesanan<<endl;
    
    }
    
    float JenisProduk::getJumlahHarga()
    {
       return(hargaProduk*bilPesanan);
    }
    
    float JenisProduk::getBilPesanan()
    {
       return(bilPesanan);
    }
    
    string JenisProduk::getKodProduk()
    {
       return(kodProduk);
    }
    
    string JenisProduk::getNamaProduk()
    {
       return(namaProduk);
    }
    
    JenisProduk::JenisProduk()
    {    kodProduk    = " ";
        namaProduk    = " ";
        hargaProduk   = 0;
        diskaunProduk = 0;
        bilPesanan    = 0;
    
    }
    Compile using
    g++ hello.cpp jenis.cpp
    or add the .cpp files into the project file
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Also:
    >>#include <stdlib.h>
    #include <cstdlib>
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Many Header Files
    By matth in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2005, 02:45 PM
  2. Problems w/ Dev C++
    By Callith in forum Tech Board
    Replies: 8
    Last Post: 11-26-2004, 06:30 AM
  3. problems with header files
    By robid1 in forum C++ Programming
    Replies: 15
    Last Post: 08-16-2004, 07:35 AM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21