bitmap

i have this bitmap file that is defining all its constructors and it is not compliling proply can anyone see any errors..thanks


using namespace std;

bitmap::bitmap()
{
//vector < vector <bool> > g;
numrows = 1;
numcols = 1;
grid.resize(numrows, vector <bool> (numcols,false));

}

void bitmap::display() const
{
for (int r = 0; r < numrows; r++)
{
for (int c = 0; c < numcols; c++)
{
if (grid[r][c] == 0)
cout << " " ;

else cout << "*";
}
cout << endl;


}

}

int bitmap::getRows() const
{
return numrows;
}

int bitmap::getCols() const
{
return numcols;
}

void bitmap::save (string filename) const
{
ofstream infile(filename.c_str());
if (infile.is_open())
{
infile << numrows;
infile << numcols;
for (int r = 0; r < numrows; r++)
{
for (int c = 0; c < numcols; c++)
{
infile << grid[r][c];
}
}
}
else
{
cout <<"Failed to open file" << cout;
}
infile.close();
}

void bitmap::read (string filename)
{

ifstream infile;
infile.open(filename.c_str());
if (infile.fail())
{
cout << "Invalid filename " << endl;

}
if (infile >> numrows >> numcols)
{
grid.resize(numrows, vector <bool> (numcols,false));
char ch;
for (int r = 0; r < numrows; r++)
for (int c = 0; c < numcols; c++)
{
infile >> ch;
grid[r][c] = (ch!= '0');
}
}
}


void bitmap::invert()
{
for (int r = 0; r < numrows; r++)
{
for (int c = 0; c < numcols; c++)
{
if (grid[r][c] = 1)
{
grid[r][c] = 0;
}
else{
grid[r][c] = 1;
}
}
}
}

void bitmap::magnify()
{
//The image is doubled both vertically and horizontally.
}

void bitmap::rotate()
{
//The image is rotated 90 degress clockwise. Note that 4 rotations should return to the original image.
}
sorry 4 posting 2..i thought i cancelled the 1st one
closed account (z05DSL3A)
> it is not compliling proply

What errors are you getting?

How to put code into your postings:
http://www.cplusplus.com/forum/articles/1624/
Last edited on
my save function does not proply work i have been told that i have to have a white space between the numebr of rows and the number of cols and the rest of the data but i dont know how 2 do this?
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void bitmap::save (string filename) const
{
    ofstream infile(filename.c_str());
    if (infile.is_open())
    {
        infile << numrows << " ";
        infile << numcols << " ";
        for (int r = 0; r < numrows; r++)
        {
            for (int c = 0; c < numcols; c++)
           { 
                infile << grid[r][c]; 
           }
        }
    }
    else
    {
        cout <<"Failed to open file" << cout;
    }
    infile.close();
}
Last edited on
thankyou 4 ur help it worked...

my invert is not working nothing shows up wen i use it

void bitmap::invert()
{
for (int r = 0; r < numrows; r++)
{
for (int c = 0; c < numcols; c++)
{
if (grid[r][c] = 1)
{
grid[r][c] = 0;
}
else{
grid[r][c] = 1;
}
}
}
}

does any one have a clue what could b wrong with it
wait i jus figured out the answer sorry about that
does anyone think they could help me out on the rotate or magnify constructors..thanks
sorry again haha i tryed 2 do this with my code
void bitmap::invert()
{
for (int r = 0; r < numrows; r++)
{
for (int c = 0; c < numcols; c++)
{
if (grid[r][c] == 0)
cout << "*" ;

else cout << " ";
}
cout << endl;

}
}

but i realized when pressing it 2wice it wouldnt go back 2 original image
closed account (z05DSL3A)
Shotjase,

You have been asked on many occasions to read the guidance articles on asking questions and inserting code into your post. You do not seem to give us the common courtesy to attempt to follow these guidelines, so I (for one) regret that I will no long be able to offer you help.
r u serious....man i tryd 2 do the code writing bit but it dont work 4 me..didnt realize u hadta b a c++ professional programer 2 ask questions on this site...mad help grey wolf
closed account (z05DSL3A)
Shotjase,

I am perfectly serious.

Just take a look at this thread; to start with the title is meaningless. You then intimate that you have a problem with your code not compiling properly but fail to say what the errors are. When asked you say that save function doesn’t have spaces in it! Well how the hell is anyone meant to figure out that that was your problem? And so on…

I’m in no way asking you to be a professional programmer, all I am saying is don’t make it hard work for people to help you. If you carry on asking extremely vague questions, using txt speak, not putting your code in simple code tags etc. people will start to ignore you. If you don’t find this advise helpful then I’m sorry, but for me, that is how it is.
Last edited on
i may just say that he tried to use the code on the first thread, if you look you can see a litlle grey box like this :


shotjase : You are supposed to put you code BETWEEN the tags not after them.
And you should also try spelling correctly when posting.

Look

Between the Tags code and /code :)
"r u serious....man i tryd 2 do the code writing bit but it dont work 4 me..didnt realize u hadta b a c++ professional programer 2 ask questions on this site...mad help grey wolf"

Err... You'd expect a "Profesional C++ Programmer" to be the lowest level of expertise before you can use a custom [code ] printf("hello world"; [/code ] tag in HTML. =\ Not very re-assuring
Last edited on
Topic archived. No new replies allowed.