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
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints the number of integer values in the file. Your program's input will be a string with the name of the file. If the file does not exist, then the program must print: Error opening the file For example, given the following CSV file input1.csv: 1,10,20,30,40 The output of your program must be: 5 You can safely assume that the input file will be a...
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare...
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare a variable of type ofstream which is used to output a stream into a file: ofstream output; // output is the name of the variable Prompt the user to input values for the grades of 3 students. Use the output operator (<<) to write the grades into grades.txt: output << grade1 << " " << grade2 << " " << grade3 << endl; You...
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>...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
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...
Summary In this lab, you declare and initialize variables in a C++ program. The program, which...
Summary In this lab, you declare and initialize variables in a C++ program. The program, which is saved in a file named NewAge.cpp, calculates your age in the year 2050. Instructions Declare an integer variable named myNewAge. Declare and initialize an integer variable named myCurrentAge. Initialize this variable with your current age. Declare and initialize an integer variable named currentYear. Initialize this variable with the value of the current year. Use four digits for the year. Execute the program by...
Write a C++ Program Consider the following incomplete C++ program: #include <iostream> using namespace std; int...
Write a C++ Program Consider the following incomplete C++ program: #include <iostream> using namespace std; int main() {    …. } Rewrite the program include the following statements. Include the header file fstream, string, and iomanip in this program. Declare inFile to be an ifstream variable and outFile to be an ofstream variable. The program will read data from the file inData.txt and write output to the file outData.txt. Include statements to open both of these files, associate inFile with...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT