hag++ 24 Junior Poster

ok, base isn't a method, and I'm smart enough to know that!

so, here's the definition:

class cmd
{
string base;
char extension[80];
};

yes, that's really all there is, it's just a way for me to organize the commands.

Wooah don't get sassy or nobody will help you. You need to declare the member variables as public if you are going to access them directly (Instead of using getter, setter methods).

jonsca commented: Yes, I totally flew past that +7
hag++ 24 Junior Poster

where does "seed" come from? and where do I use "regenerate". Do I need to change the main function? Gah, I felt like I was starting to understand earlier, but now I feel even more confused.

Wooah take a breath real quick haha. When you call srand() you need to pass it a "seed" to generate the random number. Typically you pass it the time() function with null as the argument to time():

srand(time(NULL));

You should be getting a complier error because the default constructor no longer exists. You declared your own constructor and it HAS to take one argument when you declare it. This will not work anymore:

GuessingGame game;  // ERROR: the constructor needs one argument of type int

When you create a new object you want to pass the seed to the constructor:

// Declare a new GuessingGame object
GuessingGame game(time(NULL));  // Pass time() function here

You would then want to call the regenerate() method on your object ( in main() ):

game.regenerate();
hag++ 24 Junior Poster

Er, yes you can. See the example that I just gave. The constructor gets called when you create the variable, but other than that, you can do most things with it that you can do with any other member function.

I think you misunderstood my post. The OP says he wants to reference the member variable by calling the constructor (i.e get the value of the variable). You cannot do that (The constructor cannot have a return type). In order to reference a member variable you need to create a method to return the value.

hag++ 24 Junior Poster

This constructor needs to be used to reference the random number.

This doesn't make sense. Constructors are called on the initial creation of the object. You can't "call" the constructor to have it perform a function (That is what the class's methods are for) In order to get the random number in the object, create a method that returns the variable. Something like this:

class GuessingGame
{
   int m_RanNum;  // To hold the random number

   public:

   // Insert code for the constructor and other methods here

   int getRandomNum()
   { return m_RanNum; }
};
hag++ 24 Junior Poster

Can you post more of your code? There is really not enough here to troubleshoot your issue. Also, when exactly do you get the assertion failure? After you type some characters and press [ENTER]? Before that?

hag++ 24 Junior Poster

Good luck trying to learn the Win32 API using a resource like the MSDN. MSDN should never be used as a learning tool, only as a reference. If you want to learn the Win 32 API I would start off with this book:

http://www.amazon.com/Programming-Windows-Microsoft-Charles-Petzold/dp/157231995X/ref=sr_1_5?ie=UTF8&qid=1298592783&sr=8-5

hag++ 24 Junior Poster

What API are you using? Win32? MFC? CLI?

hag++ 24 Junior Poster

Seems like people trying to learn programming get lazier and lazier every day....

hag++ 24 Junior Poster

Like this:

DialogBox(hInst,
          MAKEINTRESOURCE(IDD_DLGINTRESOURCENAME),
          hWnd,
          reinterpret_cast<DLGPROC>(nameOfDlgMessageHandlerProc));
hag++ 24 Junior Poster

ok so i have this program here i had to finish, and it was for input and output files, i wrote everything, and even wrote the data.in and data.out files but when i run it i get nothing in return. do the files have to be in the ".in" format cause when i save them, in notepad its data.in.txt

the only thing that was in data.in were four float values
but it returns blank, why? please help.

#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
	float val1, val2, val3, val4;  //declares 4 variables
	ifstream inData;              // declares input stream
	ofstream outData;            // declares output stream

	outData << fixed << showpoint;

	inData.open("data.in");
	outData.open("data.out");

	inData >> val1 >> val2 >> val3 >> val4;
	outData << val1 << endl;
	outData << val2 << endl;
	outData << val3 << endl;
	outData << val4 << endl;

	inData.close();
	outData.close();

	system("pause");
	return 0;
}

If the name of the file in windows is data.in.txt then you have to specify that name in the constructor for your ifstream object. So it should look like this instead:

inData.open("data.in.txt");

Also when opening files ALWAYS check to make sure they are open (i.e make sure you have received a valid file handle). Here are two examples:

// This uses the fstream method is_open() to make sure you have a valid file handle
if( inData.is_open() ) {/* Do something*/ }

// This example exits the program if there is no valid file handle …
hag++ 24 Junior Poster

What error are you getting?

hag++ 24 Junior Poster

Another question I have is why are you modding constants? 7 % 10 is always going to be 7 so why not just put 7?

hag++ 24 Junior Poster

Dear god people this guy is a troll.... T-R-O-L-L..... like was said before the reason he is banned from the other sites is because they dont want him around. I have seen other threads by him and the whole time it is just the OP acting stupid. The reason he keeps going is because people acknowledge him.

hag++ 24 Junior Poster

You need to get rid of the semi colon after the function header

void write_output_data(void)

Otherwise the compiler thinks it's a function declaration.

This^^^

Also,

void func_name(void)

is a valid c\c++ construct.

hag++ 24 Junior Poster

What values are you entering when running the program?

hag++ 24 Junior Poster

This

RParallel( input[5] );             // calls the funtion

should be this instead

RParallel( input );             // calls the funtion

When you are passing arrays as arguments to a function you only pass the name. The reason for the linker error is when you pass input[4] (Or whatever array subscript you want) you are now passing a variable of type double, not double[]

hag++ 24 Junior Poster

No he means not agree because of the following line:

cin >> input[1] >> input[2] >> input[3] >> input[4] >> input[5];

This is saying that the array has up to 6 elements but it is defined as int input[5]. This means that calling input[5] will cause the program to crash because it is outside the bounds of the array. It should be this:

cin >> input[0] >> input[1] >> input[2] >> input[3] >> input[4];

Also, using this

int something;
   cin>>something;

is dangerous because if the user enters a character instead of an int the program will freak out.

hag++ 24 Junior Poster

I am not sure how far along you are but this is a great example of when to use polymorphism. If you think about it, Spades, hearts, diamonds and clubs are all cards so why not make a base class Card and then child classes for the different suits.

Ex.

class Card
{
   //Insert code and methods for base class
   // Should be methods and attributes that can apply to all suits
};

class Spade : public Card
{
   // Insert methods and attributes specific to the spade suit
};

// Do that for the three other suits

// When you need to declare them
Card *hearts[13];
Card *diamonds[13];
Card *spades[13];
Card *clubs[13];

// In your for loop
spades[index] = new Spade();

// Do that for all suits
hag++ 24 Junior Poster

This is exactly why I think a screening process should be put into place before we let people post/ make new threads on DW :/

hag++ 24 Junior Poster

Hello,

Can anyone suggest a GUI library that meets the following criteria?

* Cross-Platform
* Doesn't control the main loop
* Not 100% object-oriented; similar to Xlib :)
* Not many pointers please (like FLTK that every object is a pointer)
* Free to use for closed source and open source software
* Lightweight

Thanks!

A solid GUI library that doesn't use pointers and isn't OOP? You're in trouble lol Like other people said just learn OOP and hone your pointer skills.

hag++ 24 Junior Poster

well it cant end... its an antivirus... it stays running on the system

Like WaltP said, the system call waits for the AvastUI.exe program to return. The rest of your program won't run until the system call returns.

hag++ 24 Junior Poster
while ( grade != '\n' )

Isn't grade an int or double?? This will never work unless its a character array or string.

hag++ 24 Junior Poster

Do some research on the getline() function. It is in the iostream library. It has an overloaded form that accepts a third argument which is the delimiting character.

hag++ 24 Junior Poster

I'm not really sure what your trying to accomplish here. Your for loop is incorrect because what if the file doesn't contain 81 characters? What if the file has a string with more than 81 characters? When checking for an EOF, consider looping through with a while statement like

while(!inFile.eof())

. Now as far as your code logic is concerned, why are you returning the count of characters? A string object has a built in method to tell you how big the string is. I know that you cannot change the function prototypes so I would think (Hopefully, as long as your teacher is worthy of teaching) would want the int returned to tell your program whether the function call was successful or not.

