Answer to Question #316241 in C++ for gift

Question #316241

1 .write c++ program using menu drive using switch to manipulate



case 1 for any user defined function, case 2 for passing argument by reference and value,



case 3 for passing argument by default, case 4 overloading function, case 5 recursive function, case 6 for built function.





2 .write c++ program to play game for dice by guessing the input random by using rand() function using loop.

1
Expert's answer
2022-03-22T19:07:37-0400

Here is program:

void Func()
{
	cout << "Test" << endl;
}
void Func2(int* ptr)
{
	cout << ptr << endl;
}
void Func3(int value)
{
	cout << value << endl;
}


int Func5(int n)
{
	if (n > 1)
		return n * Func5(n - 1);
	return 1;
}
inline void Func6()
{
	cout << "Hello!" << endl;
}
int main()
{
	// 1)
	int menu;
	cin >> menu;
	switch (menu)
	{
	case 1:
		Func();
		break;
	case 2:
		Func2(&menu);
		break;
	case 3:
		Func3(3);
		break;
	case 4:
		Func();
		break;
	case 5:
		Func5(4);
		break;
	case 6:
		Func6();
		break;
	default:
		break;
	}
	//2)


	srand(time(NULL));
	int random = rand() % 6;
	int n;
	for (int i = 0; i < 9999; i++)
	{
		cin >> n;
		if (n == random)
		{
			cout << "You win!" << endl;
		}
		else
		{
			cout << "You lose!" << endl;
		}
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog