//1.
#include<iostream>
using namespace std;
class Box {
public:
int getLength() { return length; }
int getWidth() { return width; }
int getHeight() { return height; }
void setLength(int length) { this->length = length; }
void setWidth(int width) { this->width = width; }
void setHeight(int height) { this->height = height; }
int getArea()
{
return 2 * (length * width + length * height + height * width);
}
int getVolume() { return length * width * height; }
private:
int length, width, height;
};
int main() {
Box box;
box.setLength(5);
box.setWidth(3);
box.setHeight(4);
cout << "长方体的表面积为:" << box.getArea() << endl;
cout << "长方体的体积为:" << box.getVolume() << endl;
return 0;
}
//2.
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student() { sno = ""; name = ""; score = 0; }
Student(string sno, string name, int scote) :
sno(sno), name(name), score(score){}
string getSno() { return sno; }
string getName() { return name; }
int getScore() { return score; }
void setSno(string sno) { this->sno = sno; }
void setName(string name) { this->name = name; }
void setScore(int score) { this->score = score; }
void show() {
cout << "Sno is:" << sno << endl;
cout << "Name is:" << name << endl;
cout << "Score is:" << score << endl;
}
private:
string sno;
string name;
int score;
};
int main() {
Student student[5] = {
Student("1001","Zhangsan",75),
Student("1001","Wangming",83),
Student("1001","Lisi",92),
Student("1001","Zhangliang",67),
Student("1001","Zhaojian",88) };
for(int i=0;i<5;i++)
{
if (student[i].getScore()>80) student[i].show();
}
return 0;
}