Project3-Introductionfol.pptx

INFO-1156 Object-Oriented Programming with C++

Project 3 - Introduction

Beginning a Project

Read handout and read the rubric.

Run the executable to discover behaviours and error messages based on certain inputs.

What is acceptable input? What is unacceptable?

What happens if input is unacceptable?

Make a list of all possible test data!

Match your program to the executable.

2

Test using: rle.exe

3

Download rle.binaries.v2.0.0.zip from the Project folder

Unzip, type cmd in the address line, enter executable

Enter various input that will test the project requirements

Input Examples

4

What happens if:

There is no input

Input file is not present

--debug switch is present

Run-length Encoding

Write a tool for encoding/decoding with run-length encoding

RLE is a very basic data compression algorithm used to compress digital data

The objective is to reduce the amount of data needed for storage or transmission

It is often used in digital signal processing (DSP) such as image processing and compression

RLE works by reducing the physical size of a repeating string of characters called a “run”

If all the values in the original data are exactly the same, RLE can reduce data to just two values

An Example:

The string “aaaaaaaaaaaaaaaa” after run-length encoding is 16a

RLE stores the encoding in bytes as 8-bit binary values

A hexadecimal representation looks like: x10x61

5

https://www.fileformat.info/mirror/egff/ch09_03.htm

Examples

“hello” string, 5 bytes

rle encoded produces:

8 bytes

“aaaaaaaaaa” string, 9 bytes

rle encoded produces:

2 bytes

rle is best applied when there is a “run” of repeating characters

6

1 2 3 4 5 6 7 8 9 10
h e l l o
1 h 1 e 2 l 1 o
x01 x68 x01 x65 x02 x6c x01 x6f
1 2 3 4 5 6 7 8 9 10
a a a a a a a a a
9 a
x09 x61

Recall: ASCII Code Chart All keyboard characters have a corresponding decimal value between 0-255 . . . . and also corresponding hex, oct, bin values

rle – things to consider

rle compresses runs by writing the file information as:

byte count, followed by character byte

Where:

byte count is stored as uint8_t

character is stored as unsigned char

uint8_t

a typedef for a C unsigned char

guaranteed to be 8 bits

stream.get(ch) gets a char and will have to be cast to unsigned char

Files must be opened in binary mode to prevent conversions

\r, \n, ^D, ^Z could be changed

8

Project 3 – Run-length encoding

9

Program Interfaces

At the end of running rle, a file is encoded and a compressed file is created

At the end of running rld, an encoded file is decoded and restored to original file

rle.exe [--debug] [--help] inputfile.txt [outputfile]
rld.exe [--debug] [--help] inputfile.txt [outputfile]

Run-length encoding data compression algorithm

Compression in which runs of data are stored as a single data value and count, rather than as the original run

aaaaabbbbbcccdd

5a5b3c2d

Algorithm:

Look at a string, character by character

Compare c[n] == c[n+1]

If the same, increment a counter

Continue until c[n] != c[n+1]

Store the c[n] and count

Repeat

10

Command line Input

No console input, only file input

If argc = 1, no file is provided, print “Help”

If argc >1, check for switches:

Is --debug present, set a bool to true,

Is --help, present, set a bool to true

If argc > 2, check for input file:

Create ifstream file

If argc > 3, check for output file:

Create ofstream file

11