pay attention to program requirements c++ last 2 are the output Paragraph Styles
ID: 3725046 • Letter: P
Question
pay attention to program requirements
c++
last 2 are the output
Explanation / Answer
here is your program : ---------------->>>>>>>>>>
#include<iostream>
#include<fstream>
#include<sstream>
using namespace std;
int getBackorderCount(){
ifstream ifs;
ifs.open("backorder.txt");
int n;
if(ifs.is_open()){
ifs>>n;
ifs.close();
}else{
ifs.close();
exit(0);
}
return n;
}
int getSpoolsOrdered(){
int n = -1;
while(n < 1){
cout<<" How many Spools would you like to purchase? ";
cin>>n;
if(n >= 1){
break;
}
cout<<" Invalid Data. number of spools must be positive .";
}
return n;
}
double getStateTaxRate(){
string st;
st.reserve(3);
cout<<" Please enter the two character state abbreviation of the shipping address? ";
cin>>st;
string rate;
stringstream ss;
rate.reserve(6);
ifstream ifs;
ifs.open("stateTax.txt");
if(ifs.is_open()){
string stf;
stf.reserve(2);
ifs>>stf;
double r;
while(!ifs.eof()){
if(stf == st){
ifs>>rate;
ss<<rate[0]<<rate[1]<<rate[2]<<rate[3];
ss<<" ";
ss>>r;
ifs.close();
return r*(0.01);
}
ifs>>rate;
ifs>>stf;
}
ifs.close();
return 0;
}else{
return -1;
}
}
double determineShippingCharges(){
char ch;
cout<<" The default shipping and handling charges is $15 per spool";
while(true){
cout<<" Are there special shipping and handling charge for this order? (y/n)";
cin>>ch;
if(ch == 'y' || ch == 'Y' || ch == 'n' || ch == 'N'){
break;
}
cout<<" That is invalid response. please respond y or n.";
}
if(ch == 'y' || ch == 'Y'){
double d;
while(true){
cout<<" What is the special shipping and handling charge for this order?";
cin>>d;
if(d >= 0){
break;
}
cout<<" Invalid Data. Shipping and handling charge must be positive.";
}
return d;
}else{
return 15;
}
}
int getStockCount(){
ifstream ifs;
ifs.open("inStock.txt");
int n;
if(ifs.is_open()){
ifs>>n;
ifs.close();
}else{
ifs.close();
exit(0);
}
return n;
}
void setBackorderCount(int backorder){
ofstream ofs;
ofs.open("backorder.txt");
if(ofs.is_open()){
ofs<<backorder;
ofs.close();
}else{
ofs.close();
exit(0);
}
}
void setInstockCount(int inst){
if(inst < 0){
return;
}
ofstream ofs;
ofs.open("inStock.txt");
if(ofs.is_open()){
ofs<<inst;
ofs.close();
}else{
exit(0);
}
}
void createInvoice(int spoolsOrdered,double shippingCharge){
int inst = getStockCount();
int ship;
double rate = getStateTaxRate();
if(rate == -1){
rate = 0;
cout<<" State Stock File Opening error ";
}
if(spoolsOrdered > inst){
cout<<" "<<(spoolsOrdered-inst)<<" spools will be backordered and shipped as soon as posible";
ship = inst;
setBackorderCount(spoolsOrdered-inst);
}else{
cout<<" You requested "<<spoolsOrdered<<" spools.";
ship = spoolsOrdered;
}
setInstockCount(inst-ship);
cout<<" We are shipping "<<inst<<" spools";
cout<<" The Acme Ethernet Cable Company ";
cout<<" Quantity cost per spool cost ";
cout<<" "<<ship<<" 154.50"<<" "<<(ship*154.50);
cout<<" SubTotal "<<(ship*154.50);
cout<<" Shipping/Handling "<<shippingCharge<<" "<<(ship*shippingCharge);
cout<<" SalesTax "<<(rate*(ship*154.50));
cout<<" Total "<<(ship*154.50 + ship*shippingCharge + rate*(ship*154.50));
}
int main(){
cout<<" Welcome to The ACME Ethernet Cable Company.";
cout<<" We sell spools of 1000 ft Cat6 Ethernet Cable for $154.50 each ";
int numSpool = getSpoolsOrdered();
double ship = determineShippingCharges();
createInvoice(numSpool,ship);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.