overload problem?

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
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;

struct Name // storing customer name.
{string lastname;

string firstname;
};
struct Address//storing customer address.
{string houseNum;

string streetname;

string city;

string state;

string zip;
};
struct phoneNum //storing customer Number.
{

	string phnum;
};
struct custAct// customer account Info.
{

	Name custname;

	Address custaddr;

	phoneNum custphnum;

	double actbalance;

	string dtlstpymt;
};

vector <custAct> amount;

void menu(string choicenum, custAct alldata,ofstream & outData);

bool choice;

int main()

{  	
custAct alldata;
ofstream outData;
string choicenum; 
vector <custAct> amount;



while (choice==true)
{
	cout<<"1. Add customer account\n";
	cout<<"2. Display customer accounts\n";
	cout<<"3. Store customer accounts\n";
	cout<<"4. Quit Program\n";
	cin>>choicenum;
	menu(choicenum, alldata,outData);
}

return 0;

}


void menu(string choicenum, custAct alldata, ofstream & outData)// i want to overload the custAct alldata
{

	if (strcmp(choicenum.c_str(),"1")==0)
	{
		// enter customer account information;
		// store information in a vector.
		cout<<"Please enter customer's last name then first name\n.";
		cout<<"Please leave a space in between the names\n.";                    // i want to overload alldata. With this info.
		cin>>alldata.custname.lastname>>alldata.custname.firstname;
		cout<<" Next enter the customer's address in this order.\n";
		cout<<" House number, street Name, city,state, zip and please leave a space in between the\n";		
		cin>>alldata.custaddr.houseNum>>alldata.custaddr.streetname>>alldata.custaddr.city>>alldata.custaddr.state>>alldata.custaddr.zip;
		cout<<"Please enter customer's phone number.\n";
		cin>>alldata.custphnum.phnum;
		amount.push_back(alldata);




	}

	if (strcmp(choicenum.c_str(),"2")==0)
	{
		//sort the vector of accounts info by lastname alphabetically and display on the screen
		// one account at a time with appropriate labels.
		int i, j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i <amount.size(); i++);
			{//sorting data that program recieves and places everything in order. but i'm not sure if its working correctly.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
				}
			cout<<"black";
		}

		system("pause");
		system("cls");

	}


	if (strcmp(choicenum.c_str(),"3")==0)
	{
		//prompt the user for a file name, open that file and essentially do item 2 
		//but writing the info to the file with out pauses, don't forget to display
		// an error message if the vector of accounts is empty, then close the
		// file. Overload the insertion operator to send the account info to the file.
		char ofile[16];
		cout<<"Please enter Filename to save :";// open file to save data
		cin>>ofile;
		outData.open (ofile);
		system("cls");

		while (amount())// I want it to loop till it reaches the end of the vector.
		{
			outData<<alldata[j].custname;
			outData<<alldata[j].custaddr;
			outData<<alldata[j].custphnum;
			outData<<alldata[j].actbalance;
			outData<<alldata[j].dtlstpymt;;
		}
		outData.close(); 

		
		int i, j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i <amount.size(); i++);
			{//sorting data that program recieves and places everything in order.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
				}
			outData<<[j];
		}

	if (strcmp(choicenum.c_str(),"4")==0)
	{
		// exit the program.
		// repeat the program until user selects item 4.
		choice==false;


	}
}
Last edited on
I see many wrong things

1) amount is declared locally and globaly, bad idea
line 44:
1
2
3
 
   vector <custAct> amount;
 


line 56:
1
2
  vector <custAct> amount;
 


2) i should start at 0 here:
line 108
 
for (i=1; i <amount.size(); i++);


3) i think you forgot to change this:

1
2
3
4
5
6
7
8
9
10
11
12
while (amount())// I want it to loop till it reaches the end of the vector.
		{
			outData<<alldata[j].custname;
			outData<<alldata[j].custaddr;
			outData<<alldata[j].custphnum;
			outData<<alldata[j].actbalance;
			outData<<alldata[j].dtlstpymt;;
		}
		outData.close(); 

		
		int i, j;

its going to run forever or never

also idk how ur Sorting alphabetically is working, and whats index?, your not setting it's value any where i see.(in choise 2)

also whats the strcmp function

i might be missing more things, i m a newbie also


fatal error C1075: end of file found before the left brace '{' i can't find where the file ends. it should be working correctly.


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
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;

struct Name // storing customer name.
{string lastname;

string firstname;
};
struct Address//storing customer address.
{string houseNum;

string streetname;

string city;

string state;

string zip;
};
struct phoneNum //storing customer Number.
{

	string phnum;
};
struct custAct// customer account Info.
{

	Name custname;

	Address custaddr;

	phoneNum custphnum;

	double actbalance;

	string dtlstpymt;
};
vector <custAct> amount;
void menu(string choicenum, custAct alldata,ofstream & outData);

bool choice;

int main()

{  	
	custAct alldata;
	ofstream outData;
	string choicenum; 




	while (choice==true)
	{
		cout<<"1. Add customer account\n";
		cout<<"2. Display customer accounts\n";
		cout<<"3. Store customer accounts\n";
		cout<<"4. Quit Program\n";
		cin>>choicenum;
		menu(choicenum, alldata,outData);
	}

	return 0;

}


void menu(string choicenum, custAct alldata, ofstream & outData)// i want to overload the custAct alldata
{

	if (strcmp(choicenum.c_str(),"1")==0)
	{
		// enter customer account information;
		// store information in a vector.
		cout<<"Please enter customer's last name then first name\n.";
		cout<<"Please leave a space in between the names\n.";                    // i want to overload alldata. With this info.
		cin>>alldata.custname.lastname>>alldata.custname.firstname;
		cout<<" Next enter the customer's address in this order.\n";
		cout<<" House number, street Name, city,state, zip and please leave a space in between the\n";		
		cin>>alldata.custaddr.houseNum>>alldata.custaddr.streetname>>alldata.custaddr.city>>alldata.custaddr.state>>alldata.custaddr.zip;
		cout<<"Please enter customer's phone number.\n";
		cin>>alldata.custphnum.phnum;
		amount.push_back(alldata);




	}

	if (strcmp(choicenum.c_str(),"2")==0)
	{
		//sort the vector of accounts info by lastname alphabetically and display on the screen
		// one account at a time with appropriate labels.
		int i, j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i< amount.size(); i++);
			{//sorting data that program recieves and places everything in order. but i'm not sure if its working correctly.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
			}
			cout<<amount[j].custname.lastname;
			cout<<amount[j].custname.firstname;
			cout<<amount[j].custaddr.houseNum;
			cout<<amount[j].custaddr.streetname;
			cout<<amount[j].custaddr.city;
			cout<<amount[j].custaddr.state;
			cout<<amount[j].custaddr.zip;
			cout<<amount[j].custphnum.phnum;
			cout<<amount[j].actbalance;
			cout<<amount[j].dtlstpymt;
		}

		system("pause");
		system("cls");

	}


	if (strcmp(choicenum.c_str(),"3")==0)
	{
		//prompt the user for a file name, open that file and essentially do item 2 
		//but writing the info to the file with out pauses, don't forget to display
		// an error message if the vector of accounts is empty, then close the
		// file. Overload the insertion operator to send the account info to the file.
		char ofile[16];
		cout<<"Please enter Filename to save :";// open file to save data
		cin>>ofile;
		outData.open (ofile);
		system("cls");
		int i=1;
		int j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i <amount.size(); i++);
			{//sorting data that program recieves and places everything in order.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
			}
			outData<<amount[j].custname.lastname;
			outData<<amount[j].custname.firstname;
			outData<<amount[j].custaddr.houseNum;
			outData<<amount[j].custaddr.streetname;
			outData<<amount[j].custaddr.city;
			outData<<amount[j].custaddr.state;
			outData<<amount[j].custaddr.zip;
			outData<<amount[j].custphnum.phnum;
			outData<<amount[j].actbalance;
			outData<<amount[j].dtlstpymt;
		}
		outData.close();

		if (strcmp(choicenum.c_str(),"4")==0)
		{
			// exit the program.
			// repeat the program until user selects item 4.
			(choice==false);
		}
	}
