Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,368 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,303 people online right now. Registration is fast and FREE... Join Now!




Tutorials

 
Reply to this topicStart new topic

Tutorials, For creating a .h, cpp and a main.cpp program

tyserman474
post 30 Aug, 2008 - 04:40 PM
Post #1


New D.I.C Head

*
Joined: 28 Mar, 2008
Posts: 49

Hi All,
I have not been able to find a good tutorial on creating a class type program with the three folders. The .h with the cpp folder and then the main.cpp folder. I have searched the net but most not be using the right keywords or something so I have not been able to come up with any that are relative to this subject. My school book is lousey in explaining it, I need to do this using C++ OOP programing.
Can anyone help me out by suppying a site or give me an idea on what keywords to search for?
Thanks
User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 30 Aug, 2008 - 05:16 PM
Post #2


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 502



Thanked 44 times

Dream Kudos: 25
My Contributions


QUOTE
class type program with the three folders

blink.gif
What does that mean? If you need help, you need to communicate clearly.
User is offlineProfile CardPM

Go to the top of the page

KYA
post 30 Aug, 2008 - 05:49 PM
Post #3


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 4,205



Thanked 50 times

Dream Kudos: 1150
My Contributions


Header files normally contain class declarations and sometimes definitions. If the class definitions are not in the header then they are included in a file of the same name in a .cpp file. Each class .cpp file includes its declaration so it knows where the stuff is coming from. On compilation an object file is created for each cpp file. Main includes the "main" header file which normally in turn contains all of the other header files.

Helpful post? wink2.gif
User is offlineProfile CardPM

Go to the top of the page

tyserman474
post 30 Aug, 2008 - 08:18 PM
Post #4


New D.I.C Head

*
Joined: 28 Mar, 2008
Posts: 49

QUOTE(JackOfAllTrades @ 30 Aug, 2008 - 06:16 PM) *

QUOTE
class type program with the three folders

blink.gif
What does that mean? If you need help, you need to communicate clearly.

Okay what I mean:
I want to create a win32 program using C++, which is no problem. Then under the "class view" I right click on the program name, then click on add & class. From here I would like a tutorial that shows me how to do things and what they mean from here on. Adding variables, get & set functions ect.
I would like to be able to do this somehow but my book is bad on explaining it.
Thanks
User is offlineProfile CardPM

Go to the top of the page

wartech
post 30 Aug, 2008 - 08:31 PM
Post #5


D.I.C Head

Group Icon
Joined: 16 Oct, 2006
Posts: 100



Thanked 3 times
My Contributions


QUOTE
The .h with the cpp folder and then the main.cpp folder.


They are actually files.
1)Functions.cpp - you can name this whatever but usually contains functions and classes
2)Functions.h - usually the same name as your .cpp(where functions and classes are declared)
3)Main.cpp - your main program

So you can setup your project as so
1)Functions.cpp
CODE

//An example of declaring a function in your function.cpp file.

#include <iostream>
#include <fstream>  
#include <string>  
#include <vector>  


bool ReadFile(vector <string> &vec)
{    
        string temp;
        ifstream rdFile;    
        rdFile.open(FILE_IN);

    if (!rdFile)
    {
        cout << "Error! Cannot find file" << endl;
        return false;
    }

    while( getline( rdFile, temp ) )
    vec.push_back(temp);
    
    return true;
}


2)Functions.h
CODE

//The prototype for your readFile function

bool ReadFile(vector<string> &vec);



3)Main.cpp
CODE

//Your main program is executed
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "Functions.h"  //INCLUDE HEADER FILE HERE SO FUNCTIONS WILL
                                 //BE AVAILABLE TO THE REST OF THE PROGRAM                        
int main()
{
bool fileFound = true;
vector <string> vec1;

fileFound = ReadFile(vec1);

}


Hopefully this helps. biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 05:12AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month