Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
E

ericelysia

@ericelysia
About
Posts
14
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Trying to pass an array
    E ericelysia

    I am having some difficulty passing an array. If someone can shed some light here, I would appreciate it greatly.

    to testCaseArray1[ ] int guessCount1 = 0; char choice1 = myChar; bool correctAnswer1 = myBool;

    C / C++ / MFC data-structures

  • Question about recursion
    E ericelysia

    OK, thanks to all of the great feedback, I have a better understanding about recursion. I am now attempting to apply it and I have come across a problem that I can't seem to pinpoint. I have written the "eight queens" program, but for some reason, I get an infinite loop. I think my base case is ok. Can someone help me figure out what I am doing wrong here? Thanks in advance, Eric #include using namespace std; const int BOARD_SIZE = 8; // function prototypes void fillBoard( int [], int, int ); bool noConflict( int [], int, int ); void printBoard( int [], int ); //-------------------------------------------------------------- // main method int main() { int chessboard[ BOARD_SIZE ]; // represents a chessboard with 8 rows (0-7) int column = 0; int count = 0; // keeps track of the count fillBoard( chessboard, column, count ); // invokes fillBoard function to start filling the chessboard return 0; // indicates sucessful termination } // end main method //-------------------------------------------------------------- // fillBoard method void fillBoard( int board[ BOARD_SIZE ], int c, int cnt ) { for( int r = 0; r <= 7; r ++ ) // for every row on the board { board[ c ] = r; // assign the value of row to the column if( noConflict( board, r, c ) ) // if there is not a conflicting queen { if( c == 7 ) // if it is the last column { printBoard( board, cnt); // output the board } else { fillBoard( board, c + 1, cnt ); // else recursively invoke fillBoard for the next column } } } } // end fillBoard method //-------------------------------------------------------------- // noConflict method bool noConflict( int board[ BOARD_SIZE ], int r, int c ) { for( int col = c - 1; col >= 0; col-- ) // for each column on the board { if( board[ col ] == r // checks horizontally to the left || board[ col ] == r + c - col // checks diagonally moving down and to the left || board[ col ] == r + col - c ) // checks diagonally moving up and to the left { return false; // there is a conflict } else { return true; // there is not a conflict } } return true; // there is not a conflict } // end noConflict method //------------------------------------------------------------- // printBoard method void printBoard( int board [ BOARD_SIZE ], int cnt ) { cout << "Count = " << ++cnt << endl; // output the count for( int r

    C / C++ / MFC tutorial question

  • Question about recursion
    E ericelysia

    OK, I still don't get it. I changed the code a little to make the invocations easier to see. #include #include using namespace std; unsigned long factorial( unsigned long ); // function prototype //------------------------------------------------------------------------- int count = 0; int main() { // Loop 2 times. During each iteration, calculate factorial( i ) and display result. for ( int i = 0; i <= 2; i++ ) { cout << "\n i = " << i << endl; cout << endl << setw( 2 ) << i << "! = " << factorial( i ) << endl; cout << endl << "--------------------------------------------" << endl; } return 0; // indicates successful termination } // end main //------------------------------------------------------------------------- // recursive definition of function factorial unsigned long factorial( unsigned long number ) { count++; cout << endl << "factorial was invoked for the " << count << " time " << " number = " << number << endl; // base case if ( number <= 1 ) { cout << endl << "number <= 1" << endl; return 1; } // recursive step else { cout << endl << "number = " << number << " factorial(number - 1) = " << factorial(number - 1) << " " << number << " * " << factorial( number - 1 ) << " = " << number * factorial( number - 1 ) << endl; return number * factorial( number - 1 ); } } // end function factorial //------------------------------------------------------------------------- OUTPUT: i = 0 factorial was invoked for the 1 time number = 0 number <= 1 0! = 1 -------------------------------------------- i = 1 factorial was invoked for the 2 time number = 1 number <= 1 1! = 1 -------------------------------------------- i = 2 factorial was invoked for the 3 time number = 2 factorial was invoked for the 4 time number = 1 number <= 1 factorial was invoked for the 5 time number = 1 number <= 1 factorial was invoked for the 6 time number = 1 number <= 1 number = 2 factorial(number - 1) = 1 2 * 1 = 2 factorial was invoked for the 7 time number = 1 number <= 1 2! = 2 -------------------------------------------- Press any key to continue */ Please walk me through the following: i = 2 factorial was invoked for the 3 time number = 2 factorial was invoked for th

    C / C++ / MFC tutorial question

  • Question about recursion
    E ericelysia

    Hasn't the output already been sent to cout? The program already output 2! = 2 and i = 3. At the point in the program where i = 3 is output, doesn't that signify the beginning of a new iteration? Thanks, Eric

    C / C++ / MFC tutorial question

  • Question about recursion
    E ericelysia

    Hello, I am trying to understand recursion by using the following example. #include #include using namespace std; unsigned long factorial( unsigned long ); // function prototype //------------------------------------------------------------------------- int main() { // Loop 4 times. During each iteration, calculate factorial( i ) and display result. for ( int i = 0; i <= 4; i++ ) { cout << "\n i = " << i << endl; cout << endl << setw( 2 ) << i << "! = " << factorial( i ) << endl; } return 0; // indicates successful termination } // end main //------------------------------------------------------------------------- // recursive definition of function factorial unsigned long factorial( unsigned long number ) { // base case if ( number <= 1 ) { return 1; } // recursive step else { cout << endl << "number = " << number << " factorial(number - 1) = " << factorial(number - 1) << " number * factorial(number - 1) = " << number * factorial( number - 1 ) << endl; return number * factorial( number - 1 ); } } // end function factorial //------------------------------------------------------------------------- /* output: i = 0 0! = 1 i = 1 1! = 1 i = 2 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 2! = 2 i = 3 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 3 factorial(number - 1) = 2 number * factorial(number - 1) = 6 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 3! = 6 i = 4 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 3 factorial(number - 1) = 2 number * factorial(number - 1) = 6 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 3 factorial(number - 1) = 2 number * factorial(number - 1) = 6 number = 2 factorial(number - 1) = 1 number * factorial(number - 1) = 2 number = 4 factorial(number - 1) = 6 number * factorial(number - 1) = 24 number = 2 factorial(number - 1) =

    C / C++ / MFC tutorial question

  • Googolplex Program
    E ericelysia

    Thank you for your time. Eric

    C / C++ / MFC c++ performance help question

  • Googolplex Program
    E ericelysia

    OK, thank you. I did not know that. That's what I will do. I would also like to be able to understand the code. Is the C version of this program much different from the C++ version? Eric

    C / C++ / MFC c++ performance help question

  • Googolplex Program
    E ericelysia

    I just want her to see all of the zeros going and going and going. Is that what that C code is doing (100 ^ 10 ^ 100) ? If so, why does it look more complex? Thanks, Eric

    C / C++ / MFC c++ performance help question

  • Googolplex Program
    E ericelysia

    Hello, I found this program online. I think it might be written in C. Can someone convert this to Visual C++ for me? I would like to show my wife that she cannot visualize what a googolplex is. Thanks, Eric #include #include int main (int argc, char *argv[]) { int *vals, *ptr, max; if (argc == 2) max = atoi (argv[1]); else max = 100; printf ("1"); if ((vals = malloc ((max + 1) * sizeof (int))) == NULL) { fprintf (stderr, "Error allocating memory.\n"); return 1; } memset (vals, '\0', (max + 1) * sizeof (int)); while (!vals[max]) { *(ptr = vals) += 1; while (*ptr == 10) { *ptr++ = 0; *ptr += 1; } printf ("0"); } printf ("\n"); free (vals); return 0; }

    C / C++ / MFC c++ performance help question

  • Help with a function.
    E ericelysia

    Oops, nevermind the INTERNAL COMPILER ERROR. I forgot a set of parenthesis (see http://lithiumdata.com/QandA/compileerror.htm[^]). Originally I had: Car::~Car { cout << "\n\n The destructor has been called.\n\n"; } Here is what it needs to be: Car::~Car() { cout << "\n\n The destructor has been called.\n\n"; } Thanks, Eric

    C / C++ / MFC help performance

  • Help with a function.
    E ericelysia

    Does anyone know what the INTERNAL COMPILER ERROR means? --------------------Configuration: Implementation - Win32 Debug-------------------- Compiling... Implementation.cpp I:\Documents and Settings\Implementation.cpp(48) : fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1794) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information Main.cpp Error executing cl.exe. Implementation.exe - 1 error(s), 0 warning(s) I found this http://owlnext.sourceforge.net/qa51.html[^]. The site says, "This error occurs only on machines with the Windows 95 or Windows 98 operating system." But I am running Win XP Home w/SP2. I'm puzzled. Thanks, Eric

    C / C++ / MFC help performance

  • Help with a function.
    E ericelysia

    OK, after tracing my code, I have fixed my previous problems (I think). As of now, my two main concerns are: 1.) Making sure I convert the ints to floats correctly (where needed). 2.) Figuring out what is going on with my destructor (this is all new to me). Every time I run the program with the destructor, I get an ENTERNAL COMPILER ERROR. I really appreciate the feedback and suggestions! Thanks, Eric Here is my program: //--------------------------------------------------------------------------- //------------------------Header.h--------------------------------------- #ifndef HEADER_H #define HEADER_H class Car { public: Car(); Car( int, string, string, string, string, int ); //~Car(); void setYear( int ); void setManufacturer( string ); void setModel( string ); void setColor( string ); void setCondition( string ); void setOdometer( int ); int getYear(); string getManufacturer(); string getModel(); string getColor(); string getCondition(); int getOdometer(); void printYear(); void printManufacturer(); void printModel(); void printColor(); void printCondition(); void printOdometer(); int getMinutes(); int getSpeed(); void drive( int, int ); void newCar(); void displayOdometer(); void reset(); void setCar( int, string, string, string, string, int ); void printCar(); private: int year; string manufacturer; string model; string color; string condition; int odometer; int speed; int minutes; }; #endif //-------------------------------------------------------------------------------- //-------------------------Implementation.cpp------------------------------ #include #include #include using namespace std; #include "Header.h" Car::Car() { system( "CLS" ); year = 9999; manufacturer = "NoManufacturerYet"; model = "NoModelYet"; color = "NoColorYet"; condition = "NoConditionYet"; odometer = 999999999; } Car::Car( int newYear, string newManufacturer, string newModel, string newColor, string newCondition, int newOdometer ) { system( "CLS" ); year = newYear; manufacturer = newManufacturer; model = newModel; color = newColor; condition = newCondition; odometer = newOdometer; } /* Car::~Car { cout << "\n\n The destructor has been called.\n\n"; } */ void Car::setYear( int yr ) { system( "CLS" ); year = yr; } void Car::setManufacturer( string manufa

    C / C++ / MFC help performance

  • Help with a function.
    E ericelysia

    My problem is that the remainderMinutes equation is not working correctly. Thank you, Eric

    C / C++ / MFC help performance

  • Help with a function.
    E ericelysia

    Hello, I am having a problem with a function. I am trying to increment a variable (odometer) using the speed and distance traveled. Below is what I have. Any suggestions are appreciated. Thanks, Eric void drive( int, int ); // this is in the class (header file) void Car::drive( int spd, int minutes ) //implementation file { int remainderMinutes = 0; int hours; int distance; system( "CLS" ); while( minutes > 60 ) { remainderMinutes += minutes % 60 * oneDividedBySixty; minutes += remainderMinutes; } hours = minutes * oneDividedBySixty; distance = spd * minutes; cout << "\n\n The distance is " << distance << "."; cout << "\n\n The speed is " << speed << "."; cout << "\n\n The time is " << minutes << " minutes."; } int main() { Car c; char choice; do { cout << "\n\n\n Please make a selection from the menu.\n\n"; cout << "\n Press 'D' to display the car attributes.\n"; cout << "\n Press 'R' to reset the car attributes.\n"; cout << "\n Press 'X' to exit the program.\n"; cin >> choice; choice = toupper( choice ); switch( toupper( choice ) ) { case 'D': c.printCar(); break; case 'R': c.reset(); break; case 'X': break; default: cout << "\n Unknown choice entered.\n" << " Enter a new choice.\n\n"; break; } } while ( choice != 'X' ); c.reset(); c.printCar(); //c.getSpeed(); //c.getMinutes(); c.drive( c.getSpeed(), c.getMinutes() ); //c.drive( speed, minutes ); cout << "\n\n\n "; return 0; }

    C / C++ / MFC help performance
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups