I am desperately need help converting my code into an OOP format.

Here is my code:

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int strLength = 141;
char strArray[strLength];
char answer;
bool quit;
int charAmount;
string line;

void vowelCount(string);
void consonantCount(string);

void consonantCount(string line)
{
	int consonants;
	consonants = 0;
	
	for(int i=0;i<charAmount;i++)
	{
		
		if (strArray[i] != '1')
		{
		if (strArray[i] != '2')
		{
		if (strArray[i] != '3')
		{
		if (strArray[i] != '4')
		{
		if (strArray[i] != '5')
		{
		if (strArray[i] != '6')
		{
		if (strArray[i] != '7')
		{
		if (strArray[i] != '8')
		{
		if (strArray[i] != '9')
		{
		if (strArray[i] != '0')
		{
		if (strArray[i] != 'a')
		{
		if (strArray[i] != 'e')
		{
		if (strArray[i] != 'i')
		{
		if (strArray[i] != 'o')
		{
		if (strArray[i] != 'u')
		{
		if (strArray[i] !=' ')
		{
			consonants++;
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}  // 16th
	}
	cout<<"\nYour String contains "<<consonants<<" consonants"<<endl;
}
// End consonantCount

void vowelCount(string line)
{
	int vowels;
	vowels = 0;
	
	for(int i=0;i<charAmount;i++)
	{		
			if (strArray[i] == 'a')
			{
				vowels++;
			}
			if (strArray[i] == 'e')
			{
				vowels++;
			}
			if (strArray[i] == 'i')
			{
				vowels++;
			}
			if (strArray[i] == 'o')
			{
				vowels++;
			}
			if (strArray[i] == 'u')
			{
				vowels++;
			}
	}
	cout<<"\nYour String contains "<<vowels<<" vowels"<<endl;
}
// End vowelCount


int main()
{
	cout << "Enter a String that is 140 characters or less" << endl;
	cin.getline(strArray, strLength);
	line = strArray;
	charAmount = strlen(strArray);

	bool quit = false;
	while (quit != true)
	{
		cout << "\nWhat would you like to do?\n" << endl;
		cout << "A) Count the number of vowels in the string." << endl;
		cout << "B) Count the number of consonants in the string." << endl;
		cout << "C) Count the number of vowels and consonants in the string." << endl;
		cout << "D) Enter a new string." << endl;
		cout << "E) Quit the program.\n" << endl;
		cin >> answer;
		
		switch(answer)
		{
		case 'A':
			vowelCount(line);
			break;
		case 'B':
			consonantCount(line);
			break;
		case 'C':
			consonantCount(line);
			vowelCount(line);
			break;
		case 'D':
			cin.ignore();
			cout << "Please enter a new string that is 140 characters or less" << endl;
			cin.getline(strArray, strLength);
			line = strArray;
			charAmount = strlen(strArray);
			cout<<"\nYou entered ''"<<line<<"'' as a string"<< endl;
			break;
		case 'E':
			quit = true;
			break;
		default:
			cout << "\nPlease enter A,B,C,D,E only!" << endl;
		}
	}
	cin.get();
	return 0;
}
// End Main

This is what I have so far, but I am getting linker errors.

Errors:
Linking...
1>TestDefine.obj : error LNK2005: "int charAmount" (?charAmount@@3HA) already defined in TEST.obj
1>TestDefine.obj : error LNK2005: "char * strArray" (?strArray@@3PADA) already defined in TEST.obj
1>TestDefine.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > line" (?line@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in TEST.obj
1>C:\TEST\Debug\TEST.exe : fatal error LNK1169: one or more multiply defined symbols found

Header.h

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int strLength = 141;
char strArray[strLength];
string line;
int charAmount;

class Test
{
public:
void vowelCount(string);
void consonantCount(string);
};

TestDefine.cpp

#include "Test Header.h"

void Test::consonantCount(string line)
{
	int consonants;
	consonants = 0;
	
	for(int i=0;i<charAmount;i++)
	{
		
		if (strArray[i] != '1')
		{
		if (strArray[i] != '2')
		{
		if (strArray[i] != '3')
		{
		if (strArray[i] != '4')
		{
		if (strArray[i] != '5')
		{
		if (strArray[i] != '6')
		{
		if (strArray[i] != '7')
		{
		if (strArray[i] != '8')
		{
		if (strArray[i] != '9')
		{
		if (strArray[i] != '0')
		{
		if (strArray[i] != 'a')
		{
		if (strArray[i] != 'e')
		{
		if (strArray[i] != 'i')
		{
		if (strArray[i] != 'o')
		{
		if (strArray[i] != 'u')
		{
		if (strArray[i] !=' ')
		{
			consonants++;
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}  // 16th
	}
	cout<<"\nYour String contains "<<consonants<<" consonants"<<endl;
}
// End consonantCount

void Test::vowelCount(string line)
{
	int vowels;
	vowels = 0;
	
	for(int i=0;i<charAmount;i++)
	{		
			if (strArray[i] == 'a')
			{
				vowels++;
			}
			if (strArray[i] == 'e')
			{
				vowels++;
			}
			if (strArray[i] == 'i')
			{
				vowels++;
			}
			if (strArray[i] == 'o')
			{
				vowels++;
			}
			if (strArray[i] == 'u')
			{
				vowels++;
			}
	}
	cout<<"\nYour String contains "<<vowels<<" vowels"<<endl;
}
// End vowelCount

TEST.cpp

#include "Test Header.h"

char answer;
bool quit;

int main()
{
	Test obj;
	cout << "Enter a String that is 140 characters or less" << endl;
	cin.getline(strArray, strLength);
	line = strArray;
	charAmount = strlen(strArray);

	bool quit = false;
	while (quit != true)
	{
		cout << "\nWhat would you like to do?\n" << endl;
		cout << "A) Count the number of vowels in the string." << endl;
		cout << "B) Count the number of consonants in the string." << endl;
		cout << "C) Count the number of vowels and consonants in the string." << endl;
		cout << "D) Enter a new string." << endl;
		cout << "E) Quit the program.\n" << endl;
		cin >> answer;
		
		switch(answer)
		{
		case 'A':
			obj.vowelCount(line);
			break;
		case 'B':
			obj.consonantCount(line);
			break;
		case 'C':
			obj.consonantCount(line);
			obj.vowelCount(line);
			break;
		case 'D':
			cin.ignore();
			cout << "Please enter a new string that is 140 characters or less" << endl;
			cin.getline(strArray, strLength);
			line = strArray;
			charAmount = strlen(strArray);
			cout<<"\nYou entered ''"<<line<<"'' as a string"<< endl;
			break;
		case 'E':
			quit = true;
			break;
		default:
			cout << "\nPlease enter A,B,C,D,E only!" << endl;
		}
	}
	cin.get();
	return 0;
}
// End Main

use
c++ -o test TEST.cpp TestDefine.cpp

for compiling your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.