insertion sort 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
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
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>

using namespace std;

struct Info
{
	string cityname;

	string day;

	int hour;

	int min;

	char colin;

	string am_or_pm;

	int length;

	double dis_35;

	double dis_60;

	double callcost;

};

struct Phonerates
{
	string cityname;

	double firstmin;

	double addmins;
};

struct AllInfo
{
	Info all;

	Phonerates phone;
};

vector <AllInfo> con;

vector <AllInfo> pho;


void Datain(ifstream &inData, AllInfo &file);

void Datacall(ifstream &bkData, AllInfo &file);

void Dataout(ofstream &outData, AllInfo file);

void CallCost(AllInfo file);



int main ()
{
	ifstream inData;
	ifstream bkData;
	AllInfo file;
	ofstream outData;
	

	char txt[15];
	cout<< "Please enter the phonerates filename :";
	cin>>txt;
	inData.open(txt);
	Datain(inData,file);
	pho.push_back(file);
	while (!inData.fail())

	{ 
		Datain(inData, file);
		if(!inData.fail())
			pho.push_back(file);
	}

	char ctxt[15];
	cout<< "\nPlease enter the call list filename :";
	cin>>ctxt;
	bkData.open(ctxt);
	Datacall(bkData, file);
	con.push_back(file);

	while (!bkData.fail())
	{ 
		Datacall(bkData, file);
		if(!bkData.fail())
			con.push_back(file);
	}


	char otxt[15];
	cout<<"\nPlease enter Filename to save :";
	cin>>otxt;
	outData.open (otxt);
	system("cls");
	Dataout(outData, file);
	outData.close();

	return 0;
}




void Datain(ifstream &inData, AllInfo &file)
{// used to read in phonerates file and loop till file has no more info.

	inData>>file.phone.cityname>>file.phone.firstmin>>file.phone.addmins;
}

void Datacall(ifstream &bkData, AllInfo &file)
{// used to read in call file.
	bkData>>file.all.cityname>>file.all.day>>file.all.hour>>file.all.colin>>file.all.min>>file.all.am_or_pm>>file.all.length;

}

void CallCost(AllInfo file)	
{ unsigned int i=0;
unsigned int j=0;
// calculations

if(pho[j].phone.cityname==con[i].all.cityname)
{
	con[i].all.callcost=(((con[i].all.length-1)*pho[j].phone.addmins)+pho[j].phone.firstmin);
	con[i].all.dis_35= ((((con[i].all.length-1)*pho[j].phone.addmins)+pho[j].phone.firstmin)*.35);
	con[i].all.dis_60= ((((con[i].all.length-1)*pho[j].phone.addmins)+pho[j].phone.firstmin)*.60);
	con.push_back(file);
}

else if (pho[j].phone.cityname!=con[i].all.cityname)
{
	do{ 
		j++;

	}while  (pho[j].phone.cityname!=con[i].all.cityname);

	if(pho[j].phone.cityname==con[i].all.cityname)
	{
		con[i].all.callcost=(((con[i].all.length-1)*pho[j].phone.addmins)+pho[j].phone.firstmin);
		con[i].all.dis_35= ((((con[i].all.length-1)*pho[j].phone.addmins)+pho[j].phone.firstmin)*.35);
		con[i].all.dis_60= ((((con[i].all.length-1)*pho[j].phone.addmins)+pho[j].phone.firstmin)*.60);
		con.push_back(file);
	}

}
}
void Dataout(ofstream &outData, AllInfo file)
{// assigns daynum a specific number when a day appears.
	string index;
	unsigned int i = 0;
	int x;

	for(i=0; i < con.size(); i++)
	{
		index= con[i].all.cityname;
		x=i; 
		while((x > 0) && (con[x-1].all.cityname > index))
		{ 
			con[x].all.cityname = con[x-1].all.cityname;
			con[x].all.day = con[x-1].all.day;
			con[x].all.hour = con[x-1].all.hour;
			con[x].all.min= con[x-1].all.min;
			con[x].all.am_or_pm = con[x-1].all.am_or_pm;
			con[x].all.length = con[x-1].all.length;
			x = x - 1;
		}
		con[x].all.cityname= index;

		CallCost(file);
		// Price for regular cost.
		if ((con[x].all.day!="Sunday" && con[x].all.day!="Saturday" && con[x].all.hour < 5 && con[x].all.am_or_pm =="pm") || 
			(con[x].all.day!="Sunday" && con[x].all.day!="Saturday" && con[x].all.hour == 12 && con[x].all.am_or_pm =="pm") ||
			(con[x].all.day!="Sunday" && con[x].all.day!="Saturday" && con[x].all.hour > 7 && con[x].all.am_or_pm =="am") || 
			(con[x].all.day!="Sunday" && con[x].all.day!="Saturday" && con[x].all.hour != 12  && con[x].all.am_or_pm =="am"))
		{
			outData<< con[x].all.cityname<<setw(20)<<con[x].all.day<<setw(10)<<con[x].all.hour<<setw(2)<<con[x].all.colin<<setw(2)<<con[x].all.min<<setw(5)
				<<con[x].all.am_or_pm<<setw(10)<<con[x].all.length<<setw(5)<<"$"<<setprecision(2)<<con[x].all.callcost<<"\n";
		}
		
		if(con[x].all.day!="Saturday" && con[x].all.hour > 4 && con[x].all.hour < 11 && con[x].all.am_or_pm =="pm")
			//Price for 35% discount cost.
		{	
			outData<<con[x].all.cityname<<setw(20)<<con[x].all.day<<setw(10)<<con[x].all.hour<<setw(2)<<con[x].all.colin<<setw(2)<<con[x].all.min<<setw(5)
				<<con[x].all.am_or_pm<<setw(10)<<con[x].all.length<<setw(5)<<"$"<<setprecision(2)<<con[x].all.dis_35<<"\n";
		}

		if((con[i].all.day=="Saturday") || 
			(con[x].all.day!="Saturday" && con[x].all.hour == 11 && con[x].all.am_or_pm =="pm") ||
			(con[x].all.day!="Saturday" && con[x].all.hour < 8 && con[x].all.am_or_pm =="am") || 
			(con[x].all.day!="Saturday" && con[x].all.hour == 12 && con[x].all.am_or_pm =="am"))
			//Price for 60% discount cost for all day saturday and for nights starting all 11 pm.
		{

			outData<<con[x].all.cityname<<setw(20)<<con[x].all.day<<setw(10)<<con[x].all.hour<<setw(2)<<con[x].all.colin<<setw(2)<<con[x].all.min<<setw(5)
				<<con[x].all.am_or_pm<<setw(10)<<con[x].all.length<<setw(5)<<"$"<<setprecision(2)<<con[x].all.dis_60<<"\n";

		}
		
		if ((con[x].all.day=="Sunday" && con[x].all.hour < 5) ||
			(con[x].all.day=="Sunday" && con[x].all.hour == 12)||
			(con[x].all.day=="Sunday" && con[x].all.hour == 11 && con[i].all.am_or_pm =="pm"))
			//Price for 60% discount cost for sunday night.
		{

			outData<<con[x].all.cityname<<setw(20)<<con[x].all.day<<setw(10)<<con[x].all.hour<<setw(2)<<con[x].all.colin<<setw(2)<<con[x].all.min<<setw(5)
				<<con[x].all.am_or_pm<<setw(10)<<con[x].all.length<<setw(5)<<"$"<<setprecision(2)<<con[x].all.dis_60<<"\n";
		}

		
	}
	outData.close();

}
Last edited on
Topic archived. No new replies allowed.