Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

of course its not necessary to use classes or structures. fstream can and frequently does work with POD (plain old data) types.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thread closed.

jasimp commented: Good idea +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. Learn to format the code better so that you and others can more easily read/understand it. Don't be afraid to make liberal use of spaces and tabs. Aligh each { with matching } and don't put the all at the same place.

2. Recognize repeating code and try to rearrange so that it doesn't repeat. For example if (x*y %10 == 2 || x*y %10 == 3 ||x*y %10 == 5 ||x*y %10 == 7 ) Here you are multiplying x and y four times which takes up a lot of processing time because multiplication and division are pretty expensive. A more efficient way to write that line is:

long n = (x * y) % 10;
switch(x)
{
   case 2: case 3: case 5: case 7: 
      // do something
}

Use of the switch above might be just personal programming style and the if statement would probably work just as well. The main thing is to remove as much repeating code as possible.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ok this may be a dumb question on line 22 i have 'case 1:' now right now i have a cout statement but it doesn't do anything so is it not possible to go from my menu back in to case 1 and then have it do a cout statement or an if statement?

First, the cout for case 1 is incorrect because the value of i is greater than the number of elements in the array. Otherwise it works ok for me, except you need to output the "\n" after the number so that the menu doesn't get screwed up again. cout << num[0] << "\n";

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look at line 18: That is an infinite loop. Delete it and your program won't loop back.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Let me know if you see anything I'm doing wrong!
If you test it then you will see for yourself if you did anything wrong. You don't need to wait for us to be your eyes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use getline() to read each line of the file then a loop to iterate through the string

