Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simon Rutgersson, 980617-5718, simru571
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- struct Debit_Note {
- string license_plate;
- int size;
- int days [31];
- int fees [200];
- int total;
- };
- int Size_Note = 0;
- Debit_Note notes[500];
- void do_invoice (string month, Debit_Note note, string license_plate)
- {
- stringstream stream;
- for(int i = 0; i <= note.size; i++)
- {
- stream << month << "/" << note.days[i] << " ";
- }
- for ( int pass = 1; pass <= Size_Note - 1; pass++ ) // passes
- {
- for (int i = 0; i < Size_Note - 1; i++ ) // one pass
- {
- if ( license_plate[ i ] > license_plate[ i + 1 ] ) // compare a pair of adjacent values
- {
- //swap
- int temp = license_plate[ i ];
- license_plate[ i ] = license_plate[ i + 1 ];
- license_plate[ i + 1 ] = temp;
- }
- }
- }
- string date_string = stream.str();
- //The output
- cout << "Invoice: " << note.license_plate << endl;
- cout << "Dates: " << date_string << endl;
- cout << "Amount to pay: " << note.total << endl;
- cout << "====================================" << endl;
- }
- void read_debit_notes(string month)
- {
- string license_plate;
- int day, fee;
- bool exists = false;
- //Reads through input and add or create new and existing notes
- while (true)
- {
- cin >> license_plate >> day >> fee;
- exists = false;
- if(license_plate == "STOP")
- {
- cout << "\nCreating invoices...\n\n";
- for(int i = 0; i < Size_Note; i++)
- {
- do_invoice(month, notes[i], license_plate);
- }
- break;
- }
- //Checking if we have license plate
- for(int i = 0; i < Size_Note; i++)
- {
- if(license_plate == notes[i].license_plate)
- {
- notes[i].days[notes[i].size+1] = day;
- notes[i].fees[notes[i].size+1] = fee;
- notes[i].size += 1;
- notes[i].total += fee;
- exists = true;
- break;
- }
- }
- //Adding one if we dont have it
- if(!exists)
- {
- Debit_Note note;
- note.license_plate = license_plate;
- note.size = 0;
- note.total = fee;
- note.days[0] = day;
- note.fees[0] = fee;
- notes[Size_Note] = note;
- Size_Note += 1;
- }
- }
- }
- //Where the program runs
- int main()
- {
- string month;
- cout << "Enter a month followed by debit notes:" << endl;
- cin >> month;
- read_debit_notes(month);
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement