Random, Forms, Oscilloscope - не понятно
От: Lofv  
Дата: 07.01.12 13:11
Оценка:
В общем опишу все как есть,но по пунктам, ибо самому страшно как это реализовать. Но прошу, пожалуйста, ответьте хоть в ту ветку форума-то написал или нет... Заранее спасибо.
Необходимо создать нечто, что включает в себя:
1) Читает .wav и затем выводит динамическую синусоиду, спектр, осцилограму, не важно особо, главное что бы видно вершины было видно примерно так.

2) С этого "графика" нужно получить самую верхню точку, нижнюю и среднее значение.
3) Эти значения нужно занести в TextBox или ListBox, это уже не суть важно. Как бонус, можно чтобы с этого самого бокса при нажатии кнопки, на форме данные сохранялись в .txt
4) Если же не строить "график" по .wav, то необходимо сгенерировать случайные числа по таймеру, к примеру задать промежуток 5 секунд и за это время генерируются случайные числа и строится график( имитация динамического, просто иначе я не смог придумать как это воплотить можно). И здесь уже будет чуть проще.
5) Отсюда, эти сгенерированные числа, также, максимальное, среднее и самое маленькое поместить в бокс, можно еще несколько дополнительных числе, также случайных.
6) График выводится на основной форме.
7) На второй форме происходит как раз таки вывод этих данных в боксе (случайных), 3 значений.
8) На третей форме запись случайных чисел может быть 5-10, полученных либо с "графика", либо из Random.
Вот вроде бы все.
График я пробовал статический вывести, но какие бы не вносил, там 2 примера есть, оба выдают ошибки. Не знаю почему...
На самом деле, понимаю что вопросы глупые и дело легко реализуемое, даже для первокурсника програмиста, но... я вовсе не он, а обычный инженер и нашему преподавателю вздумалось задать нам курсовую подобного типа сделать на языке, любом, хоть на паскале... но си++ я больше всего знаком... Но,если будет помощь на другом языке, отрекаться не стану, буду весьма благодарен. Спасибо заранее еще раз.

#pragma once
 
#include "Form3.h"
#include "Form4.h"
 
 
namespace oformlyat {
 
        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;
 
        /// <summary>
        /// Сводка для Form1
        ///
        /// Внимание! При изменении имени этого класса необходимо также изменить
        ///          свойство имени файла ресурсов ("Resource File Name") для средства компиляции управляемого ресурса,
        ///          связанного со всеми файлами с расширением .resx, от которых зависит данный класс. В противном случае,
        ///          конструкторы не смогут правильно работать с локализованными
        ///          ресурсами, сопоставленными данной форме.
        /// </summary>
 
        
        
 
        public ref class Form1 : public System::Windows::Forms::Form
        {
                static int Second = 0;
                static int Minute = 0;
        String^ Sec;
 
 
        private: System::Windows::Forms::SaveFileDialog^  saveFileDialog1;
        private: System::Windows::Forms::RichTextBox^  richTextBox1;
        private: System::Windows::Forms::Button^  button7;
        private: System::Windows::Forms::ListBox^  listBox1;
                         String^ Min;
 
 
 
        public:
                Form1(void)
                {
                        InitializeComponent();
                        //
                        //TODO: добавьте код конструктора
                        //
                }
 
        protected:
                /// <summary>
                /// Освободить все используемые ресурсы.
                /// </summary>
                ~Form1()
                {
                        if (components)
                        {
                                delete components;
                        }
                }
        private: System::Windows::Forms::Button^  button1;
        private: System::Windows::Forms::Button^  button2;
        private: System::Windows::Forms::Button^  button3;
        private: System::Windows::Forms::Button^  button4;
        private: System::Windows::Forms::Button^  button5;
        private: System::Windows::Forms::Button^  button6;
 
 
 
 
        private: System::Windows::Forms::Timer^  timer;
        private: System::Windows::Forms::Label^  Time;
        private: System::ComponentModel::IContainer^  components;
 
    protected:
 
        private:
                /// <summary>
                /// Требуется переменная конструктора.
                /// </summary>
 
 
#pragma region Windows Form Designer generated code
                /// <summary>
                /// Обязательный метод для поддержки конструктора - не изменяйте
                /// содержимое данного метода при помощи редактора кода.
                /// </summary>
                void InitializeComponent(void)
                {
                        this->components = (gcnew System::ComponentModel::Container());
                        System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
                        this->button1 = (gcnew System::Windows::Forms::Button());
                        this->button2 = (gcnew System::Windows::Forms::Button());
                        this->button3 = (gcnew System::Windows::Forms::Button());
                        this->button4 = (gcnew System::Windows::Forms::Button());
                        this->button5 = (gcnew System::Windows::Forms::Button());
                        this->button6 = (gcnew System::Windows::Forms::Button());
                        this->timer = (gcnew System::Windows::Forms::Timer(this->components));
                        this->Time = (gcnew System::Windows::Forms::Label());
                        this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
                        this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
                        this->button7 = (gcnew System::Windows::Forms::Button());
                        this->listBox1 = (gcnew System::Windows::Forms::ListBox());
                        this->SuspendLayout();
                        // 
                        // button1
                        // 
                        this->button1->Location = System::Drawing::Point(751, 60);
                        this->button1->Name = L"button1";
                        this->button1->Size = System::Drawing::Size(75, 23);
                        this->button1->TabIndex = 0;
                        this->button1->Text = L"Общий";
                        this->button1->UseVisualStyleBackColor = true;
                        this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
                        // 
                        // button2
                        // 
                        this->button2->Location = System::Drawing::Point(751, 118);
                        this->button2->Name = L"button2";
                        this->button2->Size = System::Drawing::Size(75, 23);
                        this->button2->TabIndex = 1;
                        this->button2->Text = L"Детальный";
                        this->button2->UseVisualStyleBackColor = true;
                        this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
                        // 
                        // button3
                        // 
                        this->button3->Location = System::Drawing::Point(846, 60);
                        this->button3->Name = L"button3";
                        this->button3->Size = System::Drawing::Size(75, 23);
                        this->button3->TabIndex = 2;
                        this->button3->Text = L"Форма3";
                        this->button3->UseVisualStyleBackColor = true;
                        this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
                        // 
                        // button4
                        // 
                        this->button4->Location = System::Drawing::Point(846, 118);
                        this->button4->Name = L"button4";
                        this->button4->Size = System::Drawing::Size(75, 23);
                        this->button4->TabIndex = 3;
                        this->button4->Text = L"Форма4";
                        this->button4->UseVisualStyleBackColor = true;
                        this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
                        // 
                        // button5
                        // 
                        this->button5->Location = System::Drawing::Point(751, 439);
                        this->button5->Name = L"button5";
                        this->button5->Size = System::Drawing::Size(75, 23);
                        this->button5->TabIndex = 4;
                        this->button5->Text = L"Сохранить";
                        this->button5->UseVisualStyleBackColor = true;
                        this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
                        // 
                        // button6
                        // 
                        this->button6->Location = System::Drawing::Point(846, 439);
                        this->button6->Name = L"button6";
                        this->button6->Size = System::Drawing::Size(75, 23);
                        this->button6->TabIndex = 5;
                        this->button6->Text = L"Закрыть";
                        this->button6->UseVisualStyleBackColor = true;
                        this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
                        // 
                        // timer
                        // 
                        this->timer->Enabled = true;
                        this->timer->Interval = 1000;
                        this->timer->Tick += gcnew System::EventHandler(this, &Form1::timer_Tick);
                        // 
                        // Time
                        // 
                        this->Time->AutoSize = true;
                        this->Time->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                                static_cast<System::Byte>(204)));
                        this->Time->Location = System::Drawing::Point(842, 22);
                        this->Time->Name = L"Time";
                        this->Time->Size = System::Drawing::Size(31, 20);
                        this->Time->TabIndex = 6;
                        this->Time->Text = L"0:0";
                        this->Time->TextAlign = System::Drawing::ContentAlignment::TopCenter;
                        // 
                        // saveFileDialog1
                        // 
                        this->saveFileDialog1->CheckPathExists = false;
                        this->saveFileDialog1->DefaultExt = L"txt";
                        this->saveFileDialog1->FileName = L"mynew.txt";
                        this->saveFileDialog1->InitialDirectory = L"c:\\";
                        this->saveFileDialog1->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::saveFileDialog1_FileOk);
                        // 
                        // richTextBox1
                        // 
                        this->richTextBox1->Location = System::Drawing::Point(751, 178);
                        this->richTextBox1->Name = L"richTextBox1";
                        this->richTextBox1->Size = System::Drawing::Size(170, 217);
                        this->richTextBox1->TabIndex = 8;
                        this->richTextBox1->Text = L"гормоны роста\nжидкости тела";
                        // 
                        // button7
                        // 
                        this->button7->Location = System::Drawing::Point(620, 439);
                        this->button7->Name = L"button7";
                        this->button7->Size = System::Drawing::Size(75, 23);
                        this->button7->TabIndex = 9;
                        this->button7->Text = L"button7";
                        this->button7->UseVisualStyleBackColor = true;
                        this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
                        // 
                        // listBox1
                        // 
                        this->listBox1->FormattingEnabled = true;
                        this->listBox1->Location = System::Drawing::Point(551, 255);
                        this->listBox1->Name = L"listBox1";
                        this->listBox1->Size = System::Drawing::Size(120, 95);
                        this->listBox1->TabIndex = 10;
                        this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::listBox1_SelectedIndexChanged);
                        // 
                        // Form1
                        // 
                        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                        this->ClientSize = System::Drawing::Size(954, 500);
                        this->Controls->Add(this->listBox1);
                        this->Controls->Add(this->button7);
                        this->Controls->Add(this->richTextBox1);
                        this->Controls->Add(this->Time);
                        this->Controls->Add(this->button6);
                        this->Controls->Add(this->button5);
                        this->Controls->Add(this->button4);
                        this->Controls->Add(this->button3);
                        this->Controls->Add(this->button2);
                        this->Controls->Add(this->button1);
                        this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
                        this->Name = L"Form1";
                        this->Text = L"Form1";
                        this->ResumeLayout(false);
                        this->PerformLayout();
 
                }
