$30
Task One: I/O Manipulators
Define a manipulator format in a file task1.cpp. The manipulator format can take three arguments: string of base (such as “oct”, “dec” and “hex”), the length that an integer can be displayed, and a character can be used to pad the output value when the length of the value is not long enough. Write a driver program include main() function in the file task1.cpp to test the manipular. For example: cout << format("oct", 10, '#') << 20 << endl;
The result is
########24
Change the format like
cout << format("hex", 8, '!') << 20 << endl;
The result is
!!!!!!14
Change the format like
cout << format("dec", 12, '@') << 20 << endl;
The result is
@@@@@@@@@@20
Task Two: A PGM Reader
In this task, you are required to develop a program, pgmReader, to read a gray-scale image saved in pgm format (PGM, Portable Gray Map). The task should be completed in two steps:
(a) Design and implementation of class Image as described below.
(b) Design and implement the program, pgmReader, as specified below.
An image consists of a grid of pixels (picture elements). For a gray-scale image, each pixel has one value representing its luminance or brightness. The pixel value usually ranges from 0 to 255, with 0 being the darkest (black) and 255 being the brightest (white).
PGM is a simple file format to store gray-scale images. You are required to design and develop a class, Image, that is able to read a gray scale image from a PGM image file and report the following
statistics of the image: width, height, minimum intensity, maximum intensity, and average intensity. You are required to declare the Image class in Image.h and place its implementation in Image.cpp. Read the appendix for the specifications of PGM.
Using the Image class, design and implemented a main program, pgmReader.cpp, that reads an image stored in a PGM format file, calculates and outputs the statistics. Following are examples that show how your program may be used and marked. Note: $ is assumed to be the prompt of a UNIX terminal.
$ pgmReader c01.ppm
<c01.ppm is not a PGM file
$ pgmReader c01.pgm
Read a gray-scale image from a PGM file <c01.pgm.
Statistics of the image:
Width: 1024
Height: 768
Min-Intensity: 0 Max-Intensity: 255
Ave-Intensity: 131.95
The compile directive would be something like
g++ –o pgmReader pgmReader.cpp Image.cpp
Two PGM images are provided for testing your program.