随笔分类 - 日常练习
摘要:最佳存款方案 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 double x=1000; 6 for(int i=1;i<=5;i++) 7 { 8 x=x/(1+12*0.0063); 9 if(i!=5) 10 {
阅读全文
摘要:不死身兔 1 #include <iostream> 2 using namespace std; 3 int fab(int n) 4 { 5 if(n==1 || n==2) 6 { 7 return 1; 8 } 9 if(n>2) 10 { 11 return fab(n-1)+fab(n-
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int i,j,k,temp; 6 for(i=0;i<=9;i++) 7 { 8 for(j=0;j<=9;j++) 9 { 10 if(i!=j) 11 { 12 k=
阅读全文
摘要:三天打鱼两天晒网问题 1 #include <iostream> 2 using namespace std; 3 class Date{ 4 public: 5 int year,month,day; 6 Date(int y,int m,int d):year(y),month(m),day(d
阅读全文
摘要:1,百钱买百鸡问题 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int x,y,z; 6 for(int x=0;x<=20;x++) 7 { 8 for(int y=0;y<=33;y++) 9 { 10 for(
阅读全文
摘要:第一个例题。 #include <iostream> using namespace std; template<class T> T abs(T s) { return s<0 ? -s : s; } int main(){ int n=-5; double d=-5.5; cout<<abs(n
阅读全文
摘要:定义一个CPU类 1 #include <iostream> 2 using namespace std; 3 enum Core{ 4 Single,Dual,Quad 5 }; 6 enum Words{ 7 Bits32,Bits64 8 }; 9 enum HyperThread{ 10 S
阅读全文
摘要: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;
阅读全文
摘要:时钟类的完整例题 #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
阅读全文
摘要:完成函数,参数为两个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
阅读全文