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

A Member? Please Login  
type your username and password to login
Date: July 26, 2008, 01:50 PM
223803 members and 127112 Topics
Latest Member: Sandhuz
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  I Need The Answer To This C++ Assignment By Saturday Please
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: I Need The Answer To This C++ Assignment By Saturday Please  (Read 217 views)
toluxa1 (m)
I Need The Answer To This C++ Assignment By Saturday Please
« on: March 26, 2008, 09:25 AM »

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!
klassnic
Re: I Need The Answer To This C++ Assignment By Saturday Please
« #1 on: March 26, 2008, 01:28 PM »

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).
Wallie (m)
Re: I Need The Answer To This C++ Assignment By Saturday Please
« #2 on: March 26, 2008, 11:40 PM »

#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
Ghenghis (m)
Re: I Need The Answer To This C++ Assignment By Saturday Please
« #3 on: March 27, 2008, 07:09 AM »

 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
toluxa1 (m)
Re: I Need The Answer To This C++ Assignment By Saturday Please
« #4 on: March 27, 2008, 01:40 PM »

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.

toluxa1 (m)
Re: I Need The Answer To This C++ Assignment By Saturday Please
« #5 on: March 28, 2008, 06:37 PM »

Quote from: toluxa1 on March 26, 2008, 09:25 AM
i) add two rational numbers, the result of the addition should be stored in reduced form.

I don't think this program stodes the result in REDUCED FORM.

What do you think?
 Scjp Certification-pursuit Story  Ebooktalk.com - A New Ebooks Web Site  Making Application In Vb6 Transparent   Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Jobs (2) Career Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.