# Thread: Need help with C++ programming work

1. ## Need help with C++ programming work

Hi, I'm new to programming and I'm doing a course in uni. I'm currently using "Dev-C++". I've been away on holidays and haven't been able to grasp the work we're doing now. I would really appreciate it if any of you C++ programming geniuses helped me with my work as I'm in a troubling situation with no idea what to do. If anyone is so helpful enough to help me with some of the questions or as much as you can then I will be so grateful. I will use this help to learn and understand more about C++ but for now I just need help on these questions.
Thanks.

Q.1

Option A
Using parentheses, rewrite the following expression to indicate the correct order of evaluation. Then evaluate the expression, assuming a=5, b=2, and c=4.

a % b * c && c % b * a

Option B
Determine the value of the following expression, assuming a=5, b=2, c=4, and d=5.

d % b * c > 5 || c % b * d < 7

Option C
Using parentheses, rewrite the following expression to indicate the correct order of evaluation. Then evaluate the expression, assuming a=5, b=2, and c=4.

b % c * a || a % c * b
Q.2
Option A
Write a C++ program to compute and display a person's weekly salary as determined by the following expressions:

If the number of hours worked is less than or equal to 40, the person receives \$8.00 per hour; otherwise, the person receives \$320.00, plus \$12.00 for each hour worked over 40 hours.

The program should request the hours worked as input and should display the salary as output.

Option B
Write a C++ program that accepts a character using the cin object and determines whether the character is a lowercase letter. A lowercase letter is any character that is greater than or equal to 'a' and less than or equal to 'z'. If the entered character is a lowercase letter, display the mssage The character just entered is a lowercase letter. If the entered letter is not lowercase, display the message The character just entered is not a lowercase letter.

Q.3

This question is in regard to the C++ program

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
double monthlySales, income;

cout << "Enter the value of monthly sales: ";
cin >> monthlySales;
if (monthlySales >= 50000.00)
income = 375.00 + .16 * monthlySales;
if (monthlySales >= 40000.00 && monthlySales < 50000.00)
income = 350.00 + .14 * monthlySales;

// simplified here from the one in the textbook
if (monthlySales < 40000.00)
income = 200.00 + .03 * monthlySales;

cout << "\n\n\The income is \$" << income << endl;

return 0;
}

and the C++ program

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
double monthlySales, income;

cout << "Enter the value of monthly sales: ";
cin >> monthlySales;

if (monthlySales >= 50000.00)
income = 375.00 + .16 * monthlySales;
else if (monthlySales >= 40000.00)
income = 350.00 + .14 * monthlySales;

// simplified here from the one in the textbook
else
income = 200.00 + .03 * monthlySales;

cout << "The income is \$" << income << endl;

return 0;
}

Option A

Will these two programs produce the same output?
Which program is better? Why?
Draw the flow chart for the first C++ program.

Option B

Will these two program produce the same output?
Which program is better? Why?
Draw the flow chart for the second C++ program.
Q.4

Option A, B
For the following C++ program

#include <iostream>
using namespace std;

int main()
{
int num = 0;
while (num <= 20)
{
num++;
cout << num << " ";
}

return 0;
}

determine the total number of items displayed, and the first and last numbers printed. Draw the flow chart for the C++ program, and then desk-check the program for the first 5 steps and the last 3.

2. I don't know if you read the big Homework link at the top of the forum, so here it is again just in case: Homework Policy

It doesn't matter how nicely you ask or how sorry you try to make your situation seem, we have a policy. Show your attempts and ask questions about specific questions you get stuck. Saying "I don't know anything! Do this for me!" won't get you anywhere here.

3. > I've been away on holidays and haven't been able to grasp the work we're doing now.
Well good for you - you took the prize, and now we get to do your homework for you.

Here's an idea - just drop the course, because you don't have what it takes to finish it.

> I would really appreciate it if any of you C++ programming geniuses helped me with my work
How To Ask Questions The Smart Way

4. I really am having trouble and I have attempted some of the questions. For example in question 2 I have managed this but am not sure if I am right. If any of you can please give me a full display of the program then I would appreciate it but this is my answer to question 2:

Option A
//input hours worked hr
int salary;
if(hr<=40 && hr>0)
salary=hr*4;
else
salary=320+((hr-40)*4);
//print salary
Option B
//input character ch
if(ch>='a' && ch<='z')
//print

Also for question 3 I think they produce the same output but I am not sure which program is better and why as well as how to draw a flow chart.

Finally, for question 4, I believe there's 21 items? I just need help with the flow chart and desk checking. Also have no idea for question 1.

I really am trying. Thanks.

5. Hope I can get help and thanks if you do .

6. for q.1 learn the bodmas rule and remember || is the expression for "or" and so work out the meaning for the expressions on the either side of it seperately and use logic of "or".
q.2 b. cant you compile and run your own program. as for sec.b read about ascii values and use int data type; if ur code doesnt work out.
q.3 think which program uses more checking, that should be worse.
q.4 there is nothing to tell..

7. learn the bodmas rule
Aren't we supposed to learn it at about 8 yrs of age ?

8. ya but maybe it takes a lot of time to be applied on field(for some people)..

9. For question 1, what are the % signs and the && signs? Can you just hint to me how to wor this out. I just read up on bodmas rule and understand that but can't apply it to the question. Also how do i rewrite the expression as it says. Thanks.

10. % finds the remainder..
&& ..does whatever you used & for..since learning to write the symbol..

11. I have managed this for question 1, is it correct?

Option A

a=5, b=2, and c=4.

a % b * c && c % b * a

5 % 2 * 4 && 4 % 2 * 4
((5 % 2 * 4) && (4 % 2 * 4)) on the left they are all of the same priority so only need the single set of parents.
Now do them left to right
((1 * 4) && (0 * 4))
((4) && (0))
(4 && 0) Anything not 0 is true
true && false. As I stated above in an AND statement everything must be true for the statement to be true.
So this gives you false.

Also I just need more specifics for question 3 and 4. I know that the programs produce the same output but don't know which program is better. Also need more help on flow charts for both question 3 and 4 as well as desk checking.

Thanks.

12. Use C++ to verify it.. Maybe that was the reason the task was given !

13. It seems fine. Just need hints or a solution with question 3 and 4. Thanks.

14. Can I get a hint for question 2 please? Also, the flow chart questions for 3 and 4? Don't know how to do flowcharts. Thanks.

15. Flowchart is one thing i guess everyone hates deeply and that is why it is given in every class project or exam. I am sorry to say but no one will try to teach you flow chart here.. your book is has the reqd. theory to teach it.. the best hint or whatsoevr on my part is think about the steps taken by the compiler to do it.. and try debugging on your compiler (if you want to know abput the steps).