question by using C++ programming language,and please note that only Repetition Statement and Selectionstatement (if/if-else/swtich) are allowed to be used. Do not usefunctions, OOP, Arrays and Pointers to do this question! And allprogram codes (in C++) must be inside the "int main() { return 0;}. Moreover, only return 0 in this question is allowed. Pleasedon't use other return functions, such as return 1, return sum andso on.
Please also note that your answer can follow all the sampledisplays (Only Even Version is needed!). No error is allowed.
Thank you very much.
Question 1 (30%) Write your code in Q1() that first asks the user to enter a positive integer, then prints out messages depending on the digits of the integer. The messages should be printed in the following correct order. ● Number of digits in the integer. Odd Version (6th digit of your student ID is 1, 3, 5, 7 or 9) Sum of all odd position digits of the integer. Note that the unit digit is the first position, the tenth digit is the second position and so on. For example, if the input is 123456, then the sum is 6+4+2=12. Some of the testing scenarios are given below for your reference. You should test your code using these and other important test cases to ensure it follows the specified requirements above. Odd Version (odd 6th digit in student ID) Even Version (even 6th digit in student ID) Even Version (6th digit of your student ID is 0, 2, 4, 6 or 8) Sum of all even position digits of the integer. Note that the unit digit is the first position, the tenth digit is the second position and so on. For example, if the input is 123456, then the sum is 5+3+1=9. Sample display Input: 123456 6 12 Sample display Input: 13579 5 15 2 8 Sample display Input: 38 1 0 Sample display Input: 0 Sample display Input: 123456 6 9 Sample display Input: 13579 5 10 Sample display Input: 38 2 3 Sample display Input: 0 1 0
Please help do this Question 1 (30%) Write your code in Q1() that first asks the user to enter a positive integer, then prints out messages
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am