⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program_3_5.cpp

📁 清华关于C++ 的程序讲义 值得一看 关于算法
💻 CPP
字号:
// Program 3.5: Compute the time and cost required to mow
// a lawn
#include <iostream>
#include <string>
#include <rect.h>
using namespace std;
int ApiMain() {
	// Mowing rate in square meters per second
	const float MowRate = 1.0;
	// Pay rate desired
	const float PayRate = 6.0;
	// Seconds in a minute
	const int SecondsPerMinute = 60;
	// Seconds in an hour
	const int SecondsPerHour = SecondsPerMinute * 60;
	// Length and width of display window
	const int DisplayWidth = 20;
	const int DisplayHeight = 20;
	// Scale factor for display. 100 meters equals
	// 1 centimeter
	const float ScaleFactor = 0.01;
	cout << "Please use meters for all input\n" << endl;
	int LawnLength; // Length of the lawn in meters
	cout << "Please enter the length of the lawn: ";
	cin >> LawnLength;
	int LawnWidth; // Width of the lawn in meters
	cout << "Please enter the width of the lawn: ";
	cin >> LawnWidth;
	int HouseLength; // Length of the house in meters
	cout << "Please enter the length of the house: ";
	cin >> HouseLength;
	int HouseWidth; // Width of the house in meters
	cout << "Please enter the width of the house: ";
	cin >> HouseWidth;
	// Echo the input so they can be verified
	cout << endl;
	cout << "Yard size: " << LawnLength << " by "
	<< LawnWidth << " meters" << endl;
	cout << "House size: " << HouseLength << " by "
	<< HouseWidth << " meters" << endl;
	// Compute the mowable area
	int MowableArea =  (LawnLength * LawnWidth)
	- (HouseLength * HouseWidth);
	// Compute the time to cut and display it
	int MowTimeInSeconds = MowableArea / MowRate;
	int Hours = MowTimeInSeconds / SecondsPerHour;
	int Minutes = (MowTimeInSeconds % SecondsPerHour)
	 / SecondsPerMinute;
	cout << "Approximate time to cut: " << Hours
	<< " hour(s) " << Minutes << " minute(s)" << endl;
	// Compute the cost and display it
	float DollarCost = MowTimeInSeconds * PayRate
	/ SecondsPerHour;
	int Dollars = DollarCost;
	int Cents = (DollarCost - Dollars) * 100;
	cout << "Cost to cut: " << Dollars << " dollar(s)"
	<< " and " << Cents << " cent(s)" << endl;
	// Open the windows and display the lawn
	SimpleWindow Display("Lawn and House Plot",
	 DisplayWidth, DisplayHeight);
	Display.Open();
	RectangleShape Lawn(Display, DisplayWidth / 2.0,
	 DisplayHeight / 2.0, Green, LawnLength * ScaleFactor,
	 LawnWidth * ScaleFactor);
	 Lawn.Draw();
	// Display the house
	RectangleShape House(Display, DisplayWidth / 2.0,
	 DisplayHeight /2.0, Yellow, HouseLength * ScaleFactor,
	 HouseWidth * ScaleFactor);
	House.Draw();
	cout << "Type a character followed by a\n"
	 << "return to remove the display and exit" << endl;
	char AnyChar;
	cin >> AnyChar;
	Display.Close();
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -