headers problem
Jul 30, 2011 at 7:22pm UTC
header.h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
#include <iostream>
#include <string>
using namespace std;
void prompt (string name[7], int grade[7]);
void init(int index[7]);
void sort(string name[7], int index[7]); //automatically referneced with arrays
void output(string name[7], int grade[7], int index[7]);
#endif // HEADER_H_INCLUDED
main 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#include <header.h>
int main()
{
string name[7];
int grade[7];
int index[7];
int i;
prompt(name, grade);
init(index);
sort(name, index);
output(name, grade, index);
}
void prompt (string name[7], int grade[7])
{
int i;
for (i=0;i<=6;i++)
{
cout << "Please enter name: " ;
cin >> name[i];
cout <<"Please enter grade: " ;
cin >> grade[i];
}
}
void init(int index[7])
{
int i;
for (i=0;i<=6;i++)
{
index[i] =i;
}
}
void sort(string name[7], int index[7])
{
int i;
int j;
for (i=0;i<=5;i++)
{
for (j=i+1;j<=6;j++)
{
int temp;
if (name[index[i]] > name[index[j]])
{
temp = index[i];
index[i] = index[j];
index[j] = temp;
}
}
}
}
void output(string name[7], int grade[7], int index[7])
{
int i;
for (i=0;i<=6;i++)
{
cout << endl << name[index[i]] << "\t"
<<grade[index[i]] << endl;
}
cin.get();
}
i get an error saying there is no file in directory for header.h
Jul 30, 2011 at 7:29pm UTC
Did you perhaps mean to use double quotes instead of angle brackets @ line 1?
Also, using namespaces in headers = bad form, that.
-Albatross
Jul 30, 2011 at 7:30pm UTC
Try using double quotes around header.h instead of <>
Jul 30, 2011 at 7:33pm UTC
ah thanks
yeah i know using namespace in headers is not a good idea, but it was just a test, me playing around tring to learn bits and parts of c++
Jul 30, 2011 at 7:35pm UTC
another question about headrs...
Does the header file have to be "saved" as the name that you include into the main program, or can the "saved" name be anything?
Jul 30, 2011 at 7:56pm UTC
Yes @ the header file needs to be saved as the name that's included in the C++ file. Else, the compiler won't know what you're referring to.
-Albatross
Topic archived. No new replies allowed.