Ma475 Project
Ma475 Project
Ma475 Project
h"
#include <string>
#include <iostream>
#include <map>
#include <conio.h>
#include <fstream>
#include <queue>
#pragma once
namespace ma475project {
/// <summary>
/// Resumen de AppleCompressor
/// </summary>
public ref class AppleCompressor : public System::Windows::Forms::Form
{
public:
AppleCompressor(void) {
InitializeComponent();
}
protected:
/// <summary>
/// Limpiar los recursos que se estén usando.
/// </summary>
~AppleCompressor() {
if (components) {
delete components;
}
}
void InitializeComponent(void)
{
this->openFileDialog1 = (gcnew
System::Windows::Forms::OpenFileDialog());
this->button1 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
this->openFileDialog1->FileOk += gcnew
System::ComponentModel::CancelEventHandler(this,
&AppleCompressor::openFileDialog1_FileOk);
//
// button1
//
this->button1->BackColor =
System::Drawing::SystemColors::Control;
this->button1->Location = System::Drawing::Point(143, 80);
this->button1->Margin = System::Windows::Forms::Padding(4);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(197, 28);
this->button1->TabIndex = 0;
this->button1->Text = L"Selecciona tu archivo";
this->button1->UseVisualStyleBackColor = false;
this->button1->Click += gcnew System::EventHandler(this,
&AppleCompressor::button1_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(46, 147);
this->label1->Margin = System::Windows::Forms::Padding(4, 0,
4, 0);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(44, 16);
this->label1->TabIndex = 1;
this->label1->Text = L"[Ruta del archivo]";
//
// button2
//
this->button2->Location = System::Drawing::Point(143, 201);
this->button2->Margin = System::Windows::Forms::Padding(4);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(197, 28);
this->button2->TabIndex = 2;
this->button2->Text = L"Comprimir";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this,
&AppleCompressor::button2_Click);
//
// AppleCompressor
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(482, 321);
this->Controls->Add(this->button2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Margin = System::Windows::Forms::Padding(4);
this->MaximizeBox = false;
this->Name = L"AppleCompressor";
this->StartPosition =
System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"AppleCompressor";
this->Load += gcnew System::EventHandler(this,
&AppleCompressor::AppleCompressor_Load);
this->ResumeLayout(false);
this->PerformLayout();
#pragma endregion
private: System::Void AppleCompressor_Load(System::Object^ sender,
System::EventArgs^ e) {
}
public:
String^ getFileName() {
return FileName;
}
[STAThread]
//Funcion que devuelve un mapa (nodo incluye la letra con su respectiva frecuencia)
map<char, int> FrecuenciaDeCadaLetra(string texto) {
map<char, int> mapa;
for (auto c : texto) {
mapa[c]++;
}
for (auto i = mapa.begin(); i != mapa.end(); i++) {
if (i->first == ' ') {
cout << "(espacio)";
}
if (i->first == '\n') {
cout << "(Enter)";
}
cout << i->first << " -> " << i->second << "\n";
}
return mapa;
}
return texto;
}
[STAThread]
void main()
{
Console::CursorSize = 50;
Console::SetWindowSize(180, 180);
cout << "\nEl archivo se abrio de la ruta:\n" << nombre_archivo << endl;
ifstream archivo;
archivo.open(nombre_archivo, ios::in);
if (archivo.is_open()) {
cout << "\nEl archivo se ha abierto correctamente!" << endl;
_sleep(600);
while (!archivo.eof()) {
string linea;
getline(archivo, linea);
texto += (linea + "\n");
}
archivo.close();
}
else {
cout << "El archivo no se abrio :(" << endl;
return;
}
_sleep(500);
cout << "\nEL texto tiene " << texto.length() << " caracteres.\n\n";
_sleep(800);
cout << "La frecuencia de cada caracter es: " << endl;
map<char, int> mapa = FrecuenciaDeCadaLetra(texto);
while (!cola.empty()) {
cola.pop();
}
_getch();