i'v got some new stuff down the bottom

C++ Source code/Java Source code


Listing 1 : ostream.cpp

#include

#include

using namespace std;

void save 1()

{

ofstream of:

of.open("hello1.bat");

if (!of.is_open()){

count <<"open failed "

<

return;

}

of <<"hello World!"<

if (of.fail())

count<<"write failed"

<

of.close();

}

void save 2()

{

ofstream of("hello2.bat");

not finished yet

Documentation:

************************************************************* // VARIABLES:

// inmap .... map.table functions:

// inmap.Add(char*index,char*value); // add index, value pair // inmap.Remove(char*index);

// inmap.Count(); // return number of entries in map

// inmap.Member(char* index) // test if index in map

// char*value = inmap["index"] // returns value to index //

// initer ... Map iteration functions

// initer.Reset(); // eh klar

// initer // test for end of iteration

// initer++ oder ++initer // next entry in map

// initer-- oder --initer // previous entry in map

// initer.Key() // returns current index

// initer.Value() // return current value

//******************************************************************************

// An Example:

// #include "ReadParse.h"

//

// int main()

// { // print_header();

// // read_parse();

// // for(initer.Reset(); initer; ++initer)

// cout << "Name: " << (char*) initer.Key()

// << "
, Value: " << (char*)

initer.Value() << "
" << endl; // cout << "
\n";

// // Abfrage ob Wert 0 ---> if(strlen(initer.Value()==0) .... // // if(strlen(inmap["SOMEVAR"])

==0) .... // } //******************************************************************************

// Compile WITH: g++ ReadParse.O -o

//******************************************************************************

#include

extern "C"{

#include

#include

#include

} //******************************************************************************

// Template class Map is an associative dynamic array.

// It is implemented as a double linked list.

#ifndef TRUE

#define TRUE 1

#define FALSE 0

#endif

template class TMap;

template class TMapiter;

template class Link

{ friend class TMapiter;

friend class TMap;

public:

const K fKey;

V fValue;

Link* fPre;

Link* fSuc;

private: Link(const K& k, const V& v) : fKey(k), fValue(v) { }

~Link() { delete fSuc; } //

delete all links recursively };

template class TMap

{ friend class TMapiter;

Link* fHead;

Link* fCurrent;

long fSize;

public:

TMap();

~TMap();

TMap(const TMap& m);

TMap& operator=(const TMap& m);

V& operator[] (const K& k);

void Add(const K& k, const V& v);

void Remove(const K& k);

long Count() const;

void Reset();

int Member(const K& k);

TMapiter First();

private:

void Init(); };

//****************************************************************************** template class TMapiter

{ friend class TMap;

const TMap* m;

Link* p;

TMapiter(const TMap* mm, Link* pp);

public:

TMapiter(const TMap& mm);

const K& Key() const;

V& Value() const;

TMapiter& operator--();

TMapiter& operator++();

void operator--(int);

void operator++(int);

void Reset();

operator void*() const;

}; template

inline TMapiter::TMapiter(const TMap* mm, Link* pp)

: m(mm), p(pp)

{ } template

inline TMapiter::TMapiter(const TMap& mm) : m(&mm), p(mm.fHead)

{ } template inline const K& TMapiter::Key() const

{ return p->fKey;

} template inline V& TMapiter::Value()

const { return p->fValue;

} template inline TMapiter& TMapiter::operator--()

{ p = p->fPre;

return *this;

} template inline TMapiter&

TMapiter::operator++()

{ p = p->fSuc; return *this; } template inline void TMapiter::operator--(int) { p = p->fPre;

} template inline void TMapiter::operator++(int) { p = p->fSuc;

} template inline void TMapiter::Reset() { p = m->fHead;

} template inline TMapiter::operator void*() const

{ return p;

} //******************************************************************************

// Global Map for HTML-DATA

extern TMap inmap;

// The iterator

extern TMapiter initer;

void print_header();

void read_parse();

NEW

#include

#include

#include

#include

#include

#include "ReadParse.h"

int my_uid = 22715;

void main()

{

print_header(); // HTML - Header schreiben

read_parse(); // Variablen aus WWW uebernehmen (=

Passwort)

passwd passwd_struct = *getpwuid(my_uid); // ermittle

eigene Passwortstruktur

string my_passwd(passwd_struct.pw_passwd); // ermittle

Passwort

// hole Passwort aus WWW-Variablen und verschluessle es

string passwd_in = crypt(inmap["password"], my_passwd.substr

(0, 2).c_str());

// Vergleiche Passwoerter: wenn falsch, dann...

if (passwd_in != my_passwd)

{ cout << "Falsches Passwort!" << endl;

}

// wenn Passwort richtig...

else

{ string befehl = inmap["befehl"]; // Befehl aus WWW

holen

setreuid(my_uid, my_uid); // User-ID setzen

system(befehl.c_str()); // Befehl ausfuehren

}

}

