Write a program that translates messages in the file datain

Write a program that translates messages in the file data.in to lewhalltat, line by line. To translate a message to lewhalltat use the following rules:


All numbers are converted to octal.

Each vowel is appended by ’ll’, so ’a’ becomes ’all’, ’e’ becomes ’ell’, etc.

Every ’y’ becomes a ’viv’.

Any letter in the set {b, d, p, t} is appended by ’at’, so ’b’ becomes ’bat’.

Any letter in the set {r, v, w, z} is prepended by ’le’, so ’r’ becomes ’ler’.

Any letter in the set {f, l, m, n, s} is prepended by ’a’ and appended by ’o’, so ’m’ becomes ’amo’.

All remaining characters are not changed.


(See pic below for rest of question)

Define and use the following functions: get ValidMsg which returns a non-empty string read from the input file (this requires that you pass the itstream into the function by reference). convertchar which returns an appropriate string of one or more characters when passed a non numeric character. get Number which returns the value of the number in a given string starting at a given position. makeoctal which returns the octal value in string format that corresponds to a given real value. output Message which writes a given character followed by a space then a given string to standard output. CPSC 1620 Assignment 7 To convert from decimal to octal: we convert the integer part by repeated division by 8. keeping track of the remainder and the fractional part by repeated multiplication by 8 keeping track of the integer part until the fractional part is 0 or we have 5 digits. For example: 234.3125 Calculation Quotient Remainder Calculation Whole Fractional 234 /8 0.3125 8 2 29/8 ,5 8 3/8 To get the octal number read up the remainder column and down the whole column, so 234.3125 352.24 Sample Run: File data ,in This is line 1 Hey? I like 17.5; but not 2.37 Done Program outputs This is line 1. Tathillaso illaso aloillanoell 1 Hey? Hellviv I like 17.5; but not 2.37 Ill aloillkell 21.4 batulltat anoolltat 2.27534 Datollanoell!!

Solution

#include<iostream>

#include<string>

using namespace std;

int main()

{

string line;

ifstream input(\"Data.in\");

int a=0,b=0;

if(!input)

{

cout<<\"File is not open\"<<endl;

return -1;

}

while(!input.eof())

{

getline(input,line[a],\'\ \');

for(char &c : line)

{

switch(c)

{

case a : String s=\"a\";

s.insert(1,2,l);

nline[i]=s;

i++;

break;

case e : String s=\"e\";

s.insert(1,2,l);

nline[i]=s;

i++;

break;

case i : String s=\"i\";

s.insert(1,2,l);

nline[i]=s;

i++;

break;

  

case o : String s=\"o\";

s.insert(1,2,l);

nline[i]=s;

i++;

break;

case u : String s=\"u\";

s.insert(1,2,l);

nline[i]=s;

i++;

break;

case y : nline[i]=\"viv\";

i++;

case b : string s=\"b\";

s.insert(1,\"at\");

line[i]=s;

i++;

break;

case d : string s=\"d\";

s.insert(1,\"at\");

line[i]=s;

i++;

break;

case p : string s=\"p\";

s.insert(1,\"at\");

line[i]=s;

i++;

break;

case t : string s=\"t\";

s.insert(1,\"at\");

line[i]=s;

i++;

break;

case r : string s=\"r\";

s.insert(0,\'l\');

  s.insert(1,\'e\');

line[i]=s;

i++;

break;

case v : string s=\"v\";

s.insert(0,\'l\');

  s.insert(1,\'e\');

line[i]=s;

i++;

break;

case w : string s=\"w\";

s.insert(0,\'l\');

  s.insert(1,\'e\');

line[i]=s;

i++;

break;

case z : string s=\"z\";

s.insert(0,\'l\');

  s.insert(1,\'e\');

line[i]=s;

i++;

break;

case f : string s=\"f\";

s.insert(0,\'a\');

  s.insert(2,\'o\');

line[i]=s;

i++;

break;

case l : string s=\"l\";

s.insert(0,\'a\');

  s.insert(2,\'o\');

line[i]=s;

i++;

break;

case m : string s=\"m\";

s.insert(0,\'a\');

  s.insert(2,\'o\');

line[i]=s;

i++;

break;

case n : string s=\"n\";

s.insert(0,\'a\');

  s.insert(2,\'o\');

line[i]=s;

i++;

break;

case s : string s=\"s\";

s.insert(0,\'a\');

  s.insert(2,\'o\');

line[i]=s;

i++;

break;

}

}

for(i=0;i<line.length;i++)

{

cout<<line[i]<<endl;

}

a++;

}

}

Decimal to Octal conversion

#include <iostream>
#include <cmath>
using namespace std;

int DecToOct(int decimalNumber);

int main()
{
int dec;
cout << \"Enter a decimal number: \";
cin >> dec;
cout << dec << \" in decimal = \" << DecToOct(dec) << \" in octal\";
   return 0;
}

int DecToOct(int dec)

{
int rem, i = 1, oct = 0;
while (dec != 0)
{
rem = dec % 8;
dec /= 8;
oct += rem * i;
i *= 10;
}
return oct;
}

Thank you for asking CHEGG.

Write a program that translates messages in the file data.in to lewhalltat, line by line. To translate a message to lewhalltat use the following rules: All numb
Write a program that translates messages in the file data.in to lewhalltat, line by line. To translate a message to lewhalltat use the following rules: All numb
Write a program that translates messages in the file data.in to lewhalltat, line by line. To translate a message to lewhalltat use the following rules: All numb
Write a program that translates messages in the file data.in to lewhalltat, line by line. To translate a message to lewhalltat use the following rules: All numb
Write a program that translates messages in the file data.in to lewhalltat, line by line. To translate a message to lewhalltat use the following rules: All numb
Write a program that translates messages in the file data.in to lewhalltat, line by line. To translate a message to lewhalltat use the following rules: All numb

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site