FIND THE PROBLEMS AND FIT IT !! DON\'T ADD ANY LIBRARY !! JUST FIT THE PROBLEMS!
ID: 3673026 • Letter: F
Question
FIND THE PROBLEMS AND FIT IT !!
DON'T ADD ANY LIBRARY !!
JUST FIT THE PROBLEMS!
#include <iostream>
using namespace std;
char cin_function();
void old_mssg (int &,char *&);
void resize(char *, int, char*&);
char **morse_code_array();
int step_one();
int compare_text(char );
void print_m(char **, char *, int &, int );
void p_o_m(char **,int &,char* );
void true_false(char **, char *);
void match_morse(int &);
int main (){
char **TD_array=morse_code_array();/*morse code array*/
int len, choice=0, idx , number, p;
choice = step_one();/*let the user input the choice (1 || 2)*/
if (choice==49){
char *new_mssg;/* declared the array which is holding the final mssg */
old_mssg(len, new_mssg);
cout<<" mssgage length is "<<len-2<<endl; /*length in the main so that author can use many time*/
print_m(TD_array, new_mssg,len,idx);
}
else if (choice==50){
char *new_mssg;/* declared the array which is holding the final mssg */
old_mssg(len, new_mssg);
cout<<" mssgage length is "<<len-2<<endl; /*length in the main so that author can use many time*/
p_o_m(TD_array, len, new_mssg);
}
return 0;
}
void p_o_m(char **TD_array, int &len,char* new_mssg ){
int k=0, p=0;
char *pm;
pm=new char [5];
for (int m=0; m<len; m++){
if (new_mssg[m]!=32){
pm[p]=new_mssg[m];
p++;
cout<<new_mssg[m]<<" m "<<m<<endl;
cout<<pm<<"pm in the passing"<<endl;
cout<<new_mssg[m]<<" m "<<m<<endl;
cout<<m<<endl<<endl<<endl;
}
else{
cout<<pm<<"pm in the passing"<<endl;
if(new_mssg[m]==32 && new_mssg[m-1]==32 ){
pm[p]='';
true_false(TD_array, pm);
p=0;
delete []pm;
pm=new char [5];
}
if (new_mssg[m]==32 &&new_mssg[m-6]==32 && new_mssg[m-5]==32 && new_mssg[m-4]==32 && new_mssg[m-3]==32 && new_mssg[m-2]==32 && new_mssg[m-1]==32 ){
cout<<" ";
}
}
}
}
void true_false(char **TD_array, char *pm ){
int num=0, k=0, i=0,p=0;
do{
if (TD_array[k][i]!=pm[i]){
k++;
i=0;
num=0;
}
else{
i++;
if (TD_array[k][i]=='' && pm[i]=='' )/*make sure that function check every morse code*/{
match_morse(k);
num=1;
i=0;
}
else
num=0;
}
}while (num==0);
}
void match_morse(int &k){
char letters[27]= {"abcdefghijklmnopqrstuvwxyz"};
cout << letters[k];
}
int compare_text(char letter){
int idx;
if (letter-96 >= 0){
idx=letter-97;
}
else{
idx=letter-65;
}
return idx;
}
void print_m(char **TD_array, char *new_mssg, int &len,int idx){
for ( int i=0; i <len-2; i++ ){
if (new_mssg[i]!=' '){
idx=compare_text(new_mssg[i]);
cout<<TD_array[idx];
cout<<" ";
}
else if(new_mssg[i]==' ')
cout<<" ";
}
}
int step_one(){
int num=0, choice=0;
cout<<" Text to Morse code(1), Morse code to Text(2) ";
choice=cin.get();
cin.ignore();//make sure not to the following input
return choice;
}
char **morse_code_array()
{
int row=26, col=5;
char **TD_array =new char *[row];
for (int j=0; j<row; j++){
TD_array[j]= new char [col];
}
char table[26][5] = {{".-"}/*a*/, {"-..."}/*b*/, {"-.-."}/*c*/, {"-.."}/*d*/, {"."}/*e*/, {"..-."}/*f*/, {"--."}/*g*/, {"...."}/*h*/, {".."}/*i*/, {".---"}/*j*/, {"-.-"}/*k*/, {".-.."}/*l*/, {"--"}/*m*/, {"-."}/*n*/, {"---"}/*o*/, {".--."}/*p*/, {"--.-"}/*q*/, {".-."}/*r*/, {"..."}/*s*/, {"-"}/*t*/, {"..-"}/*u*/, {"...-"}/*v*/, {".--"}/*w*/, {"-..-"}/*x*/, {"-.--"}/*y*/, {"--.."}/*z*/};
for (int j=0; j<row; j++){
for (int i=0; i<col; i++){
TD_array[j][i]= table[j][i];
}
}/* store the morse code in to the dynamical array: TD_array*/
return TD_array;
}
char cin_function(){
char c;
c=cin.get();
return c;
}
void old_mssg (int &num,char *&new_mssg){
char c;
int count=0, n=1;
char *mssg = new char[n];
cout<<" Message please , press enter when you are finish. "<<endl;
while (c!=' ') {
c=cin_function();
mssg[count]=c;
count++;
if (count>=n){
n++;
resize(mssg,n,new_mssg);
}
}
num=n;
delete [] mssg;
}
void resize(char *mssg, int n, char *&new_mssg){
new_mssg = new char[n];
for (int i=0; i < n - 1; i++){
new_mssg[i] = mssg[i];
}
mssg = new_mssg;
}
Explanation / Answer
#include <iostream>
using namespace std;
void main (){
char **TD_array=morse_code_array();/*morse code array*/
int len, choice=0, idx , number, p;
choice = step_one();/*let the user input the choice (1 || 2)*/
if (choice==49){
char *new_mssg;/* declared the array which is holding the final mssg */
old_mssg(len, new_mssg);
cout<<" mssgage length is "<<len-2<<endl; /*length in the main so that author can use many time*/
print_m(TD_array, new_mssg,len,idx);
}
else if (choice==50){
char *new_mssg;/* declared the array which is holding the final mssg */
old_mssg(len, new_mssg);
cout<<" mssgage length is "<<len-2<<endl; /*length in the main so that author can use many time*/
p_o_m(TD_array, len, new_mssg);
}
return 0;
void p_o_m(char TD_array, int len,char new_mssg ){
int k=0, p=0;
char *pm;
pm=new char [5];
for (int m=0; m<len; m++){
if (new_mssg[m]!=32){
pm[p]=new_mssg[m];
p++;
cout<<new_mssg[m]<<" m "<<m<<endl;
cout<<pm<<"pm in the passing"<<endl;
cout<<new_mssg[m]<<" m "<<m<<endl;
cout<<m<<endl<<endl<<endl;
}
else{
cout<<pm<<"pm in the passing"<<endl;
if(new_mssg[m]==32 && new_mssg[m-1]==32 ){
pm[p]='';
true_false(TD_array, pm);
p=0;
delete []pm;
pm=new char [5];
}
if (new_mssg[m]==32 &&new_mssg[m-6]==32 && new_mssg[m-5]==32 && new_mssg[m-4]==32 && new_mssg[m-3]==32 && new_mssg[m-2]==32 && new_mssg[m-1]==32 ){
cout<<" ";
}
}
}
}
void true_false(char TD_array, char pm ){
int num=0, k=0, i=0,p=0;
do{
if (TD_array[k][i]!=pm[i]){
k++;
i=0;
num=0;
}
else{
i++;
if (TD_array[k][i]=='' && pm[i]=='' )/*make sure that function check every morse code*/{
match_morse(k);
num=1;
i=0;
}
else
num=0;
}
}while (num==0);
}
void match_morse(int k){
char letters[27]= {"abcdefghijklmnopqrstuvwxyz"};
cout << letters[k];
}
int compare_text(char letter){
int idx;
if (letter-96 >= 0){
idx=letter-97;
}
else{
idx=letter-65;
}
return idx;
}
void print_m(char TD_array, char new_mssg, int len,int idx){
for ( int i=0; i <len-2; i++ ){
if (new_mssg[i]!=' '){
idx=compare_text(new_mssg[i]);
cout<<TD_array[idx];
cout<<" ";
}
else if(new_mssg[i]==' ')
cout<<" ";
}
}
int step_one(){
int num=0, choice=0;
cout<<" Text to Morse code(1), Morse code to Text(2) ";
choice=cin.get();
cin.ignore();//make sure not to the following input
return choice;
}
void morse_code_array()
{
int row=26, col=5;
char **TD_array =new char *[row];
for (int j=0; j<row; j++){
TD_array[j]= new char [col];
}
char table[26][5] = {{".-"}/*a*/, {"-..."}/*b*/, {"-.-."}/*c*/, {"-.."}/*d*/, {"."}/*e*/, {"..-."}/*f*/, {"--."}/*g*/, {"...."}/*h*/, {".."}/*i*/, {".---"}/*j*/, {"-.-"}/*k*/, {".-.."}/*l*/, {"--"}/*m*/, {"-."}/*n*/, {"---"}/*o*/, {".--."}/*p*/, {"--.-"}/*q*/, {".-."}/*r*/, {"..."}/*s*/, {"-"}/*t*/, {"..-"}/*u*/, {"...-"}/*v*/, {".--"}/*w*/, {"-..-"}/*x*/, {"-.--"}/*y*/, {"--.."}/*z*/};
for (int j=0; j<row; j++){
for (int i=0; i<col; i++){
TD_array[j][i]= table[j][i];
}
}/* store the morse code in to the dynamical array: TD_array*/
return TD_array;
}
void cin_function(){
char c;
c=cin.get();
return c;
}
void old_mssg (int num,char new_mssg){
char c;
int count=0, n=1;
char *mssg = new char[n];
cout<<" Message please , press enter when you are finish. "<<endl;
while (c!=' ') {
c=cin_function();
mssg[count]=c;
count++;
if (count>=n){
n++;
resize(mssg,n,new_mssg);
}
}
num=n;
delete [] mssg;
}
void resize(char mssg, int n, char new_mssg){
new_mssg = new char[n];
for (int i=0; i < n - 1; i++){
new_mssg[i] = mssg[i];
}
mssg = new_mssg;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.