Homework almost there, please

I am trying to come up with the right codes and answers for this Lab. But I am a little overdone at this point any help for the correction that I need to perform would be great. Eyes are crossing and mind is blown. Thanks for your help. ???

#include <iostream>
using namespace std;

void getFrac(int& numerator, int& denominator);
void readFracProblem(int& num1, int& denom1, int& num2, int& denom2, char& op);
void addFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3);
void subFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3);
void multiFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3);
void divFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3);


int main()
{

int num1, denom1, num2, denom2, num3, denom3;
char op;

cout << "Please enter 1st & 2nd fraction with slash and either +, -, *, /. " <<endl;


readFracProblem (num1, denom1, num2, denom2, op);



if (op = '+')
{
addFrac(num1, denom1, num2, denom2, num3, denom3);
cout << "Answer is: " << num3 << "/" << denom3;
}

else
if (op = '-')
{
subFrac(num1, denom1, num2, denom2, num3, denom3);
cout << "Answer is: " << num3 << "/" << denom3;
}

else
if (op = 'x', 'X', '*')
{
multiFrac(num1, denom1, num2, denom2, num3, denom3);
cout << "Answer is: " << num3 << "/" << denom3;
}

else
if (op = '/')
{
divFrac(num1, denom1, num2, denom2, num3, denom3);
cout << "Answer is: " << num3 << "/" << denom3;
}

else
cout << "Operation is invalid!" << endl;


system ("pause");

return 0;


}




void getFrac(int& numerator, int& denominator)

{
char slash;
cin >> numerator >> slash >> denominator;
}

void readFracProblem(int& num1, int& denom1, int& num2, int& denom2, char& op)

{
getFrac(num1, denom1);
cin >> op;
getFrac(num2, denom2);
}

void addFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3)

{
num3 = num1 * denom2 + num2 * denom1;
denom3 = denom1 * denom2;

}

void subFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3)

{
num3 = num1 * denom2 - num2 * denom1;
denom3 = denom1 * denom2;
}


void multiFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3)

{
num1 * num2;
denom1 * denom2;

}

void divFrac( int num1, int denom1, int num2, int denom2, int& num3, int& denom3)

{
num1 * num2;
denom1 * denom2;
}

ok so what is the point of this program? can you give me some kind of sample output?

if i know what it is supposed to do, then i can help.
1
2

Last edited on
I can't you in how many ways this is wrong: if (op = 'x', 'X', '*')
To check if a equals b:
a == b
To check if a equals b, but not c:
a == b && a != c
To check if a equals b or c:
a == b || a == c

The assignment operator returns the value of the right-hand operator, so (a = x) == x. If x != 0, (a = x) == true, otherwise, (a = x) == false, regardless of the previous value of a.


num1 * num2;
This just makes the multiplication, but doesn't assign the result to anything.
To multiply the value of a by b and store the value back in a:
a*=b;
This applies to all operators:
a+=b;
a-=b;
a*=b;
a/=b;
a^=b; //Bitwise XOR. This is not exponentiation.
a&=b;
a|=b;
a&&=b;
a||=b;
And anything else I may have forgotten.
To multiply a by b and store the value in c:
c=a*b;

kevinchkin: How about you let him do some work?
Last edited on
Pass the numerator and denominator of both fractions to the function as input parameters that performs the operation(each function you write will perform only one operation). Return the numerator and denominator of the result through that functions output parameters.

Sorry, remeber I said my brain was toast. I am very new to any programing and I make a lot of errors in the process. But with each p[rogram i write I learn from you and from me. I need you, but you do not need me. I will try to be better in a few more attempts.
Hey, I just posted the corrected code, didn't that worked?

@helios: I understand what point you are trying to make. I usually avoid posting answers. But the main thing is that, it is not my responsibility to make sure that the person is learning or not. It should be the individuals responsibility to make sure that they are learning.
So, if you don't agree with me and you feel that we should take responsibility to make sure that the person is learning, then it's your point of view. It's obviously not mine.
Last edited on
I need you, but you do not need me.

ha ha ha WTH?
If you're not going to help as best you can then why bother posting at all?
If you're not going to help as best you can then why bother posting at all?


Dude, I don't know why you are getting so high and dry. I am not messing with you. You and I have different set of principles. If you don't want to post complete solutions then don't. You do what you feel is right and I'll do what I feel is right. I hope conversation ends here.
I'm not messing with you, either.
I think what I'm saying is pretty reasonable. When you post complete solutions you're saying "I don't care if you understand this or not, as long as it makes you quiet", which isn't really any help at all.
You could argue that if the person really wants to learn then they'll not look at what you posted -- which brings into question why you posted it in the first place -- but there's a problem in this reasoning. If the person really doesn't want to learn it, just pass, they can do this until they eventually graduate (people with degrees they don't deserve is not unheard of). And now we have yet another incompetent professional out there.
And now, an even worse scenario: the question is really for work. Now we have an ignorant getting paid for doing nothing, producing worthless code some poor bastard will have to maintain later.

It may sound ridiculous, but trust me, it's not that uncommon.


Finally, it's often simpler and faster to push people in the right direction than do it for them.
And now we have yet another incompetent professional out there.


I completely agree with you on this. I have felt this hell lotta times that some undeserving person got job or scholarship, and now I am just contributing in the creation of one more undeserving person. I am sorry about posting the solution earlier. I am deleting it right away. And I am really sorry if I have offended you in any sense.

Thanks
Topic archived. No new replies allowed.