if you dont mind can you write down the code ?
if you dont mind can you write down the code ?
I will give you this much because you also need to learn how to check your code to be sure it is doing what you want it to do, don't just assume it is working just because it looks right.
it was not working so I fixed that.Code:/* string line; getline(myfile,line); outfile<<line<<endl; while(getline(myfile,line)) { myvector.push_back(line); } */ while (myfile >> firstName >> lastName >> rental >> balance) { myvector.push_back(firstName + " " + lastName + " " + rental + " " + balance); } for (auto i = myvector.begin(); i != myvector.end(); ++i) std::cout << *i << ' ';
Code:// your code was only storing this userx@slackwhere:~/bin $ ./temp starting anilo steve 0 0 userx@slackwhere:~/bin $ ./temp / my fix gives you this to work with. starting Smith Joe 15 100.50 Doe John 10 95.20 Anderson Paul 30 20.00 O'Donell Miriam 10 24.30 Foster Sam 30 15.00 Zom Pete 10 20.00 Mock Chilly 100 30 smitty Chris 200 200 xu Conor 1 200 anilo steve 0 0 userx@slackwhere:~/bin $
Last edited by userxbw; 12-11-2017 at 11:49 AM.
i have to submit the assignment and i just have like 2 hours please i would be so great if you can help me out
i trying but i couldn't do it
did you see post 18, and I'd have to whip out my google skills to even try to complete this in under two hours and I do not have a paypal account.
it is all in how you store your information, I do believe if I am correct that code I wrote turns it into one big string, then you'd have to split it again to get the last name in order to sort it.
Last edited by userxbw; 12-11-2017 at 11:59 AM.
i dont know how im gonna finish it
What if i give the whole code and you can just do the sorting code ?
It's time you just failed already.
If you put as much effort into study as you put into begging, you'd have this solved.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I did everything opening up from a file outputting it to other file but the thing i just dont get is the sorting and the first line of the input file which is the headers : Lastname, firstname, daysofrental, and balance
Code:#include <fstream> #include <iostream> #include <iomanip> #include <string> #include <cmath> #include <stdlib.h> using namespace std; const int MAX_SIZE = 50; const int NAME_SIZE = 30; const int COLUMNROW = 4; typedef char STRING_30[NAME_SIZE]; typedef STRING_30 LIST_S30[MAX_SIZE]; typedef STRING_30 LIST_COL[COLUMNROW]; typedef int LIST_I[MAX_SIZE]; typedef float LIST_F[MAX_SIZE]; int main(int argc, char *argv[]) { int choice; char drive[2]; char disk_file[15]; char file[9]; float sum = 0; float tot_balance = 0; float indx; ofstream outfile; system ("cls"); ifstream inf; inf.open("C:\\Users\\ahmed\\Downloads\\invoice1_test1 (1).txt"); LIST_S30 lastname, firstname; LIST_I daysofrent; LIST_F balancedue; LIST_COL headers; int highest = 0; int highbal = 0; int listcount = 0; while ( listcount <= 10) { if (listcount == 0) { inf >> headers [listcount] >> headers [listcount] >> headers [listcount] >> headers [listcount]; } else { inf >> lastname [listcount-1] >> firstname [listcount-1] >> daysofrent [listcount-1] >> balancedue [listcount-1]; } listcount ++; } listcount=0; while ( listcount < 10) { outfile << lastname [listcount] << ", " << firstname [listcount]; outfile << " " << daysofrent [listcount] << " " << balancedue [listcount] << endl; listcount ++; } for (int i=0; i < 10; i++ ){ tot_balance += balancedue [i]; } for (int i = 1; i < 10; i++) { if (daysofrent [highest] < daysofrent [i]) { highest = i; } } for (int i = 0; i < 10; i++) { if (balancedue [highbal] < balancedue [i]) { highbal = i; } } outfile.open ("C:\\Users\\ahmed\\Desktop\\output.txt.txt"); outfile << setiosflags(ios::showpoint | ios::fixed) << setprecision(2); listcount=0; while ( listcount < 10) { outfile << lastname [listcount] << ", " << firstname [listcount]; outfile << daysofrent [listcount] << " " << balancedue [listcount] << endl; listcount ++; } outfile << endl; outfile << left << "Total Balance Due for File: $ " << tot_balance << endl; for (int i = 0; i < 10; i++) { if (daysofrent [highest] == daysofrent [i]){ outfile << "Customer with the Highest Number of Rental Days: " << lastname [i] << ", " << firstname [i] << endl; } } for (int i=0; i < 10; i++) { if (balancedue [highbal] == balancedue [i]) { outfile << "Customer With the Highest Balance Due: " << lastname [i] << ", " << firstname [i] << endl; } } outfile.close(); cout << endl << endl; system ("pause"); return 0; }
Here what i did so far
here is what i did in my program I wrote awhile back and if you by chance figure out how to use it to your advantage, and the teacher asks you how did you figure that one out, well then that answer you give him or her is up to you isn't it?
now you have to ask yourself, does that sort meet the requirements for the two sorts you have to pick from?Code://holds the path and file name std::vector<std::string> dfile; void sort_V() { std::sort(opts.dfile.begin(), opts.dfile.end(), compareNoCase); } // Comparison; not case sensitive. bool compareNoCase (std::string first, std::string second) { unsigned long int i = 0; while ((i < first.length()) && (i < second.length())) { if (tolower (first[i]) < tolower (second[i])) return true; else if (tolower (first[i]) > tolower (second[i])) return false; i++; } if (first.length() < second.length()) return true; else return false; }
On your next assignment you get, learn how to google to ask how to's and work with small parts of your code until you get that to work first then move on to the next step in your program that needs to be done. Then if you have issues feel free to post in here or wherever for help and advice not will you do my homework I got two hours to turn it in. and not even show anything kind of work on your part in what you have been doing while waiting for an answer.
Last edited by userxbw; 12-11-2017 at 12:18 PM.
thanks for the advice
i have other assignments which is due within an hour im finishing off that