The number of lines that can be printed on a paper depends on the paper size, the point size of each character in a line, whether lines are double-spaced or single-spaced, the top and bottom margin, and the left and right margins of the paper. Assume that all characters are of the same point size and all lines are either single-spaced or double spaced. Note that 1 inch = 72 points. Moreover, assume that the lines are printed along with the width of the paper. For example, if the length of the paper is 11 inches and width is 8.5 inches, then the maximum length of a line is 8.5 inches. Write a c# .net program that calculates the number of characters in a line and the number of lines that can be printed on a paper based on the following input from the user:
a. The length and width, in inches of the paper
b. The top, bottom, left, and right margins
c. The point size of a line
d. If the lines are double-spaced, then double the point size of each character
Provide a proper GUI for the user.
using System;
class Program
{
static void Main()
{
Console.Write("Enter width: ");
double width = double.Parse(Console.ReadLine());
Console.Write("Enter length: ");
double length = double.Parse(Console.ReadLine());
Console.Write("Enter top margin: ");
double topMargin = double.Parse(Console.ReadLine());
Console.Write("Enter bottom margin: ");
double botMargin = double.Parse(Console.ReadLine());
Console.Write("Enter left margin: ");
double leftMargin = double.Parse(Console.ReadLine());
Console.Write("Enter right margin: ");
double rightMargin = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the point size of a line: ");
double points = double.Parse(Console.ReadLine());
Console.Write("Is line double-spaced? Y/N: ");
bool isDoubleSpaced = Console.ReadLine().ToUpper().Contains("Y");
var result = Calculate(width, length, topMargin, botMargin, leftMargin, rightMargin, points, isDoubleSpaced);
Console.WriteLine($"Number of characters in a line: {result.Item1}");
Console.WriteLine($"Number of lines: {result.Item2}");
}
public static Tuple<int, int> Calculate(double width, double length, double top, double bot, double left, double right,
double points, bool isDoubleSpaced)
{
var coef = 72 * (isDoubleSpaced ? 0.5 : 1);
return new Tuple<int, int>((int)((width - left - right) * coef / points), (int)((length - top - bot) * coef));
}
}
Comments
Leave a comment