You should read your compiler errors more closely.
It probably says something like:
c:\documents and settings\andy\my documents\programming\projects\msvc\test_test\test_test.cpp(419) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\andy\my documents\programming\projects\msvc\test_test\test_test.cpp(86)' was matched


Note: It says line 86 in my code because I have a few more lines that yours (and ok my file name is different because i copied and pasted).
On yours it probably says Line 74.
As you can see on line 74 - you have the opening brace for the menu function.
So it's saying it reached the end of the file before finding the closing } for that function.


You should be able to see that just by looking at the code.
Last edited on
My menu seems to be working but it will not loop.
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
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;

struct Name // storing customer name.
{string lastname;

string firstname;
};
struct Address//storing customer address.
{string houseNum;

string streetname;

string city;

string state;

string zip;
};
struct phoneNum //storing customer Number.
{

	string phnum;
};
struct custAct// customer account Info.
{

	Name custname;

	Address custaddr;

	phoneNum custphnum;

	double actbalance;

	string dtlstpymt;
};
vector <custAct> amount;
void menu(string choicenum, custAct alldata,ofstream & outData);

bool choice;

int main()

{  	
	custAct alldata;
	ofstream outData;
	string choicenum; 
	
	
	do
	{
	cout<<"1. Add customer account\n";
	cout<<"2. Display customer accounts\n";
	cout<<"3. Store customer accounts\n";
	cout<<"4. Quit Program\n";
	cin>>choicenum;			
	menu(choicenum, alldata,outData);
	}while (choice==true);
	return 0;

}


void menu(string choicenum, custAct alldata, ofstream & outData)// i want to overload the custAct alldata
{

	if (strcmp(choicenum.c_str(),"1")==0)
	{
		(choice==true);
		// enter customer account information;
		// store information in a vector.
		cout<<"Please enter customer's last name then first name\n.";
		cout<<"Please leave a space in between the names\n.";                    // i want to overload alldata. With this info.
		cin>>alldata.custname.lastname>>alldata.custname.firstname;
		cout<<" Next enter the customer's address in this order.\n";
		cout<<" House number, street Name, city,state, zip and please leave a space in between the\n";		
		cin>>alldata.custaddr.houseNum>>alldata.custaddr.streetname>>alldata.custaddr.city>>alldata.custaddr.state>>alldata.custaddr.zip;
		cout<<"Please enter customer's phone number.\n";
		cin>>alldata.custphnum.phnum;
		amount.push_back(alldata);
		
		system("cls");
	}

	if (strcmp(choicenum.c_str(),"2")==0)
	{
		(choice==true);
		//sort the vector of accounts info by lastname alphabetically and display on the screen
		// one account at a time with appropriate labels.
		int i, j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i< amount.size(); i++);
			{//sorting data that program recieves and places everything in order. but i'm not sure if its working correctly.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
			}
			cout<<amount[j].custname.lastname;
			cout<<amount[j].custname.firstname;
			cout<<amount[j].custaddr.houseNum;
			cout<<amount[j].custaddr.streetname;
			cout<<amount[j].custaddr.city;
			cout<<amount[j].custaddr.state;
			cout<<amount[j].custaddr.zip;
			cout<<amount[j].custphnum.phnum;
			cout<<amount[j].actbalance;
			cout<<amount[j].dtlstpymt;
			
		}


		system("pause");
		system("cls");

	}


	if (strcmp(choicenum.c_str(),"3")==0)
	{
		(choice==true);
		//prompt the user for a file name, open that file and essentially do item 2 
		//but writing the info to the file with out pauses, don't forget to display
		// an error message if the vector of accounts is empty, then close the
		// file. Overload the insertion operator to send the account info to the file.
		char ofile[16];
		cout<<"Please enter Filename to save :";// open file to save data
		cin>>ofile;
		outData.open (ofile);
		system("cls");
		int i=1;
		int j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i <amount.size(); i++);
			{//sorting data that program recieves and places everything in order.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
			}
			outData<<amount[j].custname.lastname;
			outData<<amount[j].custname.firstname;
			outData<<amount[j].custaddr.houseNum;
			outData<<amount[j].custaddr.streetname;
			outData<<amount[j].custaddr.city;
			outData<<amount[j].custaddr.state;
			outData<<amount[j].custaddr.zip;
			outData<<amount[j].custphnum.phnum;
			outData<<amount[j].actbalance;
			outData<<amount[j].dtlstpymt;

			outData.close();
			
		}
		if (strcmp(choicenum.c_str(),"4")==0)
		{
			// exit the program.
			// repeat the program until user selects item 4.
			(choice==false);
		}
	}
}
The lines where you are setting the choice variable is incorrect (lines 75, 93, 140, 191), you got your == and = operators mixed up
You mean to say:
choice=true or choice=false not choice ==true or code==false
(Common mistake)