#pragma endregion
        
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
                 {
 
                                /* double pi=3.14159265358979;
                                 double x[360*3+1];
                                 double y[360*3+1];
                                 float x1, y1, x2, y2;
                                 double x0=0; 
                                 //double y0=200;
                                 double y0=this->Height/2;
                                 double Mx=20;
                                 double My=100;
                                 
 
                                 Color ^col=gcnew Color();
                                 Pen ^pen=gcnew Pen(col->Red);
                                //pen->Width=5;
                                 pen->DashStyle=System::Drawing::Drawing2D::DashStyle::Dash; //DashDotDot;
 
                                
                                 Graphics ^im=this->CreateGraphics();
                                 im->Clear(col->White);
                                 //Вычисляем
                                 for (int i=0; i<=360*3+1; i++)
                                        {                                               
                                                x[i]=i/180.0*pi;
                                                y[i]=1.0*sin(x[i])+1.0*sin(2*x[i]);
                                        }
                                 //Строим график
                                 for (int i=0; i<=360*3; i++)
                                        {                                               
                                                x1=x0+Mx*x[i];
                                                y1=y0-My*y[i];
                                                x2=x0+Mx*x[i+1];
                                                y2=y0-My*y[i+1];
                                                im->DrawLine(pen, x1, y1, x2, y2);*/
                 }
 
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e)
                 {
                        /*Color ^col = gcnew Color();
                        Pen ^pen = gcnew Pen (col->Red);
                        Graphics ^im = this->CreateGraphics();
                        im->Clear(col->White);
                        float x1,y1,x2,y2;
                        x1=0; y1=0;
                        x2=x1;
                        while(x2<this->Width && y2<this->Height)
                        {
                                x2+=5;
                                y2=fs(x2)* 100;
                                if(y2<0) y2*=-1;
                                im->DrawLine(pen,x1,y1,x2,y2);
                                x1=x2; y1=y2;
                                continue;*/
 
                 }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) 
                 {
                         Form3 ^f3 = gcnew Form3();
                         f3->ShowDialog();
 
                 }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e)
                 {
                         Form4 ^f4 = gcnew Form4();
                         f4->ShowDialog();
                 }
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) 
                 {
                         this->saveFileDialog1->CreatePrompt=true;
                         this->saveFileDialog1->ShowDialog();
                 }
 
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e)
                 {
                         Close ();
                 }
 
private: System::Void timer_Tick(System::Object^  sender, System::EventArgs^  e) {
 
                          Second++;
                         if(Second == 60)
                         {
                                 Second = 0;
                                 Minute++;
                         }
 
                         Sec = Convert::ToString(Second);
                         Min = Convert::ToString(Minute);
                         Time->Text = Min + ":" + Sec;
 
                 }
private: System::Void saveFileDialog1_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) 
                 {
                 System::IO::File::WriteAllText ( this->saveFileDialog1->FileName, this->richTextBox1->Text);
                 }
 
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) 
                 {
                        Random ^ rnd = gcnew Random;
                         listBox1->Text = rnd->Next().ToString();
                        }
};
}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.