I'm writing a program with two classes, one that contains a card's rank and suit and the other contains pile of these cards. I'm having trouble when it comes to adding a pile to another pile...here's what I have so far:
class Card //Card class declaration
{
private:
int rank; //invoking rank
char suit; //invoking suit
public:
void setCard(int r,char s); //determines card suit/rank
[Code] ....
I understand that I'm calling my pile arrays incorrectly, but I'm not sure why.
I'm writing a card game and I'm having trouble getting the first part of it right, which is picking out a random card from the deck and displaying it to screen. So it's supposed to display a different card every time i run the function in the program. The problem is, I keep getting the same output every time "Nine of Hearts".
This is what I have so far,
#include <iostream> using namespace std; //declare two string arrays //one holds the "suit" of the cards, the other hold the "value" string suit[] = {"Diamonds", "Hearts", "Spades", "Clubs"}; string faceValue[] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ace", "King", "Queen", "Jack"};
[Code] ......
This is the output I keep getting every time I run the program:
Nine of Hearts
This "random selection" function I'm trying to do is meant to work as a means of shuffling the cards in the beginning of every round in the game and displaying only the top card from the deck.
I am struggling to finish up my game of War. There are a few problems I have ran in to. My shuffle function seems to work fine. I believe my problem lies within my game rules. When I run my code, the game usually plays all the way through but almost always ends in 'War'. I am struggling to get the game to restart after running once. I am not sure how to clear the list and start over.
I'm writing a program in which I have to use a matrix to represent a file in code. because it's a file, the size of the matrix is undefined, and therefore the matrix has to be dynamic. I found out that my compiler doesn't like dynamic multidimensional arrays, so I was thinking of this matrix as a dynamic (monodimensional) array of other dynamic (monodimensional) arrays. My program (and thus this example) uses unsigned chars.
I need to input values for two arrays and then add the two with all of it being print visible. I have this so far but can not figure out how to add the two arrays.
#include <iostream> using namespace std; int main () { { int const ROWS = 3; int const COLUMNS = 3; int square[ROWS][COLUMNS];
I am having troubles with dynamic arrays and pointers. All the errors are of that kind. I think when I am assigning malloc to an array we assign to its address.
Code: /*Create an array of genes of the large matrix*/ gene_t gene,gene1,gene2; gene=malloc(INITIAL*sizeof(gene2)); Code: while(...) { if (gene_num==current_size){
i was trying to make a dynamic array in this form :
int x; cin>>x; int ar[x];
my g++ (gcc) compiler on linux refused to create an array without a fixed size , however using the same code on windows on dev-cpp it was complied and executed , also it allowd me to create and use the dynamic array , i thought it was a compiler bug , however when i restarted and returned to g++ it compiled and executed the code although it never did before i tried the code on windows , how can that be and is it dangerous ?
Im trying to create a function that searches my array for a specific string, and then displays that string and the other content associated with it. I'm basically searching for a keyword within an array that has multiple strings with in each element.
You will have two file streams: an input file stream for the file to be normalized and an output file stream that contains the normalized file. You should issue an error message and exit the program if either file cannot be opened. Your program should prompt the user for the filename of the file to be normalized (the input file). The output filename should be the input filename with ".normal" added to it. For example, if the input file is "data.txt", the output file name will be "data.txt.normal".
Be careful to not leave an extra blank line at the end of your output file.
My question here is how do I rename the file that the user entered to have a ".normal" at the end of it? I was thinking along the lines of having to string names and changing the second string's name and use that as the output file. any examples cause I didn't exactly get that to work.
I need to add thevArr[I] and vArr1[I] and store in vArr2[I] but I cant figure out how to drop the value or replace with a 0 if vArr is bigger than vArr1. IE: 1st number: 123 2nd number: 4567
Ill get something like this: 1 2 3 4 5 6 7 5 7 9 -827349
I have recently bought a copy of "Jumping into C++" and have come to chapter 14 ( dynamic memory location) and have a question.
On page 153-154 an example of dynamic allocation is given for array's of int. How would the code look like for strings or structs ?
The allocation was given by:
Code: int *growArray (int* p_values, int *size) { *size *= 2; int *p_new_values = new int[ *size ]; for ( int i = 0; i < *size; ++i ) { p_new_values[ i ] = p_values[ i ]; } delete [] p_values; return p_new_values; }
Sample Code I tried to use this for an array of structs but failed completely....
I used the following struct Code:
struct user{ int days; string name; };
and the allocation function (which does not work):
Code: struct user *growarray (struct user *p_values, int *size) { *size *= 2; struct user *p_new_values = new struct user[ *size ]; for ( int i = 0; i < *size; ++i )
Say I have a class called Play now I have a constructor called Play(int, char, int); I create Play play=new Play[2]()//default const Now i want to initialise different values of play objects using play(int char int) Whats the syntax? play[i](vale, value value); ? Its not working..
I started to practice some C++. I use to program in C and a little C++. Anyway, I am writing code that creates a dynamic array. I would like to be able to do something like
galaxyobject[object] -> uniqueid = in the class but I do not think I have it setup right.
Question. 1. Is the code correct? 2. Why can't I use the above line without a compile error or segment fault?
int main() { cout << "ProteusCore Server" << endl;
// create a galaxy system with a certain amount of objects galaxy galaxysystem; galaxysystem.IntializeGalaxy(100);
[Code] ....
I made the code available to see on sourceforge as Proteus 3d Game Engine. It is something I would like to work on.
Do I really need to create a separate pointer to point to dynamic arrays?
T* temp = new T[capacity_ * 2]; T* tIter = &temp; //Do these need to be here? T* dIter = &data; //Or can I use *(temp + i) and *(data + i)? (for unsigned int i = 0; i < size_; i++) { *(tIter + i) = *(dIter + i); }
We are supposed to create a menu with an option to add a car (make, model etc) to inventory. I have the structure format set up as far as adding the car, but I am stuck on how to make it a dynamic array of structures or whatnot (I'm not really sure on what I'm trying to do in the first place!) Basically, the user can choose to add a car and its info in. How do you set up the array to add whatever number of cars is needed? Will it be able to add more cars should the user come back to the program later?
This is the instruction of this portion of the project :
Menu Application Add a car to inventory Prompted to add Make, Model and Year, Color, Miles, Price Finish (adds the car to the file) Cancel takes you to the main menu
I'd like to start out by adding an array to a C++ class. I'd like to be able to reference the array using a class object that I create, for example:
Class is Stone.
Stone Bob is an instance of "stone" that I name "Bob".
"Bob.array[1] = "granite";" tells the compiler that the second element in the array (with the first being the zeroth element) is a string containing "granite".
I'll eventually want to extend this to an n x m matrix within the "stone" class that can be referenced as: Bob.matrix[1][3]="lignite";
I tried to make this work using a text again and again last night to no avail. My code is below.
NOTE: Since I am dynamically allocating memory space, I'd like to avoid memory leaks when using this class with dynamically allocated arrays and matrices. Not sure how to do this. Also need some insight into "destructor", and why my simple version reduced to a comment below doesn't seem to please the compiler.
CODE FOLLOWS:
Code: // AINOW.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> using std:: string; using std:: cout; using std:: endl; using std:: cin;
I am currently working on a program that uses a class to store integer arrays. I have most of the code done, but I am having trouble on the main.cpp part of my program. The program should display this:
I need to create subfunctions to do basic Matrix mathematics (addition, subtraction, etc.) I need to be able to pass bot of my Matrices to subfunctions. I started with the addition sub function and I cant get the code to run. I keep getting expected primary-expression before ']' token error for line 75.
#include <iostream> #include <stdio.h> using namespace std;
I have a problem in dealing with dynamic arrays. I have initialized the objects and now i want to print them.
Code: // main char* namesList[] = {"Brad Shaw","Aimen Adams","Sal Dimitry","Cristi Anreaz","Poala James"}; int idList[]={232,444,135,52,134}; Team t1( namesList,idList,5,"waqas"); t1.Print_team(); My class Team looks something like this:
[Code] ....
The print function does not work. I have to implement the print function without taking any parameters.. How should i do that ?