1. Write a program using string functions that determine if the input word is a palindrome. A palindrome word is a word that produces the same word when it is reversed.
Write a program using standard string functions that
accepts a price of an item and display its coded value. The
base of the key is:
X C O M P U T E R S
0 1 2 3 4 5 6 7 8 9
Write a program to read the content of a file and copy its content to another file after converting all the capital case letters in the file to small case letters.
Create a Python script that will reduce an input fraction to its lowest term. The program requirements will be:
Sample Output:
Input a fraction? : 4/6
Reduced fraction is 2/3
I need the code to have an output stated above and that the requirements are met in the code.
The following code is supposed to display the positive even numbers less than 12. That is, it will
output the numbers 2, 4, 6, 8 and 10. However, there is a logical error in the code. Explain what the output
of the code below will be. Then write a small program including the code below and make the necessary
changes to fix the code so that it displays what it is intended to display. Ensure that your program works
correctly. Only submit the program, not the output.
Hint: Use variable diagrams to trace the program to help you find the logical error.
int x = 1;
while (x
!= 12)
{
cout << x <<
endl; x = x +
2;
}
A bookshop gives discount to customers as follows:
• Students get 10% discount,
• Book dealers get 12% discount and
• Pensioners get 15% discount.
• All other customers get 10% discount only if their total purchases are more than R200.
You are requested to write two versions of a program that calculates and displays the final amount that is
due, after discount.
(i) The first version of the program uses a switch statement to implement the above program.
(ii) The second version of the program uses nested-if statements.
Hint:
Use the following variables:
float amount; // the amount due before discount
char customerType; // the type of customer: 'S' (student) or
// 'D' (dealer) or 'P' (pensioner) or
COS1511/103/0/2022
5
// 'O'(other) float discount,
Include the for loop below in a small program and complete the program. The loop should execute 10
times. Do not change the for loop below. Compile and run your program to see for yourself that it works.
You do not have to submit this program and output.
for (int i = 1; i <= n;
i++) cout << i * i;
Now convert the for loop into a while loop and add any variable initialisations that you think are
necessary. Compile and run your program and submit only the program containing the while loop and its
output
You are requested to write a very simple calculator. Calculator should be able to handle the five basic mathematic operations – add, subtract, multiply, divide and modulus – on two input values. Your program should have the following structure:
Ask the user to enter two float variables named var1 and var2
Ask the user to enter a character variable named operation to represent the operation to be
performed on the two variables.
Perform the appropriate operation by using if-statements
The output must be given in fixed-point notation with two digits after the decimal point
Teacher at Leva P School needs to divide her class in different group sizes due to activity they have to do. Help her to prepare workstations for each group. For art projects the class divided in groups of 6; science projects in groups of 4. She asked to write program to get number of groups and number of pupils left to form a smaller group. There are 56 pupils in the class.
Declare three int variables nrPupils, nrGroups, and nrLeft. nrPupils represents the
number of pupils in a class, nrGroups number of groups the class divided into, and nrLeft number of pupils remaining smaller group. Assign the value 56 to nrPupils. Declare an int variable groupSize that is used by a cin statement to input a value from the keyboard and store the size of the groups the teacher requested. Display an appropriate message. Please enter the size of each group? Write the statement to calculate the number of groups of groupSize. Write the statement to calculate the number of pupils who are in the remaining smaller group
The user should enter the following values: Gross monthly income (before deductions) Estimated monthly tax deducted,Estimated monthly expenditures in each of the following categories,Groceries,Water and lights Travel costs (including petrol),Cell phone and telephone,Other expenses. The user shall be able to choose between renting accommodation or buying a property. 3. If the user selects to rent, the user shall be able to enter the monthly rental amount. 4. If the user selects to buy a property, the user shall be required to enter the following values for a home loan: a. Purchase price of the property b. Total deposit c. Interest rate % d. Number of months to repay (between 240 and 360) 5. The software shall calculate the monthly home loan repayment for buying a property based on the values that the user entered If the monthly home loan repayment is more than a third of the user’s gross monthly income, the software shall alert the user that approval of the home loan is unlikely. NB:MAKE USE OF GENERIC CLASSES