std::string line;
while( getline( infile, line ) )
{
    // make changes not shown
    //
    outfile << line << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have no idea because you have not poste the program requirements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

okay i dont know if that makes sense but whats supposed to happen is it goes through the loops, and when the function is called it is supposed to print out a value from the array that corresponds to the index value generated by the random number sequence. how can i get it to do that?

Change the parameter of the function to a single int then pass the value you want it to play

void playRandomSong (int);

<snip>
            playRandomSong(songID[randomNum]);

<snip>
void playRandomSong (int songID);
{

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 30: attempting to write out-of-bounds of the array. You probably meant to index via randomNum.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 10: That function doesn't take any parameters. It should be identical to line 48 but with a semicolon at the end.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If the file is empty that means its length is 0. You can verify it when Windows Explorer. The GetLength() function is what you want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It might have been better if you would speed it up a bit -- seems to be too long and I almost lost interest. But the final drawing was worth the wait.

BTW: I can't draw a straight line with a ruler :) I'm envouis of your talent.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Write the program just a little bit at a time so that you don't get overwhelmed by the length of the assignment.

First, create a structure with the required members. The assignment doesn't say anything about their data types but I'd assume they are character arrays.

When you get that done and it compiles without error then post what you have done and move on to the next step.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Can you do this at all
Sortof. What you do is write a public Initialize() method for class A so that it can be called by the class constructor as well as by anyone else.

class A
{
private:
    int x;
public:
    A() { Initialize(); }
    A(int w) {x = w;}
    Initialize() { x = 0; }
};

int main()
{
    A a(3);
    a.Initialize();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are writing an MFC program so surly by now you have learned to read the MSDN docs for each of the MFC functions you use. You do know about that don't you ?

Read this and you will find the function you are looking for.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Nobody is going to do your homework for you without pay. Put $1,000.00 USD in my paypal account and I'll write it for you.

Otherise, post what you have done and we'll go from there.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ancient Dragon, did you think you might have some ideas about dealing with this problem?

Since I have not seen their programming guid I have no ideas. Did you talk to one of their programmers or just to one of their know-nothing help support people? If their programmers can not help you then maybe what you want to do can't be done their their printers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The Beer Song. This is a scene from a game.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

OMG Narue, why did you make that soooo difficult ?? I think you outdid yourself on this one:) See my post if you missed it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 49: for your own sanity and the benefit of others who must read and understand your program put those } braces on separate lines and in line with the opening {. Don't be afraid to make liberal use of white space in your code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is the parameter like a refrence to another function
Yes -- it is a pointer to another function. The function can be either a normal global function or a static method of a class and must take parameters as prototyped in that line.

example:

void foo(Type** resource, char*name, char*path)
{
   // do something
}

main()
{
     ResourceManager( foo );

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 44: you can't enter two values without spaces like that. Here is a suggested alternate way to do that: Get the 2 characters as a string then split them apart. See this thread for explaination of the cin.ignore() line

#include <limits>
...
<snip>
      x_char = 0;
      y = 0;
      string input;
      cin >> input;
      cin.ignore ( std::numeric_limits<std::streamsize>::max(), cin.widen ( '\n' ) );
      if( input.length() == 2)
      {
        x_char = input[0];
        if(!isdigit(input[1]) )
        {
            cout << "Error -- second character must be a digit 1-9\n";
            cin.get();
        }
        else
            y = input[1] - '0';
      }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>what can i do with c++????
You can use vector instead of arrays.

line 5: should be <string> to get std::string class

line 24: use int main()

line 129: you need to make that function return a value if the loop never finds what it is looking for.

Spell out the words in the instructions -- don't use chatroom speak, which make your program look childish.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int main()
{
    string str = "0x0002,A5651QPR87GBZ094RTF52,D,A,000001,ABC ,10000.00 , EOT";
    string word;
    stringstream stream(str);
    while( getline(stream, word, ',') )
        cout << word << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Great Job :) Now please come and paint my house.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 11: you don't do it like that. use single quotes to compare characters if (str[x] == 'a') [edit]^^^ like he said[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So... That's what he asked for right? Or did I read it wrong?

All the above. Not sure exactly what he wanted

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Darn, I knew I read that quote somewhere, but it was in this very thread.. Sorry for being a copy-cat :P

No problem -- some people expects us to be psychics. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

getcwd() will return the full path to the current folder. Or ".\\myfile.txt" or "./myfile.txt"

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Let me look into my Crystal Ball and see what's wrong...

Ohh so now I know where I left mine :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 1: you have to include <string> header file in order to use std::string class.

line 11: you still have the wrong operator -- should be ==, not =. Remember that = is an assignment operator while == is boolean.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 9. When comparing two strings you have to use the == boolean operator for equality, not the = assignment operator. And the literal string must be in double, not single quotes if( word == "word1") line 10: The comparison on line 9 does not check for word length so the comment on line 10 is meaningless. On line 9 you probably need to check for the length of the string instead of comparing two strings. Like this: if( word.length() > 5) You have to change lines 11 and 13 similar to above.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post what you have done so far to solve this problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know the answer to your question but there's got to be a much simplier way to code that switch statement. What are you going to do if someone wants to be a level 255? Lets see -- 20 lines of code for level 2 I guess will mean over 5,000 lines of code for level 255. Not a very efficient program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I keep getting the error of form1 not identify. Why is it so?
Could be thousands of reasons, but most likely you failed to include the header file in the *.cpp file. Or to declare form1 somewhere.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've seen this identical problem just a day or so ago.

Nice you posted your homework problem, now what is it that you expect from us? I don't have my crystle ball at the moment so I can't read your mind.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>so i need a simple coding for comparison
There aitn't no such animal.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

fgets() appends the '\n' to the end of the string, so you have to truncate it before you can use fname to open the file

fgets(fname ...);
if( fname[strlen(fname)-1] == '\n')
    fname[strlen(fname)-1] = 0;

line 36: The answer to your question can be done a couple ways. I would prefer strtok() to extract the words from the line read.

char* word;
word = strtok(line," "); // assume columns are separated by space
while( word != NULL)
{
   // do something with this word
   //
   //
   word = strtok(NULL, " "); // get next word
}

Another way is to use a pointer and iterate through the string.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Didn't you read this ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb Tony., Hope to see you around.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You sound like an accident waiting to happen. Go to bed and stay there for a week or two. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I know that compiler does not support MFC but you might browse www.codeproject.com because they probably have an mfc combo box class that does something like that and will give you ideas how to do it with win32 api functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you will have to do that in several lines.
popen()
getcwd()

#include <stdio.h>

int main()
{
    char path[255] = {0};
    char command[320] = {0};
    strcpy(path, getcwd());
    strcpy(command, "explorer.exe ");
    strcat(command, path);
    
    FILE* fp = popen( command, "r" );
    // now read from the file pointer just as you would from any other file
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A structure is nothing more than a collection of items about a common topic. For example: If you want to know about students then you could write a student struct

struct student
{
    char name[40]; // student's name
    int ags;  // student's age
    char address[80]; 
    char city[40];
    char state[3];
    char zipcode[10];
};

That's all structures are -- they are a collection of attributes about something. Structures can contain other structures as well. For example

struct programming101
{
    struct student[100]; // 100 students for this course
    // other attributes may go here
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ha, just got an infraction should have known better then to hit people with a gaypenis swinging site. Anyways I figured it might be cool to see if anyone else has gotten an infraction and what for. So if you've gotten one tell me how.

SW

You are lucky I was in a good mood -- should have been a much harsher Keep It Legal infraction. Never ever at any time should you post porn here at DaniWeb because that is a sure way to get banned.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

are the user names and passwords in two different files ??? Normally they would be in the same file and on the same line. such as troula mypassword

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So is Visual Studio -- Mobile 5.0 operating system. But you mean smartphones like on our cell phones. Don't know a thing about that.