Im new and I need help very bad

I need help with this very bad. The professor wont get back to me and I am lost. All the other student aren't able to help me either. I have some code done but i have this as well to see the assignment. http://imgur.com/N011kop . Anthing can help. Thank you

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  #include <iostream>
using namespace std;
class Rational
{
	private:
		int numerator;
		int denominator;
		char signage;
		Rational();

	public:
		//double PrintFraction();
		void Set_mutator1(int num, int den, char sign);
		void Set_mutator2();
	
};
int main()
{
	int num, den;
	char sign;
	cout << "Please enter a number for the numerator." << endl;
	cin >> num;
	cout << "Please enter a number for the denominator." << endl;
	cin >> den;
	cout << sign;
	

	return 0;
}
Rational::Rational() {
	denominator = 1;
	signage = ' ';
}
void Rational::Set_mutator1(int num, int den, char sign){
	numerator = num;
	denominator = den;
	signage = sign;
	if (den >= 0 && num >= 0)
		sign = ' ';
	else
	{
		if (den < 0 && num < 0)
			sign = ' ';
		else
			sign = '-';
	}
	



}
void Rational::Set_mutator2() {


}
/*double Rational::PrintFraction() {


}*/
You are required to do:
Make a constructor which sets the denominator to 1 and the overal sign to '+'.
and you wrote:
1
2
3
4
Rational::Rational() {
	denominator = 1;
	signage = ' ';
}
Can you see what's wrong?

Next:
Include a mutator function with 2 integer arguments. It is to be used to set the (unsigned) numerator and the (unsigned) denominator, and determine the overal sign.

Either input can be negative or positive. And you have to take the absolute value of one for the numerator, the absolute value of the other for the denominator. Finally, you have to determine the sign and set it to + or -.

Can you do those steps?

First of all the sign. How do you determine the sign during division? If one is negatve, the result is negative, otherwise it's positive.

Then you have to work out how to set the absoulute value of a number. What does multiplying by -1 do to a number?

You have all the pieces, now you just need to code it.

Ok. You have more than enough information to do those two pieces. Let's see what you can do.
Last edited on
Topic archived. No new replies allowed.