Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 09:06

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



DIESER FEHLER HAT DOCH KEINEN SINN?!

Discussion on DIESER FEHLER HAT DOCH KEINEN SINN?! within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
Defkahn52's Avatar
 
elite*gold: 8
Join Date: Aug 2009
Posts: 1,504
Received Thanks: 396
DIESER FEHLER HAT DOCH KEINEN SINN?!

Hi Leute,

Ich werde bald verrückt, ich verstehe nicht wo der Fehler liegt. Denn auch im Buch C++ Primer 5th Edition steht der Code genau so.

Hier der main-code:
PHP Code:
#include <iostream>
#include "Sales_item.h"

int main()
{
    
Sales_item total;//Derzeitige Anzahl der selben Bücher

    
if (std::cin >> total)
    {
        
Sales_item trans;
        while (
std::cin >> trans)
        {
            if (
total.isbn() == trans.isbn())// Wenn die Bücher ISBN'nen übereinstimmen
                
total += trans;
            else
            {
                
std::cout << total << std::endl;
                
total trans;//Book2 wird zur neuen derzeitigen Anzahl der selben Bücher
            
}
        }
        
std::cout << total << std::endl;//Gibt nochmal die letzte Transaktion wieder
    
}
    else
    {
        
std::cerr << "Sie haben keine richtige ISBN angegeben!" << std::endl;
        return -
1;
    }

    
system("PAUSE");
    return 
0;

Hier der Header-code:
PHP Code:
/*
 * This file contains code from "C++ Primer, Fourth Edition", by Stanley B.
 * Lippman, Jose Lajoie, and Barbara E. Moo, and is covered under the
 * copyright and warranty notices given in that book:
 * 
 * "Copyright (c) 2005 by Objectwrite, Inc., Jose Lajoie, and Barbara E. Moo."
 * 
 * 
 * "The authors and publisher have taken care in the preparation of this book,
 * but make no expressed or implied warranty of any kind and assume no
 * responsibility for errors or omissions. No liability is assumed for
 * incidental or consequential damages in connection with or arising out of the
 * use of the information or programs contained herein."
 * 
 * Permission is granted for this code to be used for educational purposes in
 * association with the book, given proper citation if and when posted or
 * reproduced.Any commercial use of this code requires the explicit written
 * permission of the publisher, Addison-Wesley Professional, a division of
 * Pearson Education, Inc. Send your request for permission, stating clearly
 * what code you would like to use, and in what specific way, to the following
 * address: 
 * 
 *     Pearson Education, Inc.
 *     Rights and Contracts Department
 *     75 Arlington Street, Suite 300
 *     Boston, MA 02216
 *     Fax: (617) 848-7047
*/ 

#ifndef SALESITEM_H
#define SALESITEM_H

// Definition of Sales_item class and related functions goes here


#include <iostream>
#include <string>

class Sales_item {
friend bool operator==(const Sales_item&, const Sales_item&);
// other members as before
public:
    
// added constructors to initialize from a string or an istream
    
Sales_item(const std::string &book):
              
isbn(book), units_sold(0), revenue(0.0) { }
    
Sales_item(std::istream &is) { is >> *this; }
    
friend std::istreamoperator>>(std::istream&, Sales_item&);
    
friend std::ostreamoperator<<(std::ostream&, const Sales_item&);
public:
    
// operations on Sales_item objects
    // member binary operator: left-hand operand bound to implicit this pointer
    
Sales_itemoperator+=(const Sales_item&);
    
// other members as before
    
public:
    
// operations on Sales_item objects
    
double avg_price() const;
    
bool same_isbn(const Sales_item &rhs) const
        { return 
isbn == rhs.isbn; }
    
// default constructor needed to initialize members of built-in type
    
Sales_item(): units_sold(0), revenue(0.0) { }
// private members as before
public:
    
std::string isbn;
    
unsigned units_sold;
    
double revenue;

};


// nonmember binary operator: must declare a parameter for each operand
Sales_item operator+(const Sales_item&, const Sales_item&);

inline bool 
operator
==(const Sales_item &lhs, const Sales_item &rhs)
{
    
// must be made a friend of Sales_item
    
return lhs.units_sold == rhs.units_sold &&
           
lhs.revenue == rhs.revenue &&
       
lhs.same_isbn(rhs);
}

inline bool 
operator
!=(const Sales_item &lhs, const Sales_item &rhs)
{
    return !(
lhs == rhs); // != defined in terms of operator==
}

using std::istreamusing std::ostream;

// assumes that both objects refer to the same isbn
inline
Sales_item
Sales_item::operator+=(const Sales_itemrhs
{
    
units_sold += rhs.units_sold
    
revenue += rhs.revenue
    return *
this;
}

// assumes that both objects refer to the same isbn
inline
Sales_item 
operator
+(const Sales_itemlhs, const Sales_itemrhs
{
    
Sales_item ret(lhs);  // copy lhs into a local object that we'll return
    
ret += rhs;           // add in the contents of rhs 
    
return ret;           // return ret by value
}

inline
istream

operator>>(istreaminSales_items)
{
    
double price;
    
in >> s.isbn >> s.units_sold >> price;
    
// check that the inputs succeeded
    
if (in)
        
s.revenue s.units_sold price;
    else 
        
Sales_item();  // input failed: reset object to default state
    
return in;
}

inline
ostream

operator<<(ostreamout, const Sales_items)
{
    
out << s.isbn << "\t" << s.units_sold << "\t" 
        
<< s.revenue << "\t" <<  s.avg_price();
    return 
out;
}

inline
double Sales_item
::avg_price() const
{
    if (
units_sold
        return 
revenue/units_sold
    else 
        return 
0;
}


#endif 
Defkahn52 is offline  
Old 10/28/2012, 17:13   #2
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
würde evtl. helfen wenn du auch den fehler postest.
Dr. Coxxy is offline  
Old 10/28/2012, 17:28   #3
 
Defkahn52's Avatar
 
elite*gold: 8
Join Date: Aug 2009
Posts: 1,504
Received Thanks: 396
Oh ja^^ Mein Fehler.
PHP Code:
if (total.isbn() == trans.isbn())// Wenn die Bücher ISBN'nen übereinstimmen 
total und trans sind rot unterstrichen und der Fehler Code ist c2064
Defkahn52 is offline  
Old 10/28/2012, 17:38   #4
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
könntest auch den genauen wortlaut posten...

egal, es gibt keine funktion isbn, sondern nur einen public string in der klasse.
musst also die klammern weglassen, oder nimmst die von der klasse angebotene funktion "same_isbn".
Code:
if (total.isbn == trans.isbn)
Code:
if (total.same_isbn(trans))
und beim nächsten mal bitte nicht capslock überschrift und mal nen bisschen selber versuchen den fehler zu finden.
Dr. Coxxy is offline  
Reply


Similar Threads Similar Threads
S4 League Hack's habn keinen sinn mehr
03/15/2011 - S4 League Hacks, Bots, Cheats & Exploits - 7 Replies
Es hat keinen sinn mehr hier i.welche hacks rein zu stellen weil sie eh alle verkackt sind wer braucht denn hacks wie no Fog oda sowas ?!?! macht bitte diese scheiz regeln weg und lasst die leute hacks machen wie sie wolle oder verbietet es anz ,weil man diese scheiz trainer sowieso nicht braucht...
Kann keinen Sinn hochladen
01/24/2011 - Minecraft - 5 Replies
Heyho. Nachdem ich meinen SKinn lagweilig fande wollte ich einen neuen hochladen,aber wenn ich auf profile klicke ist da nicht des uploadfeld. Ich packe screen in anhang. Hoffe ihr könnt mir helfen. PS: IST Natürlich Premium acc. MfG Marcel
>>( Metin35 ) Down ? Heul´Mein leben hat keinen sinn mehr ..!<<
08/16/2009 - Metin2 Private Server - 8 Replies
Boah schon wieder Server Down is ja zum Kotzen ..:mad: Egal soll ja Angeblich Morgen früh wieder On sein ( 12.20oder30 uhr )..:! Hoffentlich Bringense des auch gut raus jetzt z.B Bonis unw..! Aber dann so . v.v:pimp: (Gemischti)
Das macht doch irgendwie keinen Sinn
04/23/2009 - Metin2 Private Server - 6 Replies
Irgendwie macht das keinen Sinn mehr... Jeder kennt den IS-Bug gibt ihn aber nicht weiter xDDD Irgendwie lach ich mich jedesmal kaputt das es die Leute nichtmal merken. Oder was meint ihr ?



All times are GMT +2. The time now is 09:06.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.