Assignment 1
Assignment 1
1. Void function named DisplayOptions, that displays the following calculation options to
users:
2. A returning-value function named ReadUserChoice that will read and return the user
choice to the main function. The user should enter 1,2 or 3 otherwise, the function will
ask the user to re-enter his choice again.
Based on the entered value by the user, the program will call one of the three user-defined
functions: SquareRoot, POWER, Lower.
3. SquareRoot function is a is a returning-value function that read one number from user
and return its square root (Hint*: use a pre-defined function).
4. POWER function is a returning-value function that read two numbers from user and
returned the result where the first number is the base, and second number is the exponent
(Hint*: you can use a pre-defined function).
5. Lower function is a void function that take a character from a user and check if the
passed character is lower or not, if it is not lower, it will return the lower letter (Hint*:
use reference parameter).
The program then prints the results to users within the main function. Write all the required
libraires and the right function and variables data type.
Q2: What is the output of the following program? (2 marks)
1. #include <iostream>
2. using namespace std;
3. void welcomsg();
4. int sum(int a,int b);
5. int main()
6. {
7. int Choice;
8. int x,y;
9. cout << "Please select from the following option: "<<endl
10. <<"1 to display welcoming message"<<endl
11. << "2 to calculate the summation of two numbers"<<endl;
12.
13. cin >> Choice;
14. if (Choice == 1)
15. welcomsg();
16. else if (Choice == 2)
17. cout<<sum(x,y)<<endl;
18. else
19. cout << "Invalid input" << endl;
20. return 0;
21. }
22. void welcomsg()
23. {
24. cout << "Welcome to Programming 2 course" <<endl;
25. }
26. int sum(int a,int b)
27. {
28. cout<<"please enter two numbers"<<endl;
29. cin>>a;
30. cin>>b;
31. return a+b;
32. }
1. #include <iostream>
2. using namespace std;
Good luck J