04 2023 档案
摘要:狗的继承 完成两个类,一个类Animal,表示动物类,有一个成员表示年龄。一个类Dog,继承自Animal,有一个新的数据成员表示颜色,合理设计这两个类,使得测试程序可以运行并得到正确的结果。 #include <iostream>using namespace std; class Animal{
阅读全文
摘要:一个捐款人类Donator及一个相关函数getMaxName( ),Donator类中包含捐款人的姓名及其捐款额。输出一批捐款人来到前后的捐款总金额,以及本批次捐款人中捐款最高者的姓名。 #include <iostream>using namespace std; class Donator{ p
阅读全文
摘要:计算年龄问题 定义一个Birthday类,其成员变量有3个整形变量(出生的年月日):year,month,day;提供构造方法对这3个成员变量进行初始化;成员函数有getAge(),其功能是实现计算到2017年12月25日时该Birthday对象的年龄。 #include<iostream>usin
阅读全文
摘要:立方体类Box的实现,完成计算体积、计算表面积、输出结果等功能。 #include<iostream>using namespace std; class Box {public: void seta(float a) { len=a; } float getvolume() { return le
阅读全文
摘要:判断是否为闰年 定义一个日期类Date,内有数据成员year、month和day,分别代表年、月、日,并若干有成员函数:构造函数用于初始化数据成员,isLeap函数用于闰年的判断。编写主函数:创建日期对象,判断该年是否是闰年。 #include<iostream>using namespace st
阅读全文
摘要:求两点之间距离 定义一个Point类,有两个数据成员:x和y, 分别代表x坐标和y坐标,并有若干成员函数。定义一个函数Distance(), 用于求两点之间的距离。 #include<iostream>#include<math.h>#include<iomanip>using namespace
阅读全文
摘要:创建CPU 定义一个CPU类,包含等级(Rank)、频率(frequency)、电压(voltage)等属性。其中,rank为枚举类型CPU__Rank,定义为enum CPU_Rank{P1=1,P2,P3,P4,P5,P6,P7},frequency为单位是MHz的整型数,voltage为浮点型
阅读全文
摘要:定义一个Tree(树)类,有成员ages(树龄),不带参数的构造函数对ages初始化为1,成员函数grow(int years)对ages加上years,age()显示tree对象的ages的值。 #include <iostream>using namespace std; class Tree
阅读全文
摘要:计算长方形面积和表面积 第一个函数计算长方形的面积,其中x和y是长和宽。第二个函数计算长方体的表面积,x,y和z是长,宽和高。 #include<iostream>#include<string>using namespace std;int area(int x,int y){ int a; a=
阅读全文
摘要:定义一个CPU类,包含等级(Rank)、频率(frequency)、电压(voltage)等属性。其中,rank为枚举类型CPU__Rank,定义为enum CPU_Rank{P1=1,P2,P3,P4,P5,P6,P7},frequency为单位是MHz的整型数,voltage为浮点型的电压值。
阅读全文
摘要:定义并实现一个矩形类,有长和宽两个属性,由成员函数计算矩形的面积。 #include <iostream>using namespace std; void Rectangle::setLength(int l) { length=l; } void Rectangle::setWidth(int
阅读全文
摘要:计算正五边形的周长和面积 #include <bits/stdc++.h>using namespace std;int main(){ double n,S,C; double a,b; cin>>n; a=sqrt(5); b=25+10*a; S=sqrt(b)/4*n*n; cout<<S<
阅读全文
摘要:简单的C++程序实例 #include<iostream> using namespace std; int main() { cout<<"hello!"<<endl; cout<<"welcom to C++!"<<endl; return 0; } 输出: Hello! welcome to
阅读全文