415改编的日记系统(不可以读版)

本文介绍了一个基于C++实现的日记管理系统,利用双向链表结构存储日记条目,支持日记的插入、删除、查询等功能,并能够将日记内容保存到文件中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include"stdafx.h"
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct Diary
{
	string date;
	string weather;
	string feeling;
	string substance;

	bool operator== (const Diary &x)
	{
		return date == x.date;
	}
};

ostream & operator << (ostream& os, const Diary & x)
{
	os << "日期:" << x.date << endl;
	os << "天气:" << x.weather << endl;
	os << "心情:" << x.feeling << endl;
	os << "内容:" << x.substance << endl;
	os << endl;
	return os;
}

template <typename Object>
class List
{
private:
	struct Node
	{
		Object data;
		Node * next;
		Node * prev;

		Node(const Object & d = Object(), Node *p = NULL, Node *n = NULL) :data(d),
			prev(p), next(n) {}
	};
public:
	List()
	{
		init();
	}
	//List构造函数,调用私有函数init生成一个默认的链表,有头结点,尾结点。
	~List()
	{
		clear();
		delete head;
		delete tail;
	}
	//析构函数
	void clear()
	{
		Node * p = begin();
		Node * q;
		while (p != end())
		{
			q = p;
			p = p->next;
			delete q;
		}
		theSize = 0;
	}
	//将链表里面的元素全部删除。
	int size() const
	{
		return theSize;
	}
	//返回链表的长度。
	bool empty()
	{
		return size() == 0;
	}
	//判断链表是否为空。
	Node * locate(int i)        //定位函数  返回指针地址
	{
		if (i < 0 || i > size())
			return NULL;
		else
		{
			Node * p = head;
			for (int j = 1; j <= i; ++j)
			{
				p = p->next;
			}
			return p;
		}
	}
	//返回第i个结点。
	Node * begin()
	{
		return head->next;
	}
	//返回第一个结点。
	Node * end()
	{
		return tail;
	}
	//返回尾结点。
	Object getLocate(int i)    //定位函数 返回元素
	{
		Node *p = locate(i);
		return p->data;
	}
	//返回第i个结点储存的元素。
	void push_front(const Object & x)
	{
		insert(begin(), x);
	}
	//头插入。
	void push_back(const Object & x)
	{
		insert(end(), x);
	}
	//尾插入。
	void insert(Node * p, const Object & x)
	{
		p->prev = p->prev->next = new Node(x, p->prev, p);
		theSize++;
	}
	//在p结点前插入新的结点,其元素为x。
	int search(const Object & x)
	{
		int i;
		Node * p = begin();
		for (i = 1; i <= size(); ++i)
		{
			if (p->data == x)
			{
				break;
			}
			p = p->next;
		}
	
		if (i <= size())
			return i;
		else
			return -1;
	}
	//查找元素x在链表的位置,如果不存在,返回-1
	void remove(int i)
	{
		Node * p = locate(i);
		p->prev->next = p->next;
		p->next->prev = p->prev;
		delete p;
		theSize--;
	}
	//删除第i个结点。
	void output()
	{
		Node * p = begin();
		for (int i = 1; i <= size(); ++i)
		{
			cout << p->data;
			p = p->next;
		}
		cout << endl;
	}
	//将链表依次输出。
private:
	int theSize;                                //链表的长度。
	Node * head;                                //头结点。
	Node * tail;                                //尾结点。

	void init()
	{
		theSize = 0;
		head = new Node;
		tail = new Node;
		head->next = tail;
		tail->prev = head;
	}                                           //生成默认链表。
};
int main()
{
	bool flag = false;
	bool flag1 = false;
	List<Diary> list;
	cout << "====================================欢迎进入到日记系统====================================" << endl;
	cout << "空日记已经自动建立" << endl;
	int m, m1;
	while(1)
	{
		cout << "请选择需要的操作" << endl;
		cout << "1.插入日记。 2.删除日记. 3.从文件读入日记。" << endl;
		cout << "4.向文件写入日记。 5.查询。 6.输出全部日记。 其他:退出。" << endl;
		cout << endl;
		cin >> m;
		
		if (m == 1)
		{
			int num;
			Diary x;
			cout << "请选择日记插入的方式:" << endl;
			cout << "1:头插入.2:尾插入。" << endl;
			cin >> m1;
			cout << "请输入插入日记的数目" << endl;
			cin >> num;
			if (m1 == 1)
			{
				for (int i = 1; i <= num; ++i)
				{
					cout << "请依次输入日记的日期,天气,心情,内容!" << endl;
					cin >> x.date >> x.weather >> x.feeling >> x.substance;
					list.push_front(x);
				}
				cout << "日记已经插入完毕!" << endl;
			}
			else
			{
				for (int i = 1; i <= num; i++)
				{
					cout << "请依次输入日记的日期,天气,心情,内容!" << endl;
					cin >> x.date >> x.weather >> x.feeling >> x.substance;
					list.push_back(x);
				}
				cout << "日记已经插入完毕" << endl;
			}
			if (flag1 == false)
				flag1 = true;
			cout << endl;
		}
		else if (m == 2)
		{
			int i;
			Diary y;
			cout << "请输入要删除的日记的日期" << endl;
			cin >> y.date;
			i = list.search(y);
			if (i > -1 && i <= list.size())
			{
				list.remove(i);
				cout << "删除日记及其信息完成!" << endl;
			}
			else
				cout << "对不起,这个日记表不存在您要查找的日记及其信息,请先查看全部日记信息!谢谢" << endl;
			cout << endl;
		}
		else if (m == 3)
		{
			if (!flag)
				cout << "您还没有向文件写入日记信息!请先写入" << endl;
			else
			{
				cout << "------------------------读取开始!------------------------" << endl;
				ifstream read("list.txt");
				char s;
				while (read.get(s))
					cout << s;
				cout << "------------------------读取结束!------------------------" << endl;
				read.close();
			}
			cout << endl;
		}
		else if (m == 4)
		{
			string select;
			cout << "是否已经将需要记录的学生全部记录?(该操作是依次将日记表里面的全部信息写入文件里)" << endl;
			cout << "如果选择是就输入“Y”;否则输入“N”,继续将日记信息插入日记表里。" << endl;
			cin >> select;

			if (select == "Y")
			{
				ofstream write("list.txt");
				for (int i = 1; i <= list.size(); ++i)
				{
					write << list.getLocate(i);
				}
				flag = true;
				write.close();
			}
			else
			{
				cout << "请继续插入或删除操作!" << endl;
			}
			cout << endl;
		}
		else if (m == 5)
		{
			int i;
			Diary z;
			string num;
			bool flag2 = false;
			cout << "请输入你想查询的日记的日期!" << endl;
			cin >> num;
			for (i = 1; i <= list.size(); ++i)
			{
				z = list.getLocate(i);
				if (z.date == num)
				{
					flag2 = true;
					break;
				}
			}
			if (flag2)
				cout << "该日记信息存在日记表!" << endl;
			
			else
				cout << "对不起,这个日记表不存在你要查找的日记及其信息,请先查看全部日记的信息!谢谢!!" << endl;

			cout << endl;
		}

		else if (m == 6)
		{
			if (flag1)
			{
				cout << "输出日记中全部日期的信息!" << endl;
				list.output();
			}
			else
			{
				cout << "日记表为空,请先插入日记!" << endl;
			}
			cout << endl;
		}

		else
		{
			cout << "---------------------------谢谢使用日记管理系统---------------------------" << endl;
			break;
		}
		}
	}


标题基于PHP + JavaScript的助眠小程序设计与实现AI更换标题第1章引言介绍助眠小程序的研究背景、意义,以及论文的研究内容和创新点。1.1研究背景与意义阐述助眠小程序在当前社会的重要性和应用价值。1.2国内外研究现状分析国内外在助眠小程序方面的研究进展及现状。1.3论文研究内容与创新点概述论文的主要研究内容和创新之处。第2章相关理论基础介绍助眠小程序设计与实现所涉及的相关理论基础。2.1PHP编程技术阐述PHP编程技术的基本概念、特点和在助眠小程序中的应用。2.2JavaScript编程技术介绍JavaScript编程技术的核心思想、作用及在小程序中的实现方式。2.3小程序设计原理讲解小程序的设计原则、架构和关键技术。第3章助眠小程序需求分析对助眠小程序进行详细的需求分析,为后续设计与实现奠定基础。3.1用户需求调研用户需求调研的过程和方法,总结用户需求。3.2功能需求分析根据用户需求,分析并确定助眠小程序的核心功能和辅助功能。3.3性能需求分析明确助眠小程序在性能方面的要求,如响应速度、稳定性等。第4章助眠小程序设计详细阐述助眠小程序的设计方案,包括整体架构、功能模块和界面设计。4.1整体架构设计给出助眠小程序的整体架构设计思路和实现方案。4.2功能模块设计详细介绍各个功能模块的设计思路和实现方法。4.3界面设计阐述助眠小程序的界面设计风格、布局和交互设计。第5章助眠小程序实现与测试讲解助眠小程序的实现过程,并进行详细的测试与分析。5.1开发环境搭建与配置介绍开发环境的搭建过程和相关配置信息。5.2代码实现与优化详细阐述助眠小程序的代码实现过程,包括关键技术的运用和优化措施。5.3测试与性能分析对助眠小程序进行全面的测试,包括功能测试、性能测试等,并分析测试结果。第6章结论与展望总结论文的研究成果,展望未来的研究方向和应用前景。6.1研究成果总结概括性地总结论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值