مشخصات مقاله
-
2775
-
0.0
-
6273
-
0
-
0
قالب بندی تاریخ و زمان (Custom Date and Time) در سی شارپ
همانند هر داده دیگری، لازم است تا بتوان مقادیر مربوط با تاریخ و زمان را نیز در ساختارها و قالب های گوناگون و دلخواه نمایش داد. در این مقاله به چگونگی انجام این امر خواهیم پرداخت.
- برای تنظیم قالب بندی زمان و تاریخ، فایل را به صورت زیر اصلاح کنید.
using System;
public class OrderProcessing
{
public static int Main()
{
// Price of items
const double PriceOneShirt = 0.95;
const double PriceAPairOfPants = 2.95;
const double PriceOneDress = 4.55;
const double TaxRate = 0.0575; // 5.75%
// Basic information about an order
string customerName, homePhone;
DateTime orderDate, orderTime;
// Unsigned numbers to represent cleaning items
uint numberOfShirts, numberOfPants, numberOfDresses;
// Each of these sub totals will be used for cleaning items
double subTotalShirts, subTotalPants, subTotalDresses;
// Values used to process an order
double totalOrder, taxAmount, salesTotal;
double amountTended, moneyChange;
Console.Title = "Georgetown Dry Cleaning Services";
Console.WriteLine("-/- Georgetown Dry Cleaning Services -/-");
// Request order information from the user
Console.Write("Enter Customer Name: ");
customerName = Console.ReadLine();
Console.Write("Enter Customer Phone: ");
homePhone = Console.ReadLine();
Console.Write("Enter the order date(mm/dd/yyyy): ");
orderDate = DateTime.Parse(Console.ReadLine());
Console.Write("Enter the order time(hh:mm AM/PM): ");
orderTime = DateTime.Parse(Console.ReadLine());
// Request the quantity of each category of items
Console.Write("Number of Shirts: ");
numberOfShirts = uint.Parse(Console.ReadLine());
Console.Write("Number of Pants: ");
numberOfPants = uint.Parse(Console.ReadLine());
Console.Write("Number of Dresses: ");
numberOfDresses = uint.Parse(Console.ReadLine());
// Perform the necessary calculations
subTotalShirts = numberOfShirts * PriceOneShirt;
subTotalPants = numberOfPants * PriceAPairOfPants;
subTotalDresses = numberOfDresses * PriceOneDress;
// Calculate the "temporary" total of the order
totalOrder = subTotalShirts +
subTotalPants +
subTotalDresses;
// Calculate the tax amount using a constant rate
taxAmount = totalOrder * TaxRate;
// Add the tax amount to the total order
salesTotal = totalOrder + taxAmount;
// Communicate the total to the user...
Console.WriteLine("\nThe Total order is: {0:C}",
salesTotal);
// and request money for the order
Console.Write("Amount Tended? ");
amountTended = double.Parse(Console.ReadLine());
// Calculate the difference owed to the customer
// or that the customer still owes to the store
moneyChange = amountTended - salesTotal;
Console.Clear();
// Display the receipt
Console.WriteLine("====================================");
Console.WriteLine("-/- Georgetown Dry Cleaning Services -/-");
Console.WriteLine("====================================");
Console.WriteLine("Customer: {0}", customerName);
Console.WriteLine("Home Phone: {0}", homePhone);
Console.WriteLine("Order Date: {0:D}", orderDate);
Console.WriteLine("Order Time: {0:t}", orderTime);
Console.WriteLine("------------------------------------");
Console.WriteLine("Item Type Qty Unit/Price Sub-Total");
Console.WriteLine("------------------------------------");
Console.WriteLine("Shirts {0} {1} {2}",
numberOfShirts.ToString(),
PriceOneShirt.ToString("C"),
subTotalShirts.ToString("C"));
Console.WriteLine("Pants {0} {1} {2}",
numberOfPants.ToString(),
PriceAPairOfPants.ToString("C"),
subTotalPants.ToString("C"));
Console.WriteLine("Dresses {0} {1} {2}",
numberOfDresses.ToString(),
PriceOneDress.ToString("C"),
subTotalDresses.ToString("C"));
Console.WriteLine("------------------------------------");
Console.WriteLine("Total Order: {0}",
totalOrder.ToString("C"));
Console.WriteLine("Tax Rate: {0}",
TaxRate.ToString("P"));
Console.WriteLine("Tax Amount: {0}",
taxAmount.ToString("C"));
Console.WriteLine("Net Price: {0}",
salesTotal.ToString("C"));
Console.WriteLine("------------------------------------");
Console.WriteLine("Amount Tended: {0}",
amountTended.ToString("C"));
Console.WriteLine("Difference: {0}",
moneyChange.ToString("C"));
Console.WriteLine("====================================");
System.Console.ReadKey();
return 0;
}
}
- برنامه را اجرا کنید.
-/- Georgetown Dry Cleaning Services -/- Enter Customer Name: Antoinette Calhoun Enter Customer Phone: (703) 797-1135 Enter the order date(mm/dd/yyyy): 04/12/2002 Enter the order time(hh:mm AM/PM): 2:12 PM Number of Shirts: 5 Number of Pants: 2 Number of Dresses: 1 The Total order is: $16.07 Amount Tended? 20
- اکنون کلید Enter را فشار دهید.
==================================== -/- Georgetown Dry Cleaning Services -/- ==================================== Customer: Antoinette Calhoun Home Phone: (703) 797-1135 Order Date: Friday، April 12، 2002 Order Time: 2:12 PM ------------------------------------ Item Type Qty Unit/Price Sub-Total ------------------------------------ Shirts 5 $0.95 $4.75 Pants 2 $2.95 $5.90 Dresses 1 $4.55 $4.55 ------------------------------------ Total Order: $15.20 Tax Rate: 5.75 % Tax Amount: $0.87 Net Price: $16.07 ------------------------------------ Amount Tended: $20.00 Difference: $3.93 ====================================
- پنجره ی DOS را بسته و به محیط برنامه نویسی برگردید.
- به فهرست اصلی مراجعه کرده، گزینه ی File -> Close Solution را کلیک کنید.
- زمانی که از شما درخواست شد می خواهید Save کنید یا نه روی no کلیک کنید.
1404/01/20
6273
2775
رمز عبور : tahlildadeh.com یا www.tahlildadeh.com