Jump to content

Header File

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Guest_norman_069_*

Guest_norman_069_*
  • Guests
Hello

I am not sure if this is the kind of problems you talk about but i need to ask someone who can help. I am very new to c++ and i turned in an assignment in class the other day and i got points taken off for no class/header file. When i asked a tutor at school the said i do not need a header file. So here is the code, i was wondering if some one can tell me what would be in the header file and how would it look. Our teacher is a bad teacher and doesn't explain things well so i am having a hard time.

Thanks


//William Norman
//Project 1
//CS 2310

#include <iostream>
#include <string>
#include <cstring>
#include <fstream>

using namespace std;

const int maximum = 100; 

int main()
{
	string total[maximum];
	string input;
	int n;
	int number_in;
	int number_count = 0;
	int length;
	ofstream output;

	output.open ("L:\\project1.txt");
		cout<<"Enter Number of Strings: ";
	cin>>number_in;

	cout<<"Enter String: ";
	
	for (n=0; n<number_in; n++)
	{ 
		cin>>input;
		total[n] = input;
		length = input.length();
		for (int n=0; n<length; n++)
		{ 
			if(input[n] == 'a' || input[n] == 'A'
			|| input[n] == 'e' || input[n] == 'E'
			|| input[n] == 'i' || input[n] == 'I'	
			|| input[n] == 'o' || input[n] == 'O'
			|| input[n] == 'u' || input[n] == 'U')
			{
				number_count++;
			}
			else{}
		}
	}

	output<<"The String: ";
	for (int v=0; v<number_in; v++)
		output<<total[v]<<" ";
	output<<"has "<< number_count<<" vowels";
	output<<endl;
	output<<"The Words in the String are: ";
	output<<endl;
	for (n=0; n<number_in; n++)
	{
		output<<total[n];
		output<<endl;
	}


return 0;
}


#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
I don't see what you should use a header-file for in your example. Usually header-files are used for declarations, while the source-files are used for implementations. But you do not use other functions than main nor classes, so I don't see what you should use the header-file for. The only reason I can see why you could use a header-file, is putting the global variable "maximum" in it, but it still seems unnecessary for me.

#3
Guest_norman_069_*

Guest_norman_069_*
  • Guests
Is it possible to make classes with this kind of program? I talked to my teacher about it again for help and he said just figure it out. Now i like the idea of figuring stuff out on my own but there comes a time when you have looked at it and tried it as much as you can and you just need help but my teacher doesn't understand that.

#4
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
You can make anything into classes, but I don't see it's necessary in your program.

#5
Guest_norman_069_*

Guest_norman_069_*
  • Guests
Thanks for all the help v0id. Since my teacher won't teach me about classes do you happen to know the best place to find out more about that for a beginer like me. Something that talks about classes then maybe header files. Thanks again for the help.

#6
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
I think this would be a good place to start. It's the first article of four. Use the arrows in the end of the article to navigate to the other four articles. The articles are only scratching in the surface of object-oriented programming, but it's a start, and you'll learn what it's all about. Later you can read more about the different topics.

There's not much material on header-files specific, but I've seen some over the time. I don't have a link, but you could probably find something using Google.

Good luck, and I'd hope you had a better teacher!

#7
Guest_norman_069_*

Guest_norman_069_*
  • Guests
Thanks Again