Welcome! Log In Create A New Profile

Advanced

Assignment3 Q2

Posted by Kalimukwa 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment3 Q2
May 05, 2007 09:01PM
Help!!!
Anonymous User
smoking smiley Re: Assignment3 Q2
May 07, 2007 09:32AM
Eighter! let me give you two functions to calculate the biggest/smallest(invent the inverse for this), angry smiley "I hate lazy people".

int n(int x, int y)
{
return x > y ? x : y;
}

int m(int z, int x, int y)
{
int j = n(x, y);
return z > j ? z : j ;
}

Now you only need to call this functions inside the main functions, I hope you know how to call functions if not then go back and do cos111-u and only cos111-u, because there no shortcuts in programming.
Re: Assignment3 Q2
May 08, 2007 01:55AM
Thanks for the show of your intellect. angry smiley "Really helpful"

Now for those who can read;

I got two questions for assignment 3 question2

1) I've developed MyRational class and so far, I am able to add rational numbers without a problem. Using the same structure, I would be able to implement the other requirements like *, x, - ans less. Here my questions....

How are the rational numbers supposed to be taken in? I am taking them in as two seperate ints.....
e.g.
//variable declarations
int numerator2, denomenator2;
myCout >> "Please enter the rational number";
cin >> numerator2;
cin >> denomenator2;

The above works pretty good for me but not sure if that's what is required. Any leads?

2) The functions, (sub, mul and div should return a rational value.....what data type would this be? Would it be string, array or of the datatype of my class?
e.g.
MyRational rational(5,5);
.....some code
.....return rational;

Thanks in advance.
Re: Assignment3 Q2
May 09, 2007 07:42AM
The use of the tertiary if statement is really frowned upon, especially at this level.
If you use this method of the if statement in an interview or technical review, it will probably have the opposite effect than what you had hoped.
Re: Assignment3 Q2
May 09, 2007 12:06PM
Kalimukwa,

Try to get the input the same as the output ie x/y as a string and parse the sting for the nurm and denom values (do this in the class and not in the program). As for the next question you have to overload the operators if you want to use them in your program.


so in closing, all the workings should be done in the class and the main should like so...

MyRational R, Q;

cin >> R;
cin >> Q;

cout << R + Q;


D
Re: Assignment3 Q2
May 22, 2007 01:34AM
Thanks Doug....got one question though.

I've created my input function to read in a string that it casts out to double so the math on the rational number can be carried out. In my main program, I am able to get add & subtract right now using..... a.add(b) and a.sub(b).....Now how do I relate the functionality of my INPUT function and the fact that operations(addition, subtraction.....etc.....) must be done via a.operation(b)?

Thanks in advance

....some universities\colleges will issue a marking rubric along with an assignment so you know what the professors will mark you based on.......tends to be pretty helpful...
Re: Assignment3 Q2
May 22, 2007 09:10PM
Hi

Your input should generate two ints/floats/doubles and store them in the class' members. The add function should then take the two ints from the one class' instance and add them to the other class' instance in a manner suited to rational addition.

so the add should look something like

bool MyRational::add(const MyRational &other)
{
	//use something like 
	int dem = other.getDenominator();
	//add the rational 
	//return true if successful false if not
}

int MyRational::getDenominator() const
{
	return denominator;
}
Re: Assignment3 Q2
May 23, 2007 07:13AM
Aha! So we're dealing with two different instances...if we were adding three rational numbers we'd be dealing with three instances of the Rational Class....correct?

I'll sit down and see how I can best tie it all together....surprisingly, question 3 looks easier to wrap around than 2....looks like it's basically overloading the >> operator...but hey, this is UNISA we're talking about...I love this University!

It's all good dude, it's all good!
Sorry, only registered users may post in this forum.

Click here to login