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.
The Computer Science Department follows certain criteria when a student learns to program. A number of
programming exercises must be worked through. To proceed to the next exercise a student has to obtain a mark
of 50% or more and must have completed 5 or more program runs. You are requested to write a program to validate
if a student can proceed to the next program.
Your program should have the following structure:
Declare two integer variables programsDone and result.
Validate the data captured for the two variables using a while loop.
The loop should be repeated until the value of result is greater than or equal to 50 and the value of
programsDone is greater than or equal to 5.
Display a message like "Good! You can now proceed to the next exercise"
You are requested to write a very simple calculator. Your calculator should be able to handle the five basic
mathematic operations – add, subtract, multiply, divide and modulus – on two input values.
18
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.
A typical run is displayed below:
Please enter the first float value: 35.6
Please enter the second value: 24.12
Please enter the operation required : +
The sum of 35.6 and 24.12 is 59.72
Find a good cookbook. Read the instructions for your favourite dish. Write a program to display the recipe on the
screen but with a difference. The quantity of each ingredient must be multiplied by a value entered from the
keyboard.
For example, if the recipe needs 2 cups of flour the output displayed will be something like this
Please enter the factor to multiply the ingredients with : 4
Recipe name
Ingredients
// other ingredients
8 cups flour
Method
The program has the following structure:
Declare an int variable named mFactor to store the value with which the quantity of each ingredient
must be multiplied.
The program must make use of a cin statement to input a value from the keyboard and store it in mFactor.
Submit both your program and output.
Create a program that calculates the cost of building a desk. The main() function calls four other functions. Pass all variables so that the function makes copies of any variables they receive:
Write a program that will display a calendar given a month and year as an input to the program. Will display only single month of year given. Here it’s that if given input as ( April 2003) will display only the given month of the year.
Write a program that simulates
a simple cash register. It should ask the user if a customer is to be
processed. If the user responds yes, prompts the user to enter the
price of the meal. Then it calculates the sales tax (8% of the meal price)
and the total price, which it should display to the user. Next, it asks the
user to enter the amount tendered, and displays the amount tendered, the total
price, and the customer’s change. The program then asks the user if there is
another customer to process. If the user responds yes, the program processes the
next customer in the same way. This procedure continues indefinitely until the
user responds no to the prompt for another customer. Finally, the program
displays the total number of customers it processed and the grand total of all the
meal prices. Input Validation: Do not accept a number less than 1 for the price of the meal. Do not accept a value for the amount tender that is less than the total price.
The screen size of a TV is given by the length of the rectangular diagonal. Traditional TVs come in 4:3 ratio, that is, the ratio of length to width is 4 to 3. This means, if the length is x inches, then the width is (3/4)x. LCD TVs come in 16:9 ratio. Write a program that prompts the user to input the length of the diagonal (in inches) of the screen and allows the user to select which type of TV’s screen length, screen width and screen area the user would like to calculate. Have the program display the desired results.