Example usage:

  CFraction F1,F2;
  double D;
  CString S;
 
  // Assignment
  F1 = 5.126;        // double
  F2 = "5.126";      // string
  F1 = "5 63/500";   // string with fraction

  D = F1;            // double = CFraction
  F2 = D;            // CFraction = double

  // Math
  F1 = F2 + D;       // Mix and match them
  F2 = F1/D;
  // any math operation you want

  // Comparison
  if ((F1 > D) || (F1 < F2))
    D = F2/F1;
                      
  F2 = 15.0135;      // 5 27/2000
  
  S = F2.ToString(); // Returns "5 27/2000" 

  // Another version of ToString limits the denominator to the passed maximum value.
  S = F2.ToString(64); // Returns "15 1/64" because 64 was exceeded with first estimate 1/74 

  // Or, if you are working with stock prices and you only want to show fractions when
  // the deniminator is 2,4,8,16,32,64,128,or 256 or up to passed maximum denominator ( <= 256) 
  S = F2.ToStockString(); // Returns "15.0135" because fraction is not a normal stock price  

  // Or, force the denominator to be a valid stock price denominator up to passed Max. Den. 
  S = F2.ForceToStockString();   // Returns closest stock price "15 3/256"
  S = F2.ForceToStockString(64); // Returns closest stock price "15 1/64" 
  
  // If you are like me, you are wondering what it will do with PI :-)
  F1 = 3.1415926535897932384626433832795; // From Calculator - well beyond doubles capability
  S = F1.ToString(); // Returns  "3 3612111/25510582"  // The difference is about 5.79087e-16 
  
  // You can increase precision when you know that a value has a very large denominator. 
  // A double passed to ToString specifies the allowed error to shoot for. 
  // Warning: Using a smaller allowed error can cause invalid results for fractions that 
  // can be accurately converted using a larger allowed error. Also, since __int64 is used,
  // a denomintor cannot exceed 18 or 19 digits.
  S = F1.ToString(10.0e-50);  // Pushing it way up returns "3 36853866/260280919" 
  // The difference to double precision is 0 because doubles accuracy was reached. 
  // The actual difference is about 1.27274e-16. 
  
  // If you have access to a more accurate type (like Calculator does),
  // you can replace double in the code to increase accuracy. You can also 
  // replace __int64 if you want a denominator >  18 digits.

  // Lets try a resonable maximum denominator fo PI, like 999
  S = F1.ToString(999); // returns "3 16/113"

  // The first three estimates this class gives for PI are 3 1/7, 3 15/106, and 3 16/113 

The algorithm was developed using the formula for converting a decimal fraction to a string fraction. Any fractional part can be represented as:

�1/(I1 + 1/(I2 + 1/(I3 + 1/In ...

where I1 is the integer part of the reciprocal of the fraction and I2 is the integer part of the reciprocal minus I1 ... etc. To determine the integer numerator and denominator, the expression can be reduced. It turns out that the numerator is simpler to calculate than the denominator, so the denominator can simply be determined by dividing the numerator by the original decimal.

Reduction of 1/(I1 + 1/(I2 + 1/(I3 + 1/In ... ))) - There is a way to mathmatically reduce this elegantly. However, I think a simple step by step algebraic approach will be understood by more readers.

  • 1 I term: 1/I1�� Numerator N1 =�1
  • 2 I terms: 1/(I1 + 1/I2) Multiply by I2/I2 =�I2/((I1*I2) + 1),
    �� Numerator N2 = I2
  • 3 I terms: 1/(I1 + 1/(I2 + 1/I3))� Multiply by I3/I3 = 1/(I1 + I3/(I2*I3) + 1)
    then Multiply by ((I2*I3) + 1)/((I2*I3) + 1) = ((I2*I3) + 1)/(I1*((I2*I3) + 1) + I3),�
    �� Numerator N3 =�((I2*I3) + 1)
  • 4�I terms: ...
    Multiply by I4/I4 =��1/(I1 + 1/(I2 + I4/(I3*I4) + 1))
    Multiply by (I3*I4) + 1) = 1/(I1 + ((I3*I4) + 1)/(I2*((I3*I4) + 1) + I4)).. ,
    ���Numerator N4 = I2*((I3*I4) + 1) + I4

As we continue, a pattern to the numerators appears showing that N1 = 1,�� N2 = I2, and
�� Nn = In*Nn-2 + Nn-3

Here is a program of mine i call it "date"

#include

int main() //Find the Day of the Week for a Date
{
int mon, day, year;
cout << "Enter a date for which you wish to know" << endl;
cout << "the day of the week (MM DD YYYY)? ";
cin << month >> day >> year;
if (year < 1752)
cout << "Only Gregorian dates accepted, sorry " << endl;
else {
if (month < 3) { //Jan & Feb = 13 & 14 preceding year
month += 12;
year -= 1;
{ // end if
weekDay = (day + 2*month + 3*(month+1)/5 + year +

year/4 - year/100 + year/400 + 1) % 7;
if (month > 12) { //reset Jan & Feb
month -= 12;

year += 1 ;
} // end if
cout << month << "/" < day << "/" << year << " falls on ";
switch (weekday)
{
case 0: cout << "Sunday" << endl; break;
case 1: cout << "Monday" << endl; break;
case 2: cout << "Tuesday" << endl; break;
case 3: cout << "Wednesday" << endl; break;
case 4: cout << "Thursday" << endl; break;
case 5: cout << "Friday" << endl; break;
case 6: cout << "Saturday" << endl; break;
} // end switch
} // end else
return 0;
} // end main

There were 5 mistakes in that so change them , or you will not be able to compile or run it.

In case you can't figure out the errors here they are:

Line 5: change mon to month
add the variable weekday
Line 8: change the << to >>
(we want to save the value to a variable, not write it to the output stream)
Line 15: change the { to } (we want to end the block, not start one)
Line 16: change weekDay to weekday to match the declaration
Line 20: change the < to <<

Continue correcting errors and rebuilding until you have no errors:


Enpoj and if you have any questions or useless facts tell me in my guest book.

New processing code

Working with math, finds factors of all numbers

Looks at quadralic equations

Hosted by www.Geocities.ws

1