04 2023 档案
摘要:1 #include <iostream> 2 using namespace std; 3 enum weekday{sunday,monday,tuesday,wednesday,thursday,friday,saturday 4 }; 5 int main() 6 { 7 int i; 8
阅读全文
摘要:定义一个Circle类,有半径数据成员,有求面积函数,构造一个Circle对象测试。 1 #include <iostream> 2 using namespace std; 3 #define PI 3.1415926 4 class Circle{ 5 private: 6 double rad
阅读全文
摘要:定义一个datatype类,能处理包含字符型,整形,浮点型3种类型的数据,给出其构造函数。 1 #include <iostream> 2 using namespace std; 3 4 class DataType{ 5 private: 6 char a; 7 int n; 8 float x
阅读全文
摘要:#include <iostream> using namespace std; class Date{ private: int year,month,day; public: Date(int year=1,int month=1,int day=1) { this->year=year; th
阅读全文
摘要:定义一个dog类,包含的age,weight等属性,以及对这些属性的操作方法,实现并测试这个类。 1 #include <iostream> 2 using namespace std; 3 class Dog{ 4 private: 5 int age,weight; 6 public: 7 vo
阅读全文
摘要:个人银行账户管理程序 1 #include<iostream> 2 #include <cmath> 3 using namespace std; 4 class SavingsAccount{ //储蓄账户类 5 private: 6 int id; //账号 7 double balance;
阅读全文
摘要:一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值: Z:0 1 2
阅读全文
摘要:时钟类的完整例题 #include <iostream> using namespace std; class Clock{ private : int hour,minute,second; public: void setTime(int hour=0,int minute=0,int seco
阅读全文
摘要:编写递归函数getPower计算x的y次方,在同一个程序中针对整形和实数型实现两个重载的函数。 #include <iostream> using namespace std; int getPower(int x,int y) { if(y<0) { return 0; } if(y==0) {
阅读全文
摘要:编写可以求两个数最大公约数和最小公倍数的函数。 1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 int fun1(int x,int y) 5 { 6 int temp; 7 if(x<y) 8 { 9 temp=x
阅读全文
摘要:编写函数将华氏度转化为摄氏度 #include <iostream> using namespace std; double fun(double x) { return 5.0*(x-32)/9; } int main() { double a; cin>>a; cout<<fun(a)<<end
阅读全文
摘要:现在要开发一个系统,管理对多种汽车的收费工作。给出下面的一个基类框架class Vehicle{protected:string NO;public:Vehicl virtual int fee()=0;//计算应收费用};以Vehicle为基类,构建出Car、Truck和Bus三个类。Car的收费
阅读全文
摘要:定义抽象基类Shape,由它派生出五个派生类:Circle(圆形)、Square(正方形)、Rectangle( 长方形)、Trapezoid (梯形)和Triangle (三角形),用虚函数分别计算各种图形的面积,并求出它们的和。要求用基类指针数组。使它的每一个元素指向一个派生类的对象。PI=3.
阅读全文
摘要:完成函数,参数为两个unsigned short int 型数,返回值为第一个参数除以第二个参数的结果,数据类型为short int;如果第二个参数为0,则返回值为一1。在主程序中实现输入输出。 #include <iostream> using namespace std; short int n
阅读全文
摘要:游戏规则是:每个骰子有6面,点数分别为1、2、3、4、5、6。游戏者在程序开始时输入个无符号整数,作为产生随机数的种子。每轮投两次骰子,第一轮如果和数为7或11则为胜,游戏结束;和数为2、3或12则为负,游戏结束;和数为其他值则将此值作为自己的原数,继续第二轮、第三轮……直到某轮的和数等于点数则取胜
阅读全文
摘要:3-2 输入一个8位二进制数,将其转换为十进制数输出。 1 #include <iostream> 2 using namespace std; 3 double power(double x,int n); //函数的声明,double类型防止超出整型 4 int main() 5 { 6 int
阅读全文
摘要:2-29在程序中定义一个整型变量,倔以1~100的值。要求用户猜这个数,比较两个数的大小,把结果提示给用户,直到猜对为止。分别使用while、do…while语句实现循环。 #include <iostream> using namespace std; int main() { int a=56;
阅读全文
摘要:实现一个简单的菜单程序,运行时显示“Menu:A(dd) D(elete)S(ort)Q(ui Select one:”提示用户输入,A表示增加,D表示删除,S表示排序,Q表示退出,输入为A、D、S时分别提示“数据已经增加、删除、排序。”输入为Q时程序结束。(1)要求使用if…else语句进行判断,
阅读全文
摘要:用穷举法找出1~100的质数并显示出来,分别用while,do...while,for循环语句实现 1 #include <iostream> //for循环语句的实现 2 #include <cmath> 3 using namespace std; 4 int main() 5 { 6 int
阅读全文
摘要:编写一个完整的程序,实现功能:向用户提问“现在正在下雨吗?”,提示用户输入Y或N。若输入为Y,显示“现在正在下雨。”;若输入为N,显示“现在没有下雨。”;否则继续提问“现在正在下雨吗?”。 #include <iostream> using namespace std; int main() { c
阅读全文
摘要:1.编写一个程序,运行时提示输入一个数字,再把这个数字显示出来。 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int a; 6 cout<<"输入一个数字:"; 7 cin>>a; 8 cout<<a<<endl;
阅读全文