C/C++ :: Creating And Loading Array Of Cards?
Oct 6, 2014
I am working on a program that is supposed to eventually be able to evaluate bridge hands, but one of the first things I need to do is create and load an array. The program is supposed to read in hands from a file (each line in the file is a hand of 13 cards), evaluate these hands based on a list of rules, and display the results.
Here is the file that will be used for the program:
2C QD TC AD 6C 3D TD 3H 5H 7H AS JH KH
3C 4C 2D AC QC 7S 7C TD 9C 4D KS 8D 6C
2C 3C KC JC 4C 8C 7C QC AC 5C 9C 6C TC
5H 3S 4D KC 9S 3D 4S 8H JC TC 8S 2S 4C
2S 5D 6S 8S 9D 3C 2H TH
2H 6D %S 8S 7S 4D 3H 4S KS QH JH 5C 9S
2C QD TC AD 6C 3D TD 3C 5H 7H AS JH KD QS
2C QD TC AD 6C 3D TD 2C 5D 7H AS JH KD
2H 6D TS 8Z 7S 4D 3H 4S KS QD JH 5C 9S
I've gone through and wrote out what the program is supposed to do and what I think is needed and what steps to take to accomplish this, but am getting stuck on the array. If you can't tell I'm extremely new to this and am still learning. I'm not sure how to create and load an array like this since it seems to me there'd be two elements per index, a suit and a value.
Also, the instructions mention that I will need a data structure to hold the cards in an ordered manner. I'm really confused on this as well, if I'm using an array, how does the data structure come into play?
Can the data structure be used in place of the array?
Here is the code I have so far, but keep in mind that at the moment all it actually does is open the file (The "File is open" message will be taken out as the code progresses, I just threw that in there to make sure the file was actually being opened):
//#include <program3.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
char handsArray[];
ifstream bridgeFile;
[code]....
The input should be sorted by suit and the rank within the suit and be displayed in teh following format:
Clubs 10 6 2
Diamonds A Q 10 3
Hearts K J 7 5 3
Spades A
Points = 16
View 3 Replies
ADVERTISEMENT
Aug 6, 2014
I've written this class and struct to create a singly linked list. The data is stored in the binary file which I've opened and read. I'm trying to load said data into a class type array. The errors I'm getting are "incompatible types in assignment of 'StatehoodInfo' to char[3]" Lines 130-134 is what I was working on.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring> //For char[] string functions
[Code] .....
View 2 Replies
View Related
Nov 24, 2014
I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such.
void showCards(const int cards[], int numCards, bool hideFirstCard) {
if (cards[0]) {
hideFirstCard=true;
cards[0] = '**';
} for(int a = 0; a <= numCards; a++) {
cout >> showCard(cards[a]);
} }
View 1 Replies
View Related
Sep 10, 2014
The program is supposed to read in a text file, load it into an array and assign a character to each number in the array (so for this I'm thinking I'll be creating 2 arrays, an int array with the numbers read in from the file, and a char array with the characters assigned to the numbers). It will then print these two arrays. It's then supposed to go through the initial int array and search for any numbers whose values differ from their neighboring values by more than one, if such a value is found, it's supposed to give the number the value of the average of it's neighboring values. It's supposed to make all these corrections and then assign characters to these corrected numbers and print out both arrays.
How to load the array from the file. My textbook seems to do a good job of covering arrays and files, but it doesn't really bring them together and talk about building arrays from files. Here is what the file looks like, the first number is the size of the array.
10
7 6 9 4 5 4 3 2 1 0
6 5 5 5 6 5 4 3 2 1
6 5 6 6 7 6 8 4 3 2
1 5 6 7 7 7 6 5 4 3
5 5 6 7 6 7 7 6 5 9
5 6 7 6 5 6 6 5 4 3
5 6 7 9 5 5 6 5 4 3
5 5 6 7 6 6 7 6 5 4
5 9 5 6 7 6 5 0 3 2
5 5 5 5 6 5 4 3 2 7
And here is the code I have so far:
#include <iostream>
#include <fstream>
using namespace std;
[Code]....
When I attempt to compile this (I'm working on a Linux system), I'm getting several errors:
prog1.cpp: In function ?int main()?:
prog1.cpp:37: error: expected unqualified-id before ?[? token
prog1.cpp:39: error: ?numArray? was not declared in this scope
prog1.cpp:39: error: expected primary-expression before ?]? token
View 14 Replies
View Related
Feb 14, 2013
Code:
public void dam_data_setup() {
// fill list
damgtype.Add( den1);
damgtype.Add( den2);
damgtype.Add( da1);
damgtype.Add( da2);
damgtype.Add( db1);
damgtype.Add( db2);
[Code] .....
This is a genetics program and is to parse the source array and write all possible combinations to a new array. All sections but dilute work correctly. For some reason the dilute's Boolean is not testing true when it should. This is causing data corruption.
View 3 Replies
View Related
Jul 19, 2013
I'm having troubles with loading my text file into my array.
Code:
int main(int argc,char* argv[]) {
if(argc!=3) {
printf("
Insufficient arguments
[code]...
I'm also suppose to return the size of the input at the end.
View 3 Replies
View Related
Apr 28, 2014
Heres what I am suppose to do, So it doesnt seem hard to understand my messy code!
1. Gotta load the file "FactoryData.txt"
2. Load all values in my 2D array (array[5][3])
3. Print out the array to ensure that the copying went by well.
Heres my problem:
1. The for loops is REALLY off in my eyes. From my knowledge (correct me if im wrong), its suppose to be for(r=0;r<5;r++) not <=. BUT somehow im getting the results I want (in terms of formatting). HERE IS MY OUTPUT
Quote
300 450 500 510
510 600 750 627
627 100 420 530
530 621 730 200
200 50 58 100
100 83 4 5
Press Enter to return to Quincy...
View 8 Replies
View Related
Oct 13, 2014
I'm struggling loading a class (and it's two derived classes) from an input file. I'm trying to create an array of class objects (and derived objects) and then load them based upon what is in the file.
Main class: Code: class Book
{
protected:
string sTitle;
[Code].....
Basically if the getline get's a P it's supposed to create a new object using the PrintedBook derived class and then store it to an array, if the getline get's to the "A" it's supposed to create an AudioBook object.
What I'm struggling with is writing something to parse the file line by line and create the objects on the fly and then store them into the array.
View 5 Replies
View Related
Oct 5, 2013
How would i go about loading an array with random numbers with in a range. For example, loading an array of 500 elements with random numbers in the range of 50-100.
View 9 Replies
View Related
Jan 25, 2015
I am currently working on a project that requires me to "load the data in the file into array at the beginning of the program."
I have a text file with data, and I need to populate an array with the information. From then on, I am supposed to be able to add, display, and search that array. However, I can't figure out how to add the data from the file into an array. I was trying to find out how to search the text file itself. So it threw me off balance and I've been staring so long at the screen I can't really focus.
View 7 Replies
View Related
Mar 5, 2013
I'm still new at C++, so my syntax might be a little off for getting the correct output. Currently, there are no compiler errors or warnings, but there is also no output when I run the program. It seems as if it is not calling something correctly maybe the .toString or perhaps my DeckOfCards constructor is a little off, either way, I can't seem to figure out why there is no output.
Anyways, here is my code:
Card.h
#ifndef CARD_H
#define CARD_H
#include <string>
using namespace std;
class Card {
[Code] ....
View 3 Replies
View Related
Mar 2, 2014
I am trying to write a sub-program that takes a deck of 52 cards and will shuffle it up using this algorithm:
Start with n=51
Repeatedly:
Generate a random integer between 0 and n. Call it i.
Swap card i and card n in the deck.
Decrease n by 1
However the code that I've written,
vector<int> shuffleDeck(vector<int> deckVector)//deckVector is the original deck in order
{
int temp, n, i, s;
n = 51;
[Code].....
when I output the new vector, only produces this output(note- it is a random number every time, but it just repeats over and over):
8 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8
or:
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 0 22 22 22 22
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
View 1 Replies
View Related
Sep 9, 2013
Here is my source code i am trying to write a function (fillAll) to fill all 52 cards in a deck and i would like to use my data struct for the function and make Deck one of my parameters.
enum suit{HEARTS, CLUBS, DIAMONDS, SPADES};
enum face{TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE};
struct Card{
suit suitType;
face faceType;
[Code] .....
View 10 Replies
View Related
Apr 3, 2015
I have a lstYourHand that has two cards in it, I loop through the listbox to get the values of both cards. I take the string value of the listbox item (strCardVal) and use a switch to give it an integer value (intCardVal). For some reason, when I run the code, the message Box at the end gives me the value 0 as a result, it does not register me giving it a value in the switch statement. My code is below:
Int32 intCardVal = 0;
String strCardVal;
Int32 intLoopCounter1;
for (intLoopCounter1 = 0; intLoopCounter1 == 1; intLoopCounter1++) {
strCardVal = lstYourHand.SelectedItem.ToString();
[Code] .....
View 3 Replies
View Related
Feb 6, 2014
How to make a standard deck of cards and being able to shuffle and distribute the cards. I have made an array to store each card and I can display them but I assigned them all in order according to the suit and rank. Is this a viable way to do it if I intend to have a shuffle effect? Or should I create an array, randomly generate card, check for duplicates, then put them in the array, then display the array? Each card is a structure with two void pointer members for suit and rank.
View 1 Replies
View Related
May 23, 2012
I have an application in c# that i don't want it to connect to the internet in a virtual environment, like virtualbox, vmware virtual pc and so on. Therefore i though that disabling the virtual network card inside the virtual machine would be a good idea.
View 3 Replies
View Related
Sep 9, 2013
I have a deck of 108 cards inside a 2D array and want to deal these card by 7 to 4 player. Each player had a id. The player and id are stored in a file while i've read in array each. Now I have to deal the cards.
Code:
struct card{
char color;
int rank;
char action[24];
char location[108]; Code: struct players{char name[10];
int id[5];
char hand;
};
View 2 Replies
View Related
Jan 24, 2013
I want it to read 5 cards then display a text value
Code:
#include <stdio.h>
int main( void ) {
char inputtedhand[25];
[Code]....
View 3 Replies
View Related
Nov 2, 2013
I'm gonna start a project for my own purpose. In my project I need to access GSM sim cards and send & receive messages through a PC interface. What kind of GSM Interface support for my Requirements and in feature may extend Requirements. what kind of programming language will be simple for write an pc interface to access that GSM interface device.
View 6 Replies
View Related
Dec 29, 2013
I am trying to seed a vector with 52 values ranging from 1 to 52. I already have the code written to seed the vector bu how to keep from repeating the same values from being seeded. This is for a five card stud game.
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<ctime>
using namespace std;
[Code] ....
View 3 Replies
View Related
Oct 22, 2014
Write a program to simulate a deck of 52 playing cards.
Represent your deck as a 2D Array where the value in the cell is the position of the card in the deck. Represent the names for the suits and faces as an array of Strings.
Write an algorithm to shuffle the deck.
Display the deck. For Example:
1 Jack of Spades
2 Deuce of Diamonds
3 Three of Diamonds
4 King of Spades
5 Eight of Clubs
6 King of Diamonds
7 Six of Clubs
8 Six of Spades
9 Eight of Hearts
Deal two hands of five cards each. For Example:
****** HAND 1 ******
Jack of Spades
Three of Diamonds
Eight of Clubs
Six of Clubs
Eight of Hearts
...
Below is what I have so far. Dealing two hands and displaying it. How would I be able to do that?
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
void shuffle(int[][2]);
int main()
{
int j,deck[52][2];
[Code]...
View 2 Replies
View Related
Oct 26, 2014
Write a program to simulate a deck of 52 playing cards.
Represent your deck as a 2D Array where the value in the cell is the position of the card in the deck.
Represent the names for the suits and faces as an array of Strings.
#include "stdafx.h"
#include <iostream>
#include <string>
[Code].....
The problem: I am trying to connect the 1d arrays to the 2d arrays. Right now when I write: cout << deck[3][5] << endl; The output answer is 45. How do I populate the 2d array with the 1d arrays so that when I cout deck[3][5] I get it to say "Six of Spades"?
View 8 Replies
View Related
May 21, 2014
I am writing a console application that creates a shuffled deck of cards using pointers and arrays, but I get the error "Run-Time Check Failure #2 - Stack around the variable 'deck' was corrupted" What's the stack? What does this mean and what did I do to cause the stack to be corrupt?
#define _CRT_SECURE_NO_WARNINGS
#include "stdlib.h"
#include "time.h"
#include "stdio.h"
#include "conio.h"
typedef struct card{
int cval;
[Code] .....
View 8 Replies
View Related
Apr 2, 2014
My assignment is to create a program to print a deck of 52 cards, shuffle it, deal 2 hands of 5 cards, then print the deck after dealing the 2 hands with the cards that were dealt removed. this is my code so far...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define DECK_SIZE 52
void init_deck( int deck[] , int size ) ;
void shuffle_deck( int deck[] , int size ) ;
[Code] ....
I am having trouble dealing 2 random hands and how to print the deck with the cards removed.
View 3 Replies
View Related
Oct 10, 2012
How could I create an array that would in PHP look like this:
PHP Code:
$something['argument1']['argument2'] = "some data to store";
View 14 Replies
View Related
Jul 14, 2014
How would i do this? Im trying to create an inventory but this just will not work, when i do it how i have it originally (as shown below):
cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y') {
cout << endl;
string invintory2[6] =
[Code] ....
the program outputs this:
cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y'){
cout << endl;
string invintory1[6];
[Code] ....
however programing it like this seems very... time consuming.
my other arrays (normal ones that just hold a set of int's) look like this:
int *player[] = {&yhp,&ymp,&ypatk,&ymatk,&yratk,&ypdef,&ymdef,&yrdef,&ydb,&yacc,&ycr,&yas};
Is there any way to do a string array in this way?
View 8 Replies
View Related