Verstädnis Problem (Klasse)



  • Hallo, ich habe ein riesiges Verständnisproblem für diese Aufgabe:

    Write a version of the transaction-processing program from §
    1.6 (p.24) using the Sales_data class you defined for the exercises in §
    2.6.1 (p.72).

    Alles schön und gut aber es geht so weiter:

    Das Beispiel auf der Seite 24 sieht so aus:

    #include<iostream>
    #include "Sales_item.h"
    int main()
    {
    Sales_item total; //variable to hold data for the next transaction
    //read the first transaction and ensure that there are data to process
    if (std::cin >> total) {
    Sales_item trans; //variable to hold the running sum
    //read and process the remaining transactions
    while (std::cin >> trans) {
    //if we're still processing the same book
    if (total.isbn() == trans.isbn())
    total += trans; //update the running total
    else {
    //print results for the previous book
    std::cout << total << std::endl;
    total = trans;
    //total now refers to the next book
    }
    }
    std::cout << total << std::endl; //print the last transaction
    } else {
    //no input! warn the user
    std::cerr << "No data?!" << std::endl;
    return -1;
    //indicate failure
    }
    

    und die Klasse Sales_data so:

    class Sales_data
    {
    public:
        const string& getBookNo()    const { return bookNo; }
        const double& getSalePrice() const { return salePrice; }
        const int& getSoldBooks()    const { return sold_books; }
        const int& getRevenueUnits() const { return revenue;}
    public:
        string bookNo;
        int sold_books;
        double salePrice;
        int revenue;
    };
    

    Mehr Informationen gibt es nicht.. Nun habe ich dieses Problem, dass ich nicht genau weiß, was das Programm überhaupt tut...

    Könnt ihr mir weiterhelfen?
    Mfg Tombaa


  • Mod

    Tombaa schrieb:

    Nun habe ich dieses Problem, dass ich nicht genau weiß, was das Programm überhaupt tut...

    Könnt ihr mir weiterhelfen?

    Mehr als 2 Zeilen Kommentar pro Programmzeile können wir auch nicht liefern.



  • Ich hab einen dazugehörigen Link in den ersten Zeilen des Buchs dazu gefunden.
    Es hat sich alles erledigt.
    Danke für deine Mühe.

    Mfg Tombaa



  • SeppJ schrieb:

    Mehr als 2 Zeilen Kommentar pro Programmzeile können wir auch nicht liefern.

    Haha - ich hab schon mehrere tausend zeilen code geschrieben. Mit 2 Zeilen Kommentar. Insgesamt.

    EDIT:
    Hab dann nach 2 Monaten selber nicht mehr kapiert was ich mir dabei gedacht habe und wieso es trotzdem funktioniert.



  • Hehe, das kennt wohl jeder, der mal was Größeres gemacht hat.
    Wenn ich mir Sachen angucke, die ich vor mehr als zwei Jahren gemacht habe, frage ich mich auch manchmal, auf welcher Droge ich damals gewesen sein muss.


Anmelden zum Antworten