Question

In: Computer Science

Objective: The purpose of this assignment is to: You understand and can work with C++ arrays,...

Objective:
The purpose of this assignment is to:

  • You understand and can work with C++ arrays, characters, and strings.
  • You are comfortable with writing functions in C++.
  • You are familiar with repetitive structures (loops) and selection statements (if/else or switch) in any combination and can use them in functions and manipulate array data.
  • You can approach a complex problem, break it down into various parts, and put together a solution.
  • You will be able to:
    • Use the basic set of Unix commands to manipulate directories and files
    • Create and edit files using a standard text editor
    • Transfer files from a laptop to the Unix server
    • Use the G++ compiler to compile programs
    • Execute C++ programs that you have written

Directions:

Write a C++ program that will create a menu driven program with the following options:

Menu Options:
A) Text to Morse code
B) Quit

If user selects A or a:

  • The user is asked to input a string of characters
  • Each character is converted into Morse code and displayed to the screen (see http://www.sckans.edu/~sireland/radio/code.html (Links to an external site.))
  • If the user enters a string that contains items not listed in the table below "Error : word contains symbols" is displayed to the screen

If user selects B or b:

  • The application ends

Otherwise:

  • The user is asked to enter a valid menu option

Make sure your program conforms to the following requirements:

1. This program should be called MorseCode.cpp

2. It must provide the functions defined above. You are required to use and define proper C++ functions, but for this program, you are allowed to define them (80 points).

3. Add comments wherever necessary. (5 points)

4. Run the program in linprog.cs.fsu.edu - select option A - redirect output to a file called OutputA.txt (include OutputA.txt in submission and Unix command executed) (5 points)

Sample Runs:

NOTE: not all possible runs are shown below.

Welcome to the Morse code program
Menu Options:
A) Text to Morse code
B) Quit
h
Menu Options:
A) Text to Morse code
B) Quit
a
Enter a word and I will translate it to Morse code.
-> sos
...
---
...
Menu Options:
A) Text to Morse code
B) Quit
A
Enter a word and I will translate it to Morse code.
-> ok
---
-.-
Menu Options:
A) Text to Morse code
B) Quit
a
Enter a word and I will translate it to Morse code.
-> ??
Error : word contains symbols
Menu Options:
A) Text to Morse code
B) Quit
a
Enter a word and I will translate it to Morse code.
-> ok
---
-.-
Menu Options:
A) Text to Morse code
B) Quit
B

General Requirements:

1) Include the header comment with your name and other information on the top of your files.

2. Please make sure that you're conforming to specifications (program name, print statements, expected inputs and outputs, etc.). Not doing so will result in a loss of points. This is especially important for prompts. They should match mine EXACTLY.

3. If we have listed a specification and allocated point for it, you will lose points if that particular item is missing from your code, even if it is trivial.

4. No global variables (variables outside of main()) unless they are constants.

5. All input and output must be done with streams, using the library iostream

6. You may only use the iostream, iomanip, vector, and string libraries. Including unnecessary libraries will result in a loss of points.

