Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Beginner's C++

Name: Anonymous 2012-09-13 18:16

The only things I've covered so far are cin/cout, if/while/for and adding numbers.

Here is the question in the first chapter of C++ Primer (5th edition) that I'm stuck on:

http://ideone.com/4QlDm

here is the bit about the class:

http://ideone.com/tlrsc

This has been wregking my head for days I've been looking gor a solution online but to no avail. A solution with only chapter material would be freatly appreciated. I also can't seem to satisfactorally add Sales_items:

http://ideone.com/XeAx2

and here is Sales_item.h if you want to test your solutions before posting them:

http://ideone.com/U1vCo

Thanks in advance!

Name: Anonymous 2012-09-13 19:58

That's C++11, a beginner shouldn't be doing that.

Name: Anonymous 2012-09-13 20:09

I took a look in Sales_item.h...
[m]friend[/m, operator overloading, ugly as GNU shit formatting. Fuck that!

I'll stick with my beautiful ANSI C, thanks.

Name: Anonymous 2012-09-13 21:22

ok i got this far, but how do I make it work for many isbns?:

#include <iostream>
#include "Sales_item.h"

int main()
{
    Sales_item item;
    Sales_item total;
    Sales_item total1;
    while(int i, cin >> item, i++)
    {
        if (i == 0)
        {         
            total = item;    
        }
        else if (total.isbn() == item.isbn())
        {
            total += item;
        }   
        else if (item.isbn() != total.isbn() && item.isbn() != total1.isbn())
        {
            total1 = item;
        }
        else
        {
            total1 += item;
        }
    }
    std::cout << total << std::endl << total1 << endl;
    return 0;
}

Name: Anonymous 2012-09-13 22:35

while(int i, cin >> item, i++)
What the fuck are you doing that for?

Name: Anonymous 2012-09-13 22:37

total.isbn()
ENTERPRISE quality encapsulation

Name: Anonymous 2012-09-13 22:59

>>5

oops, i meant for, not while (I'm a newb).

Name: Anonymous 2012-09-13 23:29

>>7
Even then it's not commas. Also, you're incrementing i without ever having defined it in the first place.....

Name: Anonymous 2012-09-13 23:48

#include <iostream>
#include "Sales_item.h"

int main()
{
    Sales_item total;

    if(cin >> total)
    {
        Sales_item item;
        while(std::cin >> item)
        {
            if (total.isbn() == item.isbn())
            {    
                total += item;
            }
            else
            {
                std::cout << total << std::endl;
                total = item;
            }
        }
        std::cout << total << std::endl;
    }
    else
    {
        std::cerr << "No data?!" << std::endl;
        return -1;
    }
    return 0;
}

Name: Anonymous 2013-11-27 21:56

#include <iostream>

using namespace std;

int main(void)
{
  cout << ">>11 check 'em dubz" << endl;
}

Name: Anna-bella, le λ queen 2013-11-28 1:07

>>11
nice dubs

Don't change these.
Name: Email:
Entire Thread Thread List