Sasquacz Temat założony przez niniejszego użytkownika |
Problem z Modułowością » 2014-11-27 17:11:56 Hej, Na wstępie mowie, że dopiero zaczynam zabawę z programowaniem. Pierwszy raz robie program modułowy i odrazu mam problem którego nie umiem rozwiązać mianowicie: Main #include <iostream> #include <cstdlib> #include <ctime> #include "type.h"
using namespace std;
int he; int we; ;
int main() { cout << "Podaj wysokosc: "; cin >> we; cout << "Podaj szerokosc: "; cin >> he; cout << "Zostanie stworzony obiekt obraz1."; cout << "Width = " << obraz1.getWidth(); cout << "Height = " << obraz1.getHeight(); system( "PAUSE" ); cout << endl << "Teraz dokona sie zapis pikseli" << endl; obraz1.putPixel( 0, 0, 50 ); obraz1.putPixel( 0, 1, 120 ); obraz1.putPixel( 1, 0, 99 ); obraz1.putPixel( 1, 1, 200 ); cout << endl << "Piksel na pozycji [3,3] ma wartosc: " << obraz1.getPixel( 3, 3 ) << endl; cout << endl << "Piksel na pozycji [0,0] ma wartosc: " << obraz1.getPixel( 0, 0 ) << endl; system( "PAUSE" ); cout << endl << "Wyswietlenie obrazu" << endl; obraz1.print(); system( "PAUSE" ); cout << "Tworzenie kopii" << endl; Image obraz2( obraz1 ); cout << "Width = " << obraz1.getWidth(); cout << "Height = " << obraz1.getHeight(); system( "PAUSE" ); cout << endl << "Nadawanie jasnosci piksela ." << endl; obraz2.fillInImage( 0 ); system( "PAUSE" ); cout << endl << "Wyswietlenie kopii" << endl; obraz2.print(); cout << "\n\n\n"; system( "PAUSE" ); return 0; getchar(); } Image.h #include <iostream> #include <cstdlib> #include "type.h"
using namespace std;
class Image { private: byte ** tab; int width; int height; void dealloc(); public: Image(); Image( int width, int height ); Image( const Image & image ); Image( const Image & image, int x, int y, int w, int h ); ~Image(); Image & operator =( const Image & image ); int getWidth() const; int getHeight() const; void assignFrom( const Image & image, int x, int y, int w, int h ); byte getPixel( int x, int y ); void putPixel( int x, int y, byte value ); void fillInImage( byte value ); void print(); }
void Image::alloc( int width, int height ) { this->width = width; this->height = height; tab = new byte *[ width ]; for( int i = 0; i < width; ++i ) tab[ i ] = new byte[ height ]; }
void Image::dealloc() { for( int i = 0; i < width; ++i ) delete[] tab[ i ]; delete[] tab; }
Image::Image() { alloc( 0, 0 ); }
Image::Image( int width, int height ) { alloc( width, height ); }
Image::Image( const Image & image ) { alloc( 0, 0 ); * this = image; }
Image::Image( const Image & image, int x, int y, int w, int h ) { alloc( 0, 0 ); assignFrom( image, x, y, w, h ); }
Image::~Image() { dealloc(); }
void Image::operator =( const Image & image ) { assignFrom( image, 0, 0, image.getWidth(), image.getHeight() ); }
int Image::getWidth() const { return width; }
int Image::getHeight() const { return height; }
void Image::assignFrom( const Image & image, int x, int y, int w, int h ) { dealloc(); alloc( w, h ); for( int i = 0; i < w; ++i ) { for( int j = 0; j < h; ++j ) { tab[ i ][ j ] = int( image.tab[ x + i ][ y + j ] ); } } }
byte Image::getPixel( int x, int y ) { if( x > width || y > height ) { cout << "Blad! Podane indeksy wykraczaja poza obszar obrazu."; cout << "Wpisz indeksy maksymalnie do [" << getWidth() << "][" << getHeight() << "]."; } else return tab[ x ][ y ]; }
void Image::putPixel( int x, int y, byte value ) { if( x > width || y > height ) { cout << "Blad! Podane indeksy wykraczaja poza obszar obrazu."; cout << "Wpisz indeksy maksymalnie do [" << getWidth() << "][" << getHeight() << "]."; } else tab[ x ][ y ] = value; }
void Image::fillInImage( byte value ) { for( int i = 0; i < width; i++ ) { for( int j = 0; j < height; j++ ) { tab[ i ][ j ] = value; } } }
void Image::print() { for( int i = 0; i < width; i++ ) { for( int j = 0; j < height; j++ ) { if( tab[ i ][ j ] <= 100 ) cout << "X"; else cout << " "; } } } Type.h #include <cstdlib> #include <iostream> #include <ctime>
using namespace std;
typedef unsigned char byte;
Problem następuje gdy z Maina przeniosłem do Image.h to co sie w nim znajduje:D. Wyskakuje mi bład [Error] 'obraz1' was not declared in this scope Jak go rozwiązać? jakieś odniesienie ze obraz znajduje sie teraz w image.h? Pozdrawiam |