PS (once you've corrected those, you will find a problem with option 4 - it's more to do with where you've put it. See if you can spot the problem).
i've fixed the option 4 problem, but my insertion sort is not working and i can't figure out how to overload a function.
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
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;

struct Name // storing customer name.
{string lastname;

string firstname;
};
struct Address//storing customer address.
{string houseNum;

string streetname;

string city;

string state;

string zip;
};
struct phoneNum //storing customer Number.
{

	string phnum;
};
struct custAct// customer account Info.
{

	Name custname;

	Address custaddr;

	phoneNum custphnum;

	double actbalance;

	string dtlstpymt;
};
vector <custAct> amount;
void menu(string choicenum, custAct alldata,ofstream & outData);

bool choice;

int main()

{  	
	custAct alldata;
	ofstream outData;
	string choicenum; 
	
	
	do
	{
	cout<<"1. Add customer account\n";
	cout<<"2. Display customer accounts\n";
	cout<<"3. Store customer accounts\n";
	cout<<"4. Quit Program\n";
	cin>>choicenum;			
	menu(choicenum, alldata,outData);
	}while (!strcmp(choicenum.c_str(),"4")==0);

	
	
	return 0;

}


void menu(string choicenum, custAct alldata, ofstream & outData)// i want to overload the custAct alldata
{

	if (strcmp(choicenum.c_str(),"1")==0)
	{
		
		// enter customer account information;
		// store information in a vector.
		cout<<"Please enter customer's last name then first name\n.";
		cout<<"Please leave a space in between the names\n.";                    // i want to overload alldata. With this info.
		cin>>alldata.custname.lastname>>alldata.custname.firstname;
		cout<<" Next enter the customer's address in this order.\n";
		cout<<" House number, street Name, city,state, zip and please leave a space in between the\n";		
		cin>>alldata.custaddr.houseNum>>alldata.custaddr.streetname>>alldata.custaddr.city>>alldata.custaddr.state>>alldata.custaddr.zip;
		cout<<"Please enter customer's phone number.\n";
		cin>>alldata.custphnum.phnum;
		amount.push_back(alldata);
		
		system("cls");
	}

	if (strcmp(choicenum.c_str(),"2")==0)
	{
		
		//sort the vector of accounts info by lastname alphabetically and display on the screen
		// one account at a time with appropriate labels.
		int i, j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i< amount.size(); i++);
			{//sorting data that program recieves and places everything in order. but i'm not sure if its working correctly.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
			}
			cout<<amount[j].custname.lastname;
			cout<<amount[j].custname.firstname;
			cout<<amount[j].custaddr.houseNum;
			cout<<amount[j].custaddr.streetname;
			cout<<amount[j].custaddr.city;
			cout<<amount[j].custaddr.state;
			cout<<amount[j].custaddr.zip;
			cout<<amount[j].custphnum.phnum;
			cout<<amount[j].actbalance;
			cout<<amount[j].dtlstpymt;
			
		}


		system("pause");
		system("cls");

	}


	if (strcmp(choicenum.c_str(),"3")==0)
	{
		
		//prompt the user for a file name, open that file and essentially do item 2 
		//but writing the info to the file with out pauses, don't forget to display
		// an error message if the vector of accounts is empty, then close the
		// file. Overload the insertion operator to send the account info to the file.
		char ofile[16];
		cout<<"Please enter Filename to save :";// open file to save data
		cin>>ofile;
		outData.open (ofile);
		system("cls");
		int i=1;
		int j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=1; i <amount.size(); i++);
			{//sorting data that program recieves and places everything in order.
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{
					amount[j].custname = amount[j-1].custname;
					amount[j].custaddr = amount[j-1].custaddr;
					amount[j].custphnum= amount[j-1].custphnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].dtlstpymt= amount[j-1].dtlstpymt;
					j = j - 1;
				}
				amount[j].custname.lastname= index;
			}
			outData<<amount[j].custname.lastname;
			outData<<amount[j].custname.firstname;
			outData<<amount[j].custaddr.houseNum;
			outData<<amount[j].custaddr.streetname;
			outData<<amount[j].custaddr.city;
			outData<<amount[j].custaddr.state;
			outData<<amount[j].custaddr.zip;
			outData<<amount[j].custphnum.phnum;
			outData<<amount[j].actbalance;
			outData<<amount[j].dtlstpymt;

			outData.close();
			
		}
		if (strcmp(choicenum.c_str(),"4")==0)
		{
			// exit the program.
			// repeat the program until user selects item 4.
		
		}
	}
}
and my option 2 is still giving problem
It is isn't it.

Check your for loops on lines 106 and 161 - they both have a trailing semicolon at the end.
For example Line 106
for (i=1; i< amount.size(); i++); //<- remove semicolon

PS why don't you just get rid of lines 190 -195 - (that's the if loop for option 4) it's never going to get called where it is, it's no longer any use and it is an eye sore.)

You insertion sort isn't working properly.
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
            for (i = 1; i < amount.size(); i++);
            {
                //sorting data that program recieves and places everything in order. but i'm not sure if its working correctly.
                //INDEED - It is not working properly!!!!
                
                index = amount[i].custname.lastname;//You are only saveing the lastname!!!
                j = i;
                while ((j > 0) && (amount[j-1].custname.lastname > index))
                {
                    //OK - but these 5 lines  cam be done in one line of code
                    amount[j].custname = amount[j-1].custname;
                    amount[j].custaddr = amount[j-1].custaddr;
                    amount[j].custphnum = amount[j-1].custphnum;
                    amount[j].actbalance = amount[j-1].actbalance;
                    amount[j].dtlstpymt = amount[j-1].dtlstpymt;
                    
                    j = j - 1;
                }
                
                //When you do the insertion you are only inserting the lastname
                //all the previous customer's data in the position are not changed - so
                //now you have all mixed up names and other data
                amount[j].custname.lastname = index;
            }


 


Last edited on
My data saved in vector won't print to screen.
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
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;

struct Name // storing customer name.
{string lastname;

string firstname;
};
struct Address//storing customer address.
{string houseNum;

string streetname;

string city;

string state;

string zip;
};
struct phoneNum //storing customer Number.
{

	string phnum;
};
struct dtlstpymt
{
	string month;
	string day;
	string year;
};

struct custAct// customer account Info.
{

	Name custname;

	Address custaddr;

	phoneNum custphnum;

	double actbalance;

	dtlstpymt mondayyear;
};

ostream& operator <<(std::ostream &that, custAct act) {
	cout<<"Customer Name:"<<setw(10)<<act.custname.lastname<<","<<act.custname.firstname<<"\n"<<
		"Customer Address:"<<setw(9)<<act.custaddr.houseNum<<" "<<act.custaddr.streetname<<"\n"<<
         setw(15)<<act.custaddr.city<<", "<<act.custaddr.state<<" "<<act.custaddr.zip<<"\n"<<
		"Customer Phone:"<<setw(15)<<act.custphnum.phnum<<"\n"<<
		"Customer Account Balance"<<setw(5)<<act.actbalance<<"\n"<<
		"Date of last Payment"<<setw(5)<<act.mondayyear.month<<"/"<<act.mondayyear.day<<"/"<<act.mondayyear.year;
	return that;

}

istream& operator >>(std::istream& info, custAct act)
{
	cin>>act.custname.lastname>>act.custname.firstname>>
		act.custaddr.houseNum>>act.custaddr.streetname>>act.custaddr.city>>act.custaddr.state>>act.custaddr.zip>>
		act.custphnum.phnum>>act.actbalance>>act.mondayyear.month>>act.mondayyear.day>>act.mondayyear.year;
	return info;

}

vector <custAct> amount;

void menu(string choicenum,ofstream & outData);

bool choice;

int main()

{  
	ofstream outData;
	string choicenum;


	do
	{
		cout<<"1. Add customer account\n";
		cout<<"2. Display customer accounts\n";
		cout<<"3. Store customer accounts\n";
		cout<<"4. Quit Program\n";
		cin>>choicenum;			
		system("cls");
		menu(choicenum,outData);
	}while (!strcmp(choicenum.c_str(),"4")==0);// This option exits program.



	return 0;

}


void menu(string choicenum,ofstream & outData)
{
custAct temp;
	if (strcmp(choicenum.c_str(),"1")==0)
	{

		// enter customer account information;
		// store information in a vector.
	 
		cout<<"Please enter customer's last name then first name.\n";
		cout<<"Please leave a space in between the names.\n";                   
		cout<<"Next enter the customer's address in this order.\n";
		cout<<"House number, street Name, city,state, zip and please leave a space in between each entry.\n";		
		cout<<"Please enter customer's phone number.\n";
		cout<<"Please input 0 for customer account balance and 00 00 00 for date of last payment if new account."; 
	    cin>>temp;
		amount.push_back(temp);
		system ("pause");
		system("cls");
	}

	if (strcmp(choicenum.c_str(),"2")==0)
	{

		//sort the vector of accounts info by lastname alphabetically and display on the screen
		// one account at a time with appropriate labels.
		string index;
		unsigned int i;
		int j;
	
		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=0; i< amount.size(); i++)
			{//sorting data that program recieves and places everything in order. 
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{

					amount[j].custname.lastname = amount[j-1].custname.lastname;
					amount[j].custname.firstname = amount[j-1].custname.firstname;
					amount[j].custaddr.houseNum = amount[j-1].custaddr.houseNum;
					amount[j].custaddr.streetname = amount[j-1].custaddr.streetname;
					amount[j].custaddr.city = amount[j-1].custaddr.city;
					amount[j].custaddr.state = amount[j-1].custaddr.state;
					amount[j].custaddr.zip = amount[j-1].custaddr.zip;
					amount[j].custphnum.phnum= amount[j-1].custphnum.phnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].mondayyear.month= amount[j-1].mondayyear.month;
					amount[j].mondayyear.day= amount[j-1].mondayyear.day;
					amount[j].mondayyear.year= amount[j-1].mondayyear.year;
					j = j - 1;
				}
				amount[j].custname.lastname=index;
                
				cout<<temp;
			}
		}


		system("pause");
		system("cls");

	}


	if (strcmp(choicenum.c_str(),"3")==0)
	{

		//prompt the user for a file name, open that file and essentially do item 2 
		//but writing the info to the file with out pauses, don't forget to display
		// an error message if the vector of accounts is empty, then close the
		// file. 
		char ofile[16];
		cout<<"Please enter Filename to save :";// open file to save data
		cin>>ofile;
		outData.open (ofile);
		system("cls");
		unsigned int i;
		int j;
		string index;

		if( amount.empty()==true)
			cout<<"Error, vector of accounts is empty.";
		else 
		{
			for (i=0; i< amount.size(); i++)
			{//sorting data that program recieves and places everything in order. 
				index = amount[i].custname.lastname;
				j = i;
				while ((j > 0) && (amount[j-1].custname.lastname >index))
				{

					amount[j].custname.lastname = amount[j-1].custname.lastname;
					amount[j].custname.firstname = amount[j-1].custname.firstname;
					amount[j].custaddr.houseNum = amount[j-1].custaddr.houseNum;
					amount[j].custaddr.streetname = amount[j-1].custaddr.streetname;
					amount[j].custaddr.city = amount[j-1].custaddr.city;
					amount[j].custaddr.state = amount[j-1].custaddr.state;
					amount[j].custaddr.zip = amount[j-1].custaddr.zip;
					amount[j].custphnum.phnum= amount[j-1].custphnum.phnum;
					amount[j].actbalance= amount[j-1].actbalance;
					amount[j].mondayyear.month= amount[j-1].mondayyear.month;
					amount[j].mondayyear.day= amount[j-1].mondayyear.day;
					amount[j].mondayyear.year= amount[j-1].mondayyear.year;
					j = j - 1;
				}
				amount[j].custname.lastname=index;
				outData<<temp;
			}
				outData.close();
		}
	}
}
You seem to be struggling a bit on this.
For the operator >> you should be passing the account by reference not by value.
I have made this and some other corrections/updates.
This code works. It displays to the screen, ouputs data to the file, and the sorting works.
Let us know if you have any problems.


