Programming Debugging help.... - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22

Thread: Programming Debugging help....

  1. #16
    Join Date
    Feb 2013
    Posts
    10

    Re: Programming Debugging help....

    Paul, he actually gave the us .exe file where we can't get in to the code for the ip Addresses and showed as a glitch of the algorithm in the class but even after he did I didn't fully get his explanation. We will see what's our next assignment will be, I probably be back to ask for help. Lol.

    2kaud, I apologize for the private message I am fairly new here and I don't know how things work. If I have my choice yes i will ditch this class and take another one.
    Last edited by soccerstr; March 2nd, 2013 at 08:46 AM.

  2. #17
    Join Date
    May 2009
    Posts
    103

    Re: Programming Debugging help....

    I understand peoples feelings in regards to the "content" of this program and it's potential intent... but as is evident by soccerstr's post of his programming assignment... it is not his fault, nor can he control his teacher. Could YOU when YOU were in school? Did YOU have a say in what your teachers taught YOU? Yes he could always change classes... if that is an option for his school, curriculum or educational path. We don't even know what type of school he is in. If it's not a college or prep school, maybe a highschool or something similar... he may have no choice.

    What everyone on CodeGuru as well as other similar types of forums need to remember is that these forums are setup primarily to share advice and help other programmers! People come to these forums, sometimes after doing everything in their power or knowledge to get help to solve their issues. We've all been there in the many years we have been a programmers. We've had issues that we just can't solve on our own. We used the resources at our disposal then and still do. I've been a programmer for too many years and am thoroughly pleased that there are sources like these forums at our disposal now. I wish I had them available when I started that's for sure.

    Of course, everyone is entitled to their own opinions but lets not chase a new member, new programmer away just because we don't necessarily agree with his teacher. At least he's trying to increase his knowledge and get a better career in life. Hell, I've heard of college courses at major colleges that teach you how to write a computer virus so "you can learn how to stop them"... what a bunch of B.S.

    If you don't want to help for your own personal reasons, then just let it go so that his thread doesn't get hijacked and ignored by some people who MAY be willing to help. Then he has to repost to get it back in the "sight" line of others and I am sure someone will then complain that he did that he reposted too. It's just not right.

    Again, please don't forget why these forums exist. My opinion, and I am entitled to that as well as everyone else.

  3. #18
    Join Date
    Feb 2013
    Posts
    10

    Re: Programming Debugging help....

    First and foremost I want to say Thank you very much for all the assistance you guys provided me. I am sorry it took me little longer to respond due to my hectic schedule with school and work. I submitted the homework as a working condition even though not as good as I want it to be.

    I have made my program small enough to read a few lines as well as created a file with small amount of names. Then I change a few things to make my array dynamic then played around with numbers I want to produce.

    The only problem if I could I would like to fix right now is the amount of time it takes to execute. For inquiring mind about my next homework it's sorting through a file that has ip addresses and emails together in one line. Our program should do the sorting on ip address.

    My final updated code is below.

    Best Regards,

    -aK>

    Code:
    /*
    This was written in c++ and it could be run in any visual studio environment.
    It will generate unique email addresses but not random.
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    #include <string>
    
    using namespace std;
    const int siz = 10000000;							//10 million
    
    int main()
    {
    	int e, f, ff, gf, i, j, k, l, m, n, num;
    
        string StrngF;
        string StrngL;
    
        //email addresses to assign u could add more to have a lot of uniqueness
        string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
    
    	char * Init = new char[siz];
    	Init[siz-1] = 9999;													//first initials may b used as a middle initials later on
    
    	string * fstNames = new string[siz];
    	fstNames[siz-1] = 1999;												//list of first names
    
    	string * lstNames = new string[siz];
    	lstNames[siz-1] = 9999;												//list of last names
    
    	string * InitL = new string[siz];
    	InitL[siz-1] = 9999;													//initials taken from last names
    
    	string * emails = new string[siz];
    	emails[siz-1] = 9999;												//email addresses created by last name only
    
        //
        // Give it a name so that you can print out a message.
        // You might want to change the name some day, so
        // define it in one place.
        //
    
        ifstream infilef;													//females first name file
        ifstream infilel;													//last name file
    
        ofstream outdata;                                                   //outdata is like cin
    
        //open the files to be used
        infilef.open ("frstNames.txt");
        infilel.open ("LstName.txt");
    
    	//
        // Give it a name so that you can print out a message.
        // You might want to change the name some day, so
        // define it in one place.
        //
        const char *inFname = "frstNames.txt";
    	const char *inLname = "LstNames.txt";
    
        outdata.open("example2.txt");                                       //opens the file
    
    	//
        // Test to see if it opened.
        //
        if (!infilef)
    	{
            cout << "There was a problem opening "
                 << inFname
                 << " for reading." <<endl;
            return 0;
        }
    
        //
        // Make the program tell you what it is working on.
        //
        cout << "Opened file "
             << inFname
             << " for reading."
             << endl;
    
    	if (!infilel)
    	{
            cout << "There was a problem opening "
                 << inLname
                 << " for reading." <<endl;
            return 0;
        }
    
        //
        // Make the program tell you what it is working on.
        //
        cout << "Opened file "
             << inLname
             << " for reading."
             << endl;
    
    	while(getline(infilef, StrngF))
    	{
            for(f = 0; f < 1999; ++f)
            {
                infilef >> fstNames[f];										//save first names to the array for later use
    		}
        }
    
    	while(getline(infilel, StrngL))
    	{
            for(l = 0; l < 9999; ++l)
    		{
                infilel >> lstNames[l];											//save last names to the array
                InitL[l] = lstNames[l][0];
    		}
        }
    
    	cout <<"Enter the number of email addresses you want to create: (IN MILLIONS) " ;
    	cin >> n;
    	n = n*1000000;
    
    	for(e = 0; e < n; ++e)													//f for first name count ex: fstName[0] = ab
        {
            for(l = 0; l < n; ++l)
            {
    			for(i = 0; i < 5; ++i)											//i for email prvdrs count ex: abcathotmaildotcom
                {
    				if(n <= 0)
    					break;
    				outdata << fstNames[e] + lstNames[l] + adds[i] << endl;
    				n--;
                    if(n <= 0)
    					break;
    				outdata << lstNames[l] + fstNames[e] + adds[i] << endl;
    				n--;
                    if(n <= 0)
    					break;
    				outdata << lstNames[l] + InitL[l] +"_"+fstNames[e] + adds[i] <<endl;
    				n--;
                }
            }//system("pause");
        }
    
    	infilef.close();
    	infilel.close();
    
        outdata.close();
    
    	delete [] Init;
    	delete [] fstNames;
    	delete [] lstNames;
    	delete [] InitL;
    	delete [] emails;
    
    	return 0;
    }
    Quote Originally Posted by pbrama View Post
    I understand peoples feelings in regards to the "content" of this program and it's potential intent... but as is evident by soccerstr's post of his programming assignment... it is not his fault, nor can he control his teacher. Could YOU when YOU were in school? Did YOU have a say in what your teachers taught YOU? Yes he could always change classes... if that is an option for his school, curriculum or educational path. We don't even know what type of school he is in. If it's not a college or prep school, maybe a highschool or something similar... he may have no choice.

    What everyone on CodeGuru as well as other similar types of forums need to remember is that these forums are setup primarily to share advice and help other programmers! People come to these forums, sometimes after doing everything in their power or knowledge to get help to solve their issues. We've all been there in the many years we have been a programmers. We've had issues that we just can't solve on our own. We used the resources at our disposal then and still do. I've been a programmer for too many years and am thoroughly pleased that there are sources like these forums at our disposal now. I wish I had them available when I started that's for sure.

    Of course, everyone is entitled to their own opinions but lets not chase a new member, new programmer away just because we don't necessarily agree with his teacher. At least he's trying to increase his knowledge and get a better career in life. Hell, I've heard of college courses at major colleges that teach you how to write a computer virus so "you can learn how to stop them"... what a bunch of B.S.

    If you don't want to help for your own personal reasons, then just let it go so that his thread doesn't get hijacked and ignored by some people who MAY be willing to help. Then he has to repost to get it back in the "sight" line of others and I am sure someone will then complain that he did that he reposted too. It's just not right.

    Again, please don't forget why these forums exist. My opinion, and I am entitled to that as well as everyone else.
    Last edited by soccerstr; March 2nd, 2013 at 08:42 AM.

  4. #19
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,418

    Re: Programming Debugging help....

    Quote Originally Posted by soccerstr View Post
    My final updated code is below.
    If you'd like that someone could read your "code" you used Code tags instead of the Quote ones.
    So, please, edit your post to either change tags or just remove the code snippet.
    Victor Nijegorodov

  5. #20
    Join Date
    Feb 2013
    Posts
    10

    Re: Programming Debugging help....

    Thank you!!! -aK>

  6. #21
    Join Date
    Apr 1999
    Posts
    27,429

    Re: Programming Debugging help....

    Quote Originally Posted by soccerstr View Post
    The only problem if I could I would like to fix right now is the amount of time it takes to execute.
    Code:
    n = n*1000000;
    for(e = 0; e < n; ++e)													//f for first name count     {
        for(l = 0; l < n; ++l)
    Do the math and calculate how many times the "e" loop will be executed in the worst case scenario.

    Also, please format your code properly. It is all over the place and hard to read.
    Code:
    /*
    This was written in c++ and it could be run in any visual studio environment.
    It will generate unique email addresses but not random.
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    #include <string>
    
    using namespace std;
    const int siz = 10000000;                           //10 million
    
    int main()
    {
        int e, f, ff, gf, i, j, k, l, m, n, num;
    
        string StrngF;
        string StrngL;
    
        //email addresses to assign u could add more to have a lot of uniqueness
        string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
    
        char * Init = new char[siz];
        Init[siz-1] = 9999;                                                 //first initials may b used as a middle initials later on
    
        string * fstNames = new string[siz];
        fstNames[siz-1] = 1999;                                             //list of first names
    
        string * lstNames = new string[siz];
        lstNames[siz-1] = 9999;                                             //list of last names
    
        string * InitL = new string[siz];
        InitL[siz-1] = 9999;                                                    //initials taken from last names
    
        string * emails = new string[siz];
        emails[siz-1] = 9999;                                               //email addresses created by last name only
    
        //
        // Give it a name so that you can print out a message.
        // You might want to change the name some day, so
        // define it in one place.
        //
    
        ifstream infilef;                                                   //females first name file
        ifstream infilel;                                                   //last name file
    
        ofstream outdata;                                                   //outdata is like cin
    
        //open the files to be used
        infilef.open ("frstNames.txt");
        infilel.open ("LstName.txt");
    
        //
        // Give it a name so that you can print out a message.
        // You might want to change the name some day, so
        // define it in one place.
        //
        const char *inFname = "frstNames.txt";
        const char *inLname = "LstNames.txt";
    
        outdata.open("example2.txt");                                       //opens the file
    
        //
        // Test to see if it opened.
        //
        if (!infilef)
        {
            cout << "There was a problem opening "
            << inFname
            << " for reading." <<endl;
            return 0;
        }
    
        //
        // Make the program tell you what it is working on.
        //
        cout << "Opened file "
        << inFname
        << " for reading."
        << endl;
    
        if (!infilel)
        {
            cout << "There was a problem opening "
            << inLname
            << " for reading." <<endl;
            return 0;
        }
    
        //
        // Make the program tell you what it is working on.
        //
        cout << "Opened file "
        << inLname
        << " for reading."
        << endl;
    
        while (getline(infilef, StrngF))
        {
            for (f = 0; f < 1999; ++f)
            {
                infilef >> fstNames[f];                                     //save first names to the array for later use
            }
        }
    
        while (getline(infilel, StrngL))
        {
            for (l = 0; l < 9999; ++l)
            {
                infilel >> lstNames[l];                                         //save last names to the array
                InitL[l] = lstNames[l][0];
            }
        }
    
        cout <<"Enter the number of email addresses you want to create: (IN MILLIONS) " ;
        cin >> n;
        n = n*1000000;
    
        for (e = 0; e < n; ++e)                                                  //f for first name count ex: fstName[0] = ab
        {
            for (l = 0; l < n; ++l)
            {
                for (i = 0; i < 5; ++i)                                          //i for email prvdrs count ex: abcathotmaildotcom
                {
                    if (n <= 0)
                        break;
                    outdata << fstNames[e] + lstNames[l] + adds[i] << endl;
                    n--;
                    if (n <= 0)
                        break;
                    outdata << lstNames[l] + fstNames[e] + adds[i] << endl;
                    n--;
                    if (n <= 0)
                        break;
                    outdata << lstNames[l] + InitL[l] +"_"+fstNames[e] + adds[i] <<endl;
                    n--;
                }
            }//system("pause");
        }
    
        infilef.close();
        infilel.close();
    
        outdata.close();
    
        delete [] Init;
        delete [] fstNames;
        delete [] lstNames;
        delete [] InitL;
        delete [] emails;
    
        return 0;
    }
    Code:
    n--;
    Why are you subtracting from n inside the loop, and at the same time relying on "n" to control your for() loops?
    Code:
    if (n <= 0)
         break;
    What's the reason for doing this, on top of subtracting from n? If you want to loop n times, then loop n times. Adjusting the looping criteria while in the middle of the loop itself is not only confusing, you probably are looping less times than you're supposed to.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; March 2nd, 2013 at 11:28 AM.

  7. #22
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,453

    Re: Programming Debugging help....

    Why are you opening the files using string constants then defining c strings after?

    Code:
    infilef.open ("frstNames.txt");
    infilel.open ("LstName.txt");
    
     //
     // Give it a name so that you can print out a message.
     // You might want to change the name some day, so
     // define it in one place.
     //
     const char *inFname = "frstNames.txt";
     const char *inLname = "LstNames.txt";
    You are defining Init to be an array of char (max value 255 for unsigned char) but then try to assign 9999 to an element?

    Code:
    char	*Init = new char[siz];
        Init[siz - 1] = 9999;
    Also, you are defining string arrays then try to set an element to a number!

    Code:
    string	*fstNames = new string[siz];
        fstNames[siz - 1] = 1999;
    Code:
    for (i = 0; i < 5; ++i) {		//i for email prvdrs count ex: abcathotmaildotcom
    i is used to index the adds string array. This assumes they will always be 5 elements in the array. What hapens if more names are added to the array - or some removed?

    You are defining the maximum number emails generated as 10 million. But what happens if the user enters say 20 to generate 20 million addresses? You could first ask for the number and then allocate the arrays as needed.

    Code:
    cout << "Enter the number of email addresses you want to create: (IN MILLIONS) " ;
    cin >> n;
    n *= 1000000;
    
    char	*Init = new char[n];
    //etc etc

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center