Clinton Portis 211 Practically a Posting Shark

I don't know how to do file i/o in C. I only know c++.

WaltP commented: Then why bother to post? -4
cse.avinash commented: yep. dont post then -1
Clinton Portis 211 Practically a Posting Shark
#include<windows.h>
#include<iostream>
#include<cctype>
#include<cstdlib>
#include<ctime>

using namespace std;

class Roulette
{
   public:
             
      Roulette();      
      
      void board_display();
      void prompt();
      void bet_menu();
      void place_bet();
      void set_bet(int choice);
      void set_bet(int menu_choice, int number, int amount); 
      void set_chip(int);
      void set_chip(int, int);          
      void spin_the_wheel();     
      void win_or_lose();
      void reset();
      bool quit();
      void gotoxy(int x, int y);      
        
      bool win_straight_up();   //35:1 + bet back
      bool win_column();        // 2:1 + bet back
      bool win_low();           // 1:1 + bet back
      bool win_high();          // 1:1 + bet back
      bool win_even();          // 1:1
      bool win_odd();           // 1:1
      bool win_red();           // 1:1
      bool win_black();         // 1:1
      bool is_black(int); 
      
      void input_error();
      void bet_error();
      void domain_error();
      void cap_error();
      
   private:
              
      bool is_bet,
           is_quit;      
      
      int  total,
           available,
           winnings,
           winner,
           bet_array_side[9],
           bet_array_number[36],
           zero_coords_x[2],
           zero_coords_y[2],           
           side_coords_x[6],
           side_coords_y[6],
           num_coords_x[36],
           num_coords_y[36],
           col_coords_x[3],
           col_coords_y[3];         
              
};

int main()
{
    Roulette myRoulette;
    
    myRoulette.board_display();
    
    do{          
          myRoulette.prompt();             
    
    }while(!myRoulette.quit());
    
return 0;
}


//////////////////////////////////////////////
///////////////////// Function Definitions //
////////////////////////////////////////////

Roulette::Roulette()
{
   is_bet  = FALSE;
   is_quit = FALSE;
   total  = 2500;
   available = 200;
   winnings = 0;
   
   srand((unsigned)time(NULL));  
   
   for(int i=0; i<9; i++)
   
      bet_array_side[i] = 0;
      
   for(int i=0; i<36; i++)
   
      bet_array_number[i] = 0; 
   
   for(int i=0, x=8; i<2; i++, x+=15)
   {
      zero_coords_x[i] = x;
      zero_coords_y[i] = 6;
   }      
   
   for(int i=0, y=13; i<6; i++, y+=8)
   {
      side_coords_x[i] = 35;
      side_coords_y[i] = y;
   }
   
   for(int i=0, x=5, y=10; i<36; i++, x+=10)
   {
       if(x>26)
       {               
            x = 5;
            y+= 4;
       }
       
      num_coords_x[i] = x;
      num_coords_y[i] = y;
   }
   
   for(int i=0, x=8; i<3; i++, x+=10)
   {
      col_coords_x[i] = x;
      col_coords_y[i] = 56; 
   }   
}   
   