The output data formatting needs a bit more work.

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
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
struct Name // storing customer name.
{
    string lastname;
    string firstname;
};
struct Address//storing customer address.
{
    string houseNum;
    string streetname;
    string city;
    string state;
    string zip;
};
struct phoneNum //storing customer Number.
{
    string phnum;
};
struct dtlstpymt
{
    string month;
    string day;
    string year;
};

struct custAct// customer account Info.
{
    Name custname;
    Address custaddr;
    phoneNum custphnum;
    double actbalance;
    dtlstpymt mondayyear;
};

ostream& operator <<(std::ostream &that, custAct act)
{
    //Formatting could do with tidying up
    that << "Customer Name:" << setw(10) << act.custname.lastname << "," << act.custname.firstname << "\n" <<
    "Customer Address:" << setw(9) << act.custaddr.houseNum << " " << act.custaddr.streetname << "\n" <<
    setw(15) << act.custaddr.city << ", " << act.custaddr.state << " " << act.custaddr.zip << "\n" <<
    "Customer Phone:" << setw(15) << act.custphnum.phnum << "\n" <<
    "Customer Account Balance" << setw(5) << act.actbalance << "\n" <<
    "Date of last Payment" << setw(5) << act.mondayyear.month << "/" << act.mondayyear.day << "/" << act.mondayyear.year;
    cout << endl;
    return that;
}


istream& operator >>(std::istream& info, custAct &act)//<- Corrected - pass temp by reference 
{
    cin >> act.custname.lastname >> act.custname.firstname >>
    act.custaddr.houseNum >> act.custaddr.streetname >> act.custaddr.city >> act.custaddr.state >> act.custaddr.zip >>
    act.custphnum.phnum >> act.actbalance >> act.mondayyear.month >> act.mondayyear.day >> act.mondayyear.year;
    return info;
}


vector <custAct> amount;

void menu(string choicenum, ofstream & outData);

bool choice;

