GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Apr-2011, 09:08
moey187 moey187 is offline
New Member
 
Join Date: Apr 2011
Posts: 7
moey187 is on a distinguished road

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.


Quote:
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

Quote:
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.
Quote:

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.

Quote:
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  
Old 11-Apr-2011, 09:27
moey187 moey187 is offline
New Member
 
Join Date: Apr 2011
Posts: 7
moey187 is on a distinguished road

Re: Need help with C++ programming work


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
CPP / C++ / C Code:
//input hours worked hr
int salary;
if(hr<=40 && hr>0)
salary=hr*4;
else
salary=320+((hr-40)*4);
//print salary

Option B
CPP / C++ / C Code:
//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.
Last edited by admin : 12-Apr-2011 at 23:55. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #3  
Old 11-Apr-2011, 10:01
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 969
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Need help with C++ programming work


For question #1, see the Precedence of Operators on this page.

For question #2, try splitting out the regular-time hours and overtime hours:
CPP / C++ / C Code:
int hoursWorked = 0;
cout << "Enter number of hours worked: ";
cin >> hoursWorked;
int overtimeHours = 0;
if(hoursWorked > 40) overtimeHours = hoursWorked - 40;
int regularHours = hoursWorked - overtimeHours;
int salary = hoursWorked * 8 + overtimeHours * 12;
cout << "Your salary for the week is $" << salary;

For question #3, it looks to me like they will produce the same output. Option B is the better choice because it is uses if/else/else instead of if/if/if leading to a lower chance of programmer error. Do you see why?

For question #4, I suppose you should show a table for the desk checking:
Code:
num/printed 0/1 1/2 2/3 3/4 4/5 ... 18/19 19/20 20/21
Maybe you can think of a better way of doing this.
  #4  
Old 11-Apr-2011, 11:33
moey187 moey187 is offline
New Member
 
Join Date: Apr 2011
Posts: 7
moey187 is on a distinguished road

Re: Need help with C++ programming work


Thanks mate. Ive pretty much figured it all out except for the flowchart part in questions 3 and 4. If you can give me ideas or a possible solution then I would really appreciate it.

Thanks.
  #5  
Old 11-Apr-2011, 12:20
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 969
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Need help with C++ programming work


Here is how flowcharts work. For #4, you would have a the following:
1) Start
2) num = 0
3) Is num <= 20? If yes, go to 4, otherwise go to 7
4) Increment num
5) Print num
6) Go to (3)
7) End

Obviously, you will need to make it look like a flowchart instead.
  #6  
Old 11-Apr-2011, 16:45
moey187 moey187 is offline
New Member
 
Join Date: Apr 2011
Posts: 7
moey187 is on a distinguished road

Re: Need help with C++ programming work


Can I get a hint for question 2 option b please? Thanks. Ive learnt a lot and thank you for the help .
  #7  
Old 12-Apr-2011, 07:55
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 969
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Need help with C++ programming work


CPP / C++ / C Code:
char c = // Get from user input

if(c >= 'a' && c <= 'z')
{
  // c is lowercase
}
else
{
  // c is not lowercase
}
  #8  
Old 13-Apr-2011, 08:23
quneur quneur is offline
Junior Member
 
Join Date: Mar 2011
Posts: 59
quneur has a spectacular aura about

Re: Need help with C++ programming work


Q4

I like to think of it this way:
CPP / C++ / C Code:
// while control structure
while (expression is true)
   run block of code

evaluating the expression - question is the boundary conditions
CPP / C++ / C Code:
// break down the expression and rewrite it
// num <= 20 is equal to num < 20 or num == 20. Run if either is true.

// run the value 0 and 20. Both conditions throws a true.
// hence, runs 1 (num = 0) + 20 = 21 runs.
while (num < 20 || num == 20)
  #9  
Old 14-Apr-2011, 11:44
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 675
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: Need help with C++ programming work


Quote:
Originally Posted by fakepoo
CPP / C++ / C Code:
char c = // Get from user input

if(c >= 'a' && c <= 'z')
{
  // c is lowercase
}
else
{
  // c is not lowercase
}

Your else condition comment may be "flawed," while being precariously true. If c == '?' or c == '1' neither are "lowercase" per your comment, but they're not "alpha" either, which may suggest the "wrong" thinking to someone without your skills. islower and isupper are the preferred methods for checking the "caseness" of c. I didn't read all of the OP's post, so perhaps there is a requirement to not use any standard library functions?


MxB
  #10  
Old 14-Apr-2011, 12:01
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 969
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Need help with C++ programming work


Quote:
Originally Posted by Mexican Bob
Your else condition comment may be "flawed," while being precariously true. If c == '?' or c == '1' neither are "lowercase" per your comment, but they're not "alpha" either, which may suggest the "wrong" thinking to someone without your skills. islower and isupper are the preferred methods for checking the "caseness" of c. I didn't read all of the OP's post, so perhaps there is a requirement to not use any standard library functions?


MxB
Had you read the original post, you would have seen this:
Quote:
A lowercase letter is any character that is greater than or equal to 'a' and less than or equal to 'z'.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
GUI programming crystalattice C++ Forum 5 14-Sep-2004 12:17
Why doesnt my form work correctly? rhino1616 Web Design Forum 2 06-Nov-2003 17:21
How do web redirection scripts work? rhino1616 Web Design Forum 9 27-Oct-2003 09:47

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:27.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.