tailieunhanh - Ivor Horton’s BeginningVisual C++ 2008 phần 2

Công ty Thông tin dịch vụ web được sử dụng trong các ứng dụng để trình bày tên của công ty cũng như giá cả các thông tin hiện nay. Bây giờ cần phải có một phương pháp gọi là GetCompanyInfo mà chúng ta viết mã để sử dụng một vài trong số các thuộc tính để lấy dữ liệu công ty thực tế. | Chapter 2 Data Variables and Calculations That gives you enough of a toehold in output to continue with more C CLI examples. Now you ll take a quick look at some of this in action. Try It Out Formatted Output Here s an example that calculates the price of a carpet in order to demonstrate output in a CLR console program main project file. Calculating the price of a carpet include using namespace System int main array System String A Aargs double carpetPriceSqYd double roomwidth In feet double roomLength In feet const int feetPerYard 3 double roomWidthYds roomWidth feetPerYard double roomLengthYds roomLength feetPerYard double carpetPrice roomWidthYds roomLengthYds carpetPriceSqYd Console WriteLine L Room size is 0 F2 yards by 1 F2 yards roomLengthYds roomWidthYds Console WriteLine L Room area is 0 F2 square yards roomLengthYds roomWidthYds Console WriteLine L Carpet price is 0 F2 carpetPrice return 0 The output should be Room size is yards by yards Room area is square yards Carpet price is How It Works The dimensions of the room are specified in feet whereas the carpet is priced per square yard so you have defined a constant feetPerYard to use in the conversion from feet to yards. In the expression to convert each dimension you are dividing a value of type double by a value of type int. The compiler will insert code to convert the value of type int to type double before carrying out the multiplication. After converting the room dimensions to yards you calculate the price of the carpet by multiplying the dimensions in yards to obtain the area in square yards and multiplying that by the price per square yard. The output statements use the F2 format specification to limit the output values to two decimal places. Without this there would be more decimal places in the output that would be inappropriate especially for the price. You could try removing the format specification to see the difference. 105 Chapter 2

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.