Question
C++ programming:
One line per input/output variable with the exact variable name followed by a description
1. [8 points] Write a program that reads data from the file data.in. The file consists of an unknown number of lines each of which contains the unit price and the quantity of an item. For example, if the file data.in contained the following data: 16.00 24 7.47 13 2.10 15 12.47 18 Your program should output the following to your screen Unit Price 16.00 7.47 2.10 12.47 Quantity 24 13 15 18 Item Total 384.00 97.11 31.50 224.46 Item Number 2 GST 36.85 Grand Total 773.92
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, Please find my program.

Please let me know in case of any issue:

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

int main(){

   // declaring and opening output file
   ifstream inFile;

   inFile.open("data.in");

   // setting precision of double number to 2
   cout <<setprecision(2) <<fixed;

   // file opening error checking
   if(inFile.fail()){
       cout<<"Error in opening file"<<endl;
       return -1;
   }

   int quantity;
   double unitprice;
   double GST = 36.85;
   double grandTotal = GST; // to store total of all

   cout<<"Item Number   "<<"Unit Price   "<<"Quantity "<<"Item Total"<<endl;
   int count = 1;// counter
   // reading all lines
   while(inFile>>unitprice>>quantity){
       double price = unitprice*quantity;
       grandTotal = grandTotal + price;
       cout<<count<<"\t\t"<<unitprice<<"\t\t"<<quantity<<"\t\t"<<price<<endl;
       count++;
   }
   // closing file
   inFile.close();
   cout<<"\n\t\t\t\tGST\t"<<GST<<endl;
   cout<<"\t\t\t\tGrand Total\t"<<grandTotal<<endl;

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ programming: One line per input/output variable with the exact variable name followed by a description...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this project you will write a C++ program that simulates the purchase of a single...

    In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write a C++ program that: 1. Prints out a welcome message. 2. Prompts the user for the following information: (a) Their first name (example: Roger) (b) Their last name (example: Waters) (c) The name of the product (example: Brick) (d) The unit price of the product (example: 1.99) (e) The quantity to buy (example: 200) (f)...

  • c/c++ 6 The name, ID and section number that appear at the beginning of the output...

    c/c++ 6 The name, ID and section number that appear at the beginning of the output of the program should be your own, not the ones used in the sample 7 Note: results printed must show the data entered at run time, not the data shown in the sample run below! Sample run: My name: Smith, Peter My ID: 300999999 My section: 001 Enter your last name : Smith Enter your first name: Peter 8 9 10 11 12 13...

  • I need help with this C code Can you explain line by line? Also can you...

    I need help with this C code Can you explain line by line? Also can you explain to me the flow of the code, like the flow of how the compiler reads it. I need to present this and I want to make sure I understand every single line of it. Thank you! /* * Converts measurements given in one unit to any other unit of the same * category that is listed in the database file, units.txt. * Handles...

  • c++ programming no use of classes use of functions pseudo code with comments Requirement: Provide one...

    c++ programming no use of classes use of functions pseudo code with comments Requirement: Provide one application for a business store that sale 2 models of one proo model FA218 and model FA318. The application first provides the menu to allow users can select one of the following tasks per time and when they finish one task, they can continue the application to select other task from the menu until they choose exit. All the output on the screen and...

  • C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix...

    C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. +DebugNine2.cs Instructions Build Output The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. 1/ Creates a Breakfast class 2 // and instantiates an object 3// Displays Breakfast special information 4 using static System.Console; Conpilation fatled: 2 error(s), 8 warnings DebugNine2.cs(9,61): error C$1810: Newline in constant DebugNine2.cs (11,6): error CS1525: Unexpected synbol "Writeltne class DebugNine2 7static void...

  • The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib>...

    The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...

  • Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing...

    Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing Birthday Graph Problem Description Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social E interaction among co-workers, foster friendship among classmates or even strengthen bond between E BOBO Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, UU candles with names, or it can be in the form of simple bar...

  • i need help making this program the skeleton of the code is below: //Include the following #include <iostream> #...

    i need help making this program the skeleton of the code is below: //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; /********************************************************* //Following is the declaration of a order record **********************************************************/ class order_record { public: 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; }; //Prototypes for your functions: input, output, and process will go...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT