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
|
//Include the following
#include <iostream>
#include <string>
#include <fstream> //you must include this library if you wish to do file i/o
using namespace std;
//Prototypes for your functions: input, output, and process will go here
void input(ifstream&, string&, string&, double&, double&, int&);
void output(string, string, double, double, int, double, double, double, double);
void process(double, double, int, double&, double&, double&, double&);
//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 cell_number, item_number, quantity, price, processing_plant )
//from data file.
//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, string& cell_number, string& item_number, double& quantity, double& price, int& processing_plant) // example using the call by reference mechanism in C++ -- call record is passed by reference --note & operator
{
in >> cell_number;
in >> item_number;
in >> quantity;
in >> price;
in >> processing_plant;
//add more code to read the rest of the variables (item_number, quantity, price and processing_plant)
}
///*************************************************************************************
//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(string cell_number, string item_number, double quantity, double price, int processing_plant, double tax_rate, double order_tax, double net_cost, double total_cost)
{
//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 << cell_number << "\t";
cout << item_number << "\t";
cout << quantity << "\t";
cout << price << "\t";
cout << processing_plant << "\t";
cout << int (tax_rate) << "\t";
cout << order_tax << "\t";
cout << net_cost << "\t";
cout << total_cost << endl;
//add more code to print all the variables
}
///*************************************************************************************
//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(double quantity, double price, int processing_plant, double& tax_rate, double& order_tax, double& net_cost, double& total_cost)
{
//put your code here to process/calculate the tax_rate, order_tax, net_cost, and total_cost
if (processing_plant >= 0 && processing_plant <= 50)
{
tax_rate = 6;
}
else if (processing_plant >= 51 && processing_plant <= 110)
{
tax_rate = 7;
}
else if (processing_plant >= 111 && processing_plant <= 200)
{
tax_rate = 8;
}
else if (processing_plant >= 201 && processing_plant <= 500)
{
tax_rate = 9;
}
else
{
tax_rate = 11;
}
order_tax = quantity * price * (tax_rate/100);
net_cost = quantity * price;
total_cost = net_cost + order_tax;
}
//Here is your driver to test the program
int main()
{
string cell_number;
string item_number;
double quantity;
double price;
int processing_plant;
double tax_rate;
double order_tax;
double net_cost;
double total_cost;
ifstream in; //declaring an input file stream
in.open("purchase_data.txt");
if (in.fail())
{
cout << "Input file did not open correctly" << endl;
}
else
{
while (!in.eof())
{
input(in, cell_number, item_number, quantity, price, processing_plant);
process(quantity, price, processing_plant, tax_rate, order_tax, net_cost, total_cost);
output(cell_number, item_number, quantity, price, processing_plant, tax_rate, order_tax, net_cost, total_cost);
//process(add actual arguments...);
//output(add actual arguments);
}
}
in.close();
return 0;
}
|