Resume built with C++

I'm trying to compile and output my code into an external text file. Using the servers provided by my school, it doesn't compile and there's an error with the File I/O Implementation, can someone give some help?

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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
  #include <iostream>
#include <string.h>
#include <ctype.h>
#include <fstream>
#include <iomanip>
using namespace std;

//structs provided from the assignment description
struct Edu{
	char univ[128]; // a c-string to store the university name
	char major[64]; // a c-string to store the major
	int graduate_year; // graduation year
	float GPA; // GPA
};

struct Basics{
	char fname[64]; // a c-string to store the first name
	char lname[64]; // a c-string to store the last name
	char email[64]; // a c-string to store the email address
	Edu edu; // an Edu object to store the ed. background
};

struct Exp{
	char company[64]; // a c-string to store the company name
	char start_date[64]; // a c-string to store the start date
	char end_date[64]; // a c-string to store the end date
	char des[1024]; // the description of the work experience
};

/******************************************************************* 
 ** Function: 
 ** Description: 
 ** Parameters:  
 ** Pre-conditions: 
 ** Post-conditions: 
 *******************************************************************/ 

void get_skills(string sk[], int sk_size, int *sCount){
	int skillCount = 0;
	string temp = "";
	cout << "\nEnter your skills one-by-one : (Enter a '.' to stop entering skills) " << endl;
	while (temp[0] != '.'){
		getline(cin, temp);
		sk[skillCount] = temp;
		skillCount++;
	}
	*sCount = skillCount - 1;
}

/******************************************************************* 
 ** Function: 
 ** Description: 
 ** Parameters:  
 ** Pre-conditions: 
 ** Post-conditions: 
 *******************************************************************/ 

bool validateDate(string temp){
	if (isdigit(temp[0]) && (isdigit(temp[1])) && (temp[2] == '-') && (isdigit(temp[3])) && (isdigit(temp[4])) && (temp[5] == '-') && (isdigit(temp[6])) && (isdigit(temp[7])))
		return true;
	return false;
}

/******************************************************************* 
 ** Function: 
 ** Description: 
 ** Parameters:  
 ** Pre-conditions: 
 ** Post-conditions: 
 *******************************************************************/ 

bool validateEmail(string temp){
	bool check_a = false;
	bool check_dot = false;
	for (char i : temp){
		if (i == '@')
			check_a = true;
		if (i == '.')
			check_dot = true;
	}
	return check_a && check_dot;
}

/******************************************************************* 
 ** Function: 
 ** Description: 
 ** Parameters:  
 ** Pre-conditions: 
 ** Post-conditions: 
 *******************************************************************/

void get_basics_and_edu(Basics *bc, Edu *ed){
	string temp;

	cout << "\nEnter your first name : ";
	getline(cin, temp);
	strcpy(bc->fname, temp.c_str());

	cout << "Enter your last name : ";
	getline(cin, temp);
	strcpy(bc->lname, temp.c_str());
	
	while (true){
		cout << "Enter your E-mail address : ";
		getline(cin, temp);
		if (validateEmail(temp)){
			strcpy(bc->email, temp.c_str());
			break;
		}
		else{
			cout << "E-mail not valid! Try again." << endl;
		}
    	}
	
	cout << "\nEnter your University/College : ";
	getline(cin, temp);
	strcpy(ed->univ, temp.c_str());

	cout << "Enter your Major : ";
	getline(cin, temp);
	strcpy(ed->major, temp.c_str());

	cout << "Enter your Graduation year : ";
	cin >> ed->graduate_year;
	cout << "Enter your GPA : ";
	cin >> ed->GPA;
	cin.ignore(1, '\n');
}

/******************************************************************* 
 ** Function: 
 ** Description: 
 ** Parameters:  
 ** Pre-conditions: 
 ** Post-conditions: 
 *******************************************************************/ 

void get_one_exp(Exp *ex){
	string temp;
	cout << "\nEnter your Company/Employer : ";
	getline(cin, temp);
	strcpy(ex->company, temp.c_str());
	
	while (true){
		cout << "Enter start date in dd-mm-yy format : ";
		getline(cin, temp);
		if (validateDate(temp)){
			strcpy(ex->start_date, temp.c_str());
			break;
		}
		else{
			cout << "\nDate not valid! Try again." << endl;
		}
	}
	
	while (true){
		cout << "Enter end date in dd-mm-yy format : ";
		getline(cin, temp);
		if (validateDate(temp)){
			strcpy(ex->end_date, temp.c_str());
			break;
		}
		else{
			cout << "\nDate not valid! Try again." << endl;
		}
	}
	
	cout << "Enter description : ";
	getline(cin, temp);
	if (temp == "")
		strcpy(ex->des, "None");
	else
		strcpy(ex->des, temp.c_str());
}

/******************************************************************* 
 ** Function: 
 ** Description: 
 ** Parameters:  
 ** Pre-conditions: 
 ** Post-conditions: 
 *******************************************************************/ 

void get_exp(Exp ex[], int ex_size, int *eCount){
	int expCount = 0;
	char conf;

	cout << "\nWork Experience : " << endl;
	while (true){
		get_one_exp(&(ex[expCount]));
		expCount++;
	if (expCount == ex_size)
		break;
	cout << "\nDo you want to add more experiences? (y / n) : ";
	cin >> conf;
	cin.ignore(1, '\n');
	if (tolower(conf) != 'y')
		break;
	}
	*eCount = expCount;
}

/******************************************************************* 
 ** Function: 
 ** Description: 
 ** Parameters:  
 ** Pre-conditions: 
 ** Post-conditions: 
 *******************************************************************/ 

void build_resume(ofstream &f, Basics b, Exp ex[], int ex_size, string sk[], int sk_size, Edu e){
	f << string(100, '-') << endl;
	f << string(39, ' ') << string(5, '=') << "   RESUME   " << string(5, '=') << endl;
	f << "\n\n\tBasic Information :- " << endl
		<< endl;
	f << setw(35) << "First Name "
		<< ": " << b.fname << endl;
	f << setw(35) << "Last Name "
		<< ": " << b.lname << endl;
	f << setw(35) << "Email Address "
		<< ": " << b.email << endl;

	f << "\n\n\tEducation Background :- " << endl
		<< endl;
	f << setw(35) << "University/College "
		<< ": " << e.univ << endl;
	f << setw(35) << "Major "
		<< ": " << e.major << endl;
	f << setw(35) << "Graduation year "
		<< ": " << e.graduate_year << endl;
	f << setw(35) << "GPA "
		<< ": " << e.GPA << endl;

	f << "\n\n\tWork Experience :- " << endl;
	for (int i = 0; i < ex_size; i++){
		f << endl;
		f << setw(15) << i + 1 << "." << endl;
		f << setw(35) << "Company/Employer "
			<< ": " << ex[i].company << endl;
		f << setw(35) << "Start date "
			<< ": " << ex[i].start_date << endl;
		f << setw(35) << "End date "
			<< ": " << ex[i].end_date << endl;
		f << setw(35) << "Description "
			<< ": " << ex[i].des << endl;
	}

	f << "\n\n\tSkills  :- " << endl;
	for (int i = 0; i < sk_size; i++){
		f << endl;
		f << setw(15) << i + 1 << ". ";
		f << sk[i] << endl;
	}
}

int main(){
	struct Exp *ex = new Exp[5];
	struct Basics bc;
	struct Edu ed;
	string *skills = new string[10];
	int skillCount = 0;
	int expCount = 0;

	get_basics_and_edu(&bc, &ed);
	get_exp(ex, 5, &expCount);
	get_skills(skills, 10, &skillCount);

	string ext = ".txt";
	string filename = bc.lname + ext;
	
	ofstream f;
	f.open(filename);
	build_resume(f, bc, ex, expCount, skills, skillCount, ed);
	f.close();

	delete[] ex;
	delete[] skills;
}
You're used the wrong include files. These are for c functions. Replace L2 & L3 with

1
2
#include <string>
#include <cctype> 


You then get a warning on L38 that sk_size is an unreferenced parameter.
Seems like I can compile it as c11, I am still unable to produce a file as a txt at the end, what else am I missing?
the firs t thing to check is whether you can write to where it is putting the files (many servers restrict file writes to your home folder only if unix or desktop / profile areas if windows).

what happens on line 272 with the failbit of the .open call?
Last edited on
@chickentheplay

I have run your program successfully. It produced the resume .txt file. So it therefore appears you have not searched for and found the file (when all else has failed).

I suggest you hardcode the file name for testing purposes.

As an additional piece of advice it looks like you have fallen into the age old trap of debugging 278 lines of code instead of testing a particular/small part of the functionality separate from the project. I can only guess at the mountain of hours you have endured typing in the same resume.
@chickentheplay - why are you mixing c++ std::string and c-style strings? Why not use just std::string?

Why are you passing function params by pointer? In C++ if you want to return a value in a param then it is usually passed by ref rather than by pointer (which is the c way of doing it).

Why use new when the size of the required arrays is specified at compile time?

Have you come across std::vector or std::array yet? If not, I suggest you have a look at them. They make life easier!

http://www.cplusplus.com/reference/array/array/
http://www.cplusplus.com/reference/vector/vector/
Topic archived. No new replies allowed.