i need help please to make ".h file

hi , how are you guys i hope you all fine
here
this is my program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <stdlib.h>
using namespace std;

 
 struct a {
        string name;
        int recordnum;
        int age;
        int birthdate;
        string desc;
        };
        
        class b {
                  private:
                          int c,d,e;
                          string f;
                          public:
                                b()	//	Constructor
	{	
         void addpatient();
 void editdesc();
	}

                                
                                 void addpatient() // here i wanna add full record for patient
                                 {
                                    
                                    a add[100];
                                    int r;
                                    cout<<"enter the the record num"<<endl;
                                    cin>>r;
                                    cout<<"enter name"<<endl;
                                    cin>>add[r].name;
                                    cout<<"enter record num"<<endl;
                                    cin>>add[r].recordnum;
                                    cout<<"enterage"<<endl;
                                    cin>>add[r].age;
                                    cout<<"enter birth"<<endl;
                                    cin>>add[r].birthdate;
                                    cout<<"enter desc"<<endl;
                                    cin>>add[r].desc;
                                    }
                                    void editdesc() // here i wanna edit patient  descrption (only) already exist
                                    {
                                    a edit[100];
                                    int l;
                                      cout<<"enter the the record num"<<endl;
                                    cin>>l;
                                     cout<<"enter desc"<<endl;
                                      cin>>edit[l].desc;
                                        
                                     }
                                     };
                                     
                                     int main(){
                                      b g;
                                       g.addpatient();
                                        g.editdesc();
                                         system ("pause");
                                        return 0;
                                       
                                        }; 
                                    
                                    
                                    
                                      




it works so i download it in folder my project in a1.cpp then i made another program called a1.h so i can use this in any another program a1.h but i now i get many errors i dont know why!!

maybe guys cant get it so i will explain what i want here


i want same this code in another program like

<iostream.h> it has functions and variables
i want make a1.h works to use this a1 program in another project
like this <a1.h> then i can use its functions an variables

but actually i dont know how :) i just tried but i couldn,t ,i saw my teacher did that but i forget how!
thank you
FORMATTING!

Also, you shouldn't have int main(); in a .h file

You can make this a .h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <stdlib.h>
using namespace std;

struct a {
	string name;
	int recordnum;
	int age;
	int birthdate;
	string desc;
};

class b {
private:
	int c,d,e;
	string f;
public:
	b()	//	Constructor
	{	
		void addpatient();
		void editdesc();
	}

	void addpatient() // here i wanna add full record for patient
	{
		a add[100];
		int r;
		cout<<"enter the the record num"<<endl;
		cin>>r;
		cout<<"enter name"<<endl;
		cin>>add[r].name;
		cout<<"enter record num"<<endl;
		cin>>add[r].recordnum;
		cout<<"enterage"<<endl;
		cin>>add[r].age;
		cout<<"enter birth"<<endl;
		cin>>add[r].birthdate;
		cout<<"enter desc"<<endl;
		cin>>add[r].desc;
	}
	void editdesc() // here i wanna edit patient  descrption (only) already exist
	{
		a edit[100];
		int l;
		cout<<"enter the the record num"<<endl;
		cin>>l;
		cout<<"enter desc"<<endl;
		cin>>edit[l].desc;

	}
};


Or you could split it into a .h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <stdlib.h>
using namespace std;

struct a {
	string name;
	int recordnum;
	int age;
	int birthdate;
	string desc;
};

class b {
private:
	int c,d,e;
	string f;
public:
	b();	//	Constructor
	void addpatient(); // here i wanna add full record for patient
	void editdesc(); // here i wanna edit patient  descrption (only) already exist
};

and a .cpp file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "a1.h"

b::b()	//	Constructor
{	
	void addpatient();
	void editdesc();
}

void b::addpatient() // here i wanna add full record for patient
{
	a add[100];
	int r;
	cout<<"enter the the record num"<<endl;
	cin>>r;
	cout<<"enter name"<<endl;
	cin>>add[r].name;
	cout<<"enter record num"<<endl;
	cin>>add[r].recordnum;
	cout<<"enterage"<<endl;
	cin>>add[r].age;
	cout<<"enter birth"<<endl;
	cin>>add[r].birthdate;
	cout<<"enter desc"<<endl;
	cin>>add[r].desc;
}

void b::editdesc() // here i wanna edit patient  descrption (only) already exist
{
	a edit[100];
	int l;
	cout<<"enter the the record num"<<endl;
	cin>>l;
	cout<<"enter desc"<<endl;
	cin>>edit[l].desc;

}


To call it, like so: #include <a1.h> , you need to put this file in the include directory of your compiler. Otherwise, you can use #include "a1.h" and just stick the header in the same directory as your .cpp file.
yeah , i realy dont get all wht you said but i get these things
we shouln,t put int main in .h file
and you shouldn,t do that #include<a1.h> but you you should do this #include"a1.h"
thank you alot brother the program works very well now .

best video on youtube
http://www.youtube.com/watch?v=vx_q7CeoUiM
Topic archived. No new replies allowed.