#include<bits/stdc++.h>
using namespace std;intmain(){double a=1,b=1;
cin>>a>>b;
cout<<a*b<<endl;
cout<<(a+b)*2<<endl;return0;}
7-3 例4-3游泳池改造预算
#include<bits/stdc++.h>
using namespace std;constdouble pi=3.1415926;intmain(){int r;
cin>>r;
cout<<"Fencing Cost is $"<<pi*(r+3)*70<<endl;
cout<<"Concrete Cost is $"<<pi*((r+3)*(r+3)-r*r)*20<<endl;return0;}
7-4 立方体类
#include<bits/stdc++.h>
using namespace std;intmain(){int x,y,z;
cin>>x>>y>>z;
cout<<x*y*z<<endl;return0;}
7-4 立方体类的实现
#include<bits/stdc++.h>
using namespace std;intmain(){int x;
cin>>x;
cout<<x*x*x<<" "<<x*x*6<<endl;return0;}
7-1 通过指针,输出对象数组的数据
#include<bits/stdc++.h>
using namespace std;intmain(){int number,score;for(int i=0;i<5;i++){
cin>>number>>score;
cout<<number<<" "<<score<<endl;}return0;}
7-2 计算全班学生C++课程的总成绩和平均成绩
#include<bits/stdc++.h>
using namespace std;intmain(){int x,sum;for(int i=0;cin>>x&&i<5;i++)
sum+=x;
cout<<sum<<endl;
cout<<sum/5<<endl;return0;}
7-1 两点间距离计算
#include<bits/stdc++.h>
using namespace std;intmain(){for(int ch =0; cin >> ch && ch !=0;){if(ch ==1){float a, b, z;
cin >> a >> b;
z =sqrt((a - b)*(a - b));
cout <<"Distance from Point "<< a <<" to Point "<< b <<" is "<< z << endl;}elseif(ch ==2){int a, b, c, d, z;
cin >> a >> b >> c >> d;
z =sqrt((a - c)*(a - c)+(b - d)*(b - d));
cout <<"Distance from Point"<<"("<< a <<","<< b <<")"<<" to Point("<< c <<","<< d <<") is "<< z << endl;}else{int a, b, c, d, e, f, z;
cin >> a >> b >> c >> d >> e >> f;
z =sqrt((a - d)*(a - d)+(b - e)*(b - e)+(c - f)*(c - f));
cout <<"Distance from Point"<<"("<< a <<","<< b <<","<< c <<")"<<" to Point("<< d <<","<< e <<","<< f <<") is "<< z << endl;}}return0;}
7-2 多边形周长计算(继承)
#include<bits/stdc++.h>
using namespace std;intmain(){int n, ch;
cin >> n;// 输入多边形个数for(int i =0; i < n; i++){
cin >> ch;if(ch ==0)// 多边形为边长序列{int a[100]={0}, circum =0, j =0;for(; cin >> a[j]&&(a[j]!=-1); j++)// 循环读取边长
circum += a[j];// 累加边长值到周长
cout << j <<" "<< circum << endl;// 输出边长个数和周长}elseif(ch ==1)// 矩形{int a, b;
cin >> a >> b;// 读取矩形的长和宽
cout <<"4 "<<2*(a + b)<< endl;// 输出固定个数的边和周长}else// 其他多边形类型{int number =0, side =0, circum =0;
cin >> number >> side;// 读取多边形的边数和边长
circum = side * number;// 计算周长
cout << number <<" "<< circum << endl;// 输出边数和周长}}return0;}
7-19 用虚函数计算各种图形的面积
#include<bits/stdc++.h>
using namespace std;constfloat PI =3.14159f;intmain(){float sum =0, r, s, w, h, t, b, bh, ba, th;
cin >> r >> s >> w >> h >> t >> b >> bh >> ba >> th;
sum += PI * r * r;
sum += s * s;
sum += w * h;
sum +=(t + b)* bh /2;
sum += ba * th /2;printf("%.3f\n", sum );return0;}