Program.
cs Source Code:-
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace Assignment01
{
class Program
{
public static int Menu_Selection_Validation()
{
string user_input = [Link];
bool loop_flag = false;
while (loop_flag == false)
{
[Link]("1 = Get Rectangle Length");
[Link]("2 = Change Rectangle Length");
[Link]("3 = Get Rectangle Width");
[Link]("4 = Change Rectangle Width");
[Link]("5 = Get Rectangle Perimeter");
[Link]("6 = Get Rectangle Area");
[Link]("7 = Exit\n");
[Link]("Please select an option from 1 to 7, by entering a
number:\n");
user_input = [Link]();
if (user_input != "1" &&
user_input != "2" &&
user_input != "3" &&
user_input != "4" &&
user_input != "5" &&
user_input != "6" &&
user_input != "7")
{
[Link]("That's not a valid menu option, please try
again:\n");
}
else
{
loop_flag = true;
}
}
[Link]();
return [Link](user_input);
}
public static int User_Input_Validation(string selected_option)
{
int aNumber = 1;
bool isValid = false;
while (isValid == false)
{
[Link]($"Please enter the {selected_option}:");
string user_input = [Link]();
[Link]();
bool result = ([Link](user_input, out aNumber) );
if (result == false)
{
[Link]("That's not a valid input please, please try again
with a positive integer values.\n");
}
else if (aNumber <= 0 )
{
[Link]("Please Enter The values above 0, as the length and
width cannot be zero.\n");
}
else if(aNumber > 32767)
{
[Link]("Please Enter The values below 32767 as it is the
maximum integer range.\n");
}
else
{
isValid = true;
[Link]($"Your {selected_option} has been changed to:
{aNumber}.\n");
}
}
return aNumber;
}
static void Main(string[] args)
{
Rectangle r = new Rectangle();
bool valid_initial_Selection = false;
string initial_Selection;
int selection;
while (valid_initial_Selection == false)
{
[Link]("1 = Start with Default values of Length = 1 and Width
= 1\n");
[Link]("2 = Provide Custom Length and Width\n");
[Link]("Choose a menu item to begin:");
initial_Selection = [Link]();
[Link]();
if (initial_Selection != "1" && initial_Selection != "2")
{
[Link]("That's not a valid selection, please try
again.\n");
}
else if ([Link](initial_Selection) == 1)
{
valid_initial_Selection = true;
int length = 1;
int width = 1;
[Link]($"You are selected length = {length} and width =
{width}.\n");
Rectangle default_inputs = new Rectangle(length, width);
r = default_inputs;
}
else if ([Link](initial_Selection) == 2)
{
valid_initial_Selection = true;
int length;
int width;
length = User_Input_Validation("length");
width = User_Input_Validation("width");
[Link]("You provided Length = {0} and Width = {1}.\n",
length, width);
Rectangle default_inputs = new Rectangle(length, width);
r = default_inputs;
}
}
selection = Menu_Selection_Validation();
while (selection != 7)
{
int result;
switch (selection)
{
case 1:
[Link]("Length of Rectangle is: {0}\n",
[Link]());
break;
case 2:
result = User_Input_Validation("length");
[Link](result);
break;
case 3:
[Link]("width of Rectangle is: {0}\n", [Link]());
break;
case 4:
result = User_Input_Validation("width");
[Link](result);
break;
case 5:
[Link]("Perimeter of Rectangle of Lenght: {0} and
width: {1} is: {2}\n", [Link](), [Link](), [Link]());
break;
case 6:
[Link]("Area of Rectangle of Lenght: {0} and width:
{1} is: {2}\n", [Link](), [Link](), [Link]());
break;
default:
break;
}
selection = Menu_Selection_Validation();
}
}
}