Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un numar binar, in numar zecimal. Acest program are 4 numericupdown-uri (A, B, C, D). A fiind cel mai semnificativ bit (MSB), iar D fiind cel mai putin semnificativ bit. Are 2 butoane (Ruleaza, Reset). Butonul Ruleaza are pus ca event la click o functie care va afisa numarul format din cei 4 biti de intrare. Butonul Reset seteaza biti de intrare pe 0, resetand astfel programul. Rezultatul este afisat intr-un text box. Am adaugat pe mijloc si un PictureBox care ne arata schema logica a convertorului; Printscreen:
Codul Sursa: #pragma once namespace alinrosusem2 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> / Summary for Form1 / / WARNING: If you change the name of this class, you will need to change the / 'Resource File Name' property for the managed resource compiler tool / associated with all.resx files this class depends on. Otherwise, / the designers will not be able to interact properly with localized / resources associated with this form. / </summary> public ref class Form1 : public System::Windows::Forms::Form public: Form1(void) InitializeComponent(); TODO: Add the constructor code here protected: / <summary> / Clean up any resources being used. / </summary> ~Form1() if (components) delete components; private: System::Windows::Forms::Button^ button1; protected: private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::TextBox^ textbox1;
private: System::Windows::Forms::NumericUpDown^ numericupdown1; private: System::Windows::Forms::NumericUpDown^ numericupdown2; private: System::Windows::Forms::PictureBox^ picturebox1; private: System::Windows::Forms::NumericUpDown^ numericupdown3; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::Label^ label4; private: System::Windows::Forms::NumericUpDown^ numericupdown4; private: System::Windows::Forms::Label^ label5; private: System::Windows::Forms::Label^ label6; private: / <summary> / Required designer variable. / </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / </summary> void InitializeComponent(void) 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->label1 = (gcnew this->textbox1 = (gcnew System::Windows::Forms::TextBox()); this->numericupdown1 = (gcnew System::Windows::Forms::NumericUpDown()); this->numericupdown2 = (gcnew System::Windows::Forms::NumericUpDown()); this->picturebox1 = (gcnew System::Windows::Forms::PictureBox()); this->numericupdown3 = (gcnew System::Windows::Forms::NumericUpDown()); this->label2 = (gcnew this->label3 = (gcnew this->label4 = (gcnew this->numericupdown4 = (gcnew System::Windows::Forms::NumericUpDown()); this->label5 = (gcnew this->label6 = (gcnew
>(this->numericupdown1))->begininit(); >(this->numericupdown2))->begininit(); >(this->picturebox1))->begininit(); >(this->numericupdown3))->begininit(); >(this->numericupdown4))->begininit(); this->suspendlayout(); button1 this->button1->location = System::Drawing::Point(26, 212); this->button1->name = L"button1"; this->button1->size = System::Drawing::Size(75, 23); this->button1->tabindex = 0; this->button1->text = L"Ruleaza"; this->button1->usevisualstylebackcolor = true; this->button1->click += gcnew System::EventHandler(this, &Form1::button1_Click); button2 this->button2->location = System::Drawing::Point(26, 252); this->button2->name = L"button2"; this->button2->size = System::Drawing::Size(75, 23); this->button2->tabindex = 1; this->button2->text = L"Reset"; this->button2->usevisualstylebackcolor = true; this->button2->click += gcnew System::EventHandler(this, &Form1::button2_Click); label1 this->label1->autosize = true; this->label1->location = System::Drawing::Point(639, 116); this->label1->name = L"label1"; this->label1->size = System::Drawing::Size(46, 13); this->label1->tabindex = 2; this->label1->text = L"Rezultat"; textbox1 >Location = System::Drawing::Point(627, 132); >Name = L"textBox1";
>Size = System::Drawing::Size(100, 20); >TabIndex = 4; numericupdown1 this->numericupdown1->location = System::Drawing::Point(26, 28); this->numericupdown1->name = L"numericUpDown1"; this->numericupdown1->size = System::Drawing::Size(120, 20); this->numericupdown1->tabindex = 6; numericupdown2 this->numericupdown2->location = System::Drawing::Point(26, 70); this->numericupdown2->name = L"numericUpDown2"; this->numericupdown2->size = System::Drawing::Size(120, 20); this->numericupdown2->tabindex = 7; picturebox1 this->picturebox1->backgroundimage = (cli::safe_cast<system::drawing::image^ >(resources- >GetObject(L"pictureBox1.BackgroundImage"))); this->picturebox1->location = System::Drawing::Point(143, 24); this->picturebox1->name = L"pictureBox1"; this->picturebox1->size = System::Drawing::Size(490, 247); this->picturebox1->tabindex = 8; this->picturebox1->tabstop = false; numericupdown3 this->numericupdown3->location = System::Drawing::Point(26, 109); this->numericupdown3->name = L"numericUpDown3"; this->numericupdown3->size = System::Drawing::Size(120, 20); this->numericupdown3->tabindex = 9; label2 this->label2->autosize = true; this->label2->location = System::Drawing::Point(23, 9); this->label2->name = L"label2"; this->label2->size = System::Drawing::Size(46, 13); this->label2->tabindex = 10; this->label2->text = L"A (MSB)"; label3 this->label3->autosize = true;
this->label3->location = System::Drawing::Point(23, 54); this->label3->name = L"label3"; this->label3->size = System::Drawing::Size(14, 13); this->label3->tabindex = 11; this->label3->text = L"B"; label4 this->label4->autosize = true; this->label4->location = System::Drawing::Point(23, 93); this->label4->name = L"label4"; this->label4->size = System::Drawing::Size(14, 13); this->label4->tabindex = 12; this->label4->text = L"C"; this->label4->click += gcnew System::EventHandler(this, &Form1::label4_Click); numericupdown4 this->numericupdown4->location = System::Drawing::Point(26, 147); this->numericupdown4->name = L"numericUpDown4"; this->numericupdown4->size = System::Drawing::Size(120, 20); this->numericupdown4->tabindex = 13; label5 this->label5->autosize = true; this->label5->location = System::Drawing::Point(23, 132); this->label5->name = L"label5"; this->label5->size = System::Drawing::Size(44, 13); this->label5->tabindex = 14; this->label5->text = L"D (LSB)"; label6 this->label6->autosize = true; this->label6->location = System::Drawing::Point(140, 8); this->label6->name = L"label6"; this->label6->size = System::Drawing::Size(132, 13); this->label6->tabindex = 15; this->label6->text = L"Convertor Binar -> Zecimal"; Form1 this->autoscaledimensions = System::Drawing::SizeF(6, 13); this->autoscalemode = System::Windows::Forms::AutoScaleMode::Font; this->clientsize = System::Drawing::Size(729, 312); this->controls->add(this->label6); this->controls->add(this->label5);
this->controls->add(this->numericupdown4); this->controls->add(this->label4); this->controls->add(this->label3); this->controls->add(this->label2); this->controls->add(this->numericupdown3); this->controls->add(this->numericupdown2); this->controls->add(this->numericupdown1); this->controls->add(this->textbox1); this->controls->add(this->label1); this->controls->add(this->button2); this->controls->add(this->button1); this->controls->add(this->picturebox1); this->name = L"Form1"; this->text = L"Convertor Binar -> Zecimal"; this->load += gcnew System::EventHandler(this, &Form1::Form1_Load); >(this->numericupdown1))->endinit(); >(this->numericupdown2))->endinit(); >(this->picturebox1))->endinit(); >(this->numericupdown3))->endinit(); >(this->numericupdown4))->endinit(); this->resumelayout(false); this->performlayout(); void functie(void) >numericupdown2->value==0)&&(this->numericupdown3->value==0)&&(this- >Text=System::Convert::ToString("0"); >numericupdown2->value==0)&&(this->numericupdown3->value==0)&&(this- >Text=System::Convert::ToString("1"); >numericupdown2->value==0)&&(this->numericupdown3->value==1)&&(this-
>Text=System::Convert::ToString("2"); >numericupdown2->value==0)&&(this->numericupdown3->value==1)&&(this- >Text=System::Convert::ToString("3"); >numericupdown2->value==1)&&(this->numericupdown3->value==0)&&(this- >Text=System::Convert::ToString("4"); >numericupdown2->value==1)&&(this->numericupdown3->value==0)&&(this- >Text=System::Convert::ToString("5"); >numericupdown2->value==1)&&(this->numericupdown3->value==1)&&(this- >Text=System::Convert::ToString("6"); >numericupdown2->value==1)&&(this->numericupdown3->value==1)&&(this- >Text=System::Convert::ToString("7"); >numericupdown2->value==0)&&(this->numericupdown3->value==0)&&(this- >Text=System::Convert::ToString("8"); >numericupdown2->value==0)&&(this->numericupdown3->value==0)&&(this-
>Text=System::Convert::ToString("9"); >numericupdown2->value==0)&&(this->numericupdown3->value==1)&&(this- >Text=System::Convert::ToString("10"); >numericupdown2->value==0)&&(this->numericupdown3->value==1)&&(this- >Text=System::Convert::ToString("11"); >numericupdown2->value==1)&&(this->numericupdown3->value==0)&&(this- >Text=System::Convert::ToString("12"); >numericupdown2->value==1)&&(this->numericupdown3->value==0)&&(this- >Text=System::Convert::ToString("13"); >numericupdown2->value==1)&&(this->numericupdown3->value==1)&&(this- >Text=System::Convert::ToString("14"); >numericupdown2->value==1)&&(this->numericupdown3->value==1)&&(this- >Text=System::Convert::ToString("15"); #pragma endregion private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) functie(); private: System::Void button2_click(system::object^ sender, System::EventArgs^ e) this->numericupdown1->value=0; this->numericupdown2->value=0; this->numericupdown3->value=0; this->numericupdown4->value=0; functie(); private: System::Void label4_click(system::object^ sender, System::EventArgs^ e) ;