The Virtual Weight (VW) of an integer number (which consists of more than 1 digit) is the sum of the individual digits that are composing the number. For example, consider the following two numbers; 5638 and 1145, then the VW of each is calculated as following: VW(5638) = 5+6+3+8 = 22 VW(1145) = 1+1+4+5 = 11 Then, the VW can be classified as L (mean Low) or H (means High) using a specific cut-off value. For example, if the cut-off value is 15, then the VW of the number 5638 is H (High), and the VW of the number 1145 is L because 22 > 15 and 11 ≤ 15 respectively Write a C++ program that: reads a positive integer n (where 5≤n≤20) from the user. If the user enters invalid number, then the program should continue prompting until he/she enters a valid number within the specified range. Then, the program should generate n random numbers using the built-in rand() function. Every time a random number is generated, the program will classify that number as L or H using the above method. Use a user-defined function to handle this process (see below, the description of Function1) Also the program will count how many Low and High VW’s for the generated numbers using another function named countVW(…) – see the description of the Function2. Finally, the program will compute the sum of the numbers which have Low VWs only and display the result as illustrated in the sample output. The program must use at least two functions as following: 1. A function to process the given number in the parameters list, and specify whether its VW is ‘L’ or ‘H’ based on the given cut_off value in the parameter list. The function returns one character either ‘L’ or ‘H’. The prototype is given blow: Prototype: char classify(int num, int cut_off); //--use cut_off = 15 2. A function to count the classifications of the generated numbers. Every time is called, the function increases (by 1) one of the counters that are defined in the main program to count the L or H cases. Prototype: void countVW(int &counter); //--notice the call by reference
The Virtual Weight (VW) of an integer number (which consists of more than 1 digit) is the sum
of the individual digits that are composing the number. For example, consider the following
two numbers; 5638 and 1145, then the VW of each is calculated as following:
VW(5638) = 5+6+3+8 = 22
VW(1145) = 1+1+4+5 = 11
Then, the VW can be classified as L (mean Low) or H (means High) using a specific cut-off
value. For example, if the cut-off value is 15, then the VW of the number 5638 is H (High),
and the VW of the number 1145 is L because 22 > 15 and 11 ≤ 15 respectively
Write a C++ program that:
reads a positive integer n (where 5≤n≤20) from the user. If the user enters invalid
number, then the program should continue prompting until he/she enters a valid number
within the specified range.
Then, the program should generate n random numbers using the built-in rand()
function.
Every time a random number is generated, the program will classify that number as L
or H using the above method. Use a user-defined function to handle this process (see
below, the description of Function1)
Also the program will count how many Low and High VW’s for the generated numbers
using another function named countVW(…) – see the description of the Function2.
Finally, the program will compute the sum of the numbers which have Low VWs only
and display the result as illustrated in the sample output.
The program must use at least two functions as following:
1. A function to process the given number in the parameters list, and specify whether its
VW is ‘L’ or ‘H’ based on the given cut_off value in the parameter list. The function
returns one character either ‘L’ or ‘H’. The prototype is given blow:
Prototype: char classify(int num, int cut_off);
//--use cut_off = 15
2. A function to count the classifications of the generated numbers. Every time is called,
the function increases (by 1) one of the counters that are defined in the main program
to count the L or H cases.
Prototype: void countVW(int &counter);
//--notice the call by reference
Step by step
Solved in 3 steps with 3 images