473,378 Members | 1,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

help in overloading ostream op

hi,
i have to create a program that will print the 52 cards in a deck using
the overloaded ostream operator. it worked fine....then i hve to create
a function that will print the cards in hand in random(5, 10).

//error it shld only have two parameters
ostream& operator<<(ostream& out, vector<Card>& deck2, vector<Card>&
hand)
{

for(unsigned int i = 0; i < hand.size(); i++)
{
int random;
random = randNum(0, 51);

//if the card is picked, don't add it in
hand,instead add another card/s in the vector
if(deck2[random].isPicked())
{
deck2[random].printCard(out);
out << endl;
int last = hand.size() - 1;
hand.push_back(hand[last]);
for(int i = last; i > deck2[random].isPicked();
i--)
{
hand[last] = hand[last - 1];
}

}

else
{
hand[i] = deck2[random];
deck2[random].setPicked(true);
hand[i].printCard(out);
out << endl;
}
}
return out;
}

what shld i put in the parameters of ostream& operator<<(..) in order
to print the card in hand

Jul 22 '05 #1
1 1425
sahm wrote:
hi,
i have to create a program that will print the 52 cards in a deck using
the overloaded ostream operator. it worked fine....then i hve to create
a function that will print the cards in hand in random(5, 10).
I think you need to define your problem better.
As you noted operator<< should only have two operands.

You should separate the generation of the hand from the deck
from outputing a hand or a single card. I suggest the following.

First write
ostream << Card;

Then using that also write
ostream << vector<Card>

Then right other functions that make the deck and hands.

I would suggest it would be easier if you actually removed the
cards from the deck after it is picked rather than maintaining
some sort of picked state. Think about the real world you're
attempting to model here.

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chase Bradford | last post by:
Hey all I have a class Foo, and I'm trying to overload the << operator for both the ostream and ofstream for it. This way I should have two seperate formats for output, one for files and another...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
13
by: JustSomeGuy | last post by:
I have two object types ClassA and ClassB class ClassA { public: int data; operator ClassB() { ClassB b; b.data = data + 1; return (b);
0
by: Martin Magnusson | last post by:
I have defined a number of custom stream buffers with corresponding in and out streams for IO operations in my program, such as IO::output, IO::warning and IO::debug. Now, the debug stream should...
4
by: dinks | last post by:
Hi I'm really new to c++ so please forgive me if this is really basic but im stuck... I am trying to make a data class that uses istringstram and overloaded << and >> operators to input and output...
8
by: jois.de.vivre | last post by:
Hi, I'm having some trouble overloading the << operator. I have the following, very simple code: #include <iostream> using namespace std; class test { private: int val;
1
by: yeutim | last post by:
I can't find anything wrong this with this class. Especially, Overloading Stream-Extraction Operator (in blue). Any one know what do I need to fix this problem please reply. Thank you for your...
7
by: John | last post by:
I always understood that in C++, if I said a + b a.operator+(b) is called. Now this makes sense with the operator<< when used in the following way cout << 100; // converts to ...
2
by: brzozo2 | last post by:
Hello, this program might look abit long, but it's pretty simple and easy to follow. What it does is read from a file, outputs the contents to screen, and then writes them to a different file. It...
2
by: Colonel | last post by:
It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream &...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.