Working code implemented in C++ and appropriate comments provided for better understanding:
Source code for main.cpp:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
//morse code printing function - prints one character
//toPrint is the character being printed
void printCode(char toPrint){
//convert character to upper case if character is lowercase,
example: q becomes Q
toPrint = toupper(toPrint);
//ASCII for space
if(toPrint == 32)
cout << " / ";
//letters A-Z in morse code
if(toPrint == 'A')
cout << ".-";
if(toPrint == 'B')
cout << "-...";
if(toPrint == 'C')
cout << "-.-.";
if(toPrint == 'D')
cout << "-..";
if(toPrint == 'E')
cout << ".";
if(toPrint == 'F')
cout << "..-.";
if(toPrint == 'G')
cout << "--.";
if(toPrint == 'H')
cout << "....";
if(toPrint == 'I')
cout << "..";
if(toPrint == 'J')
cout << ".---";
if(toPrint == 'K')
cout << "-.-";
if(toPrint == 'L')
cout << ".-..";
if(toPrint == 'M')
cout << "--";
if(toPrint == 'N')
cout << "-.";
if(toPrint == 'O')
cout << "---";
if(toPrint == 'P')
cout << ".--.";
if(toPrint == 'Q')
cout << "--.-";
if(toPrint == 'R')
cout << ".-.";
if(toPrint == 'S')
cout << "...";
if(toPrint == 'T')
cout << "-";
if(toPrint == 'U')
cout << "..-";
if(toPrint == 'V')
cout << "...-";
if(toPrint == 'W')
cout << ".--";
if(toPrint == 'X')
cout << "-..-";
if(toPrint == 'Y')
cout << "-.--";
if(toPrint == 'Z')
cout << "--..";
//numbers in morse code
if(toPrint == '0')
cout << "-----";
if(toPrint == '1')
cout << ".----";
if(toPrint == '2')
cout << "..---";
if(toPrint == '3')
cout << "...--";
if(toPrint == '4')
cout << "....-";
if(toPrint == '5')
cout << ".....";
if(toPrint == '6')
cout << "-....";
if(toPrint == '7')
cout << "--...";
if(toPrint == '8')
cout << "---..";
if(toPrint == '9')
cout << "----.";
//punctuation in morse code
if(toPrint == '.')
cout << ".-.-.-";
if(toPrint == ',')
cout << "--..--";
if(toPrint == ':')
cout << "---...";
if(toPrint == '?')
cout << "..--..";
if(toPrint == 39)
cout << ".----.";
if(toPrint == '-')
cout << "-....-";
if(toPrint == '/')
cout << "-..-.";
if(toPrint == 34)
cout << ".-..-.";
if(toPrint == '@')
cout << ".--.-.";
}
//void function takes in the user input, for loop outputs the sentence inputted by the user
void printString(string userString){
for(unsigned int i = 0;i<=userString.length()-1;i++){
char userChar = userString.at(i);
printCode(userChar);
}
}
//void function that takes in our initials as a string to print them in morse code in the next step
void printInitials(string userString){
for(unsigned int i = 0;i<=userString.length()-1;i=i+2){
//at() function extracts one character from the string
char userChar1 = userString.at(i);
char userChar2 = userString.at(i+1);
printCode(userChar1);
cout << " ";
printCode(userChar2);
if(i<userString.length()-3)
//adding the / mark since I'd like to include my tutor's initials
cout << " / ";
}
}
//printSentence prints the string inputted by the user
void printSentence(string userString){
for(unsigned int i = 0;i<=userString.length()-1;i++){
//at() function extracts one character from the string
char userChar1 = userString.at(i);
printCode(userChar1);
cout << " ";
}
}
int main(){
//character that the user inputs
char userChoice;
int done = 0;
//check if its done
while(done == 0){
cout << endl << endl;
cout << "Menu" << endl;
cout << "A - Alphabet" << endl;
cout << "I - Initials" << endl;
cout << "N - Numbers" << endl;
cout << "P - Punctuations" << endl;
cout << "S - User Sentence" << endl;
cout << "Q - Quit" << endl;
//takes the users command and inserts it into userChoice
cout << "Enter command: ";
cin >> userChoice;
//converts user choice to upper case if userChoice is lower
case
userChoice = toupper(userChoice);
//if user chooses A
if ( userChoice == 'A' ){
cout << "Here are the letters of the alphabet (A-Z) in morse code: " << endl;
for(int i = 65;i<=90;i++){
printCode(i);
cout << " ";
}
}
//if user chooses I
else if (userChoice == 'I') {
cout << "Here are the team member initials in morse code: " << endl;
string ourInitials = "ACJD";
printInitials(ourInitials);
}
//if user chooses N
else if (userChoice == 'N') {
cout << "Here are the numbers (0123456789) in morse code:
" << endl;
//ASCII characters 0-9 are represented by 47-56, stops at 57
for(int i = 47; i<=57;i++){
printCode(i);
cout << " ";
}
}
//if user chooses P
else if (userChoice == 'P') {
cout << "Here are the punctuation marks (.,:?'-/\"@) in morse code : ";
printSentence(".,:?'-/\"@");
}
//if user chooses S
else if (userChoice == 'S') {
cout << "Please enter a sentence: " << endl;
string yourSentence;
getline(cin,yourSentence);
getline(cin,yourSentence);
cout << "Here is your sentence in your morse code: ";
printSentence(yourSentence);
}
//When the user wants to quit
else if (userChoice == 'Q') {
cout << "Program Done!" << endl;
done = 1;
}
}
return 0;
}
Sample Output Screenshots:
Hope it helps, if you like the answer give it a thumbs up. Thank you.
so i have my c++ code and ive been working on this for hours but i...
okay so here is my c++ code and the errors im really stuck on fixing what i did wrong it seems to be the same repeated error our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses A your program should use a loop and your morse code printing...
I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in: "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...
Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...
I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account: Customer name Customer address City State ZIP code Telephone Account balance Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...
Find and fix the errors in this C++ code: * This program illustrates a variety of common loop errors. * Fix the errors in each section. */ #include <iostream> using namespace std; int main() { cout << "Welcome to Loop World" << endl; // SECTION I: update comment below on how you fixed this section's code, and tests run // FIX = // TESTS: cout << endl; cout << "******************" << endl; cout << "Section I" << endl; cout <<...
may i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #include<iostream> #include<string> #include<sstream> #include<stack> using namespace std; int main() { string inputStr; stack <int> numberStack; cout<<"Enter your expression::"; getline(cin,inputStr); int len=inputStr.length(); stringstream inputStream(inputStr); string word; int val,num1,num2; while (inputStream >> word) { //cout << word << endl; if(word[0] != '+'&& word[0] != '-' && word[0] != '*') { val=stoi(word); numberStack.push(val); // cout<<"Val:"<<val<<endl; } else if(word[0]=='+') { num1=numberStack.top(); numberStack.pop(); num2=numberStack.top(); numberStack.pop();...
C++: Need help debugging my code I am writing this and using some other examples as reference code while rewriting it with my own understanding of the material but am having trouble making it finally compile. Below is a picture of the error messages. //main.cpp //Semester Project //Created by J---on 5/6/2019 #include <iostream> #include <fstream> #include <string> #include <sstream> #include <bits/stdc++.h> using namespace std; void instructions(); //displays program details and instructions void openFile(); void takeInput(int*); void switchBoard(int*); struct price {...
I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...
Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...
Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...