7. NO C style printing is permitted. (Aka, don't use printf). Use cout if you need to print to the screen.

8. When you write source code, it should be readable and well-documented (comments).

9. Make sure you either develop with or test with g++ (to be sure it reports no compile errors or warnings) before you submit the program.

Solutions

Expert Solution

#include <iostream>

using namespace std;

// FUNCTION PROTOTYPE

void displayMenu();

bool isAlphabet(string);

string getMorseCode(char);

void convertToMorse(string);

int main()

{

char choice;

do

{

displayMenu();

cin >> choice;

switch(choice)

{

case 'A':

case 'a':

{

string input;

cin.ignore();

cout << "Enter a word and I will translate it to Morse code.\n--> ";

getline(cin, input);

convertToMorse(input);

break;

}

case 'B':

case 'b':

{

cout << "\nThanks..Goodbye!\n\n";

exit(EXIT_SUCCESS);

}

default:

cout << "\nInvalid selection!\n\n";

}

}while(choice != 'B' || choice != 'b');

}

void displayMenu()

{

cout << "Menu Options:\nA) Text to Morse code\nB) Quit\nYour choice: ";

}

string getMorseCode(char c)

{

string res = "";

switch(c)

{

case 'a':

res = ".-";

break;

case 'b':

res = "-...";

break;

case 'c':

res = "-.-.";

break;

case 'd':

res = "-..";

break;

case 'e':

res = ".";

break;

case 'f':

res = "..-.";

break;

case 'g':

res = "--.";

break;

case 'h':

res = "....";

break;

case 'i':

res = "..";

break;

case 'j':

res = ".---";

break;

case 'k':

res = "-.-";

break;

case 'l':

res = ".-..";

break;

case 'm':

res = "--";

break;

case 'n':

res = "-.";

break;

case 'o':

res = "---";

break;

case 'p':

res = ".--.";

break;

case 'q':

res = "--.-";

break;

case 'r':

res = ".-.";

break;

case 's':

res = "...";

break;

case 't':

res = "-";

break;

case 'u':

res = "..-";

break;

case 'v':

res = "...-";

break;

case 'w':

res = ".--";

break;

case 'x':

res = "-..-";

break;

case 'y':

res = "-.--";

break;

case 'z':

res = "--..";

break;

}

return res;

}

bool isAlphabet(string s)

{

bool res = true;

for(int i = 0; i < s.length(); i++)

{

if(!(s[i] >= 'A' && s[i] <= 'Z') && !(s[i] >= 'a' && s[i] <= 'z') && s[i] != ' ')

{

res = false;

break;

}

}

return res;

}

void convertToMorse(string s)

{

string res = "";

// check if "s" contains any other characters other than the alphabets

if(!isAlphabet(s))

{

cout << "Word contains symbol\n\n";

return;

}

cout << "Morse code: ";

for(int i = 0; i < s.length(); i++)

{

if(s[i] == ' ')

res += " ";

res += getMorseCode(tolower(s[i]));

}

cout << res << endl;

}

********************************************************* SCREENSHOT *******************************************************

CODE SCREENSHOTS :


Related Solutions

This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
Purpose of Assignment  The purpose of this assignment is to allow the students to understand and...
Purpose of Assignment  The purpose of this assignment is to allow the students to understand and practice the measurement of present value, future value, and interest rate using Microsoft® Excel®.  Assignment Steps  Resources: Microsoft® Office® 2013 Accessibility Tutorials, Microsoft® Excel®, Time Value of Money Calculations Template Calculate the following time value of money problems using Microsoft® Excel®: If we place $8,592.00 in a savings account paying 7.5 percent interest compounded annually, how much will our account accrue to in 9.5 years? What is the present value of...
Objective: The objective of this assignment is to allow students to understand the basic principles of...
Objective: The objective of this assignment is to allow students to understand the basic principles of arrays Program Requirements: The assignment will require the students use arrays to perform mathematical calculations. Program Setup: Functions to include in the program The program will have three functions Function 1: Responsible for setting values in the arrays Function 2: Responsible for printing values in arrays Function 3: Responsible for doing calculations to arrays Function 1 Details: Setting array values Parameters: 3 Array of...
Personal Selling Assignment: The objective for this exercise is for you to better understand and apply...
Personal Selling Assignment: The objective for this exercise is for you to better understand and apply the steps used in personal selling. This is an individual assignment. Please explain how you can use the seven steps of personal selling in the activity of getting a new job. For each step, write 1-2 sentences on how the step relates to job search, interviewing, etc. The seven steps are: PROSPECTING: The salesperson must develop a list of customers. PREAPPROACH: The salesperson must...
The purpose of this assignment is to allow you to understand scenarios and customer experiences in...
The purpose of this assignment is to allow you to understand scenarios and customer experiences in which AI and RPA can be used. You might need to do some additional research on specific technologies related to AI to complete the assignment. First, select a current process that you face in your daily life. It might be something you face in your work, or at school, or in your personal life. For this process, complete the following: 1. Select a current...
The Programming Language is C++ Objective: The purpose of this project is to expose you to:...
The Programming Language is C++ Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student...
The Programming Language is C++ Objective: The purpose of this project is to expose you to:...
The Programming Language is C++ Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student...
Project 1 - Arrays - Grader The purpose of this assignment is to practice dealing with...
Project 1 - Arrays - Grader The purpose of this assignment is to practice dealing with arrays and array parameters. Arrays are neither classes nor objects. As a result, they have their own way of being passed as a parameter and they also do not support the dot operator ( .), so you cannot determine how full they are. This results in some pain and suffering when coding with arrays. It is this awareness that I am trying to get...
The purpose of this assignment is to understand the terms import and export, and then explain...
The purpose of this assignment is to understand the terms import and export, and then explain the advantages or disadvantages of buying imports rather than buying domestic products. You could, for instance, write about an imported automobile, stereo, or household appliance that you bought or considered buying. Include all of the following points in your discussion. If you were a retailer, would you want to sell domestically made goods or imported items? Please explain why you made this choice. If...
Objective: The purpose of this assignment is to introduce declaration of list objects, the forstatement and...
Objective: The purpose of this assignment is to introduce declaration of list objects, the forstatement and the def keyword used to define functions. Problem: Write a Python module (a text file containing valid Python code) named p3.py. This file will contain the following.  Definition of a list containing strings which are in turn integers. These integers represent years, which will be used as inputs to the next item in the file  Definition of a function named isLeap. This...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT