Alphabet characters in the id string

32 views 8:55 am 0 Comments March 20, 2023
  1. Introduction

 

You will implement a C++ program to decode different string of digits from the input file. This assignment focusses on array management and string handling in C++. You will also practice string manipulation with predefined string utility functions and basic file operations.

 

  1. Input files

 

– The input file will contain a list of encoded id numbers. The input can range anywhere from 0 to 100 entries. Input might contain empty lines and spaces (empty lines and spaces need to be removed to process each entry correctly).

 

– Each entry will be on its own line and have 2 different parts: the coded characters set and id string.

 

– The id string will consist of digits, alphabet characters, and the ‘+’ sign.

 

– Alphabet characters in the id string will always have a number representation for it in the characters set, each separated by a colon.

 

– Semicolon is used to separate characters in the set and id string.

 

– The id string will always come after the characters set in the entry.

 

– Valid entry should have both parts, the characters set and the id string.

 

– Invalid entry should be ignored.

 

– Example of valid entry:

 

a:123;b:456;c:789;id:c11ba3+2b+a

 

*characters set in yellow, id string in green

 

– Example of invalid entry:

 

a:123;b:456;c:789 – missing id string

 

id:c11ba3+2b+a – missing characters set

 

  1. Decoding process

 

Example input: a:123;b:456;c:789;id:c11ba3+2b+a

 

o Replace all the alphabet characters in the id string with its number representation in the

 

characters set.

 

a:123;b:456;c:789;id:c11ba3+2b+a

 

ð 789114561233+2456+123

 

o The plus sign (+) should be replaced by the repeated sum of the previous digits (see below for

 

details on the computation). The first plus sign reduces to 5, and the second plus sign reduces

 

to 9

 

789114561233+2456+123

 

78911456123352456+123

 

78911456123352456+123

 

789114561233524569123

 

789114561233524569123

 

  1. Repeated sum of digits

 

The repeated sum of digits compresses a number of digits to a single value from 0-9.

 

Consider the digits in front of the first plus sign above. These digits are: 789114561233.

 

The sum of those digits is 50, and the sum of these digits is 5. Since this number falls in the range from 0-9,

 

this is the repeated-sum of the digits.

 

Continuing with the substitution made, the next set of digits in front of the remaining plus sign are:

 

78911456123352456.

 

The sum of those digits is 72, and the sum of these digits is 9. Since this number falls in the range from 0-9,

 

this is the repeated-sum of the digits.

 

  1. Output files

 

– The output file should contain all the valid id in the order they appeared in the input file (empty lines and

 

spaces should be removed).

 

– Each entry should be on its own line.