//by YewLi
/* TriangleInfo.cpp 函数传地址的例子 */
#include <iostream>
#include<cmath>
using namespace std;
/* 函数功能:判断输入的三边长度是否构成三角形,
并计算面积和周长输入参数a,b,c
三角形的三边长输出参数pArea,pPerimeter 通过传递变量的地址,修改变量值达到输出的目的函数返回值:
如果构成三角形返回true,否则返回false*/
bool TriangleInfo(double a, double b, double c, double *pArea, double *pPerimeter);
int main() {
cout << "计算三角形的面积和周长,请输入边长:";
double a, b, c;//从键盘输入的3边的长度
double area, perimeter;//面积和周长
/* 要求从键盘输入a,b,c,
调用函数TriangleInfo输出是否构成三角形如果构成三角形,
输出三角形的面积和周长*/
cin>>a>>b>>c;
if(TriangleInfo(a,b,c,&area,&perimeter))
cout<<"A triangle can be made of these 3 integers."<<endl<<"area is "<<area<<endl<<"perimeter is "<<perimeter;
else
cout<<"A triangle can not be made of these 3 integers."<<endl;
return 0; }
bool TriangleInfo(double a, double b, double c, double *pArea, double *pPerimeter){
if(a + b > c && a + c > b)
if(b + c > a){
double p = (a + b + c)/2;
*pArea = sqrt(p*(p - a)*(p - b)*(p - c));
*pPerimeter = a + b + c;
return 1;
}
return 0;
//请完成此函数return false;
}
面向对象第一道
符合上机模拟的基本难度
//by YewLi
//利用int student[80]数组,存储80位学生的成绩,成绩利用rand()函数生成,成绩分布区间为[50,100]。
//1、 int main()函数负责声明数组并计算平均分。
//2、 void arrayInit(int *p)函数负责利用rand()函数生成80位学生成绩。
//3、 void biggerAve(int *p, int ave)函数负责输出所有大于平均分的成绩并给出该成绩在student[]数组中的位置。
//4、 void searchOne(int *p)函数提供分数查询服务,让用户输入一个分数,输出所有成绩等于该分数在数组中的位置。
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
void arrayInit(int *p){
srand(time(NULL));
for(int i = 0;i <80;i++)
p[i] = rand()%51 +50;
return;
}
void biggerAve(int *p, int ave){
for(int i = 0;i < 80;i++)
if(p[i] > ave)cout<<"score:"<<p[i]<<" place:"<<i<<endl;
}
void searchOne(int *p){
int x;
cin>>x;
for(int i = 0;i < 80;i++)
if(p[i] == x)cout<<"place:"<<i<<endl;
}
int main(){
int student[80];
arrayInit(student);
int ave = 0;
for(int i = 0;i < 80;i++)ave += student[i];
ave /= 80;
biggerAve(student,ave);
searchOne(student);
return 0;
}
相同难度的面向对象题目
无内鬼,直接码即可