SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
C/C++

Assignment on Simulation and Modeling on “Barber Shop”

E-mail Print PDF

This article is an assignment of year fourth students of Royal University of Phnom Penh in 2004 in the course Simulation and Modeling under the Computer Science field. It describes about building a Simulation on barbershop. Choose the single server queuing system model to build the simulation. The program generation will describe on Tourbo C++ programming language. Please download document and source code in turbo C++ programming below!


 
Download Source Code
Download Document
 

How to find greatest common divisor (GCD) of two numbers in C++?

E-mail Print PDF
The below code is a function in C++ use to return GCD (greatest common divisor of two numbers.
Example:
GCD of 20 and 5 is 5
GCD of 24 and 18 is 2
int GCD(int x, int y)
{
	while(x!=y)
	{
		if(x>y)x=x-y;
		else y=y-x;
	}
	return(x);
}
 

Calculate sum of Fibonacci in C++

E-mail Print PDF
The below code is to calculate the sum of Fibonacci (s=1+2+3+5+8+....).
Example:
if n=2 => s=1+2
if n=3 => s=1+2+3
if n=4 => s=1+2+3+5
if n=5 => s=1+2+3+5+8
.....................
long Fibonacci(int n)
{
	long s=0;
	int f1, f2, f;
	f1=1;
	f2=2;
	s=f1+f2;
	for(int i=3;i<=n;i++)
	{
		f=f1+f2;
		s+=f;
		f1=f2;
		f2=f;
	}
	return s;
}
 

How to get perfect number in C++?

E-mail Print PDF
This article shows you the C++ code to display perfect number between two defined numbers.
A perfect number is a positive integer that is equal to the sum of its proper positive divisors excluding the number itself.
Example: 28=1+2+4+7+14
void showPerfectNumber(int start_n, int end_n)
{
	int s, k;
	int d[5000];
	for(int i=start_n; i<=end_n; i++)
	{
		s=0;
		k=0;
		d[k]='\0';
		for(int j=1; j<=i/2; j++)
		{
			if(i%j==0)
			{
				s+=j;	
				d[k]=j;
				k+=1;
			}
		}
		if(s==i) 
		{
			printf("%d is perfect. Its divisors are\n",i);
			for(int i=0;i<k;i++)
			{
				printf("%d",d[i]);
				if(i<k-1) printf(", ");
			}
			printf("\n");
		}
	}
}

  Download Source Code Here
 

How to know prime number in C++?

E-mail Print PDF
This article codes in Visual C++ shows you how to know one number is a prime number or is not.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Example: 2, 3, 5, 7,...
bool isPrime(int n)
{
	bool blnRe=true;
	
	for(int i=2;i<=n/2;i++)
	{
		if(n%i==0)
		{
			blnRe=false;
			break;
		}
	}

	return blnRe;
}
Download Source Code
 


Page 2 of 5