Program implementation(shipping charges)

Pages: 12
Hi all,
It is my last assignment this semester and I am currently stuck. I had a previous one but this week's assignment needs the program to read in something and display it. The description is so long but I had no other choice now... Just hope someone can help me with this... I am so grateful for any help about that!


1.You will open and parse an input file named input.txt. The first line of the input file will contain an integer that indicates the number of packages that are listed in the file. Each package’s information will take up 6 lines in the file. The first 5 lines will be the recipient’s name, street address, city, state, and zip code; each address element will be on its own line. The 6th line will contain a variable amount of numbers, depending on the package type. The first number on the line will represent the package type. The values will be 1 for overnight, 2 for two-day, and 3 for ground. If it is a ground package, the 6th line will also have the cost per ounce to ship the package and the weight of the package in ounces, separated by spaces. If it is a two-day package, the line will also have the flat fee or if it is an overnight package, it will have the additional fee per ounce.
2.Implement an additional constructor in all of your package classes that does not include arguments for fields related to the sender. This program only deals with recipient addresses, so fields related to the sender are not necessary.
3.Print each mailing label to an output file named output.txt. Each label includes the recipient’s address and the total cost for shipping the package. You should output each mailing label in the format shown in the example output on the next page.
Last edited on
my code is too long and it wont let me submit...I'm trying... But help...please!!!
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 <string>
#include <iomanip>

using namespace std;

class Package
{
private:
	string sender_name;
	string sender_address;
	string sender_city;
	string sender_state;
	string sender_ZIP;

	string recipient_name;
	string recipient_address;
	string recipient_city;
	string recipient_state;
	string recipient_ZIP;

	double weight;
	double costperounce;
public:


	Package(string sender_n, string sender_addr, string sender_c,
		string sender_s, string sender_Z, string recipient_n, string recipient_addr,
		string recipient_c, string recipient_s, string recipient_Z, double wei,
		double cost);

	void setsender_name(string sender_n);
	string getsender_name();

	void setsender_address(string sender_addr);
	string getsender_address();

	void setsender_city(string sender_c);
	string getSendCity();

	void setsender_state(string sender_s);
	string getsender_state();

	void setsender_ZIP(string sender_Z);
	string getsender_ZIP();

	void setrecipient_name(string recipient_n);
	string getrecipient_name();

	void setrecipient_address(string recipient_addr);
	string getrecipient_address();

	void setrecipient_city(string recipient_c);
	string getrecipient_city();

	void setrecipient_state(string recipient_s);
	string getrecipient_state();

	void setrecipient_ZIP(string recipient_Z);
	string getrecipient_ZIP();

	void setweight(double w);
	double getweight();

	void setcostperounce(double cost);
	double getcostperounce();

	double calculateCost();
};

Package::Package(string sender_n, string sender_addr, string sender_c, string
	sender_s, string sender_Z, string recipient_n, string recipient_addr, string
	recipient_c, string recipient_s, string recipient_Z, double wei, double cost)
{
	sender_name = sender_n;
	sender_address = sender_addr;
	sender_city = sender_c;
	sender_state = sender_s;
	sender_ZIP = sender_Z;

	recipient_name = recipient_n;
	recipient_address = recipient_addr;
	recipient_city = recipient_c;
	recipient_state = recipient_s;
	recipient_ZIP = recipient_Z;

	if (wei > 0.0 && cost > 0.0)
	{
		weight = wei;
		costperounce = cost;
	}
	else
	{
		weight = 0.0;
		costperounce = 0.0;
	}

}

void Package::setsender_name(string sender_n)
{
	sender_name = sender_n;
}
string Package::getsender_name()
{
	return sender_name;
}

void Package::setsender_address(string sender_addr)
{
	sender_address = sender_addr;
}
string Package::getsender_address()
{
	return sender_address;
}

void Package::setsender_city(string sender_c)
{
	sender_city = sender_c;
}

string Package::getSendCity()
{
	return sender_city;
}

void Package::setsender_state(string sender_s)
{
	sender_state = sender_s;
}
string Package::getsender_state()
{
	return sender_state;
}

void Package::setsender_ZIP(string sender_Z)
{
	sender_ZIP = sender_Z;
}
string Package::getsender_ZIP()
{
	return sender_ZIP;
}

void Package::setrecipient_name(string recipient_n)
{
	recipient_name = recipient_n;
}
string Package::getrecipient_name()
{
	return recipient_name;
}

void Package::setrecipient_address(string recipient_addr)
{
	recipient_address = recipient_addr;
}
string Package::getrecipient_address()
{
	return recipient_address;
}

void Package::setrecipient_city(string recipient_c)
{
	recipient_city = recipient_c;
}
string Package::getrecipient_city()
{
	return recipient_city;
}

void Package::setrecipient_state(string recipient_s)
{
	recipient_state = recipient_s;
}
string Package::getrecipient_state()
{
	return recipient_state;
}

void Package::setrecipient_ZIP(string recipient_Z)
{
	recipient_ZIP = recipient_Z;
}
string Package::getrecipient_ZIP()
{
	return recipient_ZIP;
}

void Package::setweight(double w)
{
	weight = (w < 0.0) ? 0.0 : w;
}
double Package::getweight()
{
	return weight;
}

void Package::setcostperounce(double cost)
{
	costperounce = (cost < 0.0) ? 0.0 : cost;
}

double Package::getcostperounce()
{
	return costperounce;
}

double Package::calculateCost()
{
	double result;

	result = weight * costperounce;

	return result;
}
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
class TwoDayPackage : public Package
{
private:
	double two_day_delivery_fee;
public:
	TwoDayPackage(string sender_n, string sender_addr, string
		sender_c, string sender_s, string sender_Z, string recipient_n,
		string recipient_addr, string recipient_c, string recipient_s,
		string recipient_Z, double wei, double cost, double delivery_fee);

	double gettwo_day_delivery_fee();
	void settwo_day_delivery_fee(double delivery_fee);
	double calculateCost();
};

TwoDayPackage::TwoDayPackage(string sender_n, string sender_addr,
	string sender_c, string sender_s, string sender_Z, string recipient_n,
	string recipient_addr, string recipient_c, string recipient_s,
	string recipient_Z, double wei, double cost, double delivery_fee)
	:Package(sender_n, sender_addr, sender_c, sender_s, sender_Z, recipient_n,
	recipient_addr, recipient_c, recipient_s, recipient_Z, wei, cost)
{
	settwo_day_delivery_fee(delivery_fee);

}


double TwoDayPackage::gettwo_day_delivery_fee()
{
	return two_day_delivery_fee;
}
void TwoDayPackage::settwo_day_delivery_fee(double delivery_fee)
{
	two_day_delivery_fee = delivery_fee;
}

double TwoDayPackage::calculateCost()
{
	double result;
	result = Package::calculateCost() + two_day_delivery_fee;
	return result;
}

class OvernightPackage : public Package
{
private:
	double overnight_delivery_fee;
public:

	OvernightPackage(string sender_n, string sender_addr, string sender_c,
		string sender_s, string sender_Z, string recipient_n, string recipient_addr,
		string recipient_c, string recipient_s, string recipient_Z, double wei,
		double cost, double delivery_fee);

	double calculateCost();
	double getovernight_delivery_fee();
	void setovernight_delivery_fee(double delivery_fee);

};

OvernightPackage::OvernightPackage(string sender_n, string sender_addr,
	string sender_c, string sender_s, string sender_Z, string recipient_n,
	string recipient_addr, string recipient_c, string recipient_s,
	string recipient_Z, double wei, double cost, double delivery_fee)
	:Package(sender_n, sender_addr, sender_c, sender_s, sender_Z, recipient_n,
	recipient_addr, recipient_c, recipient_s, recipient_Z, wei, cost)
{
	setovernight_delivery_fee(delivery_fee);
}

double OvernightPackage::getovernight_delivery_fee()
{
	return overnight_delivery_fee;
}
void OvernightPackage::setovernight_delivery_fee(double delivery_fee)
{
	overnight_delivery_fee = delivery_fee;
}

double OvernightPackage::calculateCost()
{
	double result;
	result = (getcostperounce() + overnight_delivery_fee) * getweight();
	return result;
}

int main(int argc, char *argv[])
{
	OvernightPackage item1("Jaime Lannister", "Penn 1800 St", "King's Landing",
		"Knowhere", "09500", "Tyrion Lannister", "123 AAA street", "Harlem", "Cali",
		"56789", 14.00, 1.50, 1.10);
	TwoDayPackage item2("Jon Snow", "123 5th Street", "Hunting Pot",
		"California", "12556", "Tony Stark", "455 Hawk Street", "Orlando", "Florida",
		"88865", 22.00, 1.50, 8.00);

	cout << fixed << setprecision(2);
	cout << "--------------------------------------\n";
	cout << "Overnight Delivery\n";
	cout << "Sender        " << item1.getsender_name() << "\n";
	cout << "              " << item1.getsender_address() << "\n";
	cout << "              " << item1.getSendCity() << " " <<
		item1.getsender_state() << " " << item1.getsender_ZIP() << "\n";
	cout << "\n";
	cout << "Recipient     " << item1.getrecipient_name() << "\n";
	cout << "              " << item1.getsender_address() << "\n";
	cout << "              " << item1.getrecipient_city() << " " <<
		item1.getrecipient_state() << " " << item1.getrecipient_ZIP() << "\n";
	cout << "Cost          $ " << item1.calculateCost() << "\n";
	cout << "--------------------------------------\n";

	cout << "\n\n";
	cout << "--------------------------------------\n";
	cout << "2 Day Delivery\n";
	cout << "Sender        " << item2.getsender_name() << "\n";
	cout << "              " << item2.getsender_address() << "\n";
	cout << "              " << item2.getSendCity() << " " <<
		item2.getsender_state() << " " << item2.getsender_ZIP() << "\n";
	cout << "\n";
	cout << "Recipient     " << item2.getrecipient_name() << "\n";
	cout << "              " << item2.getsender_address() << "\n";
	cout << "              " << item2.getrecipient_city() << " " <<
		item2.getrecipient_state() << " " << item2.getrecipient_ZIP() << "\n";
	cout << "Cost          $ " << item2.calculateCost() << "\n";
	cout << "--------------------------------------\n";
	return 0;
}
That is my code... And I dont know how to read in an input file also I do not know how to create specific code like oneday shipping as 1, twoday as 2... Please Help...
Good god please save me...
That is my code... And I dont know how to read in an input file also I do not know how to create specific code like oneday shipping as 1, twoday as 2... Please Help...


