حل السؤال
حل السؤال 47
import 'dart:io';
void main() {
print("-----------MENU-----------");
print("(D or d) Circle.");
print("(R or r) Rectangle.");
print("(S or s) Square.");
print("(T or t) Triangle.");
stdout.write("Your choice = ");
String choice = stdin.readLineSync()!.toUpperCase();
switch (choice) {
case "D":
stdout.write("Enter the radius of the circle: ");
double radius = double.parse(stdin.readLineSync()!);
if (!radius.isFinite || radius <= 0) {
print('Invalid input: a finite positive radius required.');
return;
}
double circleArea = 3.14 * radius * radius;
print("The area of the circle is $circleArea square units.");
break;
case "R":
stdout.write("Enter the length of the rectangle's long side: ");
double long = double.parse(stdin.readLineSync()!);
stdout.write("Enter the length of the rectangle's short side: ");
double short = double.parse(stdin.readLineSync()!);
if (!long.isFinite || long <= 0 || !short.isFinite || short <= 0) {
print('Invalid input: finite positive sides required.');
return;
}
double rectangleArea = long * short;
print("The area of the rectangle is $rectangleArea square units.");
break;
case "S":
stdout.write("Enter the length of one side of the square: ");
double side = double.parse(stdin.readLineSync()!);
if (!side.isFinite || side <= 0) {
print('Invalid input: a finite positive side required.');
return;
}
double squareArea = side * side;
print("The area of the square is $squareArea square units.");
break;
case "T":
stdout.write("Enter the base length of the triangle: ");
double base = double.parse(stdin.readLineSync()!);
stdout.write("Enter the height of the triangle: ");
double height = double.parse(stdin.readLineSync()!);
if (!base.isFinite || base <= 0 || !height.isFinite || height <= 0) {
print('Invalid input: finite positive dimensions required.');
return;
}
double triangleArea = (base * height) / 2;
print("The area of the triangle is $triangleArea square units.");
break;
default:
print("Invalid choice.");
}
}

