can someone help me put all of this together in my main.cpp

So I wrote this in three different parts but now I don't know how to put it all together just so that it is in just one main.cpp and not three different ones. can someone help me put it all together?

//this is my main.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Person.h"
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
using namespace std;

// reads and returns the command
string getCommand()
{
	string cmd;
	cout << "\nEnter the command (INSERT/VIEW/DELETE or EXIT to end the program):" << endl;
	getline(cin, cmd);
	while (cmd.compare("INSERT") != 0 && cmd.compare("VIEW") != 0 && cmd.compare("DELETE") != 0 && cmd.compare("EXIT") != 0)
	{
		cout << "Invalid Command. Please Try Again." << endl;
		cout << "\nEnter the command (INSERT/VIEW/DELETE or EXIT to end the program):" << endl;
		getline(cin, cmd);
	}
	return cmd;
}

// displays the persons in the array
void displayPersons(Person persons[], int count)
{
	for (int i = 0; i < count; i++)
		persons[i].display();
}

// deletes the person
void deletePerson(Person persons[], int count, int index)
{
	for (int i = index; i < count; ++i)
		persons[i] = persons[i + 1]; 
}

// find person
int findPerson(Person persons[], string fName, string lName, int count)
{
	for (int i = 0; i < count; i++)
	{
		if (persons[i].getFirstName().compare(fName) == 0 && persons[i].getLastName().compare(lName) == 0)
			return i;
	}
	return -1;
}

// main function
int main()
{
	string command;
	string fullName;
	string fName;
	string lName;
	string token;
	Person persons[100];
	int personCount = 0;
	int index;

	do
	{
		command = getCommand();
		if (command.compare("INSERT") == 0)
		{
			cout << "Enter the name of Person in LastName, FirstName format" << endl;
			getline(cin, fullName);
			size_t found = fullName.find(',');
			if (found != std::string::npos)
			{
				istringstream ss(fullName);
				getline(ss, token, ',');
				lName = token;
				getline(ss, token, ',');
				fName = token;

				// create person
				Person p(fName, lName);

				// add person to array
				persons[personCount] = p;
				personCount++;

				// sort the array
				std::sort(persons, persons + personCount,
					[](Person const & a, Person const & b) -> bool
				{ return a.getLastName().compare(b.getLastName()) < 0; });

				// display the persons
				cout << endl;
				displayPersons(persons, personCount);
			}
			else
			{
				cout << "Invalid Input." << endl;
			}
		}
		else if (command.compare("VIEW") == 0)
		{
			cout << endl;
			displayPersons(persons, personCount);
		}
		else if (command.compare("DELETE") == 0)
		{
			cout << "Enter the name of Person in LastName, FirstName format" << endl;
			getline(cin, fullName);
			size_t found = fullName.find(',');
			if (found != std::string::npos)
			{
				istringstream ss(fullName);
				getline(ss, token, ',');
				lName = token;
				getline(ss, token, ',');
				fName = token;

				// find if person exist
				index = findPerson(persons, fName, lName, personCount);
				if (index >= 0)
				{
					deletePerson(persons, personCount, index);
					personCount--;
					// display the persons
					cout << endl;
					displayPersons(persons, personCount);
				}
				else
				{
					cout << "Person not Found!" << endl;
				}
			}
			else
			{
				cout << "Invalid Input." << endl;
			}
		}

	} while (command.compare("EXIT") != 0);
	return 0;
}


//his is my person.cpp
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
#include "Person.h"
#include <iostream>
using namespace std;

Person::Person(){}

void Person::display()
{
	cout << LastName << ", " << FirstName << endl;
}

Person::Person(string fName, string lName)
{
	FirstName = fName;
	LastName = lName;
}

// returns first name
string Person::getFirstName() const
{
	return FirstName;
}

// returns last name
string Person::getLastName() const
{
	return LastName;
}


//and this is my person.h
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
// Person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;

class Person
{
	string FirstName;
	string LastName;

public:
	// default constructor
	Person();
	// parameterized constructor
	Person(string, string);
	// displays the person
	void display();
	// returns first name
	string getFirstName() const;
	// returns last name
	string getLastName() const;

};

#endif 


I need it all in my main.cpp
please and thank you!
I have 1 hour left to submit please help
What do you mean "all together in main"?

If you mean you want all the code in main.cpp, simply copy the class (in .h file) and paste it into main.cpp. Make sure you include method implementations in the class itself as well.
I have them saves as three different files and it need them all as just one
I have my main.cpp and person.cpp and person.h
I copy and paste the person.cpp into my main.cpp and added the person.h to the header files but it still gives me errors. I am using visual studio by the way
I'm assuming you wanted it the way Arslan was mentioning?

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>

using namespace std;

class Person
{
	string FirstName;
	string LastName;

public:
	// default constructor
	Person();
	// parameterized constructor
	Person(string, string);
	// displays the person
	void display();
	// returns first name
	string getFirstName() const;
	// returns last name
	string getLastName() const;

};

Person::Person() {

}

void Person::display()
{
	cout << LastName << ", " << FirstName << endl;
}

Person::Person(string fName, string lName)
{
	FirstName = fName;
	LastName = lName;
}

// returns first name
string Person::getFirstName() const
{
	return FirstName;
}

// returns last name
string Person::getLastName() const
{
	return LastName;
}

// reads and returns the command
string getCommand()
{
	string cmd;
	cout << "\nEnter the command (INSERT/VIEW/DELETE or EXIT to end the program):" << endl;
	getline(cin, cmd);
	while (cmd.compare("INSERT") != 0 && cmd.compare("VIEW") != 0 && cmd.compare("DELETE") != 0 && cmd.compare("EXIT") != 0)
	{
		cout << "Invalid Command. Please Try Again." << endl;
		cout << "\nEnter the command (INSERT/VIEW/DELETE or EXIT to end the program):" << endl;
		getline(cin, cmd);
	}
	return cmd;
}

// displays the persons in the array
void displayPersons(Person persons[], int count)
{
	for (int i = 0; i < count; i++)
		persons[i].display();
}

// deletes the person
void deletePerson(Person persons[], int count, int index)
{
	for (int i = index; i < count; ++i)
		persons[i] = persons[i + 1];
}

// find person
int findPerson(Person persons[], string fName, string lName, int count)
{
	for (int i = 0; i < count; i++)
	{
		if (persons[i].getFirstName().compare(fName) == 0 && persons[i].getLastName().compare(lName) == 0)
			return i;
	}
	return -1;
}

// main function
int main()
{
	string command;
	string fullName;
	string fName;
	string lName;
	string token;
	Person persons[100];
	int personCount = 0;
	int index;

	do
	{
		command = getCommand();
		if (command.compare("INSERT") == 0)
		{
			cout << "Enter the name of Person in LastName, FirstName format" << endl;
			getline(cin, fullName);
			size_t found = fullName.find(',');
			if (found != std::string::npos)
			{
				istringstream ss(fullName);
				getline(ss, token, ',');
				lName = token;
				getline(ss, token, ',');
				fName = token;

				// create person
				Person p(fName, lName);

				// add person to array
				persons[personCount] = p;
				personCount++;

				// sort the array
				std::sort(persons, persons + personCount,
					[](Person const & a, Person const & b) -> bool
				{ return a.getLastName().compare(b.getLastName()) < 0; });

				// display the persons
				cout << endl;
				displayPersons(persons, personCount);
			}
			else
			{
				cout << "Invalid Input." << endl;
			}
		}
		else if (command.compare("VIEW") == 0)
		{
			cout << endl;
			displayPersons(persons, personCount);
		}
		else if (command.compare("DELETE") == 0)
		{
			cout << "Enter the name of Person in LastName, FirstName format" << endl;
			getline(cin, fullName);
			size_t found = fullName.find(',');
			if (found != std::string::npos)
			{
				istringstream ss(fullName);
				getline(ss, token, ',');
				lName = token;
				getline(ss, token, ',');
				fName = token;

				// find if person exist
				index = findPerson(persons, fName, lName, personCount);
				if (index >= 0)
				{
					deletePerson(persons, personCount, index);
					personCount--;
					// display the persons
					cout << endl;
					displayPersons(persons, personCount);
				}
				else
				{
					cout << "Person not Found!" << endl;
				}
			}
			else
			{
				cout << "Invalid Input." << endl;
			}
		}

	} while (command.compare("EXIT") != 0);
	return 0;
}
Awesome! Thank you both!
Topic archived. No new replies allowed.