In Cpp/C++, Demonstrate Telegram Bill And Morse Code Translation

#include<iostream>
#include<string>

using namespace std;

void telegramBill();
void morseCode();

int main(){
	int choice;
	cout << "Welcome to Western Union Telegram Company" << endl << endl;
	cout << "1 - Process Telegram Bill" << endl;
	cout << "2 - Translate to Morse Code" << endl << endl;
	cout << "Enter your choice: ";
	cin >>  choice;
	cin.ignore();
	switch(choice){
		case 1: telegramBill(); break;
		case 2: morseCode(); break;
		default: cout << endl << choice << " is not a valid choice." << endl;
	}
	return 0;
}

void telegramBill(){
	const double RATE_PER_FIVE = 1.50;
	const double RATE_PER_SINGLE = 0.50;
	string custName, street, city, state, zip;
	int words, blockFiveWords, remSingleWords, payment, change, dollars, quarters, dimes, nickels, pennies;
	double amountDue;
	cout << "Enter the name of the customer: ";
	getline(cin, custName);
	cout << "Enter street address: ";
	getline(cin, street);
	cout << "Enter city: ";
	getline(cin, city);
	cout << "Enter state: ";
	getline(cin, state);
	cout << "Enter zip code: ";
	getline(cin, zip);
	cout << "Enter the number of words sent: ";
	cin >> words;
	cin.ignore();
	  
	blockFiveWords = words / 5;
	remSingleWords = words % 5;
	  
	amountDue = (blockFiveWords * RATE_PER_FIVE) + (remSingleWords * RATE_PER_SINGLE);

	cout << endl << custName << endl;
	cout << street << endl;
	cout << city << ", " << state << ' ' << zip << endl;
	cout << "Amount Owed: $" << amountDue << endl;
 
	cout << endl << "Enter the amount received from customer: ";
	cin >> payment;
	  
	change = payment - (amountDue * 100);
	dollars = change / 100;
	quarters = (change % 100) / 25;
	dimes = ((change % 100) - (quarters * 25)) / 10;   
	nickels = (change - (dollars*100)-(quarters*25)-(dimes*10)) / 5;   
	pennies = change - (dollars*100)-(quarters*25)-(dimes*10)-(nickels*5);   

	cout << endl << "Denomination\tNumber" << endl;
	cout << "------------\t------" << endl;
	cout << " Dollars\t" << dollars << endl;
	cout << " Quarters\t" << quarters << endl;
	cout << " Dimes\t\t" << dimes << endl;
	cout << " Nickles\t" << nickels << endl;
	cout << " Pennies\t" << pennies << endl;
}

void morseCode(){
	cout << endl << "Enter a single letter: ";
	char c;
	cin >> c;
	c = toupper(c);
	string code;
	switch(c){
		case ',': code = "--..--"; break;
		case '.': code = ".-.-.-"; break;
		case '?': code = "..--.."; break;
		case '0': code = "-----"; break;
		case '1': code = ".----"; break;
		case '2': code = "..---"; break;
		case '3': code = "...--"; break;
		case '4': code = "....-"; break;
		case '5': code = "....."; break;
		case '6': code = "-...."; break;
		case '7': code = "--..."; break;
		case '8': code = "---.."; break;
		case '9': code = "----."; break;
		case 'A': code = ".-"; break;
		case 'B': code = "-..."; break;
		case 'C': code = "-.-."; break;
		case 'D': code = "-.."; break;
		case 'E': code = "."; break;
		case 'F': code = "..-."; break;
		case 'G': code = "--."; break;
		case 'H': code = "...."; break;
		case 'I': code = ".."; break;
		case 'J': code = ".---"; break;
		case 'K': code = "-.-"; break;
		case 'L': code = ".-.."; break;
		case 'M': code = "--"; break;
		case 'N': code = "-."; break;
		case 'O': code = "---"; break;
		case 'P': code = ".--."; break;
		case 'Q': code = "--.-"; break;
		case 'R': code = ".-."; break;
		case 'S': code = "..."; break;
		case 'T': code = "-"; break;
		case 'U': code = "..-"; break;
		case 'V': code = "...-"; break;
		case 'W': code = ".--"; break;
		case 'X': code = "-..-"; break;
		case 'Y': code = "-..--"; break;
		case 'Z': code = "--.."; break;
	}
	if(!code.length()){
		code += c;
		code.append(" cannot be translated");
	} else {
		string tmp = code;
		code = "The letter ";
		code += c;
		code += " translates to ";
		code += tmp;
	}
	cout << endl << code << endl;
}
Download

Comments

Popular posts from this blog