Require programmers assistance

Hi all! I'm new to programming and there are a few questions I'm stuck on that i'm not sure the answers to.
1) Can we concatenate endl with a string in an expression? Explain.
2) Write expressions that implement the following formulas.
a. X + 2Y + Z/2
b. A2 + 2AB + B2
c.
d. X +
e. -X-sin(Y)

Help!!!!!! I'm so lost.
That doesn't really help me any... There's nothing in there that really helps me answer these questions. I also have a textbook that is not helping. I need it simplified...
The first question is asking, basically, whether you can do:
some_string + endl

The second just wants you to write how you would calculate the given formulas in code.
I know! Oh boy...nevermind... I don't know if i'm going to get any help off this site huh.
Zhuge explained as well as he could without giving away the answers. The people on these forums don't get in the habit of giving away the answers to homework problems.

How about this... try to answer them yourself and post what you think is the correct answer -- then we can help correct you or explain away anything that's confusing you.
I am still lost and really need some help. Here's what i've come up with so far:
1) endl is only used as a manipulator in an output statement, not a string expression. For example, it can be included in an output statement beginning with cout <<. Is this correct?

2) Nooooo idea. I really don't even know where to begin. Even if someone could just do the first one so I have an idea what is supposed to be done??

Please help..i'm very lost with all of this. This question is not in the textbook..it's a question made up by my prof and so I can't find any resources or comparisons...
endl is equivalent to the character/string "\n"
If I am not mistaken you should be able to just take any sting variable and use the concatenation operator to tack on the endl/"\n".
Ex:
1
2
string str;
str = str + endl // or you could write str = str + "\n" 

http://cplusplus.com/reference/string/operator+/
That should enable you to answer that part.

For the second part there in your question simply just assume the variables are already defined (unless you are told otherwise), and then just write statements that execute that expression.
For example the first one would be:
1
2
X + 2 * Y + Z / 2;  // and the spaces are not actually necessary
// you could write: X+2*Y+Z/2;  

--- Edit --- You may want to know how to use the sine function.
http://cplusplus.com/reference/clibrary/cmath/sin/
Last edited on
Thank you very much for your help! It definitely guided me in the right direction I really appreciate it.

This is what i have so far: (couldn't figure out d. and e.)
a. X + 2Y + Z/2
= X + 2 * Y + Z / 2
b. A2 + 2AB + B2
= A * A + 2 * A * B + B * B

d. X + square root of (A + B)2 *I wasn't sure how to copy the whole thing over as it wouldn't let me so I wrote out that it was in a square root formula, squared
e. -X-sin(Y)

Topic archived. No new replies allowed.