关于C++的很多编程题目。很经典
31.定义盒子Box类,要求具有以下成员:长、宽、高分别为x,y,z,可设置盒子形状;
可计算盒子体积;可计算盒子的表面积。
#include <iostream>
#include <iostream>
using namespace std;
class Box{
public:
int weight;
int length;
int hight;
void box_shape(int w, int l, int h);
int box_volume(int w, int l, int h);
int box_area(int w, int l, int h);
};
int main()
{
Box mybox;
cout << "Please Enter weight and length and hight:";
cin >> mybox.weight >> mybox.length >> mybox.hight;
int box_v, box_a;
mybox.box_shape(mybox.weight, mybox.length, mybox.hight);
box_v = mybox.box_volume(mybox.weight, mybox.length, mybox.hight);
cout << "This box's volume =" << box_v << endl;
box_a = mybox.box_area(mybox.weight, mybox.length, mybox.hight);
cout << "This box's area = " << box_a << endl;
}
void Box::box_shape(int w, int l, int h)
{
if(w == l && l == h)
cout << "This is a Cube!" << endl;
else
cout << "This is a cuboid!" << endl;
}
int Box::box_volume(int w, int l, int h)
{
return w * l * h;
}
int Box::box_area(int w, int l, int h)
{
return 2 * w * l + 2 * l * h + 2 * w * h;
}
C++编程题_计算机软件及应用_IT/计算机_专业资料。1.(分值:1.5 分)编写一...{ Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; //运算符+用于...
128 C/C++语言经典、实用、趣味程序设计编程百例精解(1) 语言经典、实用、趣味程序设计编程百例精解( ) 语言经典 1.绘制余弦曲线 绘制余弦曲线在屏幕上用“*”...
编程,输出 200 以内所有完全平方数 C(满足 C2=A2+B2)及其个数. public class Prog16 { public static void main(String[] args) { int m=0; for(int...
编程练习题一、程序控制结构编程练习题 1.有一函数如下所示: Y= x x+5 x...3.函数 int max(int a,int b,int c)是求 a、b、c 中的最大值,请实现...
C++编程题库_IT认证_资格考试/认证_教育专区。C++第一单元的考试题...{ int a,b,c; cout<<"输入三个整数 a,b,c="; cin>>a>>b>>c; ...
c++编程题_计算机软件及应用_IT/计算机_专业资料。1. 编程:求任意两个整数的... 二级C编程题 37页 免费 76道高难度C 编程题 20页 免费 C编程题库 45页 ...
《c++》编程题试卷 试卷 1.编写一个求方程 的程序, 1.编写一个求方程 ax2 + bx + c = 0 的根 的程序,用 3 个函数分别求 当 b2-4ac 大于零、等于...
C++ 编程题 C 暂无评价0人阅读0次下载举报文档C++(测试)第 3 章,函数.doc 四.编程题 73. 编写程序,求 e...
c++编程题_电脑基础知识_IT/计算机_专业资料。1. 定义一个长度为 4 的数组...{1,2,3,5,7,5,3,2,1}; int c[ ]={1,2,3,5,7,5,3}; 等等 ...
C++程序设计及题集(含答案)_电脑基础知识_IT/计算机_专业资料。本学期《程序...17. 编程求解一元二次方程 ax2+bx+c=0 的根。要求:设计完备的测试数据集,...
热门文档