hag++ 24 Junior Poster

Bump

WaltP commented: Never BUMP your threads. We'll get to them when we getr to them. -3
hag++ 24 Junior Poster

cipherText was not declared in main(). When I compiled this I had to add

string cipherText;

to main(). Your encryption and decryption functions are going to need some work because saying something like cipherText - key is not going to remove the int from the end of the string (If that is what you're trying to do.

hag++ 24 Junior Poster

gerard4143 is mistaken -- the semicolon is correct in this context.

However, I can see three potential problems and I can't tell from the code you've posted whether they're relevant:

1) What types do j and k have? If they are unsigned, then j-1 and k-1 will never be < 0.

2) Is it possible that j and k may have values that are too large? You don't seem to be checking for that.

3) Are you sure that every element of tileMap has an appropriate value?

1) j and k are of type int (signed)

2) I do check for values that are too large when for example I am checking the tiles to the right of the current one (ex. if (j + 1 > 2); <<-- this checks for array out of bounds exception that extends past the end of the array)

3) Every element in the array is properly initialized but the reason I check with the if/else statements is to make sure that when I am checking the tiles around the current tile that it does not exceed the bounds of the array.

The problem is that even when if(j - 1 < 0) is TRUE the code in the else block causes the error. I know that it would cause an error to run that code because the if() statement that checks to make sure I don't exceed the bounds of the array is true. The else block should not even …

hag++ 24 Junior Poster

When you say "only seems to run once then does nothing." do you mean the program hangs or crashes or it only goes through one iteration and then exits?

hag++ 24 Junior Poster

Hi All,

I am writing an MFC Tic Tac Toe app and I am getting a strange error when debugging it. This module loads a bunch of BOOL variables to keep track of whether or not the tile next to it matches (i.e is the tile next to me also an 'X' tile or is it an 'O' tile). The problem I'm having is that the if() statement checks to make sure that the tile that I am currently checking is not out of bounds (off the board). Here is an example:

if (k - 1 < 0 || j - 1 < 0);
else
{
	if (tileMap[k][j]->GetTileType() == tileMap[k - 1][j - 1]->GetTileType() &&
		tileMap[k][j]->GetTileType() != -1)
		tileMap[k][j]->ulCorner = TRUE;
}

Just to let you know tileMap is of type

CTile *tileMap[3][3]

(CTile is inherited from CBitmapButton, it is a 2D array of pointers to store the tiles) Also, the if statement just ends in a semicolon because if that is true I just want the else block skipped completely and to move onto the next segment. So if k - 1 or j - 1 < 0 this means that it is off the board and the else statement should not execute because it would be an array out of bounds exception. So if the if() statement is true the else block should not excecute at all because k-1 or j-1 would be out of the array. When running the debugger and I get to …

hag++ 24 Junior Poster

You need to make the lList class inherit from the Node class if you want to access the protected members in Node from lList.

class lList : public Node
{
   // Insert code for class
}
hag++ 24 Junior Poster

One way of doing it would be to use a 2 dimensional array of strings. For example:

// Array that will hold 10 different lyrics, up to 20 words per set
string lyrics[10][20];

Now say that song number 4 is chosen and you want to randomize which word is blanked out.

// This variable will hold the randomly generated index
int randIndex = rand() % 20;  // 0 - 19

// Add code here to use the random index to replace that word with an empty string in your output
hag++ 24 Junior Poster

Well first, you are going to want to modify your add_record function. It is better practice to do most of your cout's and cin's in main (or in this case you can also do them in menu() ) and pass the arguments to the function to add them to the list. If you do it this way, you can also use the add_record function in a while loop to import the records from your file.

hag++ 24 Junior Poster

In the parameter list for your function prototypes and definition you need to declare the parameter as accepting an array of that struct type. Example:

void showMenu(airplane arr[], int numberOfTickets);

When passing arguments to that function, only pass the name of the instance of your airplane struct. Example:

showMenu(tickets, numOfTickets);
hag++ 24 Junior Poster

You cant get the file to open? Does the file exist in your project directory? Also, in lines 37 and 38 you do:

if (i % 2 == 0) evenSum += i;
if (i % 2 > 0) oddSum += i;

You have never initialized i with a value. This will produce a logical error.

hag++ 24 Junior Poster

The other possibility is that the prof wants one object to hold the data about the rectangle and another object that can perform operations on it.

EX.

class Rect
{
   double len, wid;

   public:

   Rect(double l, double w) : len(l), wid(w) {}
   double getW() {return wid;}
   double getL() {return len;}
}

class Area
{
   static double getArea(const Rect &rect)
   {
      return rect.getW() * rect.getL();
   }
}
hag++ 24 Junior Poster

Explaining how file streams work in detail is not going to be something that anybody here really wants to do. What you should do is study up on file IO (Using your book, interwebs etc.), write some test code and post it with any questions/ problems.

hag++ 24 Junior Poster

Whats the compiler error that your getting?

hag++ 24 Junior Poster

I have a feeling this "skeleton code" was the code given to you by the teacher. This isn't a finish your homework for you club.

hag++ 24 Junior Poster

Keep in mind that different compilers may not interpret your code the same way. You may have to modify it. Can you post the code that you have?

hag++ 24 Junior Poster

Could you post the code? Have you done any debugging?

hag++ 24 Junior Poster

istream has a method called seekp(). This will allow you to "jump" around the file. For example, you can read from the file then, for searching purposes, set the file pointer back to the beginning of the file and search again. You can also set the pointer to stay at the current position and go to the eof.

hag++ 24 Junior Poster

Keep in mind that windows Vista and 7 have much more memory read/ write protection than XP did. Try right clicking on your executable file in Vista/ 7 and choosing 'Run as Administrator'.

hag++ 24 Junior Poster

My question was more like, how does Windows work?

WTF?? This question is going to take a lot longer to answer than you think lol

The intent behind my program is to replace all the functionality of the mouse with key presses. It will not have a graphical component. It will be a keyboard mouse.

My understanding is that the Windows Proc function of my program will have to hook the appropriate messages from the keyboard and replace them with mouse event messages.

If your program isn't going to be graphical then why are you programming with the Win32 API?

hag++ 24 Junior Poster

Unless you have to constantly read/write from the file as a requirement for the project, I wouldn't do that. I would load all the data (Since these files are not large) into a data structure of your choice (Anything from a simple array of structures to a linked list, binary tree etc.). After you have loaded the data, you can search everything in memory which is much fast and usually easier.

hag++ 24 Junior Poster

Yea your approach is definitely a little off so far. Do you want your program to count how many times a letter (that you specify) appears in a certain string? For example: How many times does the character 'p' appear in the string "apples"? And you want your class to return 2? If so, you should either make the constructor accept the search character and the string to be searched or make a method that accepts those as parameters and returns the count or a negative number if it is not found, for example.

hag++ 24 Junior Poster

Something simple like this??

const int SIZE = 10 // Or whatever size you want the array to be
int array[SIZE];
ofstream oFile("c:\\someDirectory");

// Load Array
for (int i = 0; i < SIZE; i++)
   array[i] = i;

// Output to file
for (i = 0; i < SIZE; i++)
   oFile << array[i] << endl;
oFile.close();

// Call other program to read from the file you just created
hag++ 24 Junior Poster

As for your other questions...

once I strcopy into the new array, do I append to place the space between the parts?

Personally, because you are using char arrays instead of string objects, I would append a space to the end of fName before you concatenate. If you were using strings it would be a little easier.

Do I use strlen before to make sure that the new array will be large enough to hold the copied parts?

Yes, always perform bounds checking. something like:

name = new char[strlen(fName) + strlen(lName) + 1] // Extra 1 is for null terminator
hag++ 24 Junior Poster
name = new char[n];

You are allocating memory for a new char array but you are using a variable with data type char for the size declaration. n is a char type and should not be used to declare the size of the array and it is never initialized or given a value.

hag++ 24 Junior Poster

Removed**

Said something stupid :/

hag++ 24 Junior Poster

Just by looking at the questions you are asking, I can tell you are not ready for this type of programming.