In this assignment you will write a program that provides th
In this assignment, you will write a program that provides the following features:
The program will provide an interface that includes the following:
A factorial button
A recursion log (the multiline text box on the right of the interface)
The program should perform the following functions:
User can enter an integer from 1 to 10.
When the user clicks the Factorial button, the program should compute and display the integer\'s factorial.
The recursion log should display a message indicating when each recursive call was made.
The interface should also indicate when the base case is reached, and it should list all values returned.
Save the program as Factional.cpp
Have the factorial part but can\'t make the code for the list box (multiline text box with scroll bar)
#pragma once
namespace Factional {
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 MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
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)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(89, 118);
this->textBox1->Name = L\"textBox1\";
this->textBox1->Size = System::Drawing::Size(137, 27);
this->textBox1->TabIndex = 0;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(89, 311);
this->textBox2->Name = L\"textBox2\";
this->textBox2->Size = System::Drawing::Size(137, 27);
this->textBox2->TabIndex = 1;
//
// button1
//
this->button1->Location = System::Drawing::Point(89, 196);
this->button1->Name = L\"button1\";
this->button1->Size = System::Drawing::Size(137, 43);
this->button1->TabIndex = 2;
this->button1->Text = L\"Factorial\";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(333, 118);
this->textBox3->Multiline = true;
this->textBox3->Name = L\"textBox3\";
this->textBox3->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
this->textBox3->Size = System::Drawing::Size(204, 284);
this->textBox3->TabIndex = 3;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(89, 80);
this->label1->Name = L\"label1\";
this->label1->Size = System::Drawing::Size(201, 20);
this->label1->TabIndex = 4;
this->label1->Text = L\"Enter an Integer (1-10)\";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(89, 268);
this->label2->Name = L\"label2\";
this->label2->Size = System::Drawing::Size(143, 20);
this->label2->TabIndex = 5;
this->label2->Text = L\"Factorial Result\";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(329, 80);
this->label3->Name = L\"label3\";
this->label3->Size = System::Drawing::Size(131, 20);
this->label3->TabIndex = 6;
this->label3->Text = L\"Recursion Log\";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(11, 20);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(603, 445);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Font = (gcnew System::Drawing::Font(L\"Microsoft Sans Serif\", 10.2F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->Name = L\"MyForm\";
this->Text = L\"Factorial Numbers\";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int n;
int nFact = 1;
int32::TryParse(txtNum->Text, n)
if (n > 0) {
for (int i = 1; i < <= n; i++)
nFact *= i;
txtFact->Text = nFact.ToString();
}
else
MessageBox::Show(\"Please enter a value > 0\");
}
}
};
}
a Factorial Numbers Enter an integer (1-100 Recursion Log 5 Recursion Log RECURSION RECURSION RECURSION RECURSION Factorial BASE CASE retum 1 retum 2 retum 6 Factorial result retum 24 120 retum 120Solution
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public List<string> log = new List<string>();
public static int factor = 1;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int fact;
if (textBox1.Text != string.Empty)
{
if (Convert.ToInt32(textBox1.Text) < 10)
{
log.Add(\"Recursion Log\");
fact = Factorial(Convert.ToInt32(textBox1.Text));
textBox2.Text = fact.ToString();
listBox1.DataSource = log;
}
else
{
MessageBox.Show(\"Enter Number Between 1-10\");
}
}
else
{
MessageBox.Show(\"Please Enter Number\");
}
}
public int Factorial(int number)
{
if (number == 0)
{
return 1;
}
// Add Recursion When Untill The Number Not Equal To 0
log.Add(\"Recursion\");
factor = number * Factorial(number - 1);
// Add Return After Recursion Completion
log.Add(\"return \" + factor.ToString());
return factor;
}
}
}






