C++ Assingment

Hello Everyone

Please kindly assist I am new to programming and really have not found my head around the assignment is due on Monday and now I am in desperation mode ... please help





Question 1

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.

Question 2
A teacher at Leva Primary School needs to divide her class in different group sizes according to the activity they
have to do. This will help her to prepare workstations for each group. For example, for art projects the class has to
be divided in groups of 6; for science projects the class has to be divided in groups of 4. She asked you to write a
program to determine the number of groups as well as the number of pupils who are left to form a smaller group.
There are 56 pupils in the class.
The program has the following structure:
Declare three int variables nrPupils, nrGroups, and nrLeft. nrPupils represents the number of
pupils in a class, nrGroups represents the number of groups the class is divided into, and nrLeft
represents the number of pupils, if any, who are in the 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. E.g. Please
enter the size of each group?
Write the statement to calculate the number of groups of size groupSize.
Write the statement to calculate the number of pupils who are in the remaining smaller group.
The output of the program must be displayed as follows:
There are 9 groups consisting of 6 pupils
There are 3 remaining pupils
Submit both your program and output.


Question 3
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.
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
Submit both your program and output.


Question 4
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"
Submit both your program and output.


Question 5
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.


Question 6
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
// 'O'(other)
float discount, finalAmount;
Submit both programs and their output.

Please post your code.

For Question 1, if the recipe calls for "2 cups of flour", you could do this:
cout << 2*mfactor << " cups of flour.\n";
Cplusplus doesn't answer the assignment questions. First write your own code. Then we will help you if you stuck. But anyway drop me your email. My email is Kdmuthavhine@gmail.com before the 16 May 2016
Dhyden isn't mfactor for question 1 is mFactor with capital letter F and mFactor is constant and fixed and intialized ie int mFactor =4;
Yes it's mFactor, but it isn't constant. The instructions say "The quantity of each ingredient must be multiplied by a value entered from the keyboard." and "Declare an int variable named mFactor".

So it isn't constant in the C++ sense of the word. However, it is true that once you enter the value, it doesn't change.
Topic archived. No new replies allowed.