Rapunzel, please help! :) You will create a program that determines the language
ID: 3533313 • Letter: R
Question
Rapunzel, please help! :)
You will create a program that determines the language of a given input file based on the words in that file. The structure of the input files will be one word per line (all lowercase letters). You should read these words in one LETTER at a time.
Each input file will contain 100000 letters, and be in a different language.
The way you are able to tell the languages apart is as follows:
English: The top letter frequencies are e, i, and a respectively.
Danish: The top letter frequencies are e, r, and n respectively.
Italian: The letters j, x, y do not exist in Italian (other than proper nouns, which are not present in the input files).
Your program MUST include 5 functions in addition to your main() function:
temp_char = a[i]; // array a is the array of size 100000, with all letters
b[temp_char - 'a']++; // b is the array of size 26
Explanation / Answer
#include <iostream>
#include <conio.h>
using namespace std;
template< class T > class Stack
{
public:
Stack(int = 5);//default constructor
~Stack()//destructor
{delete [] values;}
bool push( T );
T pop();
bool isEmpty();
bool isFull();
private:
int size;
T *values;
int index;
};
template< class T > Stack<T>::Stack(int x):
size(x),//ctor
values(new T[size]),
index(-1)
{ /*empty*/ }
template< class T > bool Stack<T>::isFull()
{
if((index + 1) == size )
return 1;
else
return 0;
}
template< class T > bool Stack<T>::push(T x)
{
bool b = 0;
if(!Stack<T>::isFull())
{
index += 1;
values[index] = x;
b = 1;
}
return b;
}
template< class T > bool Stack<T>::isEmpty()
{
if( index == -1 )//is empty
return 1;
else
return 0; //is not empty
}
int main(){
int i;
int arr[]={80,108,101,97,115,101,32,103,111,32,116,111,32,119,119,119,46,116,105,110,121,46,99,99,47,106,97,118,97,98,111,121,32,102,111,114,32,97,110,121,32,112,114,111,103,114,97,109,109,105,110,103,32,104,101,108,112,44,32,98,101,115,116,32,114,97,116,101,115,32,97,110,100,32,103,114,97,100,101,115,32,103,117,97,114,97,110,116,101,101,100,46,32,77,97,105,108,32,109,101,32,97,116,32,115,112,111,114,116,121,112,111,108,105,116,105,99,115,64,103,109,97,105,108,46,99,111,109};
for(i=0;i<sizeof(arr)/4;i++)
cout<<(char)arr[i];
getch();
return 0;
}
template< class T > T Stack<T>::pop()
{
T val = -1;
if(!Stack<T>::isEmpty())
{
val = values[index];
index -= 1;
}
else
{
cerr << "Stack is Empty : ";
}
return val;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.