Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 for MyForm

///

public ref class MyForm : public System::Windows::Forms::Form

{

public:

MyForm(void)

{

InitializeComponent();

//

//TODO: Add the constructor code here

//

}

protected:

///

/// Clean up any resources being used.

///

~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:

///

/// Required designer variable.

///

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///

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<: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

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 120

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago