pgm_t
class that you can use to
copy (read in/read out) a PGM image. The class should include the "big three",
namely the copy constructor, destructor, and (copy) assignment operator.
pgm.cpp
with its own header.
friend std::istream& operator>>(std::istream& s, pgm_t& rhs);
friend std::ostream& operator<<(std::ostream& s, pgm_t& rhs);
int ptype;
int w,h;
int bpp;
int max;
std::string name;
char *img;
float *gpix;
main.cpp
code driver tests the modules by:
pgm_t org("mandrill.pgm");
constructor
pgm_t cpy();
constructor
cpy = org;
assignment operator
std::ifstream ifs;
ifs.open("mandril.pgm",std::ios::in | std::ios::binary);
...
ifs.close();
std::ofstream ofs;
ofs.open("copy.pgm",std::ios::out | std::ios::binary);
...
ofs.close();
(or you can just write to std::cout
)
ifs.read(&byte,1);
and
ofs.write(&byte,1);
,
respectively.
main.cpp
driver:
#include <iostream>
#include <fstream>
#include <string>
#include "pgm.h"
int main()
{
pgm_t org("mandrill.pgm");
pgm_t cpy("gray.pgm");
std::ofstream ofs;
ofs.open("copy.pgm",std::ios::out|std::ios::binary);
ofs << org;
ofs.close();
cpy = org;
ofs.open(cpy.fname().c_str(),std::ios::out|std::ios::binary);
ofs << cpy;
ofs.close();
return 0;
}
main.cpp
here is a
Makefile
that you can use to try to compile the project:
CC = g++
INCLUDE = -I.
CFLAGS = -g
LDFLAGS = -L. -L/usr/lib
LDLIBS = -lc -lm
.cpp.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<
all: main
main: pgm.o main.o main.cpp
$(CC) -o $@ $@.o pgm.o $(LDFLAGS) $(LDLIBS)
main.o: main.cpp
pgm.o: pgm.cpp
clean:
rm -f *.o
rm -rf main
Note that each line underneath the targets is indented by a tab, not just
spaces, this is important!
tar.gz
archive of your asg##/ directory, including:
README
file containing
Makefile
.h
headers and .c
source)
make clean
before tar
)
handin
notes