1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
/*
6-60 Coding
A study of cryptography and its growth as a science can shed light on the nature of languages
and on certain aspects of history. For example, the level of education of the Boers in the Boer War
can be noted from the fact that the British officers often sent messages written in normal schoolboy Latin,
secure in the fact that if they did fall into the wrong hands, they could not be understood. One of the
simplest codes (used from the times of the Greeks) is representing the letters of the alphabet by numbers.
An array contains a series of two-digit integers. Each integer represents one character of the alphabet as follows:
00 represents a blank space
01 represents an A
02 represents a B
03 represents a C
.
.
.
26 represents a Z
Write a program that reads the entries and prints the characters corresponding to the integers.
The program should check that all integers are between 0 and 26. If this is not the case, the program should print a message
indicating that the data is invalid.
*/
#include <iostream>
using namespace std;
int main()
{
int total, num;
int alphabet [27] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
cout << "I will transcribe your numbers into letters.\n";
cout << "How many numbers are you entering: \n";
cin >> total;
for ( int n = 0; n <= total; n++)
{
cout << "Enter your number: \n";
cin >> num;
if ( num < 0 || num > 26 )
{cout << "the data is not valid.\n"; break;}
else
{cout << num << " is " << alphabet[num] << endl; }
}
system ("pause");
}
|