page168

// page168.cpp : 定义控制台应用程序的入口点。
//C++面向对象程序设计

// 判断圆形皮萨和矩形皮萨,哪一种更适合购买


#include "stdafx.h"
#include <iostream>

double unitprice(int diameter , double price );
//返回圆形皮萨每平方英寸的价格。形参的啊meter是以英寸为单位的皮萨直径,形参price是皮萨的价格

double unitprice(int length , int width , double price );
//返回矩形皮萨每平方英寸的价格
//皮萨的长度和宽度分别是length英寸和width英寸
//形参price是皮萨的价格

int _tmain(int argc, _TCHAR* argv[])
{
 using namespace std ;
 int diameter, length ,width;
 double price_round ,unit_price_round,
  price_rectangular , unitprice_rectangular ;

 cout << " Welcome to the Pizza Consumers Union.\n";
 cout << " Enter the diameter in inches"
  << " of a round pizza : ";
 cin >> diameter;
 cout << " Enter the price of a round Pizza :$";
 cin >> price_round;
 cout << " Enter length and width in inches\n"
  << " of a rectangual pizza :";
 cin >> length >> width ;
 cout << " Enter the price of a rectangular pizza :$ ";
 cin >> price_rectangular;

 
 unitprice_rectangular = unitprice( length ,  width , price_rectangular  );
 unit_price_round =  unitprice( diameter ,  price_round );
 
 cout.setf(ios::fixed);
 cout.setf(ios::showpoint);
 cout.precision(2);
 cout << endl
  << " Round pizzza : length = "
  << diameter << " inches\n"
  << " Price = $ " << price_round
  << " per squre inch = $" << unit_price_round
  << endl
  << " Rectanguarl pizza : length = "
  << length << " inches\n"
  << " Rectanguarl pizza : width = "
  << width << " inches\n"
  << " price = $ " << price_rectangular
  << " per square inch = $" << unitprice_rectangular
  << " per square inch = $ " << unitprice_rectangular
  << endl;

 if (unit_price_round < unitprice_rectangular)
 {
  cout << " The round one is the better buy .\n"; 
 }
 else
  cout << " The rectangular one is the better buy .\n";
 cout << " Buon Appetito!\n";

 cin >> diameter;
 return 0;
}

double unitprice(int diameter , double price )
{
 const double PI = 3.1415;
 double radius , area;

 radius = diameter / static_cast<double>(2);
 area = PI * radius * radius ;
 return (price / area);
}


double unitprice(int length , int width , double price )
{
 double area = length * width ;
 return (price / area);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值