-1
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

struct Item 
{
    string name;
    int quantity;
    double unitPrice;
    string description;
};    

struct ItemTotal

{
    string name;
    int quantity;
    double unitPrice;
    string description;
};   


void sort(Item list[], int n) 
{                   
   for(int i=0;i<n;i++)
   {
           for(int j=0;j<n-i-1;j++)
                       if (list[j].description<list[j+1].description)
                           swap(list[j],list[j+1]);
   }
}

void display(Item a[], int size) 
{
    for(int i = 0; i < size; i++)
        cout << a[i].name << " " << a[i].quantity << " " << a[i].unitPrice << "\n";
             cout << "\n";
}  

void swap(Item& c1, Item& c2) 
{
    Item temp = c1;
    c1 = c2;
    c2 = temp;
}  

int main(int argc, char *argv[])
{
   string infilename,outfilename;

    ifstream infile;
    char inFileName[20],outFileName[20];

    do
    {
         infile.clear();
         cout<<"Please enter file containing details of items: "<<flush;
         cin>>inFileName; 
         infile.open(inFileName); 
    } while(!infile.good());

      cout<<"Please enter output file: "<<flush;
        cin>>outFileName; 
         ofstream outfile;
         outfile.open(outFileName); 
         string line;
         getline(infile,line);
         Item Item1[10];   
          for(int i=0;i<10;i++)
         {
                  infile>>Item1[i].name;
             for (int k=0;k<5;k++)
                  infile>>Item1[i].unitPrice[k];

          Item1[i].quantity=0;
             for(int j=0;j<4;j++)
             {          Item1[i].quantity+=Item1[i].unitPrice[j];
                        Item1[i].quantity+=Item1[i].unitPrice[4]/2;
             }
         }

          for(int i=0;i<10;i++)
                    outfile<<setw(10)<<setfill(' ')<<left<<Item1[i].name<<setw(10)<<setfill(' ')<<right<<"- "<<fixed<<setprecision(2)<<Item1[i].quantity<<endl;


    system("PAUSE");
    return EXIT_SUCCESS;
}

Edited by Reverend Jim: Fixed formatting

Votes + Comments
you have 17 posts, and haven't figured out code tags
6
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by mirfan00
0

Use code tags.

You have given us nothing to go on here, does the compiler throw errors at you? Is the output wrong or not what you expected?

Remember, a decent question gives a decent answer.

0

first of, include stringstream library.

sort-function cannot use swap-function because it hasn't been declared before its called.\

and finally, indexing your itemlist-array like this

Item1[i].unitPrice[j];

will not work. For every item in your list there is only one unitPrice.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.