⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.cpp

📁 课程设计做的个人股票管理系统
💻 CPP
字号:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include "Stock.h"
#include "GuestStock.h"
#include "Guest.h"
#include "Link.h"
#include "Search.h"
#include "Exchange.h"



int TmCmp(tm *tm1, tm *tm2)
{
	if (tm1->tm_year > tm2->tm_year)
	{
		return 1;
	}
	else if (tm1->tm_year < tm2->tm_year)
	{
		return -1;
	}
	else if (tm1->tm_mon > tm2->tm_mon)
	{
		return 1;
	}
	else if (tm1->tm_mon < tm2->tm_mon)
	{
		return -1;
	}
	else if (tm1->tm_mday > tm2->tm_mday)
	{
		return 1;
	}
	else if (tm1->tm_mday < tm2->tm_mday)
	{
		return -1;
	}
	else if (tm1->tm_hour > tm2->tm_hour)
	{
		return 1;
	}
	else if (tm1->tm_hour < tm2->tm_hour)
	{
		return -1;
	}
	else if (tm1->tm_min > tm2->tm_min)
	{
		return 1;
	}
	else if (tm1->tm_min < tm2->tm_min)
	{
		return -1;
	}
	else if (tm1->tm_sec > tm2->tm_sec)
	{
		return 1;
	}
	else if (tm1->tm_sec < tm2->tm_sec)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}






void SearchByTime(Link *head[], Guest &guestObj, Stock stockObj[])
{
	tm searchTime1, searchTime2;
	//long stockCode;
	
	/*
	cout<<"请输入您要查询的股票的代码"<<endl;
	cin>>stockCode;
	*/
	
	Link *left = NULL;
	Link *right = NULL;
	
	
	
	cout<<"请输入您想要查询的起始时间:(格式:年月日时分秒,例如 2008 4 22 23 45 42)"<<endl;
	cin>>searchTime1.tm_year>>searchTime1.tm_mon>>searchTime1.tm_mday>>searchTime1.tm_hour
		>>searchTime1.tm_min>>searchTime1.tm_sec;
	cout<<"请输入您想要查询的结束时间:(格式:年月日时分秒,例如 2008 4 22 23 51 10)"<<endl;
	cin>>searchTime2.tm_year>>searchTime2.tm_mon>>searchTime2.tm_mday>>searchTime2.tm_hour
		>>searchTime2.tm_min>>searchTime2.tm_sec;
	searchTime1.tm_year -= 1900;
	searchTime2.tm_year -= 1900;
	searchTime1.tm_mon -= 1;
	searchTime2.tm_mon -= 1;


	
	for (int k=0; k<10; k++)
	{
		if (guestObj.GetGsObj()[k].GetStkCode() == 0)
		{
			cout<<"您并没有购买股票。"<<endl;
			break;
		}
		int i = SearchByStockCode(guestObj.GetGsObj()[k].GetStkCode(), stockObj);
		
		
		Link *p = head[i];
		
		if (TmCmp(&searchTime1, &searchTime2) >0)
		{
			cout<<"起始时间不能大于结束时间。"<<endl;
		}
		else
		{
			while (p != NULL)
			{
				if (TmCmp(p->today, &searchTime2) > 0)
				{
					break;
				}
				else if (TmCmp(p->today, &searchTime1) < 0)
				{
					p++;
				}
				else if ((TmCmp(p->today, &searchTime1) >= 0 && TmCmp(p->next->today, &searchTime1) <= 0))
				{	
					if (left == NULL)
					{
						left = p;
					}
					right = p++;
				}				
			}
			if (left == NULL)
			{
				cout<<"您所查询的时间段内没有股票的变化."<<endl;
			}
			else
			{
				cout<<left->today<<'\t'
					<<left->stockObj<<endl;
				cout<<right->today<<'\t'
					<<right->stockObj<<'\t';
				cout<<left->today<<'-'<<right->today<<'\t'<<endl;
				
				cout<<setw(9)<<"股票代码"
					<<setw(9)<<"股票名称"
					<<setw(8)<<"开始价"
					<<setw(8)<<"结束价"
					<<setw(9)<<"买入股数"
					<<setw(8)<<"发行量"
					<<setw(9)<<"涨跌幅%"				//char *rank
					//<<setw(5)<<"涨跌幅"<<"%"<<"\t";		//int rank
					<<setw(6)<<"排名"<<endl;
				
				cout<<setw(9)<<left->stockObj.GetStkCode()
					<<setw(9)<<left->stockObj.GetStkName()
					<<setw(8)<<left->stockObj.GetStkPrice()
					<<setw(8)<<right->stockObj.GetStkPrice()
					<<setw(9)<<100000 - right->stockObj.GetStkIss()				//权宜之计
					<<setw(8)<<right->stockObj.GetStkIss()
					<<setw(9)<<right->stockObj.GetStkPrice() / left->stockObj.GetStkPrice() - 1			//char *rank
					//<<setw(5)<<"涨跌幅"<<"%"<<"\t";		//int rank
					<<setw(6)<<right->stockObj.GetStkRank()<<endl;
				
			}
		}
	}
}

//按股票号码查找用户所持股票
int SearchGuestStockByCode(Guest &guestObj, long stockCode)
{
	int i;
	for (i=0; i<10; i++)
	{
		if (guestObj.GetGsObj()[i].GetStkCode() == 0)
		{
			break;
		}
		if (stockCode == guestObj.GetGsObj()[i].GetStkCode())
		{
			return i;
		}
	}
	return -1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -