|
|
|
HEY YOU!!!,
Our records indicate that you have never posted to our site before! Why not make your first post today by saying hello to our community in our new people forums.
To access all the good good stuff you need to post, post, and post more.
|
05-14-2004, 06:49 AM
|
#1
|
|
Guest
Posts: n/a/0
Threads:
|
This is an interesting section
Would i be able to get any C++ help from here?
That would be really sweet :rock:
|
|
|
|
|
|
|
quote
|
|
05-14-2004, 07:53 AM
|
#2
|
|
whore
Join Date: Feb 2004
Location: Ontario Canada
Posts: 719/0.41
Threads: 1
|
Re: This is an interesting section
ask?
|
|
|
|
|
|
|
quote
|
|
05-15-2004, 04:36 PM
|
#3
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
I might need help with a couple of programs, is that too much to ask?
|
|
|
|
|
|
|
quote
|
|
05-15-2004, 06:48 PM
|
#4
|
|
whore
Join Date: May 2004
Location: Dunno
Posts: 171/0.10
Threads: 0
|
Re: This is an interesting section
No.. but what he meant was "why dont you ask directly".. i dont use c++.. but im quite sure someone will help u
Greetz
|
|
|
|
|
|
|
quote
|
|
05-16-2004, 12:08 AM
|
#5
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
C++ is harder than u thought
|
|
|
|
|
|
|
quote
|
|
05-16-2004, 11:49 AM
|
#6
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
I failed C++ in college. Was very tough.
|
|
|
|
|
|
|
quote
|
|
05-16-2004, 09:03 PM
|
#7
|
|
whore
Join Date: May 2004
Location: Florida
Posts: 12/0.01
Threads: 0
|
Re: This is an interesting section
I know C, but very little of C++...sorry I can't help.
|
|
|
|
|
|
|
quote
|
|
05-17-2004, 01:44 AM
|
#8
|
|
whore
Join Date: May 2004
Location: Right Behind You
Posts: 760/0.46
Threads: 0
|
Re: This is an interesting section
Heh .. I took c++ about 4 years ago ... along with some other languages that I've forgotten.
I might still have my book. I'd suggest you ask a specific question and see if someone can answer.
good luck.
|
|
|
|
|
|
|
quote
|
|
05-17-2004, 02:46 AM
|
#9
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
You are to write a program that finds the rational number that is nearest to that number.
You should use code that you developed in CS1 or download the following interface (header) and implementation files for the rational number class: rational.h and rational.cpp.
Your assignment is to use modify this class and create a client program designed to locate a rational number < 1 that is an approximation to (PI - 3). Design methods for the class that support finding a solution and creating clear interface for the client.
As a first experiment repeatedly choose a random rational number <1 and test to see how close it is. How close can you get after 1000 iterations? How close can you get after 1,000,000 iterations? Finally, come up with an algorithm that does better than the random guess method you just tried. Run it for 1000 iterations, then for 1.000.000. How much better is your algorithm in each experiment? Submit these results as comments.
|
|
|
|
|
|
|
quote
|
|
05-17-2004, 02:46 AM
|
#10
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
oh yeah here is rational.h
// rational.h: declaration of Rational ADT
#ifndef RATIONAL_H
#define RATIONAL_H
#include <iostream>
// Rational ADT: class description
using namespace std;
class Rational {
public: // member functions
// constructors
Rational();
Rational(int numer, int denom = 1);
// some arithmetic and stream facilitators
Rational Add(const Rational &r) const;
Rational Multiply(const Rational &r) const;
void Insert(ostream &sout) const;
void Extract(istream &sin);
protected:
// inspectors
int Numerator() const;
int Denominator() const;
// mutators
void SetNumerator(int numer);
void SetDenominator(int denom);
private:
// data members
int NumeratorValue;
int DenominatorValue;
};
// Rational ADT: auxiliary operator description
Rational operator+(const Rational &r,
const Rational &s);
Rational operator*(const Rational &r,
const Rational &s);
ostream& operator<<(ostream &sout, const Rational &s);
istream& operator>>(istream &sin, Rational &r);
#endif
|
|
|
|
|
|
|
quote
|
|
05-17-2004, 02:47 AM
|
#11
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
and rational.cpp
//IMPLEMENTATION OF THE RATIONAL CLASS
#include <iostream>
#include "rational.h"
// default constructor
Rational::Rational() {
SetNumerator(0);
SetDenominator(1);
}
// (numer, denom) constructor
Rational::Rational(int numer, int denom) {
SetNumerator(numer);
SetDenominator(denom);
}
// get the numerator
int Rational::Numerator() const {
return NumeratorValue;
}
// get the denominator
int Rational::Denominator() const {
return DenominatorValue;
}
// set the numerator
void Rational::SetNumerator(int numer) {
NumeratorValue = numer;
}
// set the denominator
void Rational::SetDenominator(int denom) {
if (denom != 0)
DenominatorValue = denom;
else {
cerr << "Illegal denominator: " << denom
<< "using 1" << endl;
DenominatorValue = 1;
}
}
// adding Rationals
Rational Rational::Add(const Rational &r) const {
int a = Numerator();
int b = Denominator();
int c = r.Numerator();
int d = r.Denominator();
return Rational(a*d + b*c, b*d);
}
// multiplying Rationals
Rational Rational::Multiply(const Rational &r) const {
int a = Numerator();
int b = Denominator();
int c = r.Numerator();
int d = r.Denominator();
return Rational(a*c, b*d);
}
// inserting a Rational
void Rational::Insert(ostream &sout) const {
sout << Numerator() << '/' << Denominator();
return;
}
// extracting a Rational
void Rational::Extract(istream &sin) {
int numer;
int denom;
char slash;
sin >> numer >> slash >> denom;
SetNumerator(numer);
SetDenominator(denom);
return;
}
// adding Rationals
Rational operator+(const Rational &r,
const Rational &s) {
return r.Add(s);
}
// multiplying Rationals
Rational operator*(const Rational &r,
const Rational &s) {
return r.Multiply(s);
}
// inserting a Rational
ostream& operator<<(ostream &sout, const Rational &r) {
r.Insert(sout);
return sout;
}
// extracting a Rational
istream& operator>>(istream &sin, Rational &r) {
r.Extract(sin);
return sin;
}
|
|
|
|
|
|
|
quote
|
|
05-17-2004, 02:47 AM
|
#12
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
think you can help?
|
|
|
|
|
|
|
quote
|
|
05-17-2004, 03:02 AM
|
#13
|
|
whore
Join Date: May 2004
Location: peeing in the pool
Posts: 881/0.53
Threads: 3
|
Re: This is an interesting section
Looks like you have to write a program that returns 0.1415926....
Doesn't look like it takes any input, so write a program that calculates pi and subtracts 3 from the end result. Or you can try to calculate that decimal straight up, but I don't know the answer to that.
Try searching around google for a rational way to derive pi. I know that one exists.
The header and .cpp file look simple. I think the hardest part is knowing how to derive pi by the iteration of dividing 2 numbers.
|
|
|
|
|
|
|
quote
|
|
05-17-2004, 03:25 PM
|
#14
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
This looks like some hw to me!! Shouldnt it be your own work?
|
|
|
|
|
|
|
quote
|
|
05-18-2004, 03:12 PM
|
#15
|
|
Guest
Posts: n/a/0
Threads:
|
Re: This is an interesting section
I hate people who make other people do their homework. Especially on the forums!
|
|
|
|
|
|
|
quote
|
|
|