Treceți la conținutul principal

fisiere cpp

// tema.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "tema.h"
#include "windows.h"

//Fisier::Fisier()
//{
//}

Fisier::Fisier(char* FileName)
{
 if (FileName!=NULL)
 {
 pf=fopen(FileName,"w+b");
 fseek(pf,0,SEEK_END);
 FileSize=ftell(pf);
 fseek(pf,0,SEEK_SET);

 if (FileSize>0) {IsEOF=false;}
 else {IsEOF=true;};
 }
 else MessageBox(NULL,"Pointer to file is null",NULL,1);
}

Fisier::~Fisier()
{
 if (pf!=NULL) fclose(pf);
}

int & Fisier::operator [](int pozitie)
{
 fseek(pf,pozitie*4,SEEK_SET);
 int articol;
 fread(&articol,4,1,pf);
 int CurrentPosition=ftell(pf);
 if (CurrentPosition<FileSize) {IsEOF=false;}
 else {IsEOF=true;};

 return articol;
}

bool Fisier::TestEOF()
{
 int CurrentPosition=ftell(pf);
 if (CurrentPosition<FileSize) {return false;}
 else {return true;};
}

Pozitie::Pozitie(Fisier* MyObject)
{
pf=MyObject;
}

void Pozitie::operator =(int a)
{
if (pf->pf!=NULL) fwrite(&a,4,1,pf->pf);
}

Pozitie::operator int*()
{
 int a;
 if (pf->IsEOF==false)
 {
 return &pf[0][1];
 }
 else return 0;
}

int main(int argc, char* argv[])
{
 Fisier* ob1=new Fisier("test.dat");
 Pozitie ob2(ob1);
 int valoare;

do
{
 printf("%s","Dati o noua valoare pana dati valoarea 0: ");
 scanf("%i",&valoare);
 if (valoare==0) break;
 ob2=valoare;
} while (true);

do
{
 printf("%s","Introduceti pozitia pentru inregistrarea din fisier pana introduceti -1  : ");
 scanf("%d",&valoare);
 if (valoare==-1) break;
 printf ("Valoarea este %d\n",ob2.pf[0][valoare]);
} while (true);

 return 0;
}





// tema.h

#include "stdafx.h"
#include "stdio.h"

class Fisier
{
 public:
  Fisier(char* FileName);
  ~Fisier();
  int & operator[](int pozitie);
  bool IsEOF;
  bool TestEOF();
 public:
  FILE* pf;
  long FileSize;
};

class Pozitie
{
public :
 Pozitie(Fisier* MyObject);
 void operator=(int a);
 operator int*();
public :
 Fisier* pf;
};

Comentarii

Postări populare de pe acest blog

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…