Class HELP

Pages: 123
So I have been working on this project and I am trying to learn how to use classes. I am completely lost, this is what I have been working on and if anyone has some suggestions to help me understand what I am doing wrong and some steps to fix it would be very much appreciated.

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your information ready for the invoice\n";
}

class Process
{
	private:
	
	float hoursWorked;
	double payRate;
	
	public:	
	
	
	double process(float hoursWorked, double payRate)

	
	teamMemberAmmount = (hoursWorked * payRate);
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	invoiceNumber = rand() % 99999 + 9999; // generate a random number for the invoice number 

	return teamMemberAmmount;
}

class Input
{
	private:
		string titleName 
		string clientName
		string teamMemberName 
		char titleNameSelection 
		char userResponce
		float hoursWorked		
		double payRate		 
		double teamMemberAmmount 
		double invoiceTotal
	
	public:
	
	ofstream outputFile; //open the file outside the loop to let the user finish all the input and entering the data to the file as they put it in
	outputFile.open("AndrewSmithProjectThreeInput.txt");

	while(userResponce != 'D' )
		{	
			cout << "\nPlease enter your clients name: " ;
			cin.clear();// using some cin clears beacuse the program was skipping some inputs 
			getline (cin,clientName);

			cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
			cout << "OK lets get started! \n" << endl;
		
			cin.clear();
			
			userResponce = 'Y'; // this keeps the loop going after the user enthers in the first client
		
			while (userResponce != 'N' && userResponce != 'D' )
			{
				cout << "Please enter the team member's name: ";
				cin.clear();
				getline (cin,teamMemberName);// still need to add the not null validation 

				cout << "\nThank you!\n" << endl;
				cout << "Now please select the team member " << teamMemberName << "'s job title from the following" << endl;
				cout << "Type A: for Project Manager" << endl;
				cout << "Type B: for Network Administrator" << endl;
				cout << "Type C: for Network Analyst" << endl;
				cout << "Type D: for Network Design Engineer" << endl;
				cin >> titleNameSelection;

			
				while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
				{
					cout << "\nInvalid input please enter A or B or C or D then press enter!\n";
					cin >> titleNameSelection;
				
				}
				switch(titleNameSelection)
				{
					case 'A':titleName = "Project Manager";
							payRate = 125.00;
							break;
							
					case 'B':titleName= "Network Administrator";
							 payRate = 80.00;
							break;
							
					case 'C':titleName = "Project Manager";
							 payRate= 50.00;
							break;
							
					case 'D':titleName = "Network Design Engineer";
							 payRate = 55.00;
							break;
				}

				cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
				cin >> hoursWorked;
				
					
					if (isalpha(hoursWorked))
					{
						cout << "Invalid input please enter a number" << endl;
						cin >> hoursWorked;
						cin.clear();
						cin.ignore(10000,'\n');
					}
					
				while(hoursWorked < 0 || hoursWorked > 300)
				{
					
					cout << "Invalid input please enter the amount of hours "<< teamMemberName << " Worked" << endl;
					cin >> hoursWorked;
				}
				
				cout << "\n********" << endl;
				cout << "**Menu**" << endl;
				cout << "********" << endl;
				
				cout << "Please type in one of the following choices then press enter" << endl;
				cout << "Y- To enter another team member to this client" << endl;
				cout << "N- To start a new cliet invoice" << endl;
				cout << "D- To finish and print" << endl;
				
				
				//If you have another team member you would like to enter type Y and press enter \nIf you would like to move onto the next client type in N then press enter. \nIf you are completly done type in D and we will finish up!: ";
				cin >> userResponce;
						
				while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
				{
					cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
					cin >> userResponce;
				}
				
				Process;
		
					
				if(::count == 1)
				{
						
					outputFile << clientName << endl; //sending the data the user just entered to the output file
					outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
					outputFile << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(15) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
					
					::count = ::count + 1;
				}
				
				
				outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
				
						
				if(userResponce == 'N' || userResponce == 'D' )
				{
					outputFile << "\nTotal $" << invoiceTotal << endl;
				}
				
				
				if(userResponce == 'N')// a statement that will add the invoice titles if the user starts a new client
				{
					::count = 1;
				}
				
				cin.clear();
				cin.ignore(10000,'\n');
				system("cls");	
			}
			
			outputFile << "\n\n";
		}
		
