Lab Assignment 4
Due: Monday 7/13/2015 by 11:59 pm (i.e. midnight)
Note: Due date is pushed back because of the midterm exam; however, doing this project before the exam should help prepare you for taking the exam. So you should at least start this assignment before the exam!
Write a C++ Program (using only the C+ subset as defined in lecture) that will:
- Print out your name
- Print out your net-id
- Print out CS 107 and Semester information (Summer 2015)
- Print our the Assignment Name and Number (Lab Assignment 3)
- Print out your lab time (Wednesday at 10am)
- Print out the additional information as described below:
Converting to the International Civil Aviation Organization Alphabet
The International Civil Aviation Organization, "ICAO", created its own
alphabet where it uses a word for each letter. This is used to help spelling words over noisy or staticy connections. The word for each alphabet is listed in the following table:
- A - Alfa
- B - Bravo
- C - Charlie
- D - Delta
- E - Echo
- F - Foxtrot
- G - Golf
- H - Hotel
- I - India
- J - Juliet
- K - Kilo
- L - Lima
- M - Mike
- N - November
- O - Oscar
- P - Papa
- Q - Quebec
- R - Romeo
- S - Sierra
- T - Tango
- U - Uniform
- V - Victor
- W - Whiskey
- X - X-ray
- Y - Yankee
- Z - Zulu
For this assignment, you are towrite a C+ program that will prompt the user to enter a string as input and translate that string into the series of ICAO words that would be used to spell out the word entered. For Example:
would become
- Hotel Echo Lima Lima Oscar
The code does not distingush between upper and lower case letters. Nor does the code deal with non-letter characters (or at least the part of the code we will worry about for our assignment - the digit 9 becomes "niner" but we wont worry about that).
You should have a single space between each of the ICAO words in the output. If the string entered as input contains non-letters, print these out as a single character but again separated by a single space. For example, if the user entered:
The program should output:
- India Sierra 9 5 @ Delta 7
The C++
String library has a number of buit in operations to help with this program. Note: the syntax for some of these may seem a bit strange.
To determine the number of characters in a string use the
length "method". Length is used as follows:
// get a string from input and print out the number of characters it contains
string str1;
cin >> str1;
int characterCount;
characterCount = str1.length();
cout << "The string: " << str1 << " contains " << characterCount << " characters." << endl;
To determine what character is at what position in a string, use the
at "method". At is used as follows:
string str1;
cin >> str1;
char c1;
c1 = str1.at(0);
cout << "The character at the start of the string is: " << c1 << endl;
c1 = str1.at(4); // This assumes the string has at least 5 characters
cout << "The character at the position 4 of the string is: " << c1 << endl;
Remember that the positions in a string range from zero to the length-1.
To determine is a character is a letter or not, the
isalpha function in the ctype library can be used. The isalpha function returns a true value if the character given as a parameter is a letter, otherwise it returns false. This can be used as follows:
string str1;
cin >> str1;
char c1;
c1 = str1.at(0);
if ( isalpha( c1 ) == true )
cout << "The first character in the string is a letter." << endl;
else
cout << "The first character in the string is NOT a letter." << endl;
Submission of the Lab
The lab must be submitted electronically to the Assignment Link for Lab 3 inside of Blackboard. You will only need to submit the C++ source code file (just the ".cpp" file, not the "a.out" file).
You are to name your program file using both your NET-ID and the Lab Number. Thus for Lab 3, if you NET-ID was ptroy4, your program should be named:
ptroy4Lab3.cpp
-- Main.troy - 2015-07-08