1 Attachment(s)
the code I wrote gives me an error once it compiles. I am unable to submit a proper o
Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ifstream myfile ("C:\\Users\\sshaw2\\Documents\\Untitled3.txt");
ofstream outfile ("C:\\Users\\sshaw2\\Documents\\output.txt");
std::vector<string> myvector;
string line;
getline(myfile,line);
outfile<<line<<endl;
while(getline(myfile,line))
{
myvector.push_back(line);
}
sort(myvector.begin(),myvector.end(),greater<string>());
// variable to to store the data
float totalbalanceDue =0.0;
int highestRental = 0;
float highestDue = 0.0;
string customerName = ""; // for highest rental customer
string customerName1 = ""; // for hishest due customer
while(!myvector.empty())
{
string line = myvector.back();
outfile<<line<<endl;
myvector.pop_back();
istringstream iss(line);
int count = 0;
string lastName;
string firstName;
string rental;
string balance;
iss>>lastName;
iss>>firstName;
iss>>rental;
iss>>balance;
stringstream ss1(rental);
int x= 0;
ss1>>x;
stringstream ss2(balance);
float y=0.0;
ss2>>y;
//logic for customer having highest dues
if(y>highestDue)
{
highestDue = y;
customerName1 = firstName+ " " + lastName;
}
else if(y==highestDue)
{
customerName1 = customerName1 + ", " +firstName+" "+lastName;
}
// logic for customer having highest rental
if(x>highestRental)
{
highestRental = x;
customerName = firstName+ " " + lastName;
}
else if(x==highestRental)
{
customerName = customerName + ", " +firstName+" "+lastName;
}
}
outfile <<endl;
outfile <<endl;
outfile <<"Total Balance Due for file:";
outfile <<totalbalanceDue<<endl;
outfile <<"Customer with highest number of rental days: ";
outfile <<customerName<<endl;
outfile <<"Customer with highest balance due are: ";
outfile <<customerName1;
myfile.close();
outfile.close();
return 0;
}