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

📄 3iv.cpp

📁 C/C++程序设计导论(第二版)》程序源文件
💻 CPP
字号:
// Combcalc.cpp  Combinations calculations program
// Prompts the user for a group and committee size and then 
//   calculates the number of different committees that can be formed.

#include <iostream.h>

// Factorial()  Returns the factorial of the argument n.
// IN:  n is a positive integer
float Factorial (float n)
{	float product = 1.0;
	while (n > 1.0)
	{ 	product = product * n;
		n = n - 1.0;
	}
	return (product);
}

// Combi()  Returns the number of different of committees
//   that could be formed from group
//  IN: 	 group is a whole-number value greater than committee
//		committee is a positive whole-number value.
float Combi (float group, float committee)
{	float combinations;
	combinations = Factorial (group) / 
		(Factorial (group - committee) * Factorial (committee));
	return (combinations);
}

void main()
{	float group_size, committee_size, combinations;
	float done = 1.0;			
	while (done > 0.0)
	{	cout << "enter the size of the group and committee: ";
		cin >> group_size >> committee_size;
		if (group_size > committee_size)
		{	combinations = Combi (group_size, committee_size);
			cout << "for " << group_size << " people and " <<
				committee_size << " sized committees, the ";
			cout << "number of committees is " << 
				combinations << endl;
		}
		else  
			cout << " ** illegal values; group must be larger" << endl;
		cout << "Do you wish another calculation? ";
		cout << " enter 1.0 for yes, 0.0 for no: ";
		cin >> done;
	}
}

⌨️ 快捷键说明

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