		outputFile.close();
		
		system("cls");
}

void output()
{
	string nextLine = "";
	
	ifstream inputFile;
	
	inputFile.open("AndrewSmithProjectThreeInput.txt");
	
	while (getline(inputFile, nextLine))//output the entire file to the prompt
	{
		cout << nextLine << endl;
		
	}	   
}

int main()
{
	srand(time(0)); 
	
	welcome();
			
	Input;
	
	system("cls");
	
	output();
	
}
What is your compiler telling you?

Why did you open a new topic for this existing problem?
(http://www.cplusplus.com/forum/beginner/177558/)

At a very quick glance I see a whole bunch of code outside any function and a classs that are not "closed" with a semicolon. Perhaps you need to look at your documentation for more information on classes.
http://www.cplusplus.com/doc/tutorial/classes/

Classes cannot contain code. Instead, they have member functions.

Exaple:
1
2
3
4
5
6
7
8
9
10
Class Cxy;
{
public:
   int x,y;
   void f(int b, int d) 
  {
      x = b; 
      y = b+d;
  }
};


To run a member function, you have to call it:
1
2
3
4
5
6
7
8
9
10
11
int main()
{
  Cxy t;
  Cxy u;
  t.f(3,4);
  u.f(10,11);
  cout << "t.x: " << t.x << endl;
  cout << "t.y: " << t.y << endl;
  cout << "u.x: " << u.x << endl;
  cout << "u.y: " << u.y << endl;    
}




Last edited on
That fixed alot of errors thank you

So now I have this with the error of __'{' missing function header (old style formal list?)__
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your information ready for the invoice\n";
}

class Process;
{
	public:	
	
	float hoursWorked;
	double payRate;
	
	
	double process(float hoursWorked, double payRate)
	{
	
	
	teamMemberAmmount = (hoursWorked * payRate);
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	invoiceNumber = rand() % 99999 + 9999; // generate a random number for the invoice number 

	return teamMemberAmmount;
	}
}

class Input;
{
	public:
		string titleName 
		string clientName
		string teamMemberName 
		char titleNameSelection 
		char userResponce
		float hoursWorked		
		double payRate		 
		double teamMemberAmmount 
		double invoiceTotal
	
