当前位置: 首页>>代码示例>>C++>>正文


C++ Customer::returnMovie方法代码示例

本文整理汇总了C++中Customer::returnMovie方法的典型用法代码示例。如果您正苦于以下问题:C++ Customer::returnMovie方法的具体用法?C++ Customer::returnMovie怎么用?C++ Customer::returnMovie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Customer的用法示例。


在下文中一共展示了Customer::returnMovie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: execute

//--------------------------------Execute---------------------------------//
//this method performs the actions for the Return object, using the
//store as a parameter to access the inventory and alter accordingly
//it also uses the file stream to read in the information
//according to formatting specifications, setting it for this specified
//derived transaction class
bool Returnx::execute(ifstream& file, Store& st)
{
	int custIdx;
	file >> custIdx;
	Customer* cust = st.getCustomer(custIdx);
	//read the custtomer index and get the customer at that index
	//from the store, if the store doesn't have the customer at that
	//spot then the customer has not been created and we cannot do anything
	if (cust == NULL)
	{
		cout << "Invalid Customer ID. Transaction could not be executed.\n";
		//no need for clean up since Customer is still NULL
		return false;
	}
	else
	{
		char format;
		file >> format;
		//read in the format, the format is specified to only be DVDs
		if (format != 'D')
		{
			cout << "Invalid format. Transaction could not be executed.\n";
			//no need for clean up since Formaat is not dynamic
			return false;
		}
		else
		{
			char genre;
			file >> genre;
			//read in the genre and then use the stores movie factory
			//to create a temporary movie of this genre,
			//however, if the genre did not correspond to an appropriate
			//movie, return false
			Movie* tempMov = st.getMovieFact().createIt(genre);
			if (tempMov == NULL)
			{
				cout << "Invalid movie. Transaction could not be"
					<< "executed.\n";
				//no need for clean up since tempMov is still NULL
				return false;
			}
			else
			{
				//everything worked, now we try to set the data
				//from the format specifications of a return
				//movie, and if this didn't work, the movie was 
				//created so we must clean this up. otherwise, we try
				//to return the movie from the inventory
				if (!tempMov->readTrans(file))
				{
					delete tempMov;
					tempMov = NULL;
					return false;
				}
				else
				{
					if (!cust->returnMovie(tempMov))
					{
						cout << "Invalid movie. Transaction could not be "
							<< "executed.\n";
						delete tempMov;
						tempMov = NULL;

						return false;
					}
					else
					{
						Movie* mov;
						//use a movie locator and a movie return value
						//to try to return the movie from the stores
						//inventory, if the return couldn't occur
						//we must delete the temporary movie
						if (!st.getInventory().returnMovie(mov, tempMov))
						{
							//if we couldn't return we must clean up
							cout << "Invalid movie." <<
								"Transaction could not be "
								<< "executed.\n";
							delete tempMov;
							tempMov = NULL;

							return false;
						}
						else
						{
							//otherwise everything worked out perfectly
							//so the data is set and the customer
							//adds this transaction to his/her trans hist
							//and clean up our temp mov
							setData(cust, mov);
							//cust->returnMovie(mov);
							delete tempMov;
							tempMov = NULL;
							cust->addTransaction(this);
//.........这里部分代码省略.........
开发者ID:chrisadubois,项目名称:moviestore,代码行数:101,代码来源:returnx.cpp


注:本文中的Customer::returnMovie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。