Starting from:

$30

Program 2 "nursery_inv2.cpp"

Program 2

In this assignment you will implement a program called "nursery_inv2.cpp" to process the
customer purchase orders for a nursery. The purchase orders will be stored in order records. Each
order record contains eight fields, which are as follows: 1) a plant name (string, no spaces), 2) a
county name (string, no space), 3) the cost of the plant ( double), 4) the quantity of plants in the
purchase (integer), 5) the tax on the purchase (double), 6) the net cost of the purchase (double), 7)
the discount on the purchase (double), and 8) the total cost of the purchase. Your program will
have 3 functions: input, process. and output. Your main program will call (invoke) each function
until the end of the data file has been reached. Following are the descriptions of the functionality
of each function:
1. The function “input” will have two parameters: an input file stream called “in”, and a
customer purchase order record called “order_record”. The function will read a plant name
(pname), the name of the county the plant was purchase in (cname), the cost of the plant
(plant_cost), and the quantity of the plant purchase (quantity) into an order record from the
data file, “nursery_stock.txt”.
2. The function “process” will calculate the net cost of the purchase (net_cost), the tax on the
purchase (purchase_tax), the discount on the purchase (discount), and the total cost of the
purchase (total_cost). Please consider the following information to help you implement the
necessary calculations:
a. The tax rate (in percent) on a purchase is based on the county where the purchase
was made. If the county was dade, the tax rate is 6.5%; if the county is broward, the
tax rate is 6%; if the county was palm, the tax rate is 7%.
b. The net cost of a purchase is calculated by the following formula:
• net_cost = (quantity x plant_cost )
c. The discount is based on the quantity of plants in the purchase. The discount is
determined is follows:
• If quantity equals 0, then the discount is 0% of the net cost;
• If 1<= quantity <=5 then discount = 1% of the net cost; 6<= quantity <=11 then
discount = 3% of the net cost ; if 12<= quantity <=20 then discount = 5% of the
net cost; 21<= quantity <=50 then discount = 8% of the net cost; quantity >50
then discount =12% of the net cost) . Apply discount after the net cost has been
calculated.
d. The tax on a purchase is calculated by the following formula:
• purchase_tax = (net_cost * tax_rate / 100 (drop /100 if you converted the
rate from a percentage)
e. The total cost of a purchase (rounded to the nearest hundredth) is calculated by the
following formula:
• total_cost = net_cost +purchase_tax - discount .
 N o t e : All tax and cost calculations should be rounded to the nearest
 hundredths.
3. The function “output” will print every field of an order record to the screen. The fields
should be printed in the following order: plant name, county name, plant cost, quantity of
plants, net cost of purchase, purchase tax, discount, and total cost. See the section below
called “Input Stream” and “Format of Output ” for more information. See “Format of
Input data file, “nursery_stock.txt””.
Use the following format information to print the variables:
Field Format
======================================
Plant Name string
County Name string
Plant Cost XXXX.XX
Quantity of Plants XXXX
Net Cost of Purchase XXXXX.XX
Purchase Tax XXXXX.XX
Discount on Purchase XXXX.XX
Total Cost of Purchase XXXXXXX.XX
You may implement more functions if you find it necessary. Please start the assignment ASAP,
and ask questions to make sure you understand what you must do. It is always good to start with
the skeleton program I provide. Remember to follow all style rules and to include all necessary
documentation (consistent, indentation, proper variable names, pre/post conditions, program
header, function headers, and so forth.) .
Finally, your input data file (nursery_stock.txt) should be in the same directory as your program
source file (nursery_inv2.cpp) for your program to produce the correct output.
Output Format for the Function “output”:
Consider the following sample output table when designing and implementing the function
“output”:
(The output is in the following order: plant name, county name, plant cost, quantity, net cost,
purchase tax, discount, total cost).
owl dade 10.55 100 1055 126.6 68.58 996.98
hibiscus broward 15.82 15 236.3 11.87 14.24 239.67
rose dade 9.99 45 449.55 35.96 29.22 442.81
Input Stream:
In the assignment you will declare one ifstream to bind your input to the file “nursery_stock.txt” to
an input file stream. Whenever a program performs file i/o you must include the “fstream” library.
Add the following statements to your program:
For source file, “nursery_inv2.cpp”
• Add “#include <fstream>” to your # include statements in your source file.
• Add “#include <string>” to your # include statement in your source file.
• Add “#include <iomanip>” all formatting of output
Format of the input data file (input filename is “nursery_stock.txt”):
Do not include column titles in your data file. Field as order as follows: plant name, county name,
plant cost, quantity.
Owl dade 10.55 100
Hibiscus broward 15.82 15
Rose dade 9.99 45
carnation palm 7.99 32
Rose palm 7.99 60
Widow palm 25.75 5
carnation dade 12.55 10
carnation dade 12.55 8
Lilly broward 6.92 150
xerabtgemum palm 13.63 50
Yarrow dade 22.85 20
Zenobia palm 37.19 32
zephyranthes broward 62.82 40
Daisy broward 15.99 80
aconitum dade 30.02 72
amaryllis dade 16.14 65
Begonia broward 18.45 3
Bellflow broward 2.96 200
bergenia palm 85.92 10
Format of Output:
(plant name, county name, plant cost, quantity, net cost, discount, purchase tax, total cost)
Using the information in the data file “nursery_stock.txt” you should produce the following
output. Your output should not contain any titles, but the output must be in the proper order as
stated in the assignment. The following contains an example of the output your program should
produce if you use the contents in the data file “nursery_stock.txt”. You should double check the
results.
owl dade 10.55 100 0.065 1055.00 0.12 126.60 68.58 996.98
hibiscus broward 15.82 15 0.06 237.30 0.05 11.87 14.24 239.67
rose dade 9.99 45 0.065 449.55 0.08 35.96 29.22 442.81
carnation palm 7.99 32 0.07 255.68 0.08 20.45 17.90 253.12
rose palm 7.99 60 0.07 479.40 0.12 57.53 33.56 455.43
widow palm 25.75 5 0.07 128.75 0.01 1.29 9.01 136.48
carnation dade 12.55 10 0.065 125.50 0.03 3.77 8.16 129.89
carnation dade 12.55 8 0.065 100.40 0.03 3.01 6.53 103.91
lilly broward 6.92 150 0.06 1038.00 0.12 124.56 62.28 975.72
xerabtgemum palm 13.63 50 0.07 681.50 0.08 54.52 47.71 674.69
yarrow dade 22.85 20 0.065 457.00 0.05 22.85 29.71 463.86
zenobia palm 37.19 32 0.07 1190.08 0.08 95.21 83.31 1178.18
zephyranthes broward 62.82 40 0.06 2512.80 0.08 201.02 150.77 2462.54
daisy broward 15.99 80 0.06 1279.20 0.12 153.50 76.75 1202.45
aconitum dade 30.02 72 0.065 2161.44 0.12 259.37 140.49 2042.56
amaryllis dade 16.14 65 0.065 1049.10 0.12 125.89 68.19 991.40
bogonia broward 18.45 3 0.06 55.35 0.01 0.55 3.32 58.12
bellflow broward 2.96 200 0.06 592.00 0.12 71.04 35.52 556.48
bergenia palm 85.92 10 0.07 859.20 0.03 25.78 60.14 893.57
Use the following skeleton to help you start this program which is included as a cpp file in
the module: nursery_inv2.cpp
Professor: Dr. Lofton Bullard
Due Date: Total Points: 20
Assignment#:Assignment#2 (nursery_inv.cpp)
Description:
*******************************************************************************************************
******************/
//Include the following
#include <iostream>
#include <string>
#include <fstream> //you must include this library if you wish to do file i/o
#include <iomanip>
using namespace std;
/*********************************************************
//Following is the declaration of a order record
**********************************************************/
class order_record
{
public:
string pname;
string cname;
double plant_cost;
double quantity;
double purchase_tax;
double net_cost;
double discount;
double total_cost;
};
//Prototypes for your functions: input, output, and process will go here
void input(ifstream&, order_record&);
void output(const order_record&);
void process(order_record&);
//Function Implementations will go here
///*************************************************************************************
//Name: input
//Precondition: State what is true before the function is called.
// Example: the varialbes (formal parameters) have not been initialized
//Postcondition: State what is true after the function has executed.
// Example: the varaibles (formal parameters) have been initialized
//Description:
// Example:Get input (values of plant name, county name, plant cost, quantity )
//from data file order record (p_record).
//PURPOSE: SHOW ME THAT YOU KNOW HOW TO READ INPUT AND USE INPUT (CALL BY VALUE) & OUTPUT (CALL BY
VALUE) PARAMETERS
//*************************************************************************************
void input(ifstream& in, order_record& plant_record) // example using the call by reference mechanism
in C++ -- call record is passed by reference --note & operator
{
in >> plant_record.pname;
//add more code to read the rest of the fields (county name, plant cost, quantity) into the
//order record, plant_record.
}
///*************************************************************************************
//Name: output
//Precondition: State what is true before the function is called.
//Postcondition: State what is true after the function has executed.
//Description: Describe what the function does (purpose).
//*************************************************************************************
void output(const order_record& plant_record)
{
//Use thee following statement to help you format you our output. These statements are called
the magic formula.
cout.setf(ios::showpoint);
cout.precision(2);
cout.setf(ios::fixed);
/********************************************/
//cout << plant_record.pname << "\t";
//add more code to print all the fields in the order record
}
///*************************************************************************************
//Name: process
//Precondition: The state what is true before the function is called.
//Postcondition: State what is true after the function has executed.
//Description: Describe what the function does (purpose).
//*************************************************************************************
//Note: there is one 1 input/output parameter
void process(order_record & plant_record)
{
//put your code here to process/calculate the net cost, purchase tax, discount, and total cost
//for the plant_record
}
//Here is your driver to test the program
int main()
{
order_record purchase_record;
string pname, cname;
double cost;
int quantity;
ifstream in; //declaring an input file stream
in.open("nursery_stock.txt"); //opening the input file stream
if (in.fail())
{
cout << "Input file did not open correctly" << endl;
}
else
{ //the following while loop processes one order record at a time
while (!in.eof())
{
input(in, purchase_record);
//process(purchase_record);
//output(purchase_record);
}
}
in.close(); //always close opened files.
return 0;
}
Handing in your program:
Electronically submit "nursery_inv2.cpp" in the Assignments area of Canvas before the
due date and time.Remember, complete the assignment no matter if it is late. It is very
important that you do all assignments to master the C++ programming language and get a
passing grade.

More products