void Roulette::board_display()
{
   cout << " _____________________________ "
        << "\n|      ___ …
WaltP commented: You're kidding, right? I thougt you knew better than this! -4
Clinton Portis 211 Practically a Posting Shark

I will gladly be more specific; allow me to take this opportunity to remind ye' that YOU ARE POSTING C CODE IN A C++ FORUM. I don't go to a Java forum and post Pascal. I don't go to a C# forum and post QBasic. I don't go to McDonalds and ask for a Whopper. Why do people insist on posting C code up in here and expect results...???!

WaltP commented: Cool it. It's not the end of the world. -4
Clinton Portis 211 Practically a Posting Shark

settle down ma'am.

Clinton Portis 211 Practically a Posting Shark

i think they already made a guide called 'programming for idiots.'

Clinton Portis 211 Practically a Posting Shark

brb

Clinton Portis 211 Practically a Posting Shark

1. When reading in your pgm file, I would recommend reading it into 2D array:

int pixels[256][256];

2. You could read in the pgm file like this:

//Get file type
catIn >> type;
//Get file dimensions
catIn >> length >> width;
//Get grayscale max value 
catIn >> grayscale_max;
//Get pixels
for(int i=0; i<256; i++)
{
     for(int j=0; j<256; j++)
     {
          catIn >> pixels[i][j];
     }
}

3. Now that you have a nicely packaged pgm file.. all you need is that almighty emboss function:

void emboss(int& pixels[][])
{
     int result = 0;

     //I am using loop conditions that will start the emboss operation at the lower-right non-border pixel 
     //and work backwards through the pgm file

     //backwards row traversal
     for(int i=254; i>0; i--)
     {     
          //backwards column traversal
          for(int j=254; j>0; j--)
          {
               //Perform 'emboss math'
               result = (pixel[i+1][j+1] - pixel[i][j]) + 8;
               
               if(result < 0)
               {
                    result = 0;
               }
               else if(result > 15)
               {
                    result = 15;
               }

               //Assign the new 'emboss' value 
               pixel[i][j] = result;   
          }
     }
}

4. All there is left to do now is to use your catOut object to open a new file and write the pgm file header info and pixels[][] to file. It will conveniently look similar (yet opposite) to step #2.

All of this code is untested. It is just an idea of how I'd probably go about doing this. There are probably many many ways to get this done. If anyone see's a better way to do this …

Clinton Portis 211 Practically a Posting Shark
//Provides ability to write to the dos console (cin/cout)
#include<iostream>

using namespace std;

int main()
{
     int input = 0; 

     cout << "Enter t or f: ";
     cin >> input;

     do{

          if(input == 't') 
          {
               cout << "True";
          }
          else if(input == 'f') 
          {
               cout << "False";
          }
          else
          {
               cout << "Incorrect entry.  Try again. \n";
          }
     
     }while(input != 't' && input != 'f');

     return 0;
}
WaltP commented: You need to STOP posting code for people. Their job is to write the code. You job is to stop trying to impress everyone with your coding prowess. -2
Clinton Portis 211 Practically a Posting Shark
  • create 2 objects of type 'ifstream'
  • open the two files
  • read in the desired stuff to a container of your choice (usually string objects or vectors)
  • compare the two strings
string word1, word2;
ifstream infile1, infile2;

infile1.open("doc1.txt");
infile2.open("doc2.txt");

word1 << infile1;
word2 << infile2;

if(word1 == word2)
    cout << "Same";

else
     cout << "Different";
Clinton Portis 211 Practically a Posting Shark

are there any guarantees that any id you come up with will unique.. if so, how will you make this determination...

Clinton Portis 211 Practically a Posting Shark

You just completely misunderstood my question.

my bad. teehee.

Clinton Portis 211 Practically a Posting Shark
#include<windows.h>
#include<iostream>
#include<cctype>
#include<cstdlib>
#include<ctime>

using namespace std;

class Roulette
{
   public:
             
      Roulette();      
      
      void board_display();
      void prompt();
      void bet_menu();
      void place_bet();
      void set_bet(int choice);
      void set_bet(int menu_choice, int number, int amount); 
      void set_chip(int);
      void set_chip(int, int);          
      void spin_the_wheel();     
      void win_or_lose();
      void reset();
      bool quit();
      void gotoxy(int x, int y);      
        
      bool win_straight_up();   //35:1 + bet back
      bool win_column();        // 2:1 + bet back
      bool win_low();           // 1:1 + bet back
      bool win_high();          // 1:1 + bet back
      bool win_even();          // 1:1
      bool win_odd();           // 1:1
      bool win_red();           // 1:1
      bool win_black();         // 1:1
      bool is_black(int); 
      
      void input_error();
      void bet_error();
      void domain_error();
      void cap_error();
      
   private:
              
      bool is_bet,
           is_quit;      
      
      int  total,
           available,
           winnings,
           winner,
           bet_array_side[9],
           bet_array_number[36],
           zero_coords_x[2],
           zero_coords_y[2],           
           side_coords_x[6],
           side_coords_y[6],
           num_coords_x[36],
           num_coords_y[36],
           col_coords_x[3],
           col_coords_y[3];         
              
};

int main()
{
    Roulette myRoulette;
    
    myRoulette.board_display();
    
    do{          
          myRoulette.prompt();                
    
    }while(!myRoulette.quit());
    
return 0;
}


//////////////////////////////////////////////
///////////////////// Function Definitions //
////////////////////////////////////////////

Roulette::Roulette()
{
   is_bet  = FALSE;
   is_quit = FALSE;
   total  = 2500;
   available = 200;
   winnings = 0;
   
   srand((unsigned)time(NULL));  
   
   for(int i=0; i<9; i++)
   
      bet_array_side[i] = 0;
      
   for(int i=0; i<36; i++)
   
      bet_array_number[i] = 0; 
   
   for(int i=0, x=8; i<2; i++, x+=15)
   {
      zero_coords_x[i] = x;
      zero_coords_y[i] = 6;
   }      
   
   for(int i=0, y=13; i<6; i++, y+=8)
   {
      side_coords_x[i] = 35;
      side_coords_y[i] = y;
   }
   
   for(int i=0, x=5, y=10; i<36; i++, x+=10)
   {
       if(x>26)
       {               
            x = 5;
            y+= 4;
       }
       
      num_coords_x[i] = x;
      num_coords_y[i] = y;
   }
   
   for(int i=0, x=8; i<3; i++, x+=10)
   {
      col_coords_x[i] = x;
      col_coords_y[i] = 56; 
   }   
}   
   
void Roulette::board_display()
{
   cout << " _____________________________ "
        << "\n|      ___ …
Bench commented: You aren't helping anyone by giving out complete homework solutions -1