CS Test 4 - Problem - Solving and Design

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

CS

COMPUTER SCIENCE – DECISION MAKING

1. Sort 3 real numbers in descending order. Use nested if statements.

2. Write a program that finds the biggest of three integers, using nested if statements.

3. Write a program that finds the greatest of given 5 numbers.

4. Write a program (using Case) that applies bonus points to given scores in the range [1…9]
by the following rules:
 If the score is between 1 and 3, the program multiplies it by 10.
 If the score is between 4 and 6, the program multiplies it by 100.
 If the score is between 7 and 9, the program multiplies it by 1000.
 If the score is 0 or more than 9, the program prints an error message.

5. Your school needs to choose SRC leaders for next year. The IG and AS learners have cast
their votes. Write a program to determine the chances of a specific learner to become a SRC
leader. The following values have to be entered:

 The total number of learners in IG and the total number of learners in AS


 The number of votes the learner receives from the IG learners
 The number of votes the learner receives from the AS learners

The total number of votes is used to express the learner’s chances of becoming an SRC
leader as definitely, probable, possible or unlikely.

The criteria used to classify the learner’s chances are as follows:

Classification Criteria
Definitely 60% or more votes
Probable Less than 60% but more than 47% of votes
Possible From 40% - 47% of the votes
Unlikely Less than 40% of the votes

Display the total number of votes casted, the percentage of the total votes obtained and the
chances of the learner to become a SRC leader based on the given criteria.
6. Write a program which can be used to convert letters of the alphabet (upper and lower case)
to its corresponding ASCII value and vice versa. If a user enters an illegal number or letter,
an error message should displayed.

Computer Science Page 1 of 3


7. Write a program to generate a random number between 1 and 10 (both included).
 Allow the user to guess the secret number until the correct number is guessed.
 Count the number of guesses it took to guess the correct number.

 The program must display a message to tell the user whether the number guessed is lower
or higher than the secret number.

 For example, if the secret number is 8 and:


o If the user guesses 6, the message should be: Your number is too low!
o If the user guesses 10, the message should be: Your guess is too high!
o If the guesses the correct number, the message should be: Bingo! You are a star.

8. The organisers of a singing completion use a grading system to see whether a contestant
gets through to the final round:

 The judges and the public can cast votes.

 A score out of 100 must be calculated for each contestant using the percentage of public
votes, the number of judges’ votes and bonus points. The score of a contestant is
calculated as follows:

o The percentage of votes received from the public is converted to a value out of 60.
o The total number of votes from the judges (there are 4 judges) is converted to a value
out of 30.
o They score 10 additional bonus points if they receive more than 75% of the public
votes or more than 75% of the judges’ votes.

 To qualify to be in the final round, a contestant must have a score of at least 75 and have
the vote of at least two of the judges.

Input from the user:

 The total number of members of the public who voted, the number of member of the public
who voted for this contestant and the number of judges who voted for this contestant.

 Calculate and display the final score.

 Determine and display a message indicating whether the contestant qualifies for the final
round or not.

Computer Science Page 2 of 3


9. GVU requests a program that generates user passwords. Write a program that must accept
a student’s name and surname and generate the password as follows:
If the name starts with a consonant, a password needs to be compiled by combining the
following:

 first three letters of the name


 three digit random number between 100 and 999
 first three letters of the surname

If the name starts with a vowel, a password needs to be compiled by combining the following:

 last three letters of the name


 three digit random number between 100 and 999
 last three letters of the surname

If either the name or the surname contains less than 3 characters, an error should be
displayed.
For example:
Haydne Mole will return result Hay738Mol
Uriel Grobbelaar will return the result iel464aar
Li Xavi will return the result “Both Name and Surname should be at least 3 characters
long”

10. A company produces cooldrinks. They have three different machines that each delivers
volumes of cooldrinks per hour:
Machine A: 100 litres per hour
Machine B: 150 litres per hour
Machine C: 180 litres per hour

Write a program to do the following:

 Enter the letter indicating the machine and a number indicating the number of hours the
machine will be used that day. More than one machine can be used per day. The program
must be able to work with a capital or a lowercase letter as input.
 If the user enters an invalid letter (such as D), an error message must be displayed, and
the user must get the opportunity to re-enter the letter.
 Display the number of litres the machine will produce each time the details of that machine
is entered.
 Add up the litres for each machine, and display the following:

o The total volume of cooldrink the company will produce using all the machines for the
times that were entered that day.
o The cost to produce the total volume of cooldrink if the company produces cooldrink
at a cost of R2.00 per litre.
o The profit the company make if they sell the cooldrink at R4.50 per litre.
o If new machines are bought they can produce the cooldrink at R1.80 per litre.
Calculate and display the profit the company would have made with the figures entered
for that day if they have been using the new machines.

Computer Science Page 3 of 3

You might also like