im newbies in c++... my task is to translate code Morse into alphabet an count the word i use... the problem is i dont know how to use the ifstream to read and use the code Morse that must be kept in .text file

i only manage to write the code succesfully, but only with the code morse already in the coding... not using the the ifstream function to retreat the code Morse from .text file

help me pls... to many error

this is my code that need to rewrite and change

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

void main()
{
    int status[26]; 
    string kod[27];[COLOR="Green"] //this is the one that i need to put into .text file and access using ifstream[/COLOR]

    string alpha[27]; 
    string human[100]; 
    string temp; 
    char ans; 
    int i,jump,cool,ulang,hold; 
    for(int A=0;A<26;A++)
    {
        alpha[A]="A";               
        A++;
    }
    alpha[26]=' '; 
    [COLOR="Green"]kod[0]=".-";
    kod[1]="-...";
    kod[2]="-.-.";
    kod[3]="-..";
    kod[4]=".";
    kod[5]="..-";
    kod[6]="----";
    kod[7]="....";
    kod[8]="..";
    kod[9]=".----";
    kod[10]="-.-";
    kod[11]=".-..";
    kod[12]="--";
    kod[13]="-.";
    kod[14]="---";
    kod[15]=".--.";
    kod[16]="--.-";
    kod[17]=".-.";
    kod[18]="...";
    kod[19]="-";
    kod[20]="..-";
    kod[21]="...-";
    kod[22]=".--";
    kod[23]="-..-";
    kod[24]="-.--";
    kod[25]="--..";
    kod[26]="~";[/COLOR]

    do
    {
        for(int yo=0;yo<26;yo++)
        {
            status[yo]=0;          
        }
        ulang=0; 
        cool=0; 
        system("cls"); 
        cout<<"\n\t<Simbol '/' untuk berhenti>"; 
        cout<<"\n\n\tMasukkan S.O.S :\t"; 
        for(i=0;i<100;i++)
        {
            cin>>temp;
            if(temp=="/") 
            {
                break;
            }
            else
            {
                human[i]=temp; 
            }
        }

        cout<<"\n\tHasil          :\t";

        for(int j=0;j<i;j++)
        {
            jump=0; 

            for(int t=0;t<27;t++)
            {

                if(human[j]==kod[t])
                {
                    cout<<alpha[t]<<' '; 
                    jump++; 
                    if(human[j]!="~")
                    {
                        status[t]++; 
                        cool++; 
                    }
                }
            }

            if(jump==0)
            {
                cout<<"? ";
            }
        }

        cout<<"\n\n\tBilangan aksara yang digunakan : "<<cool<<" aksara";
        cout<<"\n\n\tSenarai aksara yang berulang :-\n";
        hold=0; 
        for(int fke=0;fke<26;fke++) 
        {
            if(status[fke]>1)
            {
                hold++; 
                cout<<"\n\t\tAksara "<<alpha[fke]<<", berulang "<<status[fke]<<" kali..";
            }
        }

        cout<<"\n\n\tBilangan aksara yang berulang : "<<hold<<" aksara";
        cout<<"\n\n\tContinue ? (y/n)\t"; 
        cin>>ans;
    }while(ans=='y'||ans=='Y'); 

    cout<<"\n\n";
}

Recommended Answers

All 4 Replies

i put all the element that i've highligt in text file which i name codemorse.txt which i've save in the same file whice i save this c++ code..... but i still cant retrieve it using ifstream and too many error when i try to use the ifstream....

>> the problem is i dont know how to use the ifstream to read and use the code Morse that must be kept in .text file

Then google it or something?

Here is one from here

...

even after i manage to retrieve the file... why it can be use again as array

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.