Question

Write a C++ program that processes orders for our company Widgets and More. Your program will...

Write a C++ program that processes orders for our company Widgets and More. Your program will read the product code and quantity for all the products in an order from a file, order.txt. You will be given a sample order.txt with the starter code. There are two items on each line of the file the first is a letter that represents the product and the second is an integer representing the number bought. Based on the product and quantity, you will calculate the total for the order. Then you will add 17% tax and 14.95 shipping costs to get the grand total for the order. You will print the order with the tax and shipping as shown below.

The unit costs for each product are listed below:

Product Unit Price
A 17.46
B 10.13
C 2.11
D 23.13
E 74.56
F 1.11
G 9.34
H 3.45

here is the starter code. PLEASE ADD THE STARTER CODE TO THIS PROGRAM. I HAVE TO USE IT. thank you.

PLEASE USE DOCUMENTATION FOR EACH STEP. I WANT TO KNOW UR THOUGHT PROCESS SO I BETTER UNDERSTAND HOW TO CREATE THIS PROGRAM MYSELF.

thank you so much for your help!!!!!!


#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;


int main()
{
//input file

   //Setting up the output table  
   cout << "Thank You! Your order is summarized below:" << endl;
   cout << setw(52) << setfill('-') << "-" << endl;
   cout << setfill(' ');
   cout << "| " << setw(15) << left << "Product" << "| " << setw(15) << "Quantity" << "| " << setw(15) << "Line Total" << "|"<< endl;
   cout << setw(52) << setfill('-') << "-" << endl;
   cout << setfill(' ');
  
  

   return 0;
}

Homework Answers

Answer #1

Attaching the well commented code snippet for the solution. Took order.txt file as input in which each line contains item name and quantity. Will attach test input and test output after the code snippet.

#include<bits/stdc++.h> //this header file includes all the necessary header files for moderate c++ and competetive coding.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <sstream> 

#define endl "\n" //try to use "\n" instead of endl as endl always flushes the output and your program may take more time than usual.

using namespace std;


int main()
{
//input file
        fstream order; //for taking input from order.txt file
        string temp, file_name; //initialized temp for word to word extraction from order.txt file and file_name for specifying file.
        
        double price[8] = {17.46 , 10.13 , 2.11 , 23.13 , 74.56 , 1.11 , 9.34 , 3.45};//price array will contain the price of all the items from A to H , 0 index representing A and so on.
        
        file_name = "order.txt";
        order.open(file_name.c_str());//for opening file
        
        int count[8] = {0};// for storing the quantity of an item from order.txt file.
        int i=0;// for identifying whether it is item name or item quantity. as the file will contain 1st word as item 2nd as quantity , then again 3rd as item and so on.Switing the value of i in the while loop.
        char item;
        while(order >> temp)//while loop for extracting word by word in temp variable.
                {
                        if(i == 0)//if word is a item
                                {
                                        item = temp[0];//item is stored in item variable, for example A,B,etc.
                                        i = 1;
                                }
                        else //if word is quantity.
                                {
                                        stringstream test(temp);//for converting quantity form string to integer.{you can also use stoi() function.
                                        int quantity = 0;
                                        test >> quantity;
                                        
                                        count[(int)(item - 'A')] += quantity;//updating the count array with quantity of item.
                                        i = 0;
                                }
                }
                
        double total = 0;

   //Setting up the output table  
   cout << "Thank You! Your order is summarized below:" << endl;
   cout << setw(52) << setfill('-') << "-" << endl;
   cout << setfill(' ');
   cout << "| " << setw(15) << left << "Product" << "| " << setw(15) << "Quantity" << "| " << setw(15) << "Line Total" << "|"<< endl;
   cout << setw(52) << setfill(' ') << "-" << endl;
   for(int i=0;i<8;i++)//This loop calculates the total price and prints item with quantity as output table.
        {
                if(count[i] != 0)
                        {
                                total += price[i]*count[i];
                                cout << "| " << setw(15) << left << (char)(65 + i) << "| " << setw(15) << count[i] << "| " << setw(15) << price[i]*count[i] << "|"<< endl;
                        }               
        }
        
        cout<<endl<<endl;
        //Price calculation
        cout<<"Total  =  "<<total<<endl;
        cout<<"Total(including 17% tax)  =  "<<total + 0.17*total<<endl;
        cout<<"Grand Total(including tax and shipping)  =  "<<total + 0.17*total + 14.95<<endl;
   cout << setfill(' ');
  
  

   return 0;
}

Thankyou

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment 2 (karatsuba.cpp) in Canvas (please do not rename file or use cout/cin statements in your solution). As a reminder, the algorithm uses recursion to produce the results, so make sure you implement it as a recursive function. Please develop your code in small The test program (karatsuba_test.cpp) is also given. PLEASE DO NOT MODIFY THE TEST FILE. KARATSUBA.CPP /* Karatsuba multiplication */ #include <iostream>...
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I feel like I know how to write that. What I'm having trouble with is implementing two files the professer gave us. I would appreicate any help in understanding their purpose as in if Im supposed to take information from those files or give it information. Thank you! I have attatched the homework instructions and the two files given. Implementation The main program, called calculator.cpp...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the values for hours, minutes and seconds are a legal military time (i.e. 00 00 00 to 23 59 59) the program should display the formatted results (i.e. 12 34 56 should be displayed as 12:34:56). If there's an error for any of the entered values, an exception should be thrown and an error message should be displayed. Note, there are three exception conditions, one...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i is saved in the array ascend[], in order. Compile and run the program; it should print 0 4 5. In this exercise, you’ll try to translate the C++ program to MIPS. Some of the more tedious parts are already given in Assignment3.F19.s. You won’t have to write the data allocation sections, some of the initializations, and the output loop at the end. So the...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT