مشخصات مقاله
-
3322
-
0.0
-
13902
-
0
-
0
کار با تاریخ و زمان (date & 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;
// 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.WriteLine("Enter the order date and " + "time (mm/dd/yyyyhh:mm AM/PM)");
orderDate = DateTime.Parse(Console.ReadLine());
// Request the quantity of each category of items
Console.Write("Number of Shirts: ");
string strShirts = Console.ReadLine();
numberOfShirts = uint.Parse(strShirts);
Console.Write("Number of Pants: ");
string strPants = Console.ReadLine();
numberOfPants = uint.Parse(strPants);
Console.Write("Number of Dresses: ");
string strDresses = Console.ReadLine();
numberOfDresses = uint.Parse(strDresses);
// 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.Write("\nThe Total order is: ");
Console.WriteLine(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.Write("Customer: ");
Console.WriteLine(customerName);
Console.Write("Home Phone: ");
Console.WriteLine(homePhone);
Console.Write("Date & Time: ");
Console.WriteLine(orderDate);
Console.WriteLine("------------------------------------");
Console.WriteLine("Item Type Qty Unit/Price Sub-Total");
Console.WriteLine("------------------------------------");
Console.Write("Shirts ");
Console.Write(numberOfShirts);
Console.Write(" ");
Console.Write(PriceOneShirt);
Console.Write(" ");
Console.WriteLine(subTotalShirts);
Console.Write("Pants ");
Console.Write(numberOfPants);
Console.Write(" ");
Console.Write(PriceAPairOfPants);
Console.Write(" ");
Console.WriteLine(subTotalPants);
Console.Write("Dresses ");
Console.Write(numberOfDresses);
Console.Write(" ");
Console.Write(PriceOneDress);
Console.Write(" ");
Console.WriteLine(subTotalDresses);
Console.WriteLine("------------------------------------");
Console.Write("Total Order: ");
Console.WriteLine(totalOrder);
Console.Write("Tax Rate: ");
Console.Write(TaxRate * 100);
Console.WriteLine('%');
Console.Write("Tax Amount: ");
Console.WriteLine(taxAmount);
Console.Write("Net Price: ");
Console.WriteLine(salesTotal);
Console.WriteLine("------------------------------------");
Console.Write("Amount Tended: ");
Console.WriteLine(amountTended);
Console.Write("Difference: ");
Console.WriteLine(moneyChange);
Console.WriteLine("====================================");
System.Console.ReadKey();
return 0;
}
}
- حال برنامه را اجرا کنید . نتیجه ی زیر به دست می آید.
-/- Georgetown Dry Cleaning Services -/- Enter Customer Name: Alexander Pappas Enter Customer Phone: (301) 397-9764 Enter the order date and time (mm/dd/yyyyhh:mm AM/PM) 06/22/98 08:26 AM Number of Shirts: 2 Number of Pants: 6 Number of Dresses: 0 The Total order is: 20.727000 Amount Tended? 50
- کلید Enter را فشار دهید.
=================================== -/- Georgetown Dry Cleaning Services -/- ==================================== Customer: Alexander Pappas Home Phone: (301) 397-9764 Date & Time: 6/22/1998 8:26:00 AM ------------------------------------ Item Type Qty Unit/Price Sub-Total ------------------------------------ Shirts 2 0.95 1.90 Pants 6 2.95 17.70 Dresses 0 4.55 0 ------------------------------------ Total Order: 19.60 Tax Rate: 5.7500% Tax Amount: 1.127000 Net Price: 20.727000 ------------------------------------ Amount Tended: 50 Difference: 29.273000 ====================================
- به محیط برنامه نویسی برگردید.
1404/01/20
13902
3322
رمز عبور : tahlildadeh.com یا www.tahlildadeh.com