## sum.h
#ifndef SUM_H
#define SUM_H
#include <iostream>
#include <stdio.h>
#endif
## loop_array.h
#include"sum.h"
#ifndef CIRCULAR_ARRAY_H
#define CIRCULAR_ARRAY_H
template <typename T, int size>
class CircularArray {
private:
T array[size];
int head;
int tail;
int count;
public:
CircularArray();
bool isFull() const;
bool isEmpty() const;
void enqueue(T item);
T dequeue();
void display() const;
};
#endif
## demo.h
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<Windows.h>
#include<iostream>
## loop_array.cpp
#include "loop_array.h"
// 构造函数实现
template <typename T, int size>
CircularArray<T, size>::CircularArray() : head(0), tail(0), count(0) {}
// isFull 函数实现
template <typename T, int size>
bool CircularArray<T, size>::isFull() const {
return count == size;
}
// isEmpty 函数实现
template <typename T, int size>
bool CircularArray<T, size>::isEmpty() const {
return count == 0;
}
// enqueue 函数实现
template <typename T, int size>
void CircularArray<T, size>::enqueue(T item) {
if (isFull()) {
std::cout << "循环数组已满,无法添加元素。" << std::endl;
return;
}
array[tail] = item;
tail = (tail + 1) % size;
count++;
}
// dequeue 函数实现
template <typename T, int size>
T CircularArray<T, size>::dequeue() {
if (isEmpty()) {
std::cout << "循环数组为空,无法移除元素。" << std::endl;
return T();
}
T item = array[head];
head = (head + 1) % size;
count--;
return item;
}
// display 函数实现
template <typename T, int size>
void CircularArray<T, size>::display() const {
if (isEmpty()) {
std::cout << "循环数组为空。" << std::endl;
return;
}
int index = head;
for (int i = 0; i < count; ++i) {
std::cout << array[index] << " ";
index = (index + 1) % size;
}
std::cout << std::endl;
}
## demo.cpp
#include"sum.h"
#define int_t unsigned int
//用数字表示方向
#define SOUTH 0x01
#define SOUTH_WEST 0x02
#define WEST 0x03
#define NORTH_WEST 0x04
#define NORTH 0x05
#define NORTH_EAST 0x06
#define EAST 0x07
#define SOUTH_EAST 0x08
//用数字表示十二宫
#define LIFE 0x01
#define BRO 0x02
#define WIFE 0x03
#define SON 0x04
#define WEALTH 0x05
#define HEALTH 0x06
#define OUT 0x07
#define FRIEND 0x08
#define CAREER 0x09
#define LAND 0x0A
#define HAPPY 0x0B
#define PARENT 0x0C
//定义结构体, 包含公历、农历月份和时辰
typedef struct {
int_t ChinaCalendar;
int_t Calendar;
int_t time;
int_t direction;
int_t house;
}Palace;
//主函数
int main(int argc, char *argv[]) {
int_t self_time[12] = {0};
std::cout << self_time[1] << std::endl;
return 0;
}
1540

被折叠的 条评论
为什么被折叠?