	void input(string clientName, char userResponce, string teamMemberName, char titleNameSelection, string titleName, double payRate, float hoursWorked, double teamMemberAmmount, double invoiceTotal)
	{
		
	ofstream outputFile; //open the file outside the loop to let the user finish all the input and entering the data to the file as they put it in
	outputFile.open("AndrewSmithProjectThreeInput.txt");

	while(userResponce != 'D' )
		{	
			cout << "\nPlease enter your clients name: " ;
			cin.clear();// using some cin clears beacuse the program was skipping some inputs 
			getline (cin,clientName);

			cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
			cout << "OK lets get started! \n" << endl;
		
			cin.clear();
			
			userResponce = 'Y'; // this keeps the loop going after the user enthers in the first client
		
			while (userResponce != 'N' && userResponce != 'D' )
			{
				cout << "Please enter the team member's name: ";
				cin.clear();
				getline (cin,teamMemberName);// still need to add the not null validation 

				cout << "\nThank you!\n" << endl;
				cout << "Now please select the team member " << teamMemberName << "'s job title from the following" << endl;
				cout << "Type A: for Project Manager" << endl;
				cout << "Type B: for Network Administrator" << endl;
				cout << "Type C: for Network Analyst" << endl;
				cout << "Type D: for Network Design Engineer" << endl;
				cin >> titleNameSelection;

			
				while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
				{
					cout << "\nInvalid input please enter A or B or C or D then press enter!\n";
					cin >> titleNameSelection;
				
				}
				switch(titleNameSelection)
				{
					case 'A':titleName = "Project Manager";
							payRate = 125.00;
							break;
							
					case 'B':titleName= "Network Administrator";
							 payRate = 80.00;
							break;
							
					case 'C':titleName = "Project Manager";
							 payRate= 50.00;
							break;
							
					case 'D':titleName = "Network Design Engineer";
							 payRate = 55.00;
							break;
				}

				cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
				cin >> hoursWorked;
				
					
					if (isalpha(hoursWorked))
					{
						cout << "Invalid input please enter a number" << endl;
						cin >> hoursWorked;
						cin.clear();
						cin.ignore(10000,'\n');
					}
					
				while(hoursWorked < 0 || hoursWorked > 300)
				{
					
					cout << "Invalid input please enter the amount of hours "<< teamMemberName << " Worked" << endl;
					cin >> hoursWorked;
				}
				
				cout << "\n********" << endl;
				cout << "**Menu**" << endl;
				cout << "********" << endl;
				
				cout << "Please type in one of the following choices then press enter" << endl;
				cout << "Y- To enter another team member to this client" << endl;
				cout << "N- To start a new cliet invoice" << endl;
				cout << "D- To finish and print" << endl;
				
				
				//If you have another team member you would like to enter type Y and press enter \nIf you would like to move onto the next client type in N then press enter. \nIf you are completly done type in D and we will finish up!: ";
				cin >> userResponce;
						
				while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
				{
					cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
					cin >> userResponce;
				}
				
				Process;
		
					
				if(::count == 1)
				{
						
					outputFile << clientName << endl; //sending the data the user just entered to the output file
					outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
					outputFile << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(15) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
					
					::count = ::count + 1;
				}
				
				
				outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
				
						
				if(userResponce == 'N' || userResponce == 'D' )
				{
					outputFile << "\nTotal $" << invoiceTotal << endl;
				}
				
				
				if(userResponce == 'N')// a statement that will add the invoice titles if the user starts a new client
				{
					::count = 1;
				}
				
				cin.clear();
				cin.ignore(10000,'\n');
				system("cls");	
			}
			
			outputFile << "\n\n";
		}
		
		outputFile.close();
		
	}	system("cls");
}

void output()
{
	string nextLine = "";
	
	ifstream inputFile;
	
	inputFile.open("AndrewSmithProjectThreeInput.txt");
	
	while (getline(inputFile, nextLine))//output the entire file to the prompt
	{
		cout << nextLine << endl;
		
	}	   
}

int main()
{
	srand(time(0)); 
	
	welcome();
			
	Input;
	
	system("cls");
	
	output();
	
}
All structures and classes must be "closed" with a brace '}' followed by a semicolon.
1
2
3
4
5
structure test
{
   int number;
   int get_number();
};  // Close the class. 


Also because your class member functions are so large you really should move them out of the class body.
1
2
3
4
int test::get_number()
{
    // Some code here.
}


Last edited on
Getting closer? thank you so much for the help, I was getting very frustrated

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your information ready for the invoice\n";
}

class Process;
{
	public:	
	
	float hoursWorked;
	double payRate;
	double teamMemberAmmount 
	double invoiceTotal
	
	
	double process(float hoursWorked, double payRate)
	{
	
	
	teamMemberAmmount = (hoursWorked * payRate);
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	invoiceNumber = rand() % 99999 + 9999; // generate a random number for the invoice number 

	
	}
};

class Input;
{
	public:
		string titleName 
		string clientName
		string teamMemberName 
		char titleNameSelection 
		char userResponce
		float hoursWorked		
		double payRate	
			
	
	
	void input(string clientName, char userResponce, string teamMemberName, char titleNameSelection, string titleName, double payRate, float hoursWorked, double teamMemberAmmount, double invoiceTotal)
};