int main()
{
    ofstream outData;
    string choicenum;
    do
    {
        cout << "1. Add customer account\n";
        cout << "2. Display customer accounts\n";
        cout << "3. Store customer accounts\n";
        cout << "4. Quit Program\n";
        cin >> choicenum;
        system("cls");
        menu(choicenum, outData);
    }
    while (!strcmp(choicenum.c_str(), "4") == 0);// This option exits program.
    return 0;
}
void menu(string choicenum, ofstream & outData)
{
    custAct temp;

    if (strcmp(choicenum.c_str(), "1") == 0)
    {
        // enter customer account information;
        // store information in a vector.

        
        cout << "Please enter customer's last name then first name.\n";
        cout << "Please leave a space in between the names.\n";
        cout << "Next enter the customer's address in this order.\n";
        cout << "House number, street Name, city,state, zip and please leave a space in between each entry.\n";
        cout << "Please enter customer's phone number.\n";
        cout << "Please input 0 for customer account balance and 00 00 00 for date of last payment if new account. \n";
        
        cin >> temp; 

        amount.push_back(temp);

        //TEST - print out the details just entered.
        cout << temp;

        system ("pause");
        system("cls");

    }
    if (strcmp(choicenum.c_str(), "2") == 0)
    {
        
        custAct index; 

        unsigned int i;
        int j;
        
        if ( amount.empty() == true)
            cout << "Error, vector of accounts is empty.";
        else
        {
            for (i = 0; i < amount.size(); i++)
            {
                //sorting data that program recieves and places everything in order.
                /*index = amount[i].custname.lastname;*/

                index = amount[i]; 
                j = i;
                while ((j > 0) && (amount[j-1].custname.lastname > index.custname.lastname))
                {
                    amount[j] = amount[j-1]; 
                    j = j - 1;
                }
                amount[j] = index;
            }

            //display data to screen
            vector <custAct>::iterator it;
            for (it= amount.begin(); it != amount.end(); it++)
            {
                cout << *it;
            }

        }
        
        
        system("pause");
        system("cls");
    }
    if (strcmp(choicenum.c_str(), "3") == 0)
    {
        //prompt the user for a file name, open that file and essentially do item 2
        //but writing the info to the file with out pauses, don't forget to display
        // an error message if the vector of accounts is empty, then close the
        // file.
        char ofile[16];
        cout << "Please enter Filename to save :";// open file to save data
        cin >> ofile;
        outData.open (ofile,ios_base::out|ios_base::trunc);
        system("cls");

        unsigned int i;
        int j;
        custAct index;

        if ( amount.empty() == true)
            cout << "Error, vector of accounts is empty.";
        else
        {
            for (i = 0; i < amount.size(); i++)
            {
                //sorting data that program recieves and places everything in order.
                index = amount[i];
                j = i;
                while ((j > 0) && (amount[j-1].custname.lastname > index.custname.lastname))
                {
                    
                    amount[j] = amount[j-1];
                    j = j - 1;
                }
                amount[j] = index;
            }

            //send the data to the file
            if(outData.is_open() )
            {
                vector <custAct>::iterator it;
                for (it= amount.begin(); it != amount.end(); it++)
                {
                    outData << *it;
                }
                
                outData.close();
            }
        }
    }
}
Last edited on
Some other notes:

1. The operator >> function
1
2
3
4
5
6
7
istream& operator >>(std::istream& info, custAct &act)//<- Corrected - pass temp by reference 
{
    cin >> act.custname.lastname >> act.custname.firstname >>
    act.custaddr.houseNum >> act.custaddr.streetname >> act.custaddr.city >> act.custaddr.state >> act.custaddr.zip >>
    act.custphnum.phnum >> act.actbalance >> act.mondayyear.month >> act.mondayyear.day >> act.mondayyear.year;
    return info;
}

We are not using the std::istream passed to the function.
We are using cin as in cin >> act.custname.lastname >> ....
That should be changed to info >> act.custname.lastname >> ...., in other words read from the stream that was passed to the function.

There was something else - but I've forgotten it now.


thanks
Topic archived. No new replies allowed.