This is an example on how to read from an input file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <string>

int main()
{
    std::string str;
    std::ifstream fin("input.txt");

    if (!fin)
    {
        std::cout << "Unable to open input file.";
        return 1;
    }
    while (getline(fin, str)) //reads a line from input file and stores inside string
    {
        // do stuff, example:
        std::cout << str << '\n';
    }
    fin.close();

    return 0;
}


I do not understand the rest of your question.
I had an brief tasks listed in the first response... Do you mind having a look at it??
I read your first post, and it explains your assignment. But I don't understand what you're trying to ask, except for the part where you say you don't know how to read in an input file.
well I dont know how to add the id for each package "The values will be 1 for overnight, 2 for two-day, and 3 for ground. If it is a ground package, the 6th line will also have the cost per ounce to ship the package and the weight of the package in ounces, separated by spaces. If it is a two-day package, the line will also have the flat fee or if it is an overnight package, it will have the additional fee per ounce."
it's just that I dont know where to start to change in my current code now...
The numbers are not some kind of package id. They are part of your input file and tell you what kind of package you're delivering. Example input file:

John Doe
123 Main Street
New York City
NY
12345
3 0.25 20

Mary Jones
321 Central Blvd
Seattle
WA
54321
2 0.25 15 3.00


So John would be getting something through ground shipping and Mary is getting something through two day shipping. (The numbers are just a guess, I don't actually know what your input file looks like.)
I got a sample.

3
John Smith
123 Any Street
Dallas
Texas
75275
2 0.79 13.20 6.50

Mary Thompson
1121 Dublin
Plano
Texas
75075
1 0.79 12.10 0.99

Sam Brown
2256 Southwestern
Dallas
Texas
75214
3 0.19 8.20
Well, there you go.

John is supposed to be receiving a 13.2 ounce package from 2 day shipping, which costs $0.79 per ounce and has a flat rate of $6.50.

Mary is getting an overnight delivery of a 12.1 ounce package, costing $0.79 per ounce, and an additional $0.99 per ounce.

Sam is getting a package through ground shipping, weighing 8.2 ounces and costing $0.19 per ounce.
Well the thing is I dont know where to add this in my code now.. I have about 40 mins left till due... Jesus.
Have you at least figured out how to get your program to read the information from the file?
Yes I have read your example.. But mixes with all my codes now I am totally lost...
What does your main function look like right now?
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
int main(int argc, char *argv[])
{
	OvernightPackage item1("Jaime Lannister", "Penn 1800 St", "King's Landing",
		"Knowhere", "09500", "Tyrion Lannister", "123 AAA street", "Harlem", "Cali",
		"56789", 14.00, 1.50, 1.10);
	TwoDayPackage item2("Jon Snow", "123 5th Street", "Hunting Pot",
		"California", "12556", "Tony Stark", "455 Hawk Street", "Orlando", "Florida",
		"88865", 22.00, 1.50, 8.00);

	cout << fixed << setprecision(2);
	cout << "--------------------------------------\n";
	cout << "Overnight Delivery\n";
	cout << "Sender        " << item1.getsender_name() << "\n";
	cout << "              " << item1.getsender_address() << "\n";
	cout << "              " << item1.getSendCity() << " " <<
		item1.getsender_state() << " " << item1.getsender_ZIP() << "\n";
	cout << "\n";
	cout << "Recipient     " << item1.getrecipient_name() << "\n";
	cout << "              " << item1.getsender_address() << "\n";
	cout << "              " << item1.getrecipient_city() << " " <<
		item1.getrecipient_state() << " " << item1.getrecipient_ZIP() << "\n";
	cout << "Cost          $ " << item1.calculateCost() << "\n";
	cout << "--------------------------------------\n";

	cout << "\n\n";
	cout << "--------------------------------------\n";
	cout << "2 Day Delivery\n";
	cout << "Sender        " << item2.getsender_name() << "\n";
	cout << "              " << item2.getsender_address() << "\n";
	cout << "              " << item2.getSendCity() << " " <<
		item2.getsender_state() << " " << item2.getsender_ZIP() << "\n";
	cout << "\n";
	cout << "Recipient     " << item2.getrecipient_name() << "\n";
	cout << "              " << item2.getsender_address() << "\n";
	cout << "              " << item2.getrecipient_city() << " " <<
		item2.getrecipient_state() << " " << item2.getrecipient_ZIP() << "\n";
	cout << "Cost          $ " << item2.calculateCost() << "\n";
	cout << "--------------------------------------\n";
	return 0;
}
A whole lot of stuff related to getter and setter function now... I have to erase all of them and turn into a read in file function in main?
Pages: 12