double a=7.890709;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(4);
cout<<a;
char symbol11,symbol12,symbol13;
cout<<"enter two initials,without any periods\n";
cin>>symbol11>>symbol12;
cout<<"the two initials are:\n";
cout<<symbol11<<symbol12<<endl;
cout<<"one more with a space\n";
symbol13=' ';
cout<<symbol11<<symbol13<<symbol12<<endl;
cout<<"that's all\n";
return 0;
}
int hours;
double gross_pay,rate;
cout<<"ener the hourly rate of pay:$";
cin>>rate;
cout<<"enter the number of hours worked,\n"
<<"rounded to a whole number of hours:";
cin>>hours;
if(hours>40)
{ cout<<"hours beyond 30\n";
gross_pay=rate*40+1.5*rate*(hours-40);}
else{cout<<"hours bellow 30\n";
gross_pay=hours*rate;}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"hours="<<hours<<endl;
cout<<"hourly pay rate=$"<<rate<<endl;
cout<<"gross_pay= $"<<gross_pay<<endl;
return 0;
int count_down;
cout<<"how many greeting do you want?";
cin>>count_down;
while(count_down>0)
{cout<<"hollo ";
count_down-=1;
}
cout<<endl;
cout<<"that's all\n";
return 0;
char ans;
do
{
cout<<"hollo\n";
cout<<"do you want another greeting?\n"
<<"press y for yes,n for no,\n"
<<"and then press return:";
cin>>ans;
}while(ans=='y'||ans=='Y');
cout<<"good bye\n";
return 0;
}
double balance=50.00;
int count=0;
cout<<"this program tell you how long it takes\n"
<<"to accumulate a debt of $100,starting with\n"
<<"an initial balance of $50 owed.\n"
<<"the interest rate is 2% per month.\n";
while(balance<100.00)
{
balance+=0.02*balance;
count++;
}
cout<<"after"<<count<<"month,\n";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"your blance due will be $"<<balance<<endl;
return 0;
//文件名:health.cpp
//作用:在此填写你的姓名
//电子邮件地址:you@yourmatchine
//作业编号:2
//说明:判断用户是否生病的程序
//最后一次修改:2012年1月2
const double normal=98.6;//华氏温度
double temperature;
cout<<"enter your temperature:";
cin>>temperature;
if(temperature>normal)
{
cout<<"you have a fever\n";//你在发烧
cout<<"drink lots of liquits and get a bed.\n";//多喝水,多休息
}
else
{
cout<<"you don't have a fever.\n";//你没有发烧
cout<<"go study.\n";//去上学吧
}
return 0;
double cost_per_sq_ft=10.50;
double budget,area,length_side;
cout<<"enter the amount budgeted for your dog house $:";
cin>>budget;
area=static_cast<int>(budget)/cost_per_sq_ft;//强制类型转换
length_side=sqrt(area);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"for a price of $"<<budget<<endl
<<"I can built a luxurious square dog house\n"
<<"that is"<<length_side
<<"feet on each side.\n";
return 0;
#include<iostream>
using namespace std;
double unitprice(int diameter,double price);
//返回比萨每平方英寸的价格
//形参diameter是以英寸为单位
//的比萨的直径,形参price是比萨的价格
int main()
{
int diameter_small,diameter_large;
double price_small,unitprice_small,price_large,unitprice_large;
cout<<"welcome to the pizza consumers union.\n";
cout<<"enter diameter of a small pizza:";
cin>>diameter_small;
cout<<"enter the price of a small pizza:$";
cin>>price_small;
cout<<"enter diameter of a large pizza:";
cin>>diameter_large;
cout<<"enter the price of a large pizza:$";
cin>>price_large;
unitprice_small=unitprice(diameter_small,price_small);
unitprice_large=unitprice(diameter_large,price_large);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"smalll pizza:\n"
<<"diameter="<<diameter_small<<"inches\n"
<<"price="<<price_small
<<"per square inch=$"<<unitprice_small<<endl
<<"large pizza:\n"
<<"diameter="<<diameter_large<<"inches\n"
<<"price="<<price_large
<<"per square inches=$"<<unitprice_large<<endl;
if(unitprice_large<unitprice_small)
{
cout<<"the large one is the better buy";
}
else
{cout<<"the smll one is the better buy. ";
}
return 0;
}
double unitprice(int diameter,double price)
{
const double pi=3.14159;
double area,radius;
radius=diameter/static_cast<double>(2);
area=radius*radius*pi;
return(price/area);
}
#include<iostream>//计算一块试验田的豌豆的平均收成
using namespace std;
double est_total(int min_peas,int max_peas,int pod_count);
//返回预计收获的豌豆总数
//形参pod-count是豆荚数
//形参min-peas和max-peas是每个豆荚中最少和最多豌豆数
int main()
{
int max,min,pod_count;
double yield,average_pea;
cout<<"enter minimum and maximum number of peas in a pod:";
cin>>min>>max;
cout<<"enter the number of pods:";
cin>>pod_count;
cout<<"enter the weight of an average peas in a pod:";
cin>>average_pea;
yield=est_total(min,max,pod_count)*average_pea;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
cout<<"min number of peas per pod="<<min<<endl
<<"max number of peas per pod="<<max<<endl
<<"average pea weight="
<<average_pea<<"ounces"<<endl
<<"estimated average yield="<<yield<<"ounces"<<endl;
return 0;
}
double est_total(int min_peas,int max_peas,int pod_count)
{
double average_pea;
average_pea=(min_peas+max_peas)/2.0;
return(average_pea*pod_count);
}
//计算一个圆的面积和一个球的体积
//两个计算使用同样的半径
#include<iostream>
#include<cmath>
const double PI=3.14159;//全局变量
double area(double radius);//return a certain radius circle's area
double volume(double radius);//return a certain radius ball's volume
int main()
{ using namespace std;
double radius_of_both,area_of_circle,volume_of_sphere;
cout<<"enter a radius to use for both a circle\n"
<<"and a sphere(in inches)";
cin>>radius_of_both;
area_of_circle=area(radius_of_both);
volume_of_sphere=volume(radius_of_both);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"radius="<<radius_of_both<<" inches\n"
<<"area of circle="<<area_of_circle<<"square inches\n"
<<"volume of sphere="<<volume_of_sphere<<"cubic inches\n";
return 0;
}
double area(double radius)
{ using namespace std;
return(PI*pow(radius,2));
}
double volume(double radius)
{ using namespace std;
return((4.0/3)*PI*pow(radius,3));
}
//律师事务所计费程序
#include<iostream>
using namespace std;
const double RATE=150.00;
double fee(int hours_worked,int minutes_worked);//返回hours—worked小时又minutes—worked分钟的律师费
int main()
{
int hours,minutes;
double bill;
cout<<"enter the hours and minutes of your consultation:\n";
cin>>hours>>minutes;
bill=fee(hours,minutes);
cout<<"for"<<hours<<"and"<<minutes<<"minutes,your bill is $"<<bill<<endl;
return 0;
}
double fee(int hours_worked,int minutes_worked)//minutes_worked是一个局部变量,已被初始化为minutes的值
{
minutes_worked=hours_worked*60+minutes_worked;
minutes_worked/=15;
return(RATE*minutes_worked);
}
#include<iostream>
int factorial(int n);//return n!
int main()
{ using namespace std;
int n;
cin>>n;
cout<<factorial(n)<<endl;
}
int factorial(int n)
{ int product=1;
while(n>0)
{
product=n*product;
n--;
}
return product;
}
//演示对函数ave的重载
#include<iostream>
double ave(double n1,double n2);//返回两数的平均值
double ave(double n1,double n2,double n3);//返回三个数的平均值
int main()
{ double n1,n2,n3;
using namespace std;
cout<<"enter three number:";
cin>>n1>>n2>>n3;
cout<<"the average of three is"<<ave(n1,n2,n3)<<endl;
cout<<"enter two number:";
cin>>n1>>n2;
cout<<"the average of two number is"<<ave(n1,n2)<<endl;
return 0;
}
double ave(double n1,double n2)
{
return((n1+n2)/2.0);
}
double ave(double n1,double n2,double n3)
{
return((n1+n2+n3)/3.0);
}
//void function
//这个程序将华氏温度换算为摄氏温度
#include