?? floatvar.cpp
字號:
//這個程序在本書所帶軟盤中,文件名為FLOATVAR.CPP
//本程序列舉了一些對浮點變量進行定義和浮點常量的應用的例子
#include <iostream.h>
#include <conio.h> //這個頭文件支持系統清屏子程序 clscr()
float tax_rate; //用float定義一個名為tax_rate的浮點變量
float price, tax, amount, total; //定義四個浮點變量,使用逗號將各變量分開
int units; //定義一個整型變量
float PI = 3.1415926; //定義一個浮點變量PI并給它賦值
float radius, circle_area, length, height, rec_area;
void main( )
{
clrscr( ); //清屏
//以下計算購物費用
tax_rate = 0.065;
price = 1.99;
units = 10;
amount = price * units;
tax = amount * tax_rate;
total = amount + tax;
//以下計算圓的面積
radius = 8.9E3;
circle_area = PI * radius * radius;
//以下計算長方形面積
length = 1.2E-3, height = 2.5E-2;
rec_area = length * height;
//以下輸出購物費用
cout << "購物費用計算結果" << endl;
cout << "價格:" << price << endl;
cout << "數量:" << units << endl;
cout << "金額:" << amount << endl;
cout << "稅額:" << tax << endl;
cout << "總金額:" << total << endl << endl;
//以下輸出圓的面積
cout << "圓面積計算結果" << endl;
cout << "半徑:" << radius << endl;
cout << "面積:" << circle_area << endl << endl;
//以下輸出長方形面積
cout << "長方形面積計算結果" << endl;
cout << "長:" << length << " 高:" << height << endl;
cout << "面積:" << rec_area << endl;
} //程序結束
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -