Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,168,867 members, 7,872,882 topics. Date: Thursday, 27 June 2024 at 01:46 AM

I Need The Answer To This C++ Assignment By Saturday Please - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Need The Answer To This C++ Assignment By Saturday Please (1771 Views)

Help! Im Stuck With This C# Program / Please Programmars Help Me Out With This C# Program! I Have Test Tommorrow!!!!! / Programmer Should Please Help Me To Solve This C++ Questions (2) (3) (4)

(1) (Reply) (Go Down)

I Need The Answer To This C++ Assignment By Saturday Please by toluxa1(m): 9:25am On Mar 26, 2008
Please, programmers in the house. I am a 200L Maths/Computer student. We were given this assignment to be submitted on Mon. (31st). I humbly request the help of a good C++ programmer to help me and either send the code to my email address (honoura1@yahoo.com) or paste it here. Thanks and God bless. Below is the question.

1a) Write a program to test for a class named rational for performing arithmetic fraction. Use integer variables to represent the private instances variables of the class. The numerator and denominator e.g. fraction 2/4 = 1/2

b) Provide a constructor that enable an object of this class to be utilised when it is declared.

c) Provide public functions (methods) that perform each of the following;
i) add two rational numbers, the result of the addition should be stored in reduced form.
ii) print rational numbers in the form, a/b (where a is the numerator and b is the denominator).
iii) multiply two rational numbers.


I will be eagerly waiting for the answer. Thanks and God bless you all.


NACOSS, networking the world!
Re: I Need The Answer To This C++ Assignment By Saturday Please by klassnic: 1:28pm On Mar 26, 2008
You got to be kidding me! With the internet at your disposal you still can't
do your assignment.Come on tell me this is just a bad joke! grin .You don't
have to out source your assignment I suggest ask the house on information
on where to get resources to help you with writing your assignment.I personally
believe in DIY(Do It Yourself).
Re: I Need The Answer To This C++ Assignment By Saturday Please by Wallie(m): 11:40pm On Mar 26, 2008
#ifndef FRACTION_HPP
#define FRACTION_HPP

// **** BEGIN namespace CPPBook ********************************
namespace CPPBook {

/* Fraction class
*/
class Fraction {

/* private: no access from outside
*/
private:
int numer;
int denom;

/* public interface
*/
public:
// default constructor
Fraction();

// constructor from int (denominator)
Fraction(int);

// constructor from two ints (numerator and denominator)
Fraction(int, int);

// output
void print();
};

} // **** END namespace CPPBook ********************************

#endif /* FRACTION_HPP */

******************************************************************************************************
******************************************************************************************************
// include header file with the class declaration
#include "frac.hpp"

// include standard header files
#include <iostream>
#include <cstdlib>

// **** BEGIN namespace CPPBook ********************************
namespace CPPBook {

/* default constructor
*/
Fraction::Fraction()
: numer(0), denom(1) // initialize fraction with 0
{
// no further statements
}

/* constructor for whole number
*/
Fraction::Fraction(int n)
: numer(n), denom(1) // initialize fraction with n
{
// no further statements
}

/* constructor for numerator and denominator
*/
Fraction::Fraction(int n, int d)
: numer(n), denom(d) // initialize numerator and denominator as passed
{
// 0 as denominator is not allowed
if (d == 0) {
// exit program with error message
std::cerr << "error: denominator is 0" << std::endl;
std::exit(EXIT_FAILURE);
}
}

/* print
*/
void Fraction::print()
{
std::cout << numer << '/' << denom << std::endl;
}

} // **** END namespace CPPBook ********************************


Here's an example that does fractions. Start by compling this example and then modifying it to suite your needs.


http://www.josuttis.com/cppbook/classes/frac1.cpp.html
Re: I Need The Answer To This C++ Assignment By Saturday Please by Ghenghis(m): 7:09am On Mar 27, 2008
cheesy
@Wallie
The plot thickens ,
And you think he'd be able to do that? i.e compile (or even know that your code is meant to be two translation files grin)
I agree with @klassnic
Re: I Need The Answer To This C++ Assignment By Saturday Please by toluxa1(m): 1:40pm On Mar 27, 2008
Thank you very much Wallie. The program I wrote yesterday was just a little different from this. This will help me reconstruct my program. I also like the REMARK style in this one. klassnic, it's not that I wanted someone to just write a program for me and then i'll copy and submit. First of all we hav'nt even gotten to this aspect of C++ in school. It's because I have read alot ahead of the lecture that I can even understande this program. 90% of my class wont even understand the program. So Ghenghis , I do understand it. The thing is when I called for help with this problem on this problem, I had'nt really understood the questions. Once again, thank you all.
Re: I Need The Answer To This C++ Assignment By Saturday Please by toluxa1(m): 6:37pm On Mar 28, 2008
toluxa1:

i) add two rational numbers, the result of the addition should be stored in reduced form.

I dont think this program stodes the result in REDUCED FORM.

What do you think?

(1) (Reply)

I Want To Become A Java Developer / Php Haters Beat This / Easily Convert PDF Files To HWP For Processing Properly

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.