随笔分类 - C++代码
摘要:/*实现运算符加与减的重载设计一个时间类,要求能够在时间类上实行以分钟为单位的加减运算,同时当分钟增或减的变化应体现日期变化。如:2012年11月28日12:10PM 增加12小时后,应变为2012年11月29日00:10AM输入一个未来时间(含日期和时间),计算时间间隔,建立一个倒计时显示的计时器(以秒为单位变化)。如当前时间为2012年12月5日15:40,输入时间为2012年12月6日14:40. 输入一个未来时间(含日期和时间),计算时间间隔,建立一个倒计时显示的计时器(以秒为单位变化)。 如当前时间为2012年12月5日15:40,输入时间为2012年12月6日14:40.*/#in
阅读全文
摘要:/*任务:一群小孩围成一圈,任意假定一个数m,从第一个小孩起,顺时针方向数,每数到第m个小孩时,该小孩便离开。小孩不断离开,圈子不断缩小。最后剩下的一个小孩便是胜者。求胜者的编号?要求以面向对象技术进行程序设计建立环状链表类程序便于维护与扩张:如易于对小孩数量n和数数间隔m进行变化改变获胜者数量,使其可设为任意值可中途增加小孩人数 将数据结构改为数组形式存放,要求尽可能少地修改程序并能够实现上述功能,保留原环链表的实现方式*///类的实现#include<iostream>using namespace std;typedef char ElemType;#define maxNu
阅读全文
摘要://utility.h#ifndef __UTILITY_H__ // 如果没有定义__UTILITY_H__#define __UTILITY_H__ // 那么定义__UTILITY_H__// 实用程序工具包#ifdef _MSC_VER // 表示是Visual C++#if _MSC_VER == 1200 // 表示Visual C++6.0// 标准库头文件#include <string.h> // 标准串和操作#include <iostream.h> // 标准流操作#include <limits.h> // 极限#include &l
阅读全文
摘要:/*任务:一群小孩围成一圈,任意假定一个数m,从第一个小孩起,顺时针方向数,每数到第m个小孩时,该小孩便离开。小孩不断离开,圈子不断缩小。最后剩下的一个小孩便是胜者。求胜者的编号?要求以面向对象技术进行程序设计建立环状链表类程序便于维护与扩张:如易于对小孩数量n和数数间隔m进行变化改变获胜者数量,使其可设为任意值可中途增加小孩人数*///类的实现#include<iostream>using namespace std;typedef int ElemType;typedef struct List{ ElemType data; struct List *next;}LinkNo
阅读全文
摘要:/*游戏者每次投掷两颗骨子,每个骰子是一个正方体,当骰子停止时,将每个骰子朝上的点数相加,在第一次投掷骰子时,如果所得到的和为7或11,那么游戏者为胜;所得和为2、3或12则输如和为4、5、6、8、9或 10,则此和为游戏者点数。如要想赢得胜利,必须继续投掷骰子,直到取和得自己的点数(也即规则2的点数)为止,如果投掷出的和为7,则为输(并非指第一次投掷的情况下)要 求main函数中可选择是继续还是退出游戏,统计并显示游戏获胜次数和输掉次数。*/#include<iostream>#include<ctime>using namespace std;void main()
阅读全文
摘要:#include<iostream>#include<algorithm>sortusing namespace std;template<class ElemType>class Array{ private: ElemType *elem; int size; public: Array(ElemType a[],int sz):elem(a),size(sz){}; ElemType Max(); ElemType Sum(); void Sort(); void Show();};template <class ElemType>Elem
阅读全文
摘要://fraction.h#include"utility.h"#include<iostream.h>class Fraction{private: int nume; int deno; int Gcf(int m,int n);public: Fraction(int n=1,int d=1); virtual ~Fraction(){}; bool dight(char ch); void Reduction(); int GetNume(){return nume;} int GetDeno(){return deno;} void SetNume(in
阅读全文
摘要:/*设计一个日期类Date,包括年、月、日等私有成员。要求实现日期的基本运算,例如某日期加上天数或减去天数,两日期相减的天数等。实现要求:实现运算符加与减的重载*/#include<iostream>#include<string>#include<iomanip>#include<cmath>using namespace std;class Date{private: int year; int month; int day; static int sumDays;public: int monthDay(int year1,int mont
阅读全文
摘要:/*能够显示公元后任意年份的日历,日历以月份顺序排列,每月以星期顺序排列,类似于一般挂历上的格式。先以2000年1月1日周六作为推算起点来判定实现指定2000年后的日历再将起点日期改为公元元年一月一日是星期几注意判断闰年、月、周的判别*/#include<iostream>#include<iomanip>#include<cmath>using namespace std;class Date{private: int year;public: int monthDay(int year1,int month1); void setDate(); void
阅读全文
摘要:#include<iostream>using namespace std;typedef int ElemType;typedef struct List{ ElemType data; struct List *next;}LinkNode,*LinkList;LinkNode *creat_List(int number){ LinkList first=new LinkNode; first->data=-1; LinkList p=first; if(first==NULL) { cout<<"分配内存失败"<<endl;
阅读全文

浙公网安备 33010602011771号