void input(string clientName, char userResponce, string teamMemberName, char titleNameSelection, string titleName, double payRate, float hoursWorked, double teamMemberAmmount, double invoiceTotal)
	{
		
	ofstream outputFile; //open the file outside the loop to let the user finish all the input and entering the data to the file as they put it in
	outputFile.open("AndrewSmithProjectThreeInput.txt");

	while(userResponce != 'D' )
		{	
			cout << "\nPlease enter your clients name: " ;
			cin.clear();// using some cin clears beacuse the program was skipping some inputs 
			getline (cin,clientName);

			cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
			cout << "OK lets get started! \n" << endl;
		
			cin.clear();
			
			userResponce = 'Y'; // this keeps the loop going after the user enthers in the first client
		
			while (userResponce != 'N' && userResponce != 'D' )
			{
				cout << "Please enter the team member's name: ";
				cin.clear();
				getline (cin,teamMemberName);// still need to add the not null validation 

				cout << "\nThank you!\n" << endl;
				cout << "Now please select the team member " << teamMemberName << "'s job title from the following" << endl;
				cout << "Type A: for Project Manager" << endl;
				cout << "Type B: for Network Administrator" << endl;
				cout << "Type C: for Network Analyst" << endl;
				cout << "Type D: for Network Design Engineer" << endl;
				cin >> titleNameSelection;

			
				while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
				{
					cout << "\nInvalid input please enter A or B or C or D then press enter!\n";
					cin >> titleNameSelection;
				
				}
				switch(titleNameSelection)
				{
					case 'A':titleName = "Project Manager";
							payRate = 125.00;
							break;
							
					case 'B':titleName= "Network Administrator";
							 payRate = 80.00;
							break;
							
					case 'C':titleName = "Project Manager";
							 payRate= 50.00;
							break;
							
					case 'D':titleName = "Network Design Engineer";
							 payRate = 55.00;
							break;
				}

				cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
				cin >> hoursWorked;
				
					
					if (isalpha(hoursWorked))
					{
						cout << "Invalid input please enter a number" << endl;
						cin >> hoursWorked;
						cin.clear();
						cin.ignore(10000,'\n');
					}
					
				while(hoursWorked < 0 || hoursWorked > 300)
				{
					
					cout << "Invalid input please enter the amount of hours "<< teamMemberName << " Worked" << endl;
					cin >> hoursWorked;
				}
				
				cout << "\n********" << endl;
				cout << "**Menu**" << endl;
				cout << "********" << endl;
				
				cout << "Please type in one of the following choices then press enter" << endl;
				cout << "Y- To enter another team member to this client" << endl;
				cout << "N- To start a new cliet invoice" << endl;
				cout << "D- To finish and print" << endl;
				
				
				//If you have another team member you would like to enter type Y and press enter \nIf you would like to move onto the next client type in N then press enter. \nIf you are completly done type in D and we will finish up!: ";
				cin >> userResponce;
						
				while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
				{
					cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
					cin >> userResponce;
				}
				
				Process;
		
					
				if(::count == 1)
				{
						
					outputFile << clientName << endl; //sending the data the user just entered to the output file
					outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
					outputFile << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(15) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
					
					::count = ::count + 1;
				}
				
				
				outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
				
						
				if(userResponce == 'N' || userResponce == 'D' )
				{
					outputFile << "\nTotal $" << invoiceTotal << endl;
				}
				
				
				if(userResponce == 'N')// a statement that will add the invoice titles if the user starts a new client
				{
					::count = 1;
				}
				
				cin.clear();
				cin.ignore(10000,'\n');
				system("cls");	
			}
			
			outputFile << "\n\n";
		}
		
		outputFile.close();
		
	}	system("cls");
	
void output()
{
	string nextLine = "";
	
	ifstream inputFile;
	
	inputFile.open("AndrewSmithProjectThreeInput.txt");
	
	while (getline(inputFile, nextLine))//output the entire file to the prompt
	{
		cout << nextLine << endl;
		
	}	   
}

int main()
{
	srand(time(0)); 
	
	welcome();
			
	Input;
	
	system("cls");
	
	output();
	
}
Getting closer?

What is the compiler telling you?

If you're getting compile errors or warnings post the complete error/warning messages, all of them, exactly as they appear in your development environment. These messages have important information embedded within them to aid in locating and fixing the problems. You really need to start learning to understand your compiler, this is a critical skill you must master sooner rather than later. By posting the messages perhaps someone can help you understand the messages.
Last edited on
I'm using VS2015 x86 Native Tools Command Prompt I don't know how to post the error and the one that is showing up and I do not know how to fix is the

line24--- '{' missing function header (old style formal list?)
The
line24--- '{' missing function header (old style formal list?)
was because of semicolons and i fixed that now all my errors are undeclared identifiers
I'm using VS2015 x86 Native Tools Command Prompt I don't know how to post the error

Have you tried highlighting the error messages with your mouse and copying then pasting that text into a post?

When dealing with error messages always start at the line the compiler points out, and if everything looks good proceed to the previous lines. Many times the error is located somewhere before the stated line, as is the case this time.

Also IMO you're trying to cut and paste too much too quickly. Start by creating the class definition, then create the member functions with blank bodies. Compiling often. Then cut and paste the code into the functions. Also IMO your "functions" seem to be doing way too much. You should strive to keep your functions simple, most times doing one thing, but doing that one thing well.

Also when converting from a procedural program to a class based function you should probably be rethinking the flow of the program, not just cutting and pasting.

Errors on line 69 and 74 for undeclared identifiers but if I declare them there it says they have already been used

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

int count = 0;

double getMemAmmount(float hoursWorked, double payRate)
{
	double teamMemberAmmount;
	
	teamMemberAmmount = (hoursWorked * payRate);
	
	return teamMemberAmmount;
}

double getMemTotal(double teamMemberAmmount)
{
	double invoiceTotal;
	
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	
	return invoiceTotal;
}

class GetAmmount 
{
	private:
	double payRate;
	float hoursWorked;
	
	public:
	
	double teamMemberAmmount = getMemAmmount(hoursWorked, payRate);
	double invoiceTotal = getMemTotal(teamMemberAmmount);
	
};

void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your information ready for the invoice\n";
}

void outputToFile(char userResponce, string clientName, string teamMemberName, string titleName, float hoursWorked, double payRate)
{
ofstream outputFile; //open the file outside the loop to let the user finish all the input and entering the data to the file as they put it in
outputFile.open("AndrewSmithProjectThreeInput.txt");

srand(time(0)); 
int invoiceNumber = (rand() % 99999 + 9999);

GetAmmount();


if(::count == 1)
	{
			
		outputFile << clientName << endl; //sending the data the user just entered to the output file
		outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
		outputFile << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(14) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
		
		::count = ::count + 1;
	}
	
	
	outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
	
			
	if(userResponce == 'N' || userResponce == 'D' )
	{
		outputFile << "\nTotal $" << invoiceTotal << endl;
	}
	
	
	if(userResponce == 'N')// a statement that will add the invoice titles if the user starts a new client
	{
		::count = 1;
	}
	
	cin.clear();
	cin.ignore(10000,'\n');
	
	system("cls");	
	
	outputFile << "\n\n";
	outputFile.close();
}

void outputToConsole()
{
	string nextLine = "";
	
	ifstream inputFile;
	
	inputFile.open("AndrewSmithProjectThreeInput.txt");
	
	while (getline(inputFile, nextLine))//output the entire file to the prompt
	{
		cout << nextLine << endl;
		
	}	   
}

int main()
{
	char titleNameSelection;
	char userResponce = 'Y';
	string clientName;
	string teamMemberName;
	string titleName;
	double payRate;
	float hoursWorked;
	
	welcome();

	while(userResponce != 'D' )
	{	
		cout << "\nPlease enter your clients name: " ;
		cin.clear();// using some cin clears beacuse the program was skipping some inputs 
		getline (cin,clientName);

		cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
		cout << "OK lets get started! \n" << endl;
	
		cin.clear();
		
		userResponce = 'Y'; // this keeps the loop going after the user enthers in the first client
	
		while (userResponce != 'N' && userResponce != 'D' )
		{
			cout << "Please enter the team member's name: ";
			cin.clear();
			getline (cin,teamMemberName);// still need to add the not null validation 

			cout << "\nThank you!\n" << endl;
			cout << "Now please select the team member " << teamMemberName << "'s job title from the following" << endl;
			cout << "Type A: for Project Manager" << endl;
			cout << "Type B: for Network Administrator" << endl;
			cout << "Type C: for Network Analyst" << endl;
			cout << "Type D: for Network Design Engineer" << endl;
			cin >> titleNameSelection;

		
			while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
			{
				cout << "\nInvalid input please enter A or B or C or D then press enter!\n";
				cin >> titleNameSelection;
			
			}
			switch(titleNameSelection)
			{
				case 'A':titleName = "Project Manager";
						payRate = 125.00;
						break;
						
				case 'B':titleName= "Network Administrator";
						 payRate = 80.00;
						break;
						
				case 'C':titleName = "Project Manager";
						 payRate= 50.00;
						break;
						
				case 'D':titleName = "Network Design Engineer";
						 payRate = 55.00;
						break;
			}

			cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
			cin >> hoursWorked;
			
			/*if (isalpha(hoursWorked)) // cant get this to validate for input type
			{
				cout << "Invalid input please enter a number" << endl;
				cin >> hoursWorked;
				cin.clear();
				cin.ignore(10000,'\n');
			}*/
			
		while(hoursWorked < 0 || hoursWorked > 300)
		{
			
			cout << "Invalid input please enter the amount of hours "<< teamMemberName << " Worked" << endl;
			cin >> hoursWorked;
		}
			
			cout << "\n********" << endl;
			cout << "**Menu**" << endl;
			cout << "********" << endl;
				
			cout << "Please type in one of the following choices then press enter" << endl;
			cout << "Y- To enter another team member to this client" << endl;
			cout << "N- To start a new cliet invoice" << endl;
			cout << "D- To finish and print" << endl;
			cin >> userResponce;
						
			while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
			{
				cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
				cin >> userResponce;
			}
			
			outputToFile(userResponce, clientName, teamMemberName, titleName, hoursWorked, payRate);
				
		}
		
	}
	
	outputToConsole();
	system("cls");
}
Without the complete error messages I can't help you.

And please do something about those obnoxiously long lines.

Jim
>> class Process;

It's my fault.

class names should not be followed by ;
closed account (48T7M4Gy)
I am completely lost

And hopefully you can see the reason why. Basically you have written 214 lines of uncoordinated code that focuses on long-winded messages, comments and formatting stuff that detracts from your stated purpose of learning about classes.

I suggest you put this program to one side for a while and design a class (or two) and build on them by creating a short main() test program. Forget about sytsem cls and trying to fancy up the displays until you get the basics right.

As another observation a class name like GetAmount indicates you possibly don't quite grasp what a class is.

GetAmount is a method/procedure/function rather than a class, which is an object or a thing. Getting an amount is not a thing it is an action. The distinction in object oriented programming is vitally important.

As a suggestion, and you need to think about what is right for your program, it appears the things you are dealing with are Accounts and Users. Those two might be your starting point for classes of objects.

Also, as mentioned above, if you have more than about 60 characters on a line then you are either too verbose, the functions are over-bloated with variables or the output stream info needs to be spread judiciously and tidily over several lines.

Blank lines are generally unnecessary unless a spacing between blocks and sub units. Double spacing is bad.

But don't throw away what you have. Come back to it when you sub-units are working properly and the confusion dissipates. :)
Last edited on
closed account (48T7M4Gy)
PS As a low priority stringstreams are an ideal way of avoiding the traumas of console display and file handling of output (and input).

(
response - :)
responce - :(
)
Thank you guys for the input I have messed around with it a little more trying to grasp the concept but I don't think I will post anymore code on this issue until I have a reasonable problem... it seems.
closed account (48T7M4Gy)
Keeping it really simple, you also might have just two classes - Employee and Occupation.

- each Employee has a Surname, Occupation and HoursWorked
- each Occupation has a JobDescription and HourlyRate

From these two you can create each Employee and their pay with Occupation being the 'link' and there would be a method in the Employee class which would take the relevant attributes to work out that employees pay - say double CalculatePay() ... etc

Once you get that working you can extend this as required to a whole payroll system.

PS for an invoice you just work on this adding a bit for profit, maybe.
Last edited on
closed account (48T7M4Gy)
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
#include <string>
#include <iostream>

// OCCUPATION
class Occupation
{
public:
	Occupation( std::string aJobDescription = "Worker", double rate = 15.00 )
	{
		jobDescription = aJobDescription;
		hourlyRate = rate;
	}

	~Occupation() {}

	double getHourlyRate()
	{
		return hourlyRate;
	}
private:
	std::string jobDescription;
	double hourlyRate;
};

// EMPLOYEE
class Employee {
public:
	Employee(std::string name, Occupation anOccupation, double hours )
	{
		surname = name;
		occupation = anOccupation;
		hoursWorked = hours;
	}

	~Employee() {}

	std::string getSurname()
	{
		return surname;
	}

	double CalculatePay()
	{
		return hoursWorked * occupation.getHourlyRate();
	}
private:
	std::string surname;
	Occupation occupation;
	double hoursWorked;
};

int main()
{
	Occupation job1("Gardener", 15.00);
	Employee employee1("Smith", job1, 20);

	std::cout 
		<< "Name: " << employee1.getSurname() 
		<< " Pay: $" << employee1.CalculatePay() 
		<< std::endl;
        return 0;
}
Last edited on
Great!! Thank you!! Very helpful
So I know I said I wasn't going to post anything but I learned a little more a figured, why not...
^.^ any advice will be useful.

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

int count = 0;
void outputToFile();

class invoice
{
	private :	
	char titleNameSelection;	
	char userResponse;
	string clientName;
	string teamMemberName;
	string titleName;
	double payRate;
	float hoursWorked;
	
	public:
	
		invoice()
		{
			userResponse = 'Y';
		}
	
		double getMemAmmount(float times , double by)
		{
			double amount;
			amount = (times * by);
			return amount;
		}

		double getMemTotal(double increment)
		{
			double incrementTotal;
			incrementTotal = incrementTotal + increment;
			return incrementTotal;
		}
							
		void userInput()
		{
			while(userResponse != 'D' )
			{	
				cout << "\nPlease enter your clients name: " ;
				cin.clear();// using some cin clears beacuse the program was skipping some inputs 
				getline (cin,clientName);
				
				cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
				cout << "OK lets get started! \n" << endl;
				cin.clear();
				userResponse = 'Y'; // this keeps the loop going after the user enthers in the first client
			
				while (userResponse != 'N' && userResponse != 'D' )
				{
					cout << "Please enter the team member's name: ";
					cin.clear();
					getline (cin,teamMemberName);// still need to add the not null validation
					cout << "\nThank you!\n" << endl;
					cout << "Now please select the team member " << teamMemberName << "'s job title from the following" << endl;
					cout << "Type A: for Project Manager" << endl;
					cout << "Type B: for Network Administrator" << endl;
					cout << "Type C: for Network Analyst" << endl;
					cout << "Type D: for Network Design Engineer" << endl;
					cin >> titleNameSelection;

					while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
					{
						cout << "\nInvalid input please enter A or B or C or D then press enter!\n";
						cin >> titleNameSelection;
					
					}
					switch(titleNameSelection)
					{
						case 'A':titleName = "Project Manager";
								payRate = 125.00;
								break;
								
						case 'B':titleName= "Network Administrator";
								 payRate = 80.00;
								break;
								
						case 'C':titleName = "Project Manager";
								 payRate= 50.00;
								break;
								
						case 'D':titleName = "Network Design Engineer";
								 payRate = 55.00;
								break;
					}

					cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
					cin >> hoursWorked;
					
					/*if (isalpha(hoursWorked)) // cant get this to validate for input type
					{
						cout << "Invalid input please enter a number" << endl;
						cin >> hoursWorked;
						cin.clear();
						cin.ignore(10000,'\n');
					}*/
					
		
					while(hoursWorked < 0 || hoursWorked > 300)
					{ 
						cout << "\nPlease enter the amount of hours "<< teamMemberName << " Worked" << endl;
						cin >> hoursWorked;
						cout << "Invalid input please enter a number" << endl;
					}
						
					
					cout << "\n********" << endl;
					cout << "**Menu**" << endl;
					cout << "********" << endl;	
					cout << "Please type in one of the following choices then press enter" << endl;
					cout << "Y- To enter another team member to this client" << endl;
					cout << "N- To start a new cliet invoice" << endl;
					cout << "D- To finish and print" << endl;
					cin >> userResponse;
								
					while(userResponse != 'Y' && userResponse != 'N' && userResponse != 'D')
					{
						cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
						cin >> userResponse;
					}	
				}
			}
		}
};

void outputToFile(string cName, string tMemberName, string tName, float hWorked, double pRate, char uResponse)
	{
		ofstream outputFile; //open the file outside the loop to let the user finish all the input and entering the data to the file as they put it in
		outputFile.open("AndrewSmithProjectThreeInput.txt");
		
		srand(time(0)); 
		int invoiceNumber = (rand() % 99999 + 9999);
		
		//double teamMemberAmmount;
		//double invoiceTotal;
		
		
		invoice.teamMemberAmmount =  getMemAmmount();
		invoice.invoiceTotal =  getMemTotal();
		
		
		if(::count == 1)
		{		
			outputFile << cName << endl; //sending the data the user just entered to the output file
			outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
			outputFile << left << setw(19) <<"Team Member Name:" << right << "|";
			outputFile << left << setw(25) << "Title:" << right << "|";
			outputFile << left << setw(7) << "Hours:" << right << "|" ;
			outputFile << left << setw(14) << "Hourly Rate:" << right << "|" ;
			outputFile << left << setw(18) << "Team Member Amount:" << endl;
			::count = ::count + 1;
		}
		
		
		outputFile << left << setw(19) << tMemberName << right << "|" ;
		outputFile << left << setw(25) << tName << right << "|";
		outputFile << left  << "$" << setw(7) << hWorked << right << "|" ;
		outputFile << left  << "$" << setw(14) << pRate << right << "|" ;
		outputFile << left  << "$" << setw(18) << teamMemberAmmount << endl; 
		
				
		if(uResponse == 'N' || uResponse == 'D' )
		{
			outputFile << "\nTotal $" << invoiceTotal << endl;
		}
		
		
		if(uResponse == 'N')// a statement that will add the invoice titles if the user starts a new client
		{
			::count = 1;
		}
		
		cin.clear();
		cin.ignore(10000,'\n');
		system("cls");	
		outputFile << "\n\n";
		outputFile.close();
	}

void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your information ready for the invoice\n";
}


void outputToConsole()
{
	string nextLine = "";
	ifstream inputFile;
	inputFile.open("AndrewSmithProjectThreeInput.txt");
	
	while (getline(inputFile, nextLine))//output the entire file to the prompt
	{
		cout << nextLine << endl;
	}	   
}

int main()
{	
	welcome();
	
	invoice print;
	
	print.outputToFile(clientName, teamMemberName, titleName, hoursWorked, payRate, userResponse);
	
	outputToConsole();
	system("cls");
}
Pages: 123