Thread: Need help with C++ programming work

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    8

    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. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    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. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    Hope I can get help and thanks if you do .

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    50
    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. #7
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    learn the bodmas rule
    Aren't we supposed to learn it at about 8 yrs of age ?

  8. #8
    Registered User
    Join Date
    Apr 2011
    Posts
    50
    ya but maybe it takes a lot of time to be applied on field(for some people)..

  9. #9
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    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. #10
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    % finds the remainder..
    && ..does whatever you used & for..since learning to write the symbol..

  11. #11
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    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. #12
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Use C++ to verify it.. Maybe that was the reason the task was given !

  13. #13
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    It seems fine. Just need hints or a solution with question 3 and 4. Thanks.

  14. #14
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    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. #15
    Registered User
    Join Date
    Apr 2011
    Posts
    50
    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).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to co-work in programming?
    By ovid in forum C++ Programming
    Replies: 3
    Last Post: 05-24-2010, 12:28 PM
  2. New to programming: home work
    By chaos_defined in forum C Programming
    Replies: 4
    Last Post: 09-07-2006, 12:43 PM
  3. device driver programming....how does it work
    By the bassinvader in forum C Programming
    Replies: 4
    Last Post: 07-09-2006, 03:31 AM
  4. Replies: 5
    Last Post: 01-18-2006, 08:59 AM
  5. Replies: 7
    Last Post: 03-23-